blob: 4d0dd58fbfb4db12b071c5f60978fbda01b9db62 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.user;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import org.eclipse.e4.core.di.extensions.EventUtils;
import org.eclipse.e4.core.services.translation.TranslationService;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.osbp.ui.api.user.IUser;
import org.eclipse.osbp.ui.api.useraccess.IUserAccessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class User represents the subject currently signed in and carries his
* data. User can be injected. It conforms the vaaclipse AuthenticationProvider
* mechanism.
*/
public class User extends Hashtable<String, Object> implements IUser {
/** The application. */
private transient MApplication application;
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The id. */
private String id;
/** The user name. */
private String userName;
/** The position. */
private String position;
/** The perspective. */
private String perspective;
/** The extra password. */
private String extraPassword;
/** The supervisor. */
private boolean supervisor;
/** The email. */
private String email;
/** The roles. */
private Collection<String> roles;
/** The locale. */
private Locale locale;
/** The layouting strategy. */
private String layoutingStrategy;
/** The focusing strategy. */
private String focusingStrategy;
/** The theme. */
private String theme;
/** The print service. */
private String printService;
/** The Constant LOGGER. */
private static final Logger LOGGER = LoggerFactory.getLogger(User.class);
/** The listeners. */
private transient List<UserLocaleListener> listeners;
/** The profile image id. */
private String profileImageId;
/**
* Instantiates a new user.
*
* @param userName
* the user name
*/
/**
* @param userName
* the user name
*/
public User(String userName) {
super();
this.userName = userName;
if (UserBinder.getUserAccessService() != null) {
profileImageId = UserBinder.getUserAccessService().getProfileimageId();
position = UserBinder.getUserAccessService().getPositionName();
perspective = UserBinder.getUserAccessService().getPerspective();
extraPassword = UserBinder.getUserAccessService().getExtraPassword();
supervisor = UserBinder.getUserAccessService().isSupervisor();
email = UserBinder.getUserAccessService().getEmail();
roles = UserBinder.getUserAccessService().getRoles();
id = UserBinder.getUserAccessService().getId();
layoutingStrategy = UserBinder.getUserAccessService().getLayoutingStrategy();
focusingStrategy = UserBinder.getUserAccessService().getFocusingStrategy();
theme = UserBinder.getUserAccessService().getTheme();
printService = UserBinder.getUserAccessService().getPrintService();
if (UserBinder.getUserAccessService().getLocaleTag() != null) {
locale = Locale.forLanguageTag(UserBinder.getUserAccessService().getLocaleTag());
} else {
locale = Locale.forLanguageTag("en-US");
}
} else {
locale = Locale.forLanguageTag("en-US");
}
put(EventUtils.DATA, this);
put(userClass, IUser.class);
LOGGER.debug("User is initialized");
}
/**
* Gets the layouting strategy.
*
* @return the layouting strategy
*/
public String getLayoutingStrategy() {
return layoutingStrategy;
}
/**
* Gets the focusing strategy.
*
* @return the focusing strategy
*/
public String getFocusingStrategy() {
return focusingStrategy;
}
/**
* Gets the theme.
*
* @return the theme
*/
public String getTheme() {
return theme;
}
/**
* Gets the print service.
*
* @return the print service
*/
public String getPrintService() {
return printService;
}
/**
* Sets the print service.
*
* @param printService
* the new print service
*/
public void setPrintService(String printService) {
this.printService = printService;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.osbp.vaaclipse.publicapi.authentication.IUser#getUserName()
*/
public String getUserName() {
return userName;
}
/**
* Sets the user name.
*
* @param userName
* the new user name
*/
public void setUserName(String userName) {
this.userName = userName;
}
public String getProfileImageId() {
return profileImageId;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Gets the position.
*
* @return the position
*/
public String getPosition() {
return position;
}
/**
* Gets the extra password.
*
* @return the extra password
*/
public String getExtraPassword() {
return extraPassword;
}
/**
* Gets the supervisor.
*
* @return the supervisor
*/
public boolean isSupervisor() {
return supervisor;
}
/**
* Gets the perspective id.
*
* @return the perspective id
*/
public String getPerspective() {
return perspective;
}
/**
* Gets the email.
*
* @return the email
*/
public String getEmail() {
return email;
}
/**
* Gets the roles.
*
* @return the roles
*/
public Collection<String> getRoles() {
return roles;
}
/**
* Gets the locale.
*
* @return the locale
*/
public Locale getLocale() {
return locale;
}
/**
* Sets the locale.
*
* @param locale
* the new locale
*/
public void setLocale(Locale locale) {
this.locale = locale;
// force e4 application to switch locale and update localization
if (application != null) {
application.getContext().set(TranslationService.LOCALE, locale);
ApplicationLocalization.updateLocalization(application);
}
Locale.setDefault(locale);
notifyUserLocaleChanged(locale);
}
/**
* Gets the user access service.
*
* @return the user access service
*/
public IUserAccessService getUserAccessService() {
return UserBinder.getUserAccessService();
}
@Override
public void addUserLocaleListener(UserLocaleListener listener) {
if (listeners == null) {
listeners = new ArrayList<>();
}
if (!listeners.contains(listener)) {
listeners.add(listener);
if (locale != null) {
listener.localeChanged(locale);
}
}
}
@Override
public void removeUserLocaleListener(UserLocaleListener listener) {
if (listeners == null) {
return;
}
listeners.remove(listener);
}
@Override
public void notifyUserLocaleChanged(Locale locale) {
if (listeners == null) {
return;
}
for (UserLocaleListener listener : listeners.toArray(new UserLocaleListener[listeners.size()])) {
listener.localeChanged(locale);
}
}
@Override
public void setApplication(MApplication application) {
this.application = application;
setLocale(locale);
}
}