Search in sources :

Example 1 with UserSearch

use of com.autentia.tnt.dao.search.UserSearch in project TNTConcept by autentia.

the class ContractExpirationNotificationBean method checkExpirationDate.

public int checkExpirationDate() throws MessagingException {
    authenticateAs(ConfigurationUtil.getDefault().getAdminUser());
    Date today = Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
    Date inThreeMonths = Date.from(LocalDate.now().plusMonths(3).atStartOfDay(ZoneId.systemDefault()).toInstant());
    // User with a contract ending within 3 months
    UserSearch search = new UserSearch();
    search.setActive(true);
    search.setStartEndContractDate(today);
    search.setEndEndContractDate(inThreeMonths);
    List<User> users = UserManager.getDefault().getAllEntities(search, null);
    // Users with a probation ending within 3 months
    search.reset();
    search.setActive(true);
    search.setStartEndTestPeriodDate(today);
    search.setEndEndTestPeriodDate(inThreeMonths);
    users.addAll(UserManager.getDefault().getAllEntities(search, null));
    log.info("Number of users with contract or probation to be expired: " + users.size());
    // send email
    if (!users.isEmpty()) {
        String emailSubject = ConfigurationUtil.getDefault().getMailNotificationContractSubject();
        StringBuilder emailContent = new StringBuilder();
        for (User user : users) {
            emailContent.append("\nUserId: " + user.getId() + ", Nombre: " + user.getName() + ", Email: " + user.getEmail());
        }
        log.info("Email content: " + emailContent);
        for (String recipient : ConfigurationUtil.getDefault().getMailNotificationContractSendTo()) {
            mailService.send(recipient, emailSubject, emailContent.toString());
            log.info("Email sent to: " + recipient);
        }
    }
    return users.size();
}
Also used : User(com.autentia.tnt.businessobject.User) Date(java.util.Date) LocalDate(java.time.LocalDate) UserSearch(com.autentia.tnt.dao.search.UserSearch)

Example 2 with UserSearch

use of com.autentia.tnt.dao.search.UserSearch in project TNTConcept by autentia.

the class UserDAO method searchByActive.

/* user - generated by stajanov (do not edit/delete) */
/**
 * Get User objects from database based on active flag sorted by the given criteria
 * @param sort the sorting criteria
 * @return a list with User objects matching the search criteria
 * @throws DataAccException on error
 */
public List<User> searchByActive(boolean active, SortCriteria sort) throws DataAccException {
    UserSearch search = new UserSearch();
    search.setActive(active);
    return super.search(User.class, search, sort);
}
Also used : UserSearch(com.autentia.tnt.dao.search.UserSearch)

Example 3 with UserSearch

use of com.autentia.tnt.dao.search.UserSearch in project TNTConcept by autentia.

the class AvailabilityBean method getAll.

public List<Availability> getAll() {
    List<Availability> ret = new ArrayList<Availability>();
    UserSearch searchUser = new UserSearch();
    searchUser.setActive(true);
    SortCriteria sCriteria = new SortCriteria("name");
    List<User> users = userMgr.getAllEntities(searchUser, sCriteria);
    for (User user : users) {
        OcupationModelImpl model = new OcupationModelImpl();
        Availability availability = new Availability();
        availability.setUser(user);
        availability.setModel(model);
        fillModelHolidays(user, model);
        fillAvailability(user, model);
        ret.add(availability);
    }
    return ret;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) User(com.autentia.tnt.businessobject.User) ArrayList(java.util.ArrayList) UserSearch(com.autentia.tnt.dao.search.UserSearch)

Example 4 with UserSearch

use of com.autentia.tnt.dao.search.UserSearch in project TNTConcept by autentia.

the class UserHolidaysStateBean method getAll.

public List<UserHolidaysState> getAll() {
    List<UserHolidaysState> ret = new ArrayList<UserHolidaysState>();
    if (chargeYear == null)
        return ret;
    UserManager userManager = UserManager.getDefault();
    UserSearch searchUser = new UserSearch();
    searchUser.setActive(true);
    List<User> users = userManager.getAllEntities(searchUser, new SortCriteria(sortColumn, sortAscending));
    for (User us : users) {
        ret.add(manager.calculateUserHolidaysState(us, this.getChargeYear()));
    }
    return ret;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) User(com.autentia.tnt.businessobject.User) UserManager(com.autentia.tnt.manager.admin.UserManager) ArrayList(java.util.ArrayList) UserHolidaysState(com.autentia.tnt.businessobject.UserHolidaysState) UserSearch(com.autentia.tnt.dao.search.UserSearch)

Example 5 with UserSearch

use of com.autentia.tnt.dao.search.UserSearch in project TNTConcept by autentia.

the class UserDAO method searchByLogin.

/**
 * Get a user given her login.
 * @return the user
 * @param login login of user
 * @throws com.autentia.tnt.dao.DataNotFoundException if user does not exist
 * @throws com.autentia.tnt.dao.DataIntegrityException if user is duplicated (bad thing)
 * @throws com.autentia.tnt.dao.DataAccException if something fails accesind DB
 */
public User searchByLogin(String login) throws DataAccException, DataNotFoundException, DataIntegrityException {
    UserSearch search = new UserSearch();
    search.setLogin(login);
    List<User> found = super.search(User.class, search, null);
    if (found.size() == 0) {
        throw new DataNotFoundException(User.class, search);
    } else if (found.size() > 1) {
        throw new DataIntegrityException(User.class, "duplicate login '" + login + "'");
    } else {
        return found.get(0);
    }
}
Also used : DataNotFoundException(com.autentia.tnt.dao.DataNotFoundException) User(com.autentia.tnt.businessobject.User) DataIntegrityException(com.autentia.tnt.dao.DataIntegrityException) UserSearch(com.autentia.tnt.dao.search.UserSearch)

Aggregations

UserSearch (com.autentia.tnt.dao.search.UserSearch)7 User (com.autentia.tnt.businessobject.User)5 SortCriteria (com.autentia.tnt.dao.SortCriteria)3 UserManager (com.autentia.tnt.manager.admin.UserManager)2 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 Activity (com.autentia.tnt.businessobject.Activity)1 Project (com.autentia.tnt.businessobject.Project)1 ProjectRole (com.autentia.tnt.businessobject.ProjectRole)1 UserHolidaysState (com.autentia.tnt.businessobject.UserHolidaysState)1 DataIntegrityException (com.autentia.tnt.dao.DataIntegrityException)1 DataNotFoundException (com.autentia.tnt.dao.DataNotFoundException)1 ActivitySearch (com.autentia.tnt.dao.search.ActivitySearch)1 MailService (com.autentia.tnt.mail.MailService)1 ActivityManager (com.autentia.tnt.manager.activity.ActivityManager)1 AuthenticationManager (com.autentia.tnt.manager.security.AuthenticationManager)1 Principal (com.autentia.tnt.manager.security.Principal)1 ConfigurationUtil (com.autentia.tnt.util.ConfigurationUtil)1 ZoneId (java.time.ZoneId)1 java.util (java.util)1