Search in sources :

Example 66 with User

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

the class CommissioningManager method getAllEntities.

/**
 * List commissionings.
 *
 * @param search
 *            search filter to apply
 * @param sort
 *            sorting criteria
 * @return the list of all commissionings sorted by requested criterion
 */
public List<Commissioning> getAllEntities(CommissioningSearch search, SortCriteria sort) {
    final User actualUser = AuthenticationManager.getDefault().getCurrentPrincipal().getUser();
    // FIXME no se si se puede hacer con acegi, pero no deberia hacerse asi
    if (!actualUser.getRole().getId().equals(ConfigurationUtil.getDefault().getRoleAdminId())) {
        List<User> reviser = new ArrayList<User>();
        reviser.add(actualUser);
        search.setRevisers(reviser);
    }
    return commissioningDAO.search(search, sort);
}
Also used : User(com.autentia.tnt.businessobject.User) ArrayList(java.util.ArrayList)

Example 67 with User

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

the class LinkBean method checkLinkAndResetPassword.

public String checkLinkAndResetPassword(String link) {
    List<Link> links = getLinksWithLink(link);
    if (!links.isEmpty() && isOnTime(links.get(0))) {
        User user = getUserByName(links.get(0).getUser());
        if (user != null && user.isActive()) {
            deleteLinkFromBD(links.get(0));
            String resetPassword = resetPassword(user);
            return "Tu nueva contraseña es: <b>" + resetPassword + "</b></br> <p>Se te pedirá que la modifiques al entrar por primera vez.</p>";
        }
    }
    return "<p>El enlace no existe o ha caducado</p>";
}
Also used : User(com.autentia.tnt.businessobject.User) Link(com.autentia.tnt.businessobject.Link)

Example 68 with User

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

the class GlobalHoursReportBean method getNextUserTotal.

public float getNextUserTotal() {
    ActivitySearch search = new ActivitySearch();
    Calendar init = Calendar.getInstance();
    init.setTime(startDate);
    Calendar last = Calendar.getInstance();
    last.setTime(endDate);
    init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY));
    init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE));
    init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND));
    init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND));
    last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY));
    last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE));
    last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND));
    last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND));
    search.setStartStartDate(init.getTime());
    search.setEndStartDate(last.getTime());
    if (billable)
        search.setBillable(true);
    if (iterator == null)
        iterator = getUsers().iterator();
    User user = null;
    try {
        user = iterator.next();
    } catch (NoSuchElementException e) {
        iterator = getUsers().iterator();
        user = iterator.next();
    }
    search.setUser(user);
    // Search activities during indicated dates
    List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name"));
    // Search for projects in activities and create the global list.
    float totalHours = 0.0f;
    for (Activity act : activities) {
        float horas = act.getDuration() / 60.0f;
        totalHours = totalHours + horas;
    }
    return totalHours;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) User(com.autentia.tnt.businessobject.User) Calendar(java.util.Calendar) Activity(com.autentia.tnt.businessobject.Activity) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch) NoSuchElementException(java.util.NoSuchElementException)

Example 69 with User

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

the class OccupationBean method getUsers.

// Getters to list possible values of related entities
/**
 * Get the list of all users
 * @return the list of all users
 */
public List<SelectItem> getUsers() {
    List<User> refs = UserManager.getDefault().getAllEntities(null, new SortCriteria("name"));
    ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
    for (User ref : refs) {
        ret.add(new SelectItem(ref, ref.getName()));
    }
    return ret;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) User(com.autentia.tnt.businessobject.User) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList)

Example 70 with User

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

User (com.autentia.tnt.businessobject.User)70 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)17 SortCriteria (com.autentia.tnt.dao.SortCriteria)15 SelectItem (javax.faces.model.SelectItem)11 UserDAO (com.autentia.tnt.dao.hibernate.UserDAO)10 Date (java.util.Date)9 Link (com.autentia.tnt.businessobject.Link)6 UserSearch (com.autentia.tnt.dao.search.UserSearch)5 Attributes (javax.naming.directory.Attributes)5 BasicAttributes (javax.naming.directory.BasicAttributes)5 Activity (com.autentia.tnt.businessobject.Activity)4 Attribute (javax.naming.directory.Attribute)4 BasicAttribute (javax.naming.directory.BasicAttribute)4 GlobalHourReport (com.autentia.tnt.businessobject.GlobalHourReport)3 GlobalHoursReportBean (com.autentia.tnt.bean.activity.GlobalHoursReportBean)2 Commissioning (com.autentia.tnt.businessobject.Commissioning)2 Objective (com.autentia.tnt.businessobject.Objective)2 Occupation (com.autentia.tnt.businessobject.Occupation)2 DataIntegrityException (com.autentia.tnt.dao.DataIntegrityException)2