Search in sources :

Example 6 with ProjectRole

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

the class BillManagerTest method createRolesForContext.

private Set<ProjectRole> createRolesForContext(Project project, Date date) {
    final Set<ProjectRole> projectRoleSet = new HashSet<ProjectRole>();
    final ProjectRole projectRole = new ProjectRole();
    projectRole.setName("Senior");
    projectRole.setCostPerHour(new BigDecimal("100"));
    projectRole.setExpectedHours(50);
    projectRole.setProject(project);
    projectRole.setActivities(createActivitiesForContext(projectRole, date));
    projectRoleSet.add(projectRole);
    return projectRoleSet;
}
Also used : ProjectRole(com.autentia.tnt.businessobject.ProjectRole) BigDecimal(java.math.BigDecimal) HashSet(java.util.HashSet)

Example 7 with ProjectRole

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

the class ActivityBean method getRolesBySelectedProject.

public List<SelectItem> getRolesBySelectedProject() {
    ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
    ProjectRoleSearch prjRolSearch = new ProjectRoleSearch();
    prjRolSearch.setProject(getSelectedProject());
    List<ProjectRole> refs = ProjectRoleManager.getDefault().getAllEntities(prjRolSearch, new SortCriteria("name", false));
    if (refs != null) {
        for (ProjectRole ref : refs) {
            ret.add(new SelectItem(ref, ref.getName()));
        }
        // proyecto, por que sino borrariamos y creariamos una situaciĆ³n inconsistente
        if (this.getRole() != null && this.getRole().getProject() != null && !this.getRole().getProject().equals(this.getSelectedProject())) {
            HtmlSelectOneRadio optRole = (HtmlSelectOneRadio) FacesUtils.getComponent("activity").findComponent("tabActivity").findComponent("role");
            this.setRole(refs.get(0));
            optRole.setValue(this.getRole());
        }
    }
    return ret;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList) ProjectRoleSearch(com.autentia.tnt.dao.search.ProjectRoleSearch) ProjectRole(com.autentia.tnt.businessobject.ProjectRole) HtmlSelectOneRadio(javax.faces.component.html.HtmlSelectOneRadio)

Example 8 with ProjectRole

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

the class ActivityEvidenceNotificationBean method checkActivitiesWithNoEvidence.

public void checkActivitiesWithNoEvidence() throws MessagingException {
    log.info("Checking for users with no activity evidence images attached for the past 7 days");
    authenticateAs(ConfigurationUtil.getDefault().getAdminUser());
    Date oneWeekAgo = Date.from(LocalDate.now().plusDays(-7).atStartOfDay(ZoneId.systemDefault()).toInstant());
    UserSearch userSearch = new UserSearch();
    userSearch.setActive(true);
    List<User> users = UserManager.getDefault().getAllEntities(userSearch, null).stream().filter(user -> user.getEmail() != null).collect(Collectors.toList());
    for (User user : users) {
        ActivitySearch search = new ActivitySearch();
        search.setStartStartDate(oneWeekAgo);
        search.setUser(user);
        List<Activity> activities = ActivityManager.getDefault().getAllEntities(search, null);
        activities = activities.stream().filter(activity -> doesProjectContainRoleWithRequiredEvidence(activity.getRole().getProject())).collect(Collectors.toList());
        if (activities.isEmpty()) {
            continue;
        }
        HashMap<Project, List<Activity>> groupedActivities = groupedActivitiesByProject(activities);
        for (Project project : groupedActivities.keySet()) {
            List<Activity> prjActivities = groupedActivities.get(project);
            if (prjActivities.stream().anyMatch(activity -> activity.getRole().getRequireEvidence()) && prjActivities.stream().noneMatch(this::doesActivitityHasEvidence)) {
                List<ProjectRole> roles = prjActivities.stream().map(Activity::getRole).filter(ProjectRole::getRequireEvidence).collect(Collectors.toList());
                prjActivities.stream().findFirst().ifPresent(activity -> {
                    try {
                        sendEmail(project, roles, user.getEmail());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                });
            }
        }
    }
}
Also used : MailService(com.autentia.tnt.mail.MailService) Authentication(org.acegisecurity.Authentication) java.util(java.util) AuthenticationManager(com.autentia.tnt.manager.security.AuthenticationManager) Principal(com.autentia.tnt.manager.security.Principal) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch) MessagingException(javax.mail.MessagingException) Project(com.autentia.tnt.businessobject.Project) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) User(com.autentia.tnt.businessobject.User) UsernamePasswordAuthenticationToken(org.acegisecurity.providers.UsernamePasswordAuthenticationToken) ConfigurationUtil(com.autentia.tnt.util.ConfigurationUtil) LocalDate(java.time.LocalDate) ProjectRole(com.autentia.tnt.businessobject.ProjectRole) SecurityContextHolder(org.acegisecurity.context.SecurityContextHolder) Log(org.apache.commons.logging.Log) Activity(com.autentia.tnt.businessobject.Activity) LogFactory(org.apache.commons.logging.LogFactory) UserManager(com.autentia.tnt.manager.admin.UserManager) UserSearch(com.autentia.tnt.dao.search.UserSearch) ActivityManager(com.autentia.tnt.manager.activity.ActivityManager) User(com.autentia.tnt.businessobject.User) Activity(com.autentia.tnt.businessobject.Activity) ProjectRole(com.autentia.tnt.businessobject.ProjectRole) LocalDate(java.time.LocalDate) MessagingException(javax.mail.MessagingException) UserSearch(com.autentia.tnt.dao.search.UserSearch) Project(com.autentia.tnt.businessobject.Project) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch)

Aggregations

ProjectRole (com.autentia.tnt.businessobject.ProjectRole)8 SortCriteria (com.autentia.tnt.dao.SortCriteria)6 ArrayList (java.util.ArrayList)5 SelectItem (javax.faces.model.SelectItem)4 Activity (com.autentia.tnt.businessobject.Activity)3 Project (com.autentia.tnt.businessobject.Project)3 ActivitySearch (com.autentia.tnt.dao.search.ActivitySearch)3 ProjectRoleSearch (com.autentia.tnt.dao.search.ProjectRoleSearch)3 User (com.autentia.tnt.businessobject.User)2 BigDecimal (java.math.BigDecimal)2 LocalDate (java.time.LocalDate)2 SettingBean (com.autentia.tnt.bean.admin.SettingBean)1 BillBreakDown (com.autentia.tnt.businessobject.BillBreakDown)1 DocumentCategory (com.autentia.tnt.businessobject.DocumentCategory)1 ExternalActivity (com.autentia.tnt.businessobject.ExternalActivity)1 Organization (com.autentia.tnt.businessobject.Organization)1 ProjectCost (com.autentia.tnt.businessobject.ProjectCost)1 Setting (com.autentia.tnt.businessobject.Setting)1 ActivityDAO (com.autentia.tnt.dao.hibernate.ActivityDAO)1 ProjectCostDAO (com.autentia.tnt.dao.hibernate.ProjectCostDAO)1