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();
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations