Search in sources :

Example 6 with SortCriteria

use of com.autentia.tnt.dao.SortCriteria in project TNTConcept by autentia.

the class ActivityBean method getRoles.

/**
 * Get the list of all roles
 *
 * @return the list of all roles
 */
public List<SelectItem> getRoles() {
    ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
    List<ProjectRole> refs = roleDAO.search(new SortCriteria("name"));
    for (ProjectRole ref : refs) {
        ret.add(new SelectItem(ref, ref.getName()));
    }
    return ret;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList) ProjectRole(com.autentia.tnt.businessobject.ProjectRole)

Example 7 with SortCriteria

use of com.autentia.tnt.dao.SortCriteria in project TNTConcept by autentia.

the class ActivityBean method getProjects.

/**
 * Get the list of all projects
 *
 * @return the list of all projects
 */
public List<SelectItem> getProjects() {
    ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
    List<Project> refs = projectManager.getAllEntities(null, new SortCriteria("name"));
    for (Project ref : refs) {
        ret.add(new SelectItem(ref, ref.getClient().getName() + " - " + ref.getName()));
    }
    return ret;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) Project(com.autentia.tnt.businessobject.Project) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList)

Example 8 with SortCriteria

use of com.autentia.tnt.dao.SortCriteria 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 9 with SortCriteria

use of com.autentia.tnt.dao.SortCriteria in project TNTConcept by autentia.

the class ActivityBean method getOrganizations.

/**
 * @return Organizaciones con proyectos abiertos que ademas tengan ROLES creados
 */
public List<SelectItem> getOrganizations() {
    ArrayList<SelectItem> ret = new ArrayList<SelectItem>(32);
    List<Project> projects = projectManager.getDefault().getOpenProjects(new SortCriteria("name"));
    HashMap<Integer, Organization> companies = new HashMap<Integer, Organization>(32);
    if (!CollectionUtils.isEmpty(projects)) {
        for (Project project : projects) {
            if ((!project.isFinished()) && (project.getOpen())) {
                Set<ProjectRole> roles = project.getRoles();
                if (!CollectionUtils.isEmpty(roles)) {
                    Organization company = project.getClient();
                    if (!companies.containsKey(company.getId())) {
                        companies.put(company.getId(), company);
                        ret.add(new SelectItem(company, company.getName()));
                    }
                }
            }
        }
    }
    Collections.sort(ret, new OperacionesComparator());
    if ((this.selectedOrganization == null) && (ret.size() > 0)) {
        this.setSelectedOrganization((Organization) ret.get(0).getValue());
    }
    return ret;
}
Also used : Organization(com.autentia.tnt.businessobject.Organization) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectRole(com.autentia.tnt.businessobject.ProjectRole) SortCriteria(com.autentia.tnt.dao.SortCriteria) Project(com.autentia.tnt.businessobject.Project) SelectItem(javax.faces.model.SelectItem)

Example 10 with SortCriteria

use of com.autentia.tnt.dao.SortCriteria in project TNTConcept by autentia.

the class UserBean method getContractTypes.

/**
 * Get the list of all contractTypes
 *
 * @return the list of all contractTypes
 */
public List<SelectItem> getContractTypes() {
    List<ContractType> refs = ContractTypeManager.getDefault().getAllEntities(null, new SortCriteria("name"));
    ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
    for (ContractType ref : refs) {
        ret.add(new SelectItem(ref, ref.getName()));
    }
    return ret;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList) ContractType(com.autentia.tnt.businessobject.ContractType)

Aggregations

SortCriteria (com.autentia.tnt.dao.SortCriteria)136 ArrayList (java.util.ArrayList)114 SelectItem (javax.faces.model.SelectItem)107 Organization (com.autentia.tnt.businessobject.Organization)15 User (com.autentia.tnt.businessobject.User)15 Department (com.autentia.tnt.businessobject.Department)9 Project (com.autentia.tnt.businessobject.Project)9 Position (com.autentia.tnt.businessobject.Position)7 Calendar (java.util.Calendar)7 GregorianCalendar (java.util.GregorianCalendar)7 Activity (com.autentia.tnt.businessobject.Activity)6 ProjectRole (com.autentia.tnt.businessobject.ProjectRole)6 ActivitySearch (com.autentia.tnt.dao.search.ActivitySearch)6 PositionSearch (com.autentia.tnt.dao.search.PositionSearch)6 Account (com.autentia.tnt.businessobject.Account)5 Contact (com.autentia.tnt.businessobject.Contact)5 Bill (com.autentia.tnt.businessobject.Bill)4 Inventary (com.autentia.tnt.businessobject.Inventary)4 AccountEntryType (com.autentia.tnt.businessobject.AccountEntryType)3 ExternalActivity (com.autentia.tnt.businessobject.ExternalActivity)3