TaskFacadeEjb implements TaskFacade { @Override public List<TaskIndexDto> getIndexList(TaskCriteria taskCriteria, Integer first, Integer max, List<SortProperty> sortProperties) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<TaskIndexDto> cq = cb.createQuery(TaskIndexDto.class); Root<Task> task = cq.from(Task.class); TaskJoins joins = new TaskJoins(task); cq.multiselect(task.get(Task.UUID), task.get(Task.TASK_CONTEXT), joins.getCaze().get(Case.UUID), joins.getCasePerson().get(Person.FIRST_NAME), joins.getCasePerson().get(Person.LAST_NAME), joins.getEvent().get(Event.UUID), joins.getEvent().get(Event.DISEASE), joins.getEvent().get(Event.DISEASE_DETAILS), joins.getEvent().get(Event.EVENT_STATUS), joins.getEvent().get(Event.START_DATE), joins.getContact().get(Contact.UUID), joins.getContactPerson().get(Person.FIRST_NAME), joins.getContactPerson().get(Person.LAST_NAME), joins.getContactCasePerson().get(Person.FIRST_NAME), joins.getContactCasePerson().get(Person.LAST_NAME), task.get(Task.TASK_TYPE), task.get(Task.PRIORITY), task.get(Task.DUE_DATE), task.get(Task.SUGGESTED_START), task.get(Task.TASK_STATUS), joins.getCreator().get(User.UUID), joins.getCreator().get(User.FIRST_NAME), joins.getCreator().get(User.LAST_NAME), task.get(Task.CREATOR_COMMENT), joins.getAssignee().get(User.UUID), joins.getAssignee().get(User.FIRST_NAME), joins.getAssignee().get(User.LAST_NAME), task.get(Task.ASSIGNEE_REPLY), joins.getCaseReportingUser().get(User.UUID), joins.getCaseRegion().get(Region.UUID), joins.getCaseDistrict().get(Region.UUID), joins.getCaseCommunity().get(Community.UUID), joins.getCaseFacility().get(Community.UUID), joins.getCasePointOfEntry().get(Community.UUID), joins.getContactReportingUser().get(User.UUID), joins.getContactRegion().get(Region.UUID), joins.getContactDistrict().get(District.UUID), joins.getContactCommunity().get(Community.UUID), joins.getContactCaseReportingUser().get(User.UUID), joins.getContactCaseRegion().get(User.UUID), joins.getContactCaseDistrict().get(User.UUID), joins.getContactCaseCommunity().get(User.UUID), joins.getContactCaseHealthFacility().get(User.UUID), joins.getContactCasePointOfEntry().get(User.UUID), joins.getEventReportingUser().get(User.UUID), joins.getEventSurveillanceOfficer().get(User.UUID), joins.getEventRegion().get(Region.UUID), joins.getEventDistrict().get(District.UUID), joins.getEventCommunity().get(Community.UUID) ); Predicate filter = null; if (taskCriteria == null || !taskCriteria.hasContextCriteria()) { filter = taskService.createUserFilter(cb, cq, task); } else { filter = AbstractAdoService.and(cb, filter, taskService.createAssigneeFilter(cb, joins.getAssignee())); } if (taskCriteria != null) { Predicate criteriaFilter = taskService.buildCriteriaFilter(taskCriteria, cb, task); filter = AbstractAdoService.and(cb, filter, criteriaFilter); } if (filter != null) { cq.where(filter); } cq.distinct(true); List<Order> order = new ArrayList<Order>(); if (sortProperties != null && sortProperties.size() > 0) { for (SortProperty sortProperty : sortProperties) { Expression<?> expression; switch (sortProperty.propertyName) { case TaskIndexDto.UUID: case TaskIndexDto.ASSIGNEE_REPLY: case TaskIndexDto.CREATOR_COMMENT: case TaskIndexDto.PRIORITY: case TaskIndexDto.DUE_DATE: case TaskIndexDto.SUGGESTED_START: case TaskIndexDto.TASK_CONTEXT: case TaskIndexDto.TASK_STATUS: case TaskIndexDto.TASK_TYPE: expression = task.get(sortProperty.propertyName); break; case TaskIndexDto.ASSIGNEE_USER: expression = joins.getAssignee().get(User.LAST_NAME); order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression)); expression = joins.getAssignee().get(User.FIRST_NAME); break; case TaskIndexDto.CREATOR_USER: expression = joins.getCreator().get(User.LAST_NAME); order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression)); expression = joins.getCreator().get(User.FIRST_NAME); break; case TaskIndexDto.CAZE: expression = joins.getCasePerson().get(Person.LAST_NAME); order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression)); expression = joins.getCasePerson().get(Person.FIRST_NAME); break; case TaskIndexDto.CONTACT: expression = joins.getContactPerson().get(Person.LAST_NAME); order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression)); expression = joins.getContactPerson().get(Person.FIRST_NAME); break; case TaskIndexDto.EVENT: expression = joins.getEvent().get(Event.START_DATE); break; default: throw new IllegalArgumentException(sortProperty.propertyName); } order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression)); } } order.add(cb.desc(task.get(Task.DUE_DATE))); cq.orderBy(order); List<TaskIndexDto> tasks; if (first != null && max != null) { tasks = em.createQuery(cq).setFirstResult(first).setMaxResults(max).getResultList(); } else { tasks = em.createQuery(cq).getResultList(); } if (!tasks.isEmpty()) { List<String> assigneeUserUuids = tasks.stream().map(t -> t.getAssigneeUser().getUuid()).collect(Collectors.toList()); Map<String, Long> pendingTaskCounts = new HashMap<>(); IterableHelper.executeBatched(assigneeUserUuids, ModelConstants.PARAMETER_LIMIT, e -> { pendingTaskCounts.putAll(getPendingTaskCountPerUser(e)); }); for (TaskIndexDto singleTask : tasks) { UserReferenceDto assigneeUser = singleTask.getAssigneeUser(); Long taskCount = pendingTaskCounts.get(assigneeUser.getUuid()); assigneeUser.setCaption(assigneeUser.getCaption() + " (" + (taskCount != null ? taskCount.toString() : "") + ")"); } Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue)); Pseudonymizer emptyValuePseudonymizer = Pseudonymizer.getDefault(userService::hasRight); pseudonymizer.pseudonymizeDtoCollection( TaskIndexDto.class, tasks, t -> taskJurisdictionChecker.isInJurisdictionOrOwned(t.getJurisdiction()), (t, ignored) -> { if (t.getCaze() != null) { emptyValuePseudonymizer.pseudonymizeDto( CaseReferenceDto.class, t.getCaze(), caseJurisdictionChecker.isInJurisdictionOrOwned(t.getJurisdiction().getCaseJurisdiction()), null); } if (t.getContact() != null) { pseudonymizeContactReference(emptyValuePseudonymizer, t.getContact(), t.getJurisdiction().getContactJurisdiction()); } if (t.getEvent() != null) { emptyValuePseudonymizer.pseudonymizeDto( EventReferenceDto.class, t.getEvent(), eventJurisdictionChecker.isInJurisdictionOrOwned(t.getJurisdiction().getEventJurisdiction()), null); } }, true); } return tasks; }  Task fromDto(TaskDto source); TaskDto toDto(Task task, Pseudonymizer pseudonymizer); @Override TaskDto saveTask(TaskDto dto); @Override List<String> getAllActiveUuids(); @Override List<TaskDto> getAllActiveTasksAfter(Date date); @Override long count(TaskCriteria taskCriteria); @Override List<TaskIndexDto> getIndexList(TaskCriteria taskCriteria, Integer first, Integer max, List<SortProperty> sortProperties); @Override List<TaskDto> getAllByCase(CaseReferenceDto caseRef); @Override List<TaskDto> getAllByContact(ContactReferenceDto contactRef); @Override List<TaskDto> getAllByEvent(EventReferenceDto eventRef); @Override List<TaskDto> getByUuids(List<String> uuids); @Override List<TaskDto> getAllPendingByCase(CaseReferenceDto caseRef); @Override long getPendingTaskCountByContact(ContactReferenceDto contactRef); @Override long getPendingTaskCountByEvent(EventReferenceDto eventRef); @Override Map<String, Long> getPendingTaskCountPerUser(List<String> userUuids); @Override TaskDto getByUuid(String uuid); @Override void deleteTask(TaskDto taskDto); @Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) void sendNewAndDueTaskMessages();  }
@Test public void testGetIndexList() { RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility"); UserDto user = creator .createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR); assertNotNull(getTaskFacade().getIndexList(null, 0, 100, null)); }