Search in sources :

Example 26 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class RegionsGrid method setLazyDataProvider.

public void setLazyDataProvider() {
    DataProvider<RegionIndexDto, RegionCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getRegionFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> {
        return (int) FacadeProvider.getRegionFacade().count(query.getFilter().orElse(null));
    });
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : RegionIndexDto(de.symeda.sormas.api.infrastructure.region.RegionIndexDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) RegionCriteria(de.symeda.sormas.api.infrastructure.region.RegionCriteria)

Example 27 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class CaseFacadeEjbTest method testGetIndexList.

@Test
public void testGetIndexList() {
    String districtName = "District";
    RDCF rdcf = creator.createRDCF("Region", districtName, "Community", "Facility");
    useSurveillanceOfficerLogin(rdcf);
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    String lastName = "Person";
    PersonDto cazePerson = creator.createPerson("Case", lastName);
    creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf, c -> c.setHealthFacilityDetails("abc"));
    creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf, c -> c.setHealthFacilityDetails("xyz"));
    List<CaseIndexDto> results = getCaseFacade().getIndexList(null, 0, 100, Arrays.asList(new SortProperty(CaseIndexDto.DISEASE), new SortProperty(CaseIndexDto.PERSON_FIRST_NAME), new SortProperty(CaseIndexDto.RESPONSIBLE_DISTRICT_NAME), new SortProperty(CaseIndexDto.HEALTH_FACILITY_NAME, false), new SortProperty(CaseIndexDto.SURVEILLANCE_OFFICER_UUID)));
    // List should have one entry
    assertEquals(3, results.size());
    assertEquals(districtName, results.get(0).getResponsibleDistrictName());
    assertEquals(lastName, results.get(0).getPersonLastName());
    assertEquals("Facility - xyz", results.get(0).getHealthFacilityName());
    assertEquals("Facility - abc", results.get(1).getHealthFacilityName());
    assertEquals("Facility", results.get(2).getHealthFacilityName());
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CasePersonDto(de.symeda.sormas.api.caze.CasePersonDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Date(java.util.Date) LocalDate(java.time.LocalDate) CaseIndexDto(de.symeda.sormas.api.caze.CaseIndexDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 28 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class ContactFacadeEjbTest method testGetIndexDetailedList.

@Test
public void testGetIndexDetailedList() {
    ContactCriteria contactCriteria = new ContactCriteria();
    contactCriteria.setIncludeContactsFromOtherJurisdictions(true);
    List<SortProperty> sortProperties = Collections.emptyList();
    List<ContactIndexDetailedDto> result;
    // 0. No data: empty list
    result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
    assertThat(result, is(empty()));
    // Create needed structural data
    RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    UserReferenceDto reportingUser = new UserReferenceDto(user.getUuid());
    EventDto event1 = creator.createEvent(reportingUser, DateHelper.subtractDays(new Date(), 1));
    EventDto event2 = creator.createEvent(reportingUser, new Date());
    PersonDto contactPerson = creator.createPerson("Contact", "Person");
    ContactDto contact1 = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
    // 1a. one Contact without Event
    result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
    assertThat(result, hasSize(1));
    {
        ContactIndexDetailedDto dto = result.get(0);
        assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
        assertThat(dto.getEventCount(), equalTo(0L));
        assertNull(dto.getLatestEventId());
        assertNull(dto.getLatestEventTitle());
        assertThat(dto.getVisitCount(), equalTo(0));
    }
    // 1b. one Contact with one Event
    creator.createEventParticipant(new EventReferenceDto(event1.getUuid()), contactPerson, reportingUser);
    result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
    assertThat(result, hasSize(1));
    {
        ContactIndexDetailedDto dto = result.get(0);
        assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
        assertThat(dto.getEventCount(), equalTo(1L));
        assertThat(dto.getLatestEventId(), equalTo(event1.getUuid()));
        assertThat(dto.getLatestEventTitle(), equalTo(event1.getEventTitle()));
        assertThat(dto.getVisitCount(), equalTo(0));
    }
    // 1c. one Contact with two Events, second is leading
    creator.createEventParticipant(new EventReferenceDto(event2.getUuid()), contactPerson, reportingUser);
    result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
    assertThat(result, hasSize(1));
    {
        ContactIndexDetailedDto dto = result.get(0);
        assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
        assertThat(dto.getEventCount(), equalTo(2L));
        assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
        assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
        assertThat(dto.getVisitCount(), equalTo(0));
    }
    // 1d. one Contact with two Events and one visit
    creator.createVisit(new PersonReferenceDto(contactPerson.getUuid()));
    result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
    assertThat(result, hasSize(1));
    {
        ContactIndexDetailedDto dto = result.get(0);
        assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
        assertThat(dto.getEventCount(), equalTo(2L));
        assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
        assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
        assertThat(dto.getVisitCount(), equalTo(1));
    }
    // 1e. one Contact with two Events and three visits
    creator.createVisit(new PersonReferenceDto(contactPerson.getUuid()));
    creator.createVisit(new PersonReferenceDto(contactPerson.getUuid()));
    result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
    assertThat(result, hasSize(1));
    {
        ContactIndexDetailedDto dto = result.get(0);
        assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
        assertThat(dto.getEventCount(), equalTo(2L));
        assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
        assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
        assertThat(dto.getVisitCount(), equalTo(3));
    }
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) EventDto(de.symeda.sormas.api.event.EventDto) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto) Date(java.util.Date) LocalDate(java.time.LocalDate) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 29 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class UserGrid method setLazyDataProvider.

public void setLazyDataProvider() {
    DataProvider<UserDto, UserCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getUserFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> {
        return (int) FacadeProvider.getUserFacade().count(query.getFilter().orElse(null));
    });
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) UserCriteria(de.symeda.sormas.api.user.UserCriteria) UserDto(de.symeda.sormas.api.user.UserDto)

Example 30 with SortProperty

use of de.symeda.sormas.api.utils.SortProperty in project SORMAS-Project by hzi-braunschweig.

the class DistrictFacadeEjb method getIndexList.

@Override
public List<DistrictIndexDto> getIndexList(DistrictCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<District> cq = cb.createQuery(District.class);
    Root<District> district = cq.from(District.class);
    Join<District, Region> region = district.join(District.REGION, JoinType.LEFT);
    Predicate filter = null;
    if (criteria != null) {
        filter = service.buildCriteriaFilter(criteria, cb, district);
    }
    if (filter != null) {
        cq.where(filter);
    }
    if (CollectionUtils.isNotEmpty(sortProperties)) {
        List<Order> order = new ArrayList<>(sortProperties.size());
        for (SortProperty sortProperty : sortProperties) {
            Expression<?> expression;
            switch(sortProperty.propertyName) {
                case District.NAME:
                case District.EPID_CODE:
                case District.GROWTH_RATE:
                case District.EXTERNAL_ID:
                    expression = district.get(sortProperty.propertyName);
                    break;
                case District.REGION:
                    expression = region.get(Region.NAME);
                    break;
                default:
                    throw new IllegalArgumentException(sortProperty.propertyName);
            }
            order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
        }
        cq.orderBy(order);
    } else {
        cq.orderBy(cb.asc(region.get(Region.NAME)), cb.asc(district.get(District.NAME)));
    }
    cq.select(district);
    return QueryHelper.getResultList(em, cq, first, max, this::toIndexDto);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty) Region(de.symeda.sormas.backend.infrastructure.region.Region)

Aggregations

SortProperty (de.symeda.sormas.api.utils.SortProperty)73 ArrayList (java.util.ArrayList)42 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)37 Order (javax.persistence.criteria.Order)37 Predicate (javax.persistence.criteria.Predicate)34 Date (java.util.Date)14 District (de.symeda.sormas.backend.infrastructure.district.District)13 Region (de.symeda.sormas.backend.infrastructure.region.Region)10 Pseudonymizer (de.symeda.sormas.backend.util.Pseudonymizer)10 PersonDto (de.symeda.sormas.api.person.PersonDto)9 Location (de.symeda.sormas.backend.location.Location)8 AbstractDomainObject (de.symeda.sormas.backend.common.AbstractDomainObject)7 Person (de.symeda.sormas.backend.person.Person)7 User (de.symeda.sormas.backend.user.User)7 Collectors (java.util.stream.Collectors)6 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)5 UserDto (de.symeda.sormas.api.user.UserDto)5 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)5 Case (de.symeda.sormas.backend.caze.Case)5 Selection (javax.persistence.criteria.Selection)5