Search in sources :

Example 1 with TaskExportDto

use of de.symeda.sormas.api.task.TaskExportDto in project SORMAS-Project by hzi-braunschweig.

the class TaskFacadeEjbPseudonymizationTest method testPseudonymizeExportList.

@Test
public void testPseudonymizeExportList() {
    CaseDataDto caze1 = creator.createCase(user2.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf2);
    TaskDto task1 = createCaseTask(caze1);
    CaseDataDto caze2 = creator.createCase(user1.toReference(), creator.createPerson("John", "Smith").toReference(), rdcf1);
    ContactDto contact1 = creator.createContact(user2.toReference(), null, creator.createPerson("John", "Smith").toReference(), caze2, new Date(), new Date(), Disease.CORONAVIRUS, rdcf2);
    TaskDto task2 = createCaseTask(caze2);
    TaskDto task3 = createContactTask(contact1);
    ContactDto contact2 = creator.createContact(user1.toReference(), null, creator.createPerson("John", "Smith").toReference(), caze2, new Date(), new Date(), Disease.CORONAVIRUS, rdcf1);
    TaskDto task4 = createContactTask(contact2);
    List<TaskExportDto> exportList = getTaskFacade().getExportList(new TaskCriteria(), null, 1, 100);
    TaskExportDto export1 = exportList.stream().filter(t -> t.getUuid().equals(task1.getUuid())).findFirst().get();
    assertThat(export1.getPersonFirstName(), is("John"));
    assertThat(export1.getPersonLastName(), is("Smith"));
    TaskExportDto export2 = exportList.stream().filter(t -> t.getUuid().equals(task2.getUuid())).findFirst().get();
    assertThat(export2.getPersonFirstName(), is("Confidential"));
    assertThat(export2.getPersonLastName(), is("Confidential"));
    TaskExportDto export3 = exportList.stream().filter(t -> t.getUuid().equals(task3.getUuid())).findFirst().get();
    assertThat(export3.getPersonFirstName(), is("John"));
    assertThat(export3.getPersonLastName(), is("Smith"));
    TaskExportDto export4 = exportList.stream().filter(t -> t.getUuid().equals(task4.getUuid())).findFirst().get();
    assertThat(export4.getPersonFirstName(), is("Confidential"));
    assertThat(export4.getPersonLastName(), is("Confidential"));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) TaskCriteria(de.symeda.sormas.api.task.TaskCriteria) TaskDto(de.symeda.sormas.api.task.TaskDto) TaskExportDto(de.symeda.sormas.api.task.TaskExportDto) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 2 with TaskExportDto

use of de.symeda.sormas.api.task.TaskExportDto in project SORMAS-Project by hzi-braunschweig.

the class TaskFacadeEjb method getExportList.

@Override
@RolesAllowed(UserRight._TASK_EXPORT)
public List<TaskExportDto> getExportList(TaskCriteria criteria, Collection<String> selectedRows, int first, int max) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<TaskExportDto> cq = cb.createQuery(TaskExportDto.class);
    Root<Task> task = cq.from(Task.class);
    TaskQueryContext taskQueryContext = new TaskQueryContext(cb, cq, task);
    TaskJoins joins = taskQueryContext.getJoins();
    CaseQueryContext caseQueryContext = new CaseQueryContext(cb, cq, joins.getCaseJoins());
    ContactQueryContext contactQueryContext = new ContactQueryContext(cb, cq, joins.getContactJoins());
    LocationJoins casePersonAddressJoins = caseQueryContext.getJoins().getPersonJoins().getAddressJoins();
    LocationJoins contactPersonAddressJoins = contactQueryContext.getJoins().getPersonJoins().getAddressJoins();
    // @formatter:off
    cq.multiselect(task.get(Task.UUID), task.get(Task.TASK_CONTEXT), joins.getCaze().get(Case.UUID), joins.getContact().get(Contact.UUID), joins.getEvent().get(Event.UUID), 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), CriteriaBuilderHelper.coalesce(cb, joins.getCaseRegion().get(Region.NAME), joins.getContactRegion().get(Region.NAME), joins.getEventRegion().get(Region.NAME)), CriteriaBuilderHelper.coalesce(cb, joins.getCaseDistrict().get(District.NAME), joins.getContactDistrict().get(District.NAME), joins.getEventDistrict().get(District.NAME)), CriteriaBuilderHelper.coalesce(cb, joins.getCaseCommunity().get(Community.NAME), joins.getContactCommunity().get(Community.NAME), joins.getEventCommunity().get(Community.NAME)), getPersonFieldPath(cb, joins, Person.FIRST_NAME), getPersonFieldPath(cb, joins, Person.LAST_NAME), getPersonFieldPath(cb, joins, Person.SEX), getPersonFieldPath(cb, joins, Person.BIRTHDATE_DD), getPersonFieldPath(cb, joins, Person.BIRTHDATE_MM), getPersonFieldPath(cb, joins, Person.BIRTHDATE_YYYY), CriteriaBuilderHelper.coalesce(cb, casePersonAddressJoins.getRegion().get(Region.NAME), contactPersonAddressJoins.getRegion().get(Region.NAME)), CriteriaBuilderHelper.coalesce(cb, casePersonAddressJoins.getDistrict().get(District.NAME), contactPersonAddressJoins.getDistrict().get(District.NAME)), CriteriaBuilderHelper.coalesce(cb, casePersonAddressJoins.getCommunity().get(Community.NAME), contactPersonAddressJoins.getCommunity().get(Community.NAME)), CriteriaBuilderHelper.coalesce(cb, casePersonAddressJoins.getFacility().get(Facility.NAME), contactPersonAddressJoins.getFacility().get(Facility.NAME)), getPersonAddressFieldPath(cb, joins, Location.FACILITY_DETAILS), getPersonAddressFieldPath(cb, joins, Location.CITY), getPersonAddressFieldPath(cb, joins, Location.STREET), getPersonAddressFieldPath(cb, joins, Location.HOUSE_NUMBER), getPersonAddressFieldPath(cb, joins, Location.POSTAL_CODE), CriteriaBuilderHelper.coalesce(cb, caseQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_PHONE_SUBQUERY), contactQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_PHONE_SUBQUERY)), CriteriaBuilderHelper.coalesce(cb, caseQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_PHONE_OWNER_SUBQUERY), contactQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_PHONE_OWNER_SUBQUERY)), CriteriaBuilderHelper.coalesce(cb, caseQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_EMAIL_SUBQUERY), contactQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_EMAIL_SUBQUERY)), CriteriaBuilderHelper.coalesce(cb, caseQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_OTHER_CONTACT_DETAILS_SUBQUERY), contactQueryContext.getSubqueryExpression(CaseQueryContext.PERSON_OTHER_CONTACT_DETAILS_SUBQUERY)), JurisdictionHelper.booleanSelector(cb, taskService.inJurisdictionOrOwned(taskQueryContext)));
    // @formatter:on
    Predicate filter = null;
    if (criteria == null || !criteria.hasContextCriteria()) {
        filter = taskService.createUserFilter(taskQueryContext);
    } else {
        filter = CriteriaBuilderHelper.and(cb, filter, taskService.createAssigneeFilter(cb, joins.getAssignee()));
    }
    if (criteria != null) {
        Predicate criteriaFilter = taskService.buildCriteriaFilter(criteria, 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);
    cq.orderBy(cb.desc(task.get(Task.DUE_DATE)));
    List<TaskExportDto> tasks = QueryHelper.getResultList(em, cq, first, max);
    Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
    pseudonymizer.pseudonymizeDtoCollection(TaskExportDto.class, tasks, TaskExportDto::isInJurisdiction, (t, inJurisdiction) -> pseudonymizer.pseudonymizeDto(BirthDateDto.class, t.getPersonBirthDate(), inJurisdiction, null));
    return tasks;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) LocationJoins(de.symeda.sormas.backend.location.LocationJoins) Predicate(javax.persistence.criteria.Predicate) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) BirthDateDto(de.symeda.sormas.api.caze.BirthDateDto) TaskExportDto(de.symeda.sormas.api.task.TaskExportDto) RolesAllowed(javax.annotation.security.RolesAllowed)

Aggregations

TaskExportDto (de.symeda.sormas.api.task.TaskExportDto)2 BirthDateDto (de.symeda.sormas.api.caze.BirthDateDto)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 TaskCriteria (de.symeda.sormas.api.task.TaskCriteria)1 TaskDto (de.symeda.sormas.api.task.TaskDto)1 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)1 CaseQueryContext (de.symeda.sormas.backend.caze.CaseQueryContext)1 ContactQueryContext (de.symeda.sormas.backend.contact.ContactQueryContext)1 LocationJoins (de.symeda.sormas.backend.location.LocationJoins)1 Pseudonymizer (de.symeda.sormas.backend.util.Pseudonymizer)1 Date (java.util.Date)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 Test (org.junit.Test)1