Search in sources :

Example 1 with Setting

use of com.autentia.tnt.businessobject.Setting in project TNTConcept by autentia.

the class ActivityBean method doAfterSave.

@Override
public String doAfterSave(String result) {
    /* If user is editing an Activity... */
    if (activity != null) {
        Setting val = settings.get(SettingPath.BITACORE_LAST_BILLABLE, true);
        SettingManager.setValue(val, activity.isBillable());
        settings.save(val);
        val = settings.get(SettingPath.BITACORE_LAST_ROLEID, true);
        SettingManager.setValue(val, activity.getRole().getId());
        settings.save(val);
    }
    return super.doAfterSave(result);
}
Also used : Setting(com.autentia.tnt.businessobject.Setting)

Example 2 with Setting

use of com.autentia.tnt.businessobject.Setting in project TNTConcept by autentia.

the class ActivityBean method create.

/**
 * Go to create page
 *
 * @return forward to CREATE page
 */
public String create() {
    activity = new Activity();
    externalActivity = new ExternalActivity();
    selectedOrganization = null;
    selectedProject = null;
    organizations.clear();
    projects.clear();
    cal.setTime(scheduleModel.getSelectedDate());
    if (scheduleModel.getMode() == ScheduleModel.MONTH || scheduleModel.getMode() == ScheduleModel.WEEK) {
        cal.set(Calendar.HOUR_OF_DAY, ((SettingBean) FacesUtils.getBean("settingBean")).getMySettings().getWorkingDayHourStarts());
    }
    activity.setStartDate(cal.getTime());
    activity.setDescription(FacesUtils.getMessage("activity.description"));
    activity.setUser(authManager.getCurrentPrincipal().getUser());
    externalActivity.setStartDate(cal.getTime());
    // it is going to end in the same day
    externalActivity.setEndDate(cal.getTime());
    externalActivity.setComments(FacesUtils.getMessage("offer.observations"));
    externalActivity.setOwnerId(authManager.getCurrentPrincipal().getUser().getId());
    externalActivity.setDepartmentId(authManager.getCurrentPrincipal().getUser().getDepartmentId());
    DocumentCategory padre = dcManager.getDocumentCategoryParent();
    // User category
    DocumentCategory extActDocCategory = new DocumentCategory();
    extActDocCategory.setName(externalActivity.getName());
    extActDocCategory.setDescription(externalActivity.getName());
    extActDocCategory.setPadre(padre);
    externalActivity.setDocumentCategory(extActDocCategory);
    // Preselect last selected options
    Setting val = settings.get(SettingPath.BITACORE_LAST_ROLEID, false);
    int projectRoleId = SettingManager.getInt(val, -1);
    Project pr = null;
    if (projectRoleId != -1) {
        ProjectRole projectRole;
        try {
            projectRole = projectRoleMgr.getEntityById(projectRoleId);
            if (!projectRole.getProject().isFinished()) {
                setRole(projectRole);
                setSelectedProject(projectRole.getProject());
                setSelectedOrganization(getSelectedProject().getClient());
                pr = projectRole.getProject();
            }
        } catch (ObjectNotFoundException onfex) {
        // Caso especial. Si no se localiza el anterior rol, continuamos con la
        // ejecucion.
        }
    }
    if (pr != null) {
        setBillable(pr.getBillable());
        setDefaultBillable(pr.getBillable());
    } else {
        val = settings.get(SettingPath.BITACORE_LAST_BILLABLE, false);
        setBillable(SettingManager.getBoolean(val, false));
    }
    if (scheduleModel.getMode() == ScheduleModel.MONTH || scheduleModel.getMode() == ScheduleModel.WEEK) {
        ActivitySearch searchToday = new ActivitySearch();
        ExternalActivitySearch extActivitySearchToday = new ExternalActivitySearch();
        Calendar initToday = Calendar.getInstance();
        initToday.setTime(DateUtils.minHourInDate(scheduleModel.getSelectedDate()));
        Calendar lastToday = Calendar.getInstance();
        lastToday.setTime(DateUtils.maxHourInDate(scheduleModel.getSelectedDate()));
        searchToday.setStartStartDate(initToday.getTime());
        searchToday.setEndStartDate(lastToday.getTime());
        extActivitySearchToday.setStartStartDate(initToday.getTime());
        extActivitySearchToday.setEndStartDate(lastToday.getTime());
        // Try to obtain the last hour in day.
        searchToday.setUser(authManager.getCurrentPrincipal().getUser());
        extActivitySearchToday.setOwner(authManager.getCurrentPrincipal().getUser());
        List<Activity> activities = manager.getAllEntities(searchToday, new SortCriteria(sortColumn, sortAscending));
        List<ExternalActivity> extActivities = externalActivityManager.getAllEntities(extActivitySearchToday, new SortCriteria(sortColumn, sortAscending));
        if (activities.size() > 0 && extActivities.size() <= 0) {
            // No externalActivities
            // sort is descendent
            Collections.sort(activities, new compareActivitiesByStartAndDuration());
            activity.setStartDate(activities.get(0).getEndDate());
            externalActivity.setStartDate(activities.get(0).getEndDate());
            externalActivity.setEndDate(activities.get(0).getEndDate());
        } else if (activities.size() <= 0 && extActivities.size() > 0) {
            // No activities
            Collections.sort(extActivities, new compareExternalActivitiesActivitiesByStartAndDuration());
            activity.setStartDate(extActivities.get(0).getEndDate());
            externalActivity.setStartDate(extActivities.get(0).getEndDate());
            externalActivity.setEndDate(extActivities.get(0).getEndDate());
        } else if (activities.size() > 0 && extActivities.size() > 0) {
            Collections.sort(activities, new compareActivitiesByStartAndDuration());
            Collections.sort(extActivities, new compareExternalActivitiesActivitiesByStartAndDuration());
            Date lastActivityEndDate = activities.get(0).getEndDate();
            Date lastExtActivityEndDate = extActivities.get(0).getEndDate();
            Date startDate = (lastActivityEndDate.compareTo(lastExtActivityEndDate) > 0) ? lastActivityEndDate : lastExtActivityEndDate;
            activity.setStartDate(startDate);
            externalActivity.setStartDate(startDate);
            externalActivity.setEndDate(startDate);
        }
    }
    tabsRendered = NO_EDIT_SELECTED;
    return NavigationResults.CREATE;
}
Also used : ExternalActivitySearch(com.autentia.tnt.dao.search.ExternalActivitySearch) Setting(com.autentia.tnt.businessobject.Setting) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) Activity(com.autentia.tnt.businessobject.Activity) ExternalActivity(com.autentia.tnt.businessobject.ExternalActivity) ProjectRole(com.autentia.tnt.businessobject.ProjectRole) DocumentCategory(com.autentia.tnt.businessobject.DocumentCategory) Date(java.util.Date) LocalDate(java.time.LocalDate) ExternalActivity(com.autentia.tnt.businessobject.ExternalActivity) SortCriteria(com.autentia.tnt.dao.SortCriteria) Project(com.autentia.tnt.businessobject.Project) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) SettingBean(com.autentia.tnt.bean.admin.SettingBean) ExternalActivitySearch(com.autentia.tnt.dao.search.ExternalActivitySearch) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch)

Example 3 with Setting

use of com.autentia.tnt.businessobject.Setting in project TNTConcept by autentia.

the class SettingManager method get.

/**
 * Get a property's persistent object
 *
 * @param propertyPath
 *            property path
 * @param returnNewIfNotExists
 *            return a newly created object if it does not exist (null
 *            otherwise)
 * @return the Setting object which stores the property in database (if it
 *         exists) or a new Setting or null
 *
 *         Paco changed the visibility of this method... (ask him why)
 */
public Setting get(String propertyPath, boolean returnNewIfNotExists) {
    SettingSearch s = new SettingSearch();
    s.setName(propertyPath);
    s.setOwnerId(AuthenticationManager.getDefault().getCurrentPrincipal().getUser().getId());
    List<Setting> vals = settingDAO.search(s, null);
    if (vals.size() > 0) {
        return vals.get(0);
    } else if (returnNewIfNotExists) {
        Setting val = new Setting();
        val.setName(propertyPath);
        return val;
    } else {
        return null;
    }
}
Also used : SettingSearch(com.autentia.tnt.dao.search.SettingSearch) Setting(com.autentia.tnt.businessobject.Setting)

Example 4 with Setting

use of com.autentia.tnt.businessobject.Setting in project TNTConcept by autentia.

the class AuthenticationManager method loadUserByUsername.

/**
 * Load a User for ACEGI given its user name
 *
 * @param username user name
 * @throws org.acegisecurity.userdetails.UsernameNotFoundException
 * @throws org.springframework.dao.DataAccessException
 * @return the user object description as specified by ACEGI
 */
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    try {
        Version db = Version.getDatabaseVersion();
        Version code = Version.getApplicationVersion();
        if (db.compareTo(code, Version.MINOR) == 0) {
            log.info("loadUserByUsername - getting user " + username + " using Hibernate");
            User user = userDAO.searchByLogin(username);
            GrantedAuthority[] auths = userRolesService.getAuthorities(user);
            if (log.isDebugEnabled()) {
                StringBuilder sb = new StringBuilder();
                for (GrantedAuthority auth : auths) {
                    sb.append(auth);
                    sb.append(" ");
                }
                log.debug("loadUserByUsername - user roles: " + sb);
            }
            final Principal principal = new Principal(user, auths);
            // setting user preferred Locale
            final SettingSearch s = new SettingSearch();
            s.setName(SettingPath.GENERAL_PREFERRED_LOCALE);
            s.setOwnerId(user.getId());
            final List<Setting> vals = settings.search(s, null);
            final Setting val = (vals != null && vals.size() > 0) ? vals.get(0) : null;
            if (val != null) {
                final Locale local = new Locale(val.getValue());
                principal.setLocale(local);
            }
            return principal;
        } else {
            log.info("loadUserByUsername - getting user " + username + " using JDBC");
            return jdbcSearchByLogin(username);
        }
    } catch (SecException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new DataRetrievalFailureException("Error getting roles for user: " + username, e);
    } catch (DataIntegrityException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new DataIntegrityViolationException("Inconsistent user name: " + username, e);
    } catch (DataNotFoundException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new UsernameNotFoundException("User not found: " + username, e);
    } catch (DataAccException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new DataRetrievalFailureException("Error getting user: " + username, e);
    } catch (SQLException e) {
        log.warn("loadUserByUsername - exception", e);
        throw new DataRetrievalFailureException("Error getting user: " + username, e);
    }
}
Also used : Locale(java.util.Locale) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) DataNotFoundException(com.autentia.tnt.dao.DataNotFoundException) User(com.autentia.tnt.businessobject.User) DataAccException(com.autentia.tnt.dao.DataAccException) SecException(com.autentia.tnt.manager.security.exception.SecException) SQLException(java.sql.SQLException) DataIntegrityException(com.autentia.tnt.dao.DataIntegrityException) GrantedAuthority(org.acegisecurity.GrantedAuthority) Setting(com.autentia.tnt.businessobject.Setting) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Version(com.autentia.tnt.version.Version) SettingSearch(com.autentia.tnt.dao.search.SettingSearch) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException)

Example 5 with Setting

use of com.autentia.tnt.businessobject.Setting in project TNTConcept by autentia.

the class GeneralSettingsBean method save.

public void save() {
    Setting val = settings.get(SettingPath.BITACORE_PREFERRED_THEME, true);
    SettingManager.setValue(val, theme);
    settings.save(val);
    val = settings.get(SettingPath.BITACORE_PREFERRED_MODE, true);
    SettingManager.setValue(val, mode);
    settings.save(val);
    val = settings.get(SettingPath.BITACORE_PREFERRED_DISPLAY_HOUR_FROM, true);
    SettingManager.setValue(val, displayHourFrom);
    settings.save(val);
    val = settings.get(SettingPath.BITACORE_PREFERRED_DISPLAY_HOUR_UNTIL, true);
    SettingManager.setValue(val, displayHourUntil);
    settings.save(val);
    val = settings.get(SettingPath.BITACORE_PREFERRED_DAY_HOUR_START, true);
    SettingManager.setValue(val, workingDayHourStarts);
    settings.save(val);
    val = settings.get(SettingPath.BITACORE_PREFERRED_DAY_HOURS, true);
    SettingManager.setValue(val, workingHours);
    settings.save(val);
    val = settings.get(SettingPath.BITACORE_PREFERRED_HEADER_FORMAT, true);
    SettingManager.setValue(val, headerFormat);
    settings.save(val);
    val = settings.get(SettingPath.GENERAL_PREFERRED_LIST_SIZE, true);
    SettingManager.setValue(val, listSize);
    settings.save(val);
    val = settings.get(SettingPath.GENERAL_PREFERRED_LOCALE, true);
    SettingManager.setValue(val, locale);
    settings.save(val);
    val = settings.get(SettingPath.REPORTS_PREFERRED_SHOW_LEGAL_WARNING, true);
    SettingManager.setValue(val, showLegalWarning);
    settings.save((val));
    val = settings.get(SettingPath.REPORTS_PREFERRED_LEGAL_WARNING, true);
    SettingManager.setValue(val, legalWarning);
    settings.save(val);
    Locale local = new Locale(locale);
    AuthenticationManager.getDefault().getCurrentPrincipal().setLocale(local);
    FacesUtils.setViewLocale(local);
    generateSelectItems();
}
Also used : Locale(java.util.Locale) Setting(com.autentia.tnt.businessobject.Setting)

Aggregations

Setting (com.autentia.tnt.businessobject.Setting)5 SettingSearch (com.autentia.tnt.dao.search.SettingSearch)2 Locale (java.util.Locale)2 SettingBean (com.autentia.tnt.bean.admin.SettingBean)1 Activity (com.autentia.tnt.businessobject.Activity)1 DocumentCategory (com.autentia.tnt.businessobject.DocumentCategory)1 ExternalActivity (com.autentia.tnt.businessobject.ExternalActivity)1 Project (com.autentia.tnt.businessobject.Project)1 ProjectRole (com.autentia.tnt.businessobject.ProjectRole)1 User (com.autentia.tnt.businessobject.User)1 DataAccException (com.autentia.tnt.dao.DataAccException)1 DataIntegrityException (com.autentia.tnt.dao.DataIntegrityException)1 DataNotFoundException (com.autentia.tnt.dao.DataNotFoundException)1 SortCriteria (com.autentia.tnt.dao.SortCriteria)1 ActivitySearch (com.autentia.tnt.dao.search.ActivitySearch)1 ExternalActivitySearch (com.autentia.tnt.dao.search.ExternalActivitySearch)1 SecException (com.autentia.tnt.manager.security.exception.SecException)1 Version (com.autentia.tnt.version.Version)1 SQLException (java.sql.SQLException)1 LocalDate (java.time.LocalDate)1