001: package ru.emdev.EmForge.security;
002:
003: import org.emforge.projectmanager.base.ProjectDO;
004:
005: import ru.emdev.EmForge.security.dao.UserSettings;
006: import ru.emdev.EmForge.security.dao.UserSettingsDao;
007:
008: /**
009: * User Settings Service bean used for processing current user's settings
010: */
011: public class UserSettingsService {
012:
013: protected UserSettingsDao m_userSettingsDao;
014: protected UserFactory m_userFactory;
015:
016: /**
017: * @param io_userSettingsDao
018: */
019: public void setUserSettingsDao(UserSettingsDao io_userSettingsDao) {
020:
021: m_userSettingsDao = io_userSettingsDao;
022: }
023:
024: /**
025: * @param io_userService
026: */
027: public void setUserFactory(UserFactory io_userService) {
028:
029: m_userFactory = io_userService;
030: }
031:
032: /**
033: * @return User factory
034: */
035: public UserFactory getUserFactory() {
036:
037: return m_userFactory;
038: }
039:
040: /**
041: * Retrieves the current user
042: *
043: * @return the current user
044: */
045: public EmForgeUserDetails getCurrentUser() {
046:
047: return m_userFactory.getCurrentUser();
048: }
049:
050: /**
051: * @return
052: */
053: public ProjectDO getDefaultProject() {
054:
055: EmForgeUserDetails currentUser = getCurrentUser();
056: if (currentUser == null) {
057: return null;
058: } else {
059: UserSettings userSettings = m_userSettingsDao
060: .getUserSettings(currentUser.getUsername());
061:
062: return userSettings.getDefaultProject();
063: }
064: }
065:
066: /**
067: * @param i_project
068: */
069: public void setDefaultProject(ProjectDO i_project) {
070:
071: EmForgeUserDetails currentUser = getCurrentUser();
072:
073: // do not change settings for anonymous user
074: if (!currentUser.isAnonymous()) {
075: UserSettings userSettings = m_userSettingsDao
076: .getUserSettings(currentUser.getUsername());
077: userSettings.setDefaultProject((ProjectDO) i_project);
078: m_userSettingsDao.saveUserSettings(userSettings);
079: }
080: }
081:
082: /**
083: * @return
084: */
085: public Integer getNumberOfRows() {
086:
087: EmForgeUserDetails currentUser = getCurrentUser();
088: UserSettings userSettings = m_userSettingsDao
089: .getUserSettings(currentUser.getUsername());
090:
091: if (userSettings.getNumRows() == null) {
092: return 20;
093: } else {
094: return userSettings.getNumRows();
095: }
096: }
097:
098: /**
099: * @return
100: */
101: public boolean isUseTaskToolTip() {
102:
103: EmForgeUserDetails currentUser = getCurrentUser();
104: UserSettings userSettings = m_userSettingsDao
105: .getUserSettings(currentUser.getUsername());
106:
107: if (userSettings.getUseTaskToolTip() == null) {
108: return false;
109: } else {
110: return userSettings.getUseTaskToolTip();
111: }
112: }
113: }
|