use of de.symeda.sormas.api.task.TaskJurisdictionFlagsDto in project SORMAS-Project by hzi-braunschweig.
the class TaskFacadeEjb method getIndexList.
@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);
TaskQueryContext taskQueryContext = new TaskQueryContext(cb, cq, task);
TaskJoins joins = taskQueryContext.getJoins();
// Filter select based on case/contact/event region/district/community
Expression<Object> region = cb.selectCase().when(cb.isNotNull(joins.getCaseResponsibleRegion()), joins.getCaseResponsibleRegion().get(Region.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getCaseRegion()), joins.getCaseRegion().get(Region.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getContactRegion()), joins.getContactRegion().get(Region.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getEventRegion()), joins.getEventRegion().get(Region.NAME)).otherwise(joins.getTravelEntryResponsibleRegion().get(Region.NAME)))));
Expression<Object> district = cb.selectCase().when(cb.isNotNull(joins.getCaseResponsibleDistrict()), joins.getCaseResponsibleDistrict().get(District.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getCaseDistrict()), joins.getCaseDistrict().get(District.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getContactDistrict()), joins.getContactDistrict().get(District.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getEventDistrict()), joins.getEventDistrict().get(District.NAME)).otherwise(joins.getTravelEntryResponsibleDistrict().get(District.NAME)))));
Expression<Object> community = cb.selectCase().when(cb.isNotNull(joins.getCaseResponsibleCommunity()), joins.getCaseResponsibleCommunity().get(Community.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getCaseCommunity()), joins.getCaseCommunity().get(Community.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getContactCommunity()), joins.getContactCommunity().get(Community.NAME)).otherwise(cb.selectCase().when(cb.isNotNull(joins.getEventCommunity()), joins.getEventCommunity().get(Community.NAME)).otherwise(joins.getTravelEntryResponsibleCommunity().get(Community.NAME)))));
List<Selection<?>> selections = new ArrayList<>(Arrays.asList(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.EVENT_TITLE), joins.getEvent().get(Event.DISEASE), joins.getEvent().get(Event.DISEASE_DETAILS), joins.getEvent().get(Event.EVENT_STATUS), joins.getEvent().get(Event.EVENT_INVESTIGATION_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), joins.getTravelEntry().get(TravelEntry.UUID), joins.getTravelEntry().get(TravelEntry.EXTERNAL_ID), joins.getTravelEntryPerson().get(Person.FIRST_NAME), joins.getTravelEntryPerson().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), cb.selectCase().when(cb.isNotNull(joins.getCaze()), joins.getCaze().get(Case.DISEASE)).when(cb.isNotNull(joins.getContact()), joins.getContact().get(Contact.DISEASE)).when(cb.isNotNull(joins.getEvent()), joins.getEvent().get(Event.DISEASE)).otherwise(joins.getTravelEntry().get(TravelEntry.DISEASE)), 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), region, district, community));
selections.addAll(taskService.getJurisdictionSelections(taskQueryContext));
cq.multiselect(selections);
Predicate filter = null;
if (taskCriteria == null || !taskCriteria.hasContextCriteria()) {
filter = taskService.createUserFilter(taskQueryContext);
} else {
filter = CriteriaBuilderHelper.and(cb, filter, taskService.createAssigneeFilter(cb, joins.getAssignee()));
}
if (taskCriteria != null) {
Predicate criteriaFilter = taskService.buildCriteriaFilter(taskCriteria, taskQueryContext);
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
}
if (filter != null) {
cq.where(filter);
}
// Distinct is necessary here to avoid duplicate results due to the user role join in taskService.createAssigneeFilter
cq.distinct(true);
List<Order> order = new ArrayList<>();
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;
case TaskIndexDto.DISTRICT:
expression = district;
break;
case TaskIndexDto.REGION:
expression = region;
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 = QueryHelper.getResultList(em, cq, first, max);
if (!tasks.isEmpty()) {
List<String> assigneeUserUuids = tasks.stream().map(t -> t.getAssigneeUser().getUuid()).collect(Collectors.toList());
Map<String, Long> pendingTaskCounts = getPendingTaskCountPerUser(assigneeUserUuids);
for (TaskIndexDto singleTask : tasks) {
// Workaround for Vaadin renderers not having access to their row reference; we therefore update the caption
// directly instead of storing the task count in TaskIndexDto
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 -> t.getTaskJurisdictionFlagsDto().getInJurisdiction(), (t, ignored) -> {
final TaskJurisdictionFlagsDto taskJurisdictionFlagsDto = t.getTaskJurisdictionFlagsDto();
if (t.getCaze() != null) {
emptyValuePseudonymizer.pseudonymizeDto(CaseReferenceDto.class, t.getCaze(), taskJurisdictionFlagsDto.getCaseInJurisdiction(), null);
}
if (t.getContact() != null) {
pseudonymizeContactReference(emptyValuePseudonymizer, t.getContact(), taskJurisdictionFlagsDto.getContactInJurisdiction(), taskJurisdictionFlagsDto.getContactCaseInJurisdiction());
}
if (t.getEvent() != null) {
emptyValuePseudonymizer.pseudonymizeDto(EventReferenceDto.class, t.getEvent(), taskJurisdictionFlagsDto.getEventInJurisdiction(), null);
}
if (t.getTravelEntry() != null) {
emptyValuePseudonymizer.pseudonymizeDto(TravelEntryReferenceDto.class, t.getTravelEntry(), taskJurisdictionFlagsDto.getTravelEntryInJurisdiction(), null);
}
}, true);
}
return tasks;
}
use of de.symeda.sormas.api.task.TaskJurisdictionFlagsDto in project SORMAS-Project by hzi-braunschweig.
the class TaskFacadeEjb method toDto.
public TaskDto toDto(Task source, Pseudonymizer pseudonymizer) {
if (source == null) {
return null;
}
TaskDto target = new TaskDto();
DtoHelper.fillDto(target, source);
target.setAssigneeUser(UserFacadeEjb.toReferenceDto(source.getAssigneeUser()));
target.setAssigneeReply(source.getAssigneeReply());
target.setCreatorUser(UserFacadeEjb.toReferenceDto(source.getCreatorUser()));
target.setCreatorComment(source.getCreatorComment());
if (source.getObserverUsers() != null) {
target.setObserverUsers(source.getObserverUsers().stream().map(UserFacadeEjb::toReferenceDto).collect(Collectors.toSet()));
}
target.setPriority(source.getPriority());
target.setDueDate(source.getDueDate());
target.setSuggestedStart(source.getSuggestedStart());
target.setPerceivedStart(source.getPerceivedStart());
target.setStatusChangeDate(source.getStatusChangeDate());
target.setTaskContext(source.getTaskContext());
target.setTaskStatus(source.getTaskStatus());
target.setTaskType(source.getTaskType());
target.setCaze(CaseFacadeEjb.toReferenceDto(source.getCaze()));
target.setContact(ContactFacadeEjb.toReferenceDto(source.getContact()));
target.setEvent(EventFacadeEjb.toReferenceDto(source.getEvent()));
target.setTravelEntry(travelEntryFacade.toRefDto(source.getTravelEntry()));
target.setClosedLat(source.getClosedLat());
target.setClosedLon(source.getClosedLon());
target.setClosedLatLonAccuracy(source.getClosedLatLonAccuracy());
TaskJurisdictionFlagsDto taskJurisdictionFlagsDto = taskService.inJurisdictionOrOwned(source);
pseudonymizer.pseudonymizeDto(TaskDto.class, target, taskJurisdictionFlagsDto.getInJurisdiction(), t -> {
if (source.getCaze() != null) {
pseudonymizer.pseudonymizeDto(CaseReferenceDto.class, target.getCaze(), taskJurisdictionFlagsDto.getCaseInJurisdiction(), null);
}
if (source.getContact() != null) {
pseudonymizeContactReference(pseudonymizer, target.getContact(), taskJurisdictionFlagsDto.getContactInJurisdiction(), taskJurisdictionFlagsDto.getContactCaseInJurisdiction());
}
if (source.getEvent() != null) {
pseudonymizer.pseudonymizeDto(EventReferenceDto.class, target.getEvent(), taskJurisdictionFlagsDto.getEventInJurisdiction(), null);
}
if (source.getTravelEntry() != null) {
pseudonymizer.pseudonymizeDto(TravelEntryReferenceDto.class, target.getTravelEntry(), taskJurisdictionFlagsDto.getTravelEntryInJurisdiction(), null);
}
});
return target;
}
use of de.symeda.sormas.api.task.TaskJurisdictionFlagsDto in project SORMAS-Project by hzi-braunschweig.
the class TaskService method inJurisdictionOrOwned.
public TaskJurisdictionFlagsDto inJurisdictionOrOwned(Task task) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TaskJurisdictionFlagsDto> cq = cb.createQuery(TaskJurisdictionFlagsDto.class);
Root<Task> root = cq.from(Task.class);
cq.multiselect(getJurisdictionSelections(new TaskQueryContext(cb, cq, root)));
cq.where(cb.equal(root.get(Task.UUID), task.getUuid()));
return em.createQuery(cq).getSingleResult();
}
Aggregations