Search in sources :

Example 1 with DocumentCategory

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

the class ActivityBean method createDocument.

public String createDocument() {
    Document doc = new Document();
    HashSet<DocumentCategory> categories = new HashSet<DocumentCategory>();
    categories.add(externalActivity.getDocumentCategory());
    doc.setCategories(categories);
    doc.setOwnerId(externalActivity.getOwnerId());
    doc.setDepartmentId(externalActivity.getDepartmentId());
    doc.setCreationDate(new Date());
    // docVersion.setCreationDate(new Date());
    // docVersion.setOwnerId(externalActivity.getOwnerId());
    // docVersion.setDepartmentId(externalActivity.getDepartmentId());
    // docVersion.setDocument(doc);
    // docVersion.setVersion(EXT_ACT_DOC_VERSION);
    // 
    // if (doc.getVersions() == null) {
    // doc.setVersions(new HashSet<DocumentVersion>());
    // }
    // 
    // doc.getVersions().add(docVersion);
    documents.add(doc);
    return null;
}
Also used : Document(com.autentia.tnt.businessobject.Document) DocumentCategory(com.autentia.tnt.businessobject.DocumentCategory) Date(java.util.Date) LocalDate(java.time.LocalDate) HashSet(java.util.HashSet)

Example 2 with DocumentCategory

use of com.autentia.tnt.businessobject.DocumentCategory 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 DocumentCategory

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

the class UserBean method goDocuments.

/**
 * Saves and goes to user's document category
 */
public String goDocuments() {
    User currentUser = user;
    final Integer userId = user.getId();
    // Save user's data
    save();
    // Prepares the category bean filter
    final DocumentBean documentBean = (DocumentBean) FacesUtils.getBean("documentBean");
    final List<DocumentCategory> categories = new ArrayList<DocumentCategory>();
    categories.add(currentUser.getDocumentCategory());
    documentBean.setSearchCategoriesValid(true);
    documentBean.setSearchCategories(categories);
    documentBean.getSearch().setOwnerId(userId);
    return "goDocuments";
}
Also used : User(com.autentia.tnt.businessobject.User) DocumentBean(com.autentia.tnt.bean.document.DocumentBean) ArrayList(java.util.ArrayList) DocumentCategory(com.autentia.tnt.businessobject.DocumentCategory)

Example 4 with DocumentCategory

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

the class UserManager method doBeforeSave.

/* user - generated by stajanov (do not edit/delete) */
private void doBeforeSave(User user, boolean agreementYearDuration) {
    if (user.getId() != null) {
        user.setDocumentCategory(DocumentCategoryDAO.getDefault().recoverDocumentCategoryFromUser(user));
        if (user.getDocumentCategory() != null) {
            user.getDocumentCategory().setName(user.getName());
            user.getDocumentCategory().setDescription(user.getName());
        }
    } else {
        DocumentCategory padre = DocumentCategoryManager.getDefault().getDocumentCategoryParent();
        // User category
        DocumentCategory userDocCategory = new DocumentCategory();
        userDocCategory.setName(user.getName());
        userDocCategory.setDescription(user.getName());
        userDocCategory.setPadre(padre);
        user.setDocumentCategory(userDocCategory);
    }
    if (agreementYearDuration) {
        user.setAgreementYearDuration(null);
    }
}
Also used : DocumentCategory(com.autentia.tnt.businessobject.DocumentCategory)

Example 5 with DocumentCategory

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

the class ActivityBean method edit.

/**
 * Go to edit page
 *
 * @return forward to EDIT page
 */
public String edit() {
    ScheduleEntry entry = scheduleModel.getSelectedEntry();
    String tmpId = entry.getId();
    String[] tmpIdParts = tmpId.split("_");
    Integer id = Integer.parseInt(tmpIdParts[tmpIdParts.length - 1]);
    if (entry instanceof ActivityScheduleEntry) {
        activity = manager.getEntityById(id);
        selectedProject = activity.getRole().getProject();
        selectedOrganization = selectedProject.getClient();
        setDefaultBillable(selectedProject.getBillable());
        tabsRendered = EDIT_ACTIVITY;
    } else if (entry instanceof ExternalActivityScheduleEntry) {
        externalActivity = externalActivityManager.getEntityById(id);
        ArrayList<DocumentCategory> categories = new ArrayList<DocumentCategory>();
        categories.add(externalActivity.getDocumentCategory());
        docSearch = new DocumentSearch();
        docSearch.setCategories(categories);
        documents = docManager.getAllEntities(docSearch, null);
        tabsRendered = EDIT_EXTERNAL_ACTIVITY;
    } else {
        tabsRendered = NO_EDIT_SELECTED;
        return NavigationResults.LIST;
    }
    return NavigationResults.EDIT;
}
Also used : ScheduleEntry(org.apache.myfaces.custom.schedule.model.ScheduleEntry) ArrayList(java.util.ArrayList) DocumentSearch(com.autentia.tnt.dao.search.DocumentSearch) DocumentCategory(com.autentia.tnt.businessobject.DocumentCategory)

Aggregations

DocumentCategory (com.autentia.tnt.businessobject.DocumentCategory)7 ArrayList (java.util.ArrayList)3 SortCriteria (com.autentia.tnt.dao.SortCriteria)2 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2 SettingBean (com.autentia.tnt.bean.admin.SettingBean)1 DocumentBean (com.autentia.tnt.bean.document.DocumentBean)1 Activity (com.autentia.tnt.businessobject.Activity)1 Document (com.autentia.tnt.businessobject.Document)1 ExternalActivity (com.autentia.tnt.businessobject.ExternalActivity)1 Project (com.autentia.tnt.businessobject.Project)1 ProjectRole (com.autentia.tnt.businessobject.ProjectRole)1 Setting (com.autentia.tnt.businessobject.Setting)1 User (com.autentia.tnt.businessobject.User)1 ActivitySearch (com.autentia.tnt.dao.search.ActivitySearch)1 DocumentSearch (com.autentia.tnt.dao.search.DocumentSearch)1 ExternalActivitySearch (com.autentia.tnt.dao.search.ExternalActivitySearch)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1