Skip to content

Commit

Permalink
use UserSession.getData() instead of data field
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Dec 13, 2017
1 parent 2c55c16 commit 2d2b0e9
Showing 1 changed file with 42 additions and 28 deletions.
70 changes: 42 additions & 28 deletions src/main/java/de/metas/ui/web/session/UserSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,22 @@ public static boolean isWebuiThread()
private static UserSession _staticUserSession = null;

@Autowired
private InternalUserSessionData data; // session scoped
private InternalUserSessionData _data; // session scoped

@Autowired
public UserSession(final ApplicationEventPublisher eventPublisher)
{
this.eventPublisher = eventPublisher;
}

private InternalUserSessionData getData()
{
return _data;
}

public String getSessionId()
{
return data.getSessionId();
return getData().getSessionId();
}

/**
Expand All @@ -167,26 +172,27 @@ public String getSessionId()
*/
Properties getCtx()
{
return data.getCtx();
return getData().getCtx();
}

public Evaluatee toEvaluatee()
{
return Evaluatees.ofCtx(data.getCtx());
return Evaluatees.ofCtx(getData().getCtx());
}

public UserPreference getUserPreference()
{
return data.getUserPreference();
return getData().getUserPreference();
}

public boolean isLoggedIn()
{
return data.isLoggedIn();
return getData().isLoggedIn();
}

public void setLoggedIn(final boolean loggedIn)
{
final InternalUserSessionData data = getData();
final boolean currentlyLoggedIn = data.isLoggedIn();
if (currentlyLoggedIn == loggedIn)
{
Expand All @@ -209,7 +215,7 @@ public void setLoggedIn(final boolean loggedIn)

public void assertLoggedIn()
{
if (!data.isLoggedIn())
if (!getData().isLoggedIn())
{
throw new NotLoggedInException();
}
Expand All @@ -219,7 +225,7 @@ public void assertLoggedInAsSysAdmin()
{
assertLoggedIn();

final int adRoleId = data.getAD_Role_ID();
final int adRoleId = getData().getAD_Role_ID();
if (adRoleId != IUserRolePermissions.SYSTEM_ROLE_ID)
{
throw new NotLoggedInAsSysAdminException();
Expand All @@ -228,7 +234,7 @@ public void assertLoggedInAsSysAdmin()

public void assertNotLoggedIn()
{
if (data.isLoggedIn())
if (getData().isLoggedIn())
{
throw new AlreadyLoggedInException();
}
Expand All @@ -246,6 +252,7 @@ String setAD_Language(final String adLanguage)
{
Check.assumeNotEmpty(adLanguage, "adLanguage is not empty");
final Language lang = Language.getLanguage(adLanguage);
final InternalUserSessionData data = getData();
final String adLanguageOld = data.verifyLanguageAndSet(lang);
final String adLanguageNew = data.getAdLanguage();
logger.info("Changed AD_Language: {} -> {}, {}", adLanguageOld, adLanguageNew, lang);
Expand All @@ -261,22 +268,22 @@ String setAD_Language(final String adLanguage)

public int getAD_Client_ID()
{
return data.getAD_Client_ID();
return getData().getAD_Client_ID();
}

public int getAD_Org_ID()
{
return data.getAD_Org_ID();
return getData().getAD_Org_ID();
}

public String getAD_Language()
{
return data.getAdLanguage();
return getData().getAdLanguage();
}

public Language getLanguage()
{
return data.getLanguage();
return getData().getLanguage();
}

public JSONLookupValue getLanguageAsJson()
Expand All @@ -287,7 +294,7 @@ public JSONLookupValue getLanguageAsJson()

public Locale getLocale()
{
return data.getLocale();
return getData().getLocale();
}

public UserSessionLocale getUserSessionLocale()
Expand All @@ -297,73 +304,77 @@ public UserSessionLocale getUserSessionLocale()

public boolean isUseHttpAcceptLanguage()
{
return data.isUseHttpAcceptLanguage();
return getData().isUseHttpAcceptLanguage();
}

public void setUseHttpAcceptLanguage(final boolean useHttpAcceptLanguage)
{
final InternalUserSessionData data = getData();
final boolean useHttpAcceptLanguageOld = data.isUseHttpAcceptLanguage();
data.setUseHttpAcceptLanguage(useHttpAcceptLanguage);
logSettingChanged("UseHttpAcceptLanguage", useHttpAcceptLanguage, useHttpAcceptLanguageOld);
}

public int getAD_User_ID()
{
return data.getAD_User_ID();
return getData().getAD_User_ID();
}

public String getUserName()
{
return data.getUserName();
return getData().getUserName();
}

public String getRoleName()
{
return data.getRoleName();
return getData().getRoleName();
}

public UserRolePermissionsKey getUserRolePermissionsKey()
{
// TODO: cache the permissions key
return UserRolePermissionsKey.of(data.getCtx());
return UserRolePermissionsKey.of(getData().getCtx());
}

public IUserRolePermissions getUserRolePermissions()
{
return Env.getUserRolePermissions(data.getCtx());
return Env.getUserRolePermissions(getData().getCtx());
}

public String getAvatarId()
{
return data.getAvatarId();
return getData().getAvatarId();
}

public String getUserEmail()
{
return data.getUserEmail();
return getData().getUserEmail();
}

public String getUserFullname()
{
return data.getUserFullname();
return getData().getUserFullname();
}

String setAvatarId(final String avatarId)
{
final InternalUserSessionData data = getData();
final String avatarIdOld = data.getAvatarId();
data.setAvatarId(avatarId);
return avatarIdOld;
}

String setUserEmail(final String userEmail)
{
final InternalUserSessionData data = getData();
final String userEmailOld = data.getUserEmail();
data.setUserEmail(userEmail);
return userEmailOld;
}

String setUserFullname(final String userFullname)
{
final InternalUserSessionData data = getData();
final String userFullnameOld = data.getUserFullname();
data.setUserFullname(userFullname);
return userFullnameOld;
Expand All @@ -377,7 +388,7 @@ public String getWebsocketEndpoint()

public void assertDeprecatedRestAPIAllowed()
{
if (!data.isAllowDeprecatedRestAPI())
if (!getData().isAllowDeprecatedRestAPI())
{
throw new DeprecatedRestAPINotAllowedException();
}
Expand All @@ -392,38 +403,41 @@ private static final void logSettingChanged(final String name, final Object valu

public boolean isAllowDeprecatedRestAPI()
{
return data.isAllowDeprecatedRestAPI();
return getData().isAllowDeprecatedRestAPI();
}

public void setAllowDeprecatedRestAPI(final boolean allowDeprecatedRestAPI)
{
final InternalUserSessionData data = getData();
final boolean allowDeprecatedRestAPIOld = data.isAllowDeprecatedRestAPI();
data.setAllowDeprecatedRestAPI(allowDeprecatedRestAPI);
logSettingChanged("AllowDeprecatedRestAPI", allowDeprecatedRestAPI, allowDeprecatedRestAPIOld);
}

public boolean isShowColumnNamesForCaption()
{
return data.isShowColumnNamesForCaption();
return getData().isShowColumnNamesForCaption();
}

public void setShowColumnNamesForCaption(final boolean showColumnNamesForCaption)
{
final InternalUserSessionData data = getData();
final boolean showColumnNamesForCaptionOld = data.isShowColumnNamesForCaption();
data.setShowColumnNamesForCaption(showColumnNamesForCaption);
logSettingChanged("ShowColumnNamesForCaption", showColumnNamesForCaption, showColumnNamesForCaptionOld);
}

public void setHttpCacheMaxAge(final int httpCacheMaxAge)
{
final InternalUserSessionData data = getData();
final int httpCacheMaxAgeOld = data.getHttpCacheMaxAge();
data.setHttpCacheMaxAge(httpCacheMaxAge);
logSettingChanged("HttpCacheMaxAge", httpCacheMaxAge, httpCacheMaxAgeOld);
}

public int getHttpCacheMaxAge()
{
return data.getHttpCacheMaxAge();
return getData().getHttpCacheMaxAge();
}

/**
Expand Down

0 comments on commit 2d2b0e9

Please sign in to comment.