Skip to content

Commit

Permalink
some more work with user's locale and time zone
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Apr 10, 2016
1 parent b069f4c commit 6831743
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
Expand Up @@ -20,6 +20,7 @@

import com.evolveum.midpoint.web.security.MidPointApplication;
import org.apache.commons.lang.LocaleUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;

import com.evolveum.midpoint.gui.api.page.PageBase;
Expand Down Expand Up @@ -50,6 +51,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.WebSession;

/**
* Utility class that contains methods that interact with ModelService and other
Expand Down Expand Up @@ -357,6 +359,10 @@ public static String getLoggedInUserOid() {
return principal.getOid();
}

public static Locale getLocale() {
return getLocale(null);
}

public static Locale getLocale(UserType user) {
MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
Locale locale = null;
Expand Down Expand Up @@ -390,10 +396,38 @@ public static Locale getLocale(UserType user) {
//default locale for web application
return MidPointApplication.getDefaultLocale();
}
return locale;
}
}
}
return null;
}

public static TimeZone getTimezone() {
return getTimezone(null);
}

public static TimeZone getTimezone(UserType user) {
MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
if (principal != null && user == null) {
user = principal.getUser();
}
String timeZone;

if (user != null && StringUtils.isNotEmpty(user.getTimezone())) {
timeZone = user.getTimezone();
} else {
timeZone = principal != null && principal.getAdminGuiConfiguration() != null ?
principal.getAdminGuiConfiguration().getDefaultTimezone() : "";
}
try {
if (timeZone != null) {
return TimeZone.getTimeZone(timeZone);
}
} catch (Exception ex){
LOGGER.debug("Error occurred while getting user time zone, " + ex.getMessage());
}
return null;
}

}
Expand Up @@ -99,6 +99,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.apache.wicket.protocol.http.WebSession;

public abstract class PageAdminFocus<F extends FocusType> extends PageAdminObjectDetails<F>
implements ProgressReportingAwarePage {
Expand Down Expand Up @@ -194,6 +195,9 @@ public void finishProcessing(AjaxRequestTarget target, OperationResult result) {
}
Session.get().setLocale(WebModelServiceUtils.getLocale(user));
LOGGER.debug("Using {} as locale", getLocale());
WebSession.get().getClientInfo().getProperties().
setTimeZone(WebModelServiceUtils.getTimezone(user));
LOGGER.debug("Using {} as time zone", WebSession.get().getClientInfo().getProperties().getTimeZone());
}
boolean userAdded = getDelta() != null && getDelta().isAdd() && StringUtils.isNotEmpty(getDelta().getOid());
if (!isKeepDisplayingResults() && getProgressReporter().isAllSuccess()
Expand Down
Expand Up @@ -171,22 +171,13 @@ private void setClientCustomization(){
MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
if (principal != null) {
//setting locale
setLocale(WebModelServiceUtils.getLocale(null));
setLocale(WebModelServiceUtils.getLocale());
LOGGER.debug("Using {} as locale", getLocale());

PrismObject<UserType> user = principal.getUser().asPrismObject();
//set time zone
String timeZone;
if (user != null && user.asObjectable().getTimezone() != null) {
timeZone = user.asObjectable().getTimezone();
} else {
timeZone = principal.getAdminGuiConfiguration().getDefaultTimezone();
}
if (timeZone != null) {
WebSession.get().getClientInfo().getProperties().
setTimeZone(TimeZone.getTimeZone(timeZone));
LOGGER.debug("Using {} as time zone", timeZone);
}
WebSession.get().getClientInfo().getProperties().
setTimeZone(WebModelServiceUtils.getTimezone());
LOGGER.debug("Using {} as time zone", WebSession.get().getClientInfo().getProperties().getTimeZone());
}
}
}

0 comments on commit 6831743

Please sign in to comment.