PersonFacadeEjb implements PersonFacade { @Override public List<PersonQuarantineEndDto> getLatestQuarantineEndDates(Date since) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<PersonQuarantineEndDto> cq = cb.createQuery(PersonQuarantineEndDto.class); Root<Contact> contactRoot = cq.from(Contact.class); Join<Contact, Person> personJoin = contactRoot.join(Contact.PERSON, JoinType.LEFT); Predicate filter = contactService.createUserFilter(cb, cq, contactRoot); if (since != null) { filter = PersonService.and(cb, filter, contactService.createChangeDateFilter(cb, contactRoot, since)); } if (filter != null) { cq.where(filter); } cq.multiselect(personJoin.get(Person.UUID), contactRoot.get(Contact.QUARANTINE_TO)); cq.orderBy(cb.asc(personJoin.get(Person.UUID)), cb.desc(contactRoot.get(Contact.QUARANTINE_TO))); return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList()); }  @Override List<String> getAllUuids(); @Override List<PersonNameDto> getMatchingNameDtos(UserReferenceDto userRef, PersonSimilarityCriteria criteria); @Override List<SimilarPersonDto> getSimilarPersonsByUuids(List<String> personUuids); @Override Boolean isValidPersonUuid(String personUuid); @Override Map<Disease, Long> getDeathCountByDisease(CaseCriteria caseCriteria, boolean excludeSharedCases, boolean excludeCasesFromContacts); @Override List<PersonDto> getPersonsAfter(Date date); @Override List<PersonDto> getByUuids(List<String> uuids); @Override List<PersonDto> getDeathsBetween(Date fromDate, Date toDate, DistrictReferenceDto districtRef, Disease disease); @Override PersonReferenceDto getReferenceByUuid(String uuid); @Override PersonDto getPersonByUuid(String uuid); @Override JournalPersonDto getPersonForJournal(String Uuid); @Override PersonDto savePerson(PersonDto source); @Override void validate(PersonDto source); @Override List<PersonQuarantineEndDto> getLatestQuarantineEndDates(Date since); @Override List<PersonFollowUpEndDto> getLatestFollowUpEndDates(Date since, boolean forSymptomJournal); @Override Date getLatestFollowUpEndDateByUuid(String Uuid); @Override boolean setSymptomJournalStatus(String personUuid, SymptomJournalStatus status); void onPersonChanged(PersonDto existingPerson, Person newPerson); Person fillOrBuildEntity(@NotNull PersonDto source, Person target); PersonDto convertToDto(Person p, Pseudonymizer pseudonymizer, boolean inJurisdiction); static PersonReferenceDto toReferenceDto(Person entity); static SimilarPersonDto toSimilarPersonDto(Person entity); static PersonDto toDto(Person source);  }
@Test public void testGetLatestQuarantineEndDates() { RDCFEntities rdcfEntities = creator.createRDCFEntities(); UserDto user = creator.createUser(rdcfEntities, UserRole.REST_EXTERNAL_VISITS_USER); creator.createPerson(); final PersonDto person1 = creator.createPerson(); final PersonDto person2 = creator.createPerson(); final ContactDto contact11 = creator.createContact(user.toReference(), person1.toReference()); final ContactDto contact12 = creator.createContact(user.toReference(), person1.toReference()); final ContactDto contact2 = creator.createContact(user.toReference(), person2.toReference()); Date now = new Date(); contact11.setQuarantineTo(DateHelper.subtractDays(now, 20)); contact12.setQuarantineTo(DateHelper.subtractDays(now, 8)); contact2.setQuarantineTo(now); getContactFacade().saveContact(contact11); getContactFacade().saveContact(contact12); getContactFacade().saveContact(contact2); List<PersonQuarantineEndDto> quarantineEndDtos = getPersonFacade().getLatestQuarantineEndDates(null); assertThat(quarantineEndDtos, hasSize(2)); Optional<PersonQuarantineEndDto> result1 = quarantineEndDtos.stream().filter(p -> p.getPersonUuid().equals(person1.getUuid())).findFirst(); assertTrue(result1.isPresent()); assertTrue(DateHelper.isSameDay(result1.get().getLatestQuarantineEndDate(), DateHelper.subtractDays(now, 8))); Optional<PersonQuarantineEndDto> result2 = quarantineEndDtos.stream().filter(p -> p.getPersonUuid().equals(person2.getUuid())).findFirst(); assertTrue(result2.isPresent()); assertTrue(DateHelper.isSameDay(result2.get().getLatestQuarantineEndDate(), now)); }