Context ctx = req.getContext();
if (ctx != null)
{
UserEnvironment userEnv = null;
try
{
userEnv = (UserEnvironment) ctx.get(UserEnvironment.CONTEXT_KEY);
}
catch (ContextException x)
{
}
try
{
if (userEnv != null && userEnv.getUid() != UserEnvironment.ANONYMOUS_UID)
{
if (userEnv.getAttribute("sessionInfoLoaded") == null
|| "N".equals(userEnv.getAttribute("sessionInfoLoaded")))
{
try
{
PersistentFactory persistentManager = (PersistentFactory) req.getService(
PersistentFactory.ROLE, req.getDomain());
Persistent preferences = persistentManager.create("aktera.Preferences");
preferences.setField("userId", new Integer(userEnv.getUid()));
preferences.find();
userEnv.setAttribute("sessionPreferences", preferences.getBean());
Persistent party = persistentManager.create("aktera.Party");
party.setField("userId", new Integer(userEnv.getUid()));
if (party.find())
{
Persistent address = persistentManager.create("aktera.Address");
address.setField("partyId", party.getField("partyId"));
if (address.find())
{
String firstName = address.getFieldString("firstName");
String lastName = address.getFieldString("lastName");
String displayName = (firstName != null ? firstName + " " : "") + lastName;
userEnv.setAttribute("sessionDisplayName", displayName);
userEnv.setAttribute("sessionFirstName", firstName != null ? firstName : "");
userEnv.setAttribute("sessionLastName", lastName != null ? lastName : "");
Locale locale = (Locale) languages.get(preferences.getFieldString("language"));
userEnv.setAttribute("sessionLanguage", locale != null ? locale : Locale.GERMAN);
userEnv.setAttribute(I18N.USER_CONTEXT_LOCALE_KEY, locale != null ? locale
: Locale.GERMAN);
userEnv.setAttribute("sessionInfoLoaded", "Y");
}
}
}
catch (PersistenceException x)
{
throw new ModelException(x);
}
}
res.addOutput("sessionDisplayName", (String) userEnv.getAttribute("sessionDisplayName"));
res.addOutput("sessionFirstName", (String) userEnv.getAttribute("sessionFirstName"));
res.addOutput("sessionLastName", (String) userEnv.getAttribute("sessionLastName"));
res.addOutput("sessionLoginName", (String) userEnv.getLoginName());
Output lang = res.createOutput("sessionLanguage");
lang.setContent(userEnv.getAttribute("sessionLanguage"));
res.add(lang);
}
else
{
Output lang = res.createOutput("sessionLanguage");