Search in sources :

Example 1 with TaskJurisdictionFlagsDto

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;
}
Also used : Arrays(java.util.Arrays) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) RolesAllowed(javax.annotation.security.RolesAllowed) Valid(javax.validation.Valid) Page(de.symeda.sormas.api.common.Page) TransactionAttributeType(javax.ejb.TransactionAttributeType) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Set(java.util.Set) CronService(de.symeda.sormas.backend.common.CronService) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) CaseFacadeEjbLocal(de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) EventFacadeEjb(de.symeda.sormas.backend.event.EventFacadeEjb) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) Selection(javax.persistence.criteria.Selection) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) Case(de.symeda.sormas.backend.caze.Case) Calendar(java.util.Calendar) LocalBean(javax.ejb.LocalBean) ConfigFacadeEjbLocal(de.symeda.sormas.backend.common.ConfigFacadeEjb.ConfigFacadeEjbLocal) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) TravelEntryFacadeEjb(de.symeda.sormas.backend.travelentry.TravelEntryFacadeEjb) DataHelper(de.symeda.sormas.api.utils.DataHelper) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) SortProperty(de.symeda.sormas.api.utils.SortProperty) TravelEntryService(de.symeda.sormas.backend.travelentry.services.TravelEntryService) Captions(de.symeda.sormas.api.i18n.Captions) TravelEntryReferenceDto(de.symeda.sormas.api.travelentry.TravelEntryReferenceDto) ContactService(de.symeda.sormas.backend.contact.ContactService) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) ContactFacadeEjb(de.symeda.sormas.backend.contact.ContactFacadeEjb) TaskJurisdictionFlagsDto(de.symeda.sormas.api.task.TaskJurisdictionFlagsDto) EventService(de.symeda.sormas.backend.event.EventService) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LoggerFactory(org.slf4j.LoggerFactory) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) TaskFacade(de.symeda.sormas.api.task.TaskFacade) NotificationService(de.symeda.sormas.backend.common.NotificationService) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) TaskDto(de.symeda.sormas.api.task.TaskDto) CaseService(de.symeda.sormas.backend.caze.CaseService) NotificationDeliveryFailedException(de.symeda.sormas.backend.common.messaging.NotificationDeliveryFailedException) Person(de.symeda.sormas.backend.person.Person) Collection(java.util.Collection) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) TaskType(de.symeda.sormas.api.task.TaskType) Objects(java.util.Objects) List(java.util.List) MessageContents(de.symeda.sormas.backend.common.messaging.MessageContents) BirthDateDto(de.symeda.sormas.api.caze.BirthDateDto) Order(javax.persistence.criteria.Order) Location(de.symeda.sormas.backend.location.Location) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) LocationJoins(de.symeda.sormas.backend.location.LocationJoins) TaskIndexDto(de.symeda.sormas.api.task.TaskIndexDto) HashMap(java.util.HashMap) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) HashSet(java.util.HashSet) TransactionAttribute(javax.ejb.TransactionAttribute) TaskStatus(de.symeda.sormas.api.task.TaskStatus) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) TaskContext(de.symeda.sormas.api.task.TaskContext) Logger(org.slf4j.Logger) Validations(de.symeda.sormas.api.i18n.Validations) MessageSubject(de.symeda.sormas.backend.common.messaging.MessageSubject) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Event(de.symeda.sormas.backend.event.Event) TaskExportDto(de.symeda.sormas.api.task.TaskExportDto) UserRight(de.symeda.sormas.api.user.UserRight) NotificationType(de.symeda.sormas.api.user.NotificationType) MessagingService(de.symeda.sormas.backend.common.messaging.MessagingService) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) Collections(java.util.Collections) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Selection(javax.persistence.criteria.Selection) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) TaskJurisdictionFlagsDto(de.symeda.sormas.api.task.TaskJurisdictionFlagsDto) TaskIndexDto(de.symeda.sormas.api.task.TaskIndexDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject)

Example 2 with TaskJurisdictionFlagsDto

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;
}
Also used : TaskJurisdictionFlagsDto(de.symeda.sormas.api.task.TaskJurisdictionFlagsDto) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) TaskDto(de.symeda.sormas.api.task.TaskDto)

Example 3 with TaskJurisdictionFlagsDto

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TaskJurisdictionFlagsDto(de.symeda.sormas.api.task.TaskJurisdictionFlagsDto)

Aggregations

TaskJurisdictionFlagsDto (de.symeda.sormas.api.task.TaskJurisdictionFlagsDto)3 TaskDto (de.symeda.sormas.api.task.TaskDto)2 UserFacadeEjb (de.symeda.sormas.backend.user.UserFacadeEjb)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 BirthDateDto (de.symeda.sormas.api.caze.BirthDateDto)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 Page (de.symeda.sormas.api.common.Page)1 ContactReferenceDto (de.symeda.sormas.api.contact.ContactReferenceDto)1 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)1 Captions (de.symeda.sormas.api.i18n.Captions)1 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)1 Validations (de.symeda.sormas.api.i18n.Validations)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 TaskContext (de.symeda.sormas.api.task.TaskContext)1 TaskCriteria (de.symeda.sormas.api.task.TaskCriteria)1 TaskExportDto (de.symeda.sormas.api.task.TaskExportDto)1 TaskFacade (de.symeda.sormas.api.task.TaskFacade)1 TaskIndexDto (de.symeda.sormas.api.task.TaskIndexDto)1 TaskStatus (de.symeda.sormas.api.task.TaskStatus)1 TaskType (de.symeda.sormas.api.task.TaskType)1