use of com.autentia.tnt.dao.search.ActivitySearch in project TNTConcept by autentia.
the class GlobalHoursReportBean method getTotalHours.
public float getTotalHours() {
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);
// 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;
}
use of com.autentia.tnt.dao.search.ActivitySearch 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;
}
use of com.autentia.tnt.dao.search.ActivitySearch 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();
}
});
}
}
}
}
Aggregations