EventParticipantFacadeEjb implements EventParticipantFacade { @Override public List<EventParticipantExportDto> getExportList( EventParticipantCriteria eventParticipantCriteria, int first, int max, Language userLanguage) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<EventParticipantExportDto> cq = cb.createQuery(EventParticipantExportDto.class); Root<EventParticipant> eventParticipant = cq.from(EventParticipant.class); Join<EventParticipant, Person> person = eventParticipant.join(EventParticipant.PERSON, JoinType.LEFT); Join<Person, Location> address = person.join(Person.ADDRESS); Join<EventParticipant, Event> event = eventParticipant.join(EventParticipant.EVENT, JoinType.LEFT); Join<Event, Location> eventLocation = event.join(Event.EVENT_LOCATION, JoinType.LEFT); Join<EventParticipant, Case> resultingCase = eventParticipant.join(EventParticipant.RESULTING_CASE, JoinType.LEFT); cq.multiselect( eventParticipant.get(EventParticipant.ID), person.get(Person.ID), person.get(Person.UUID), eventParticipant.get(EventParticipant.UUID), person.get(Person.NATIONAL_HEALTH_ID), person.get(Location.ID), eventParticipant.join(EventParticipant.REPORTING_USER, JoinType.LEFT).get(User.UUID), event.get(Event.UUID), event.get(Event.EVENT_STATUS), event.get(Event.DISEASE), event.get(Event.TYPE_OF_PLACE), event.get(Event.START_DATE), event.get(Event.END_DATE), event.get(Event.EVENT_TITLE), event.get(Event.EVENT_DESC), eventLocation.join(Location.REGION, JoinType.LEFT).get(Region.NAME), eventLocation.join(Location.DISTRICT, JoinType.LEFT).get(District.NAME), eventLocation.join(Location.COMMUNITY, JoinType.LEFT).get(Community.NAME), eventLocation.get(Location.CITY), eventLocation.get(Location.STREET), eventLocation.get(Location.HOUSE_NUMBER), person.get(Person.FIRST_NAME), person.get(Person.LAST_NAME), person.get(Person.SEX), eventParticipant.get(EventParticipant.INVOLVEMENT_DESCRIPTION), person.get(Person.APPROXIMATE_AGE), person.get(Person.APPROXIMATE_AGE_TYPE), person.get(Person.BIRTHDATE_DD), person.get(Person.BIRTHDATE_MM), person.get(Person.BIRTHDATE_YYYY), person.get(Person.PRESENT_CONDITION), person.get(Person.DEATH_DATE), person.get(Person.BURIAL_DATE), person.get(Person.BURIAL_CONDUCTOR), person.get(Person.BURIAL_PLACE_DESCRIPTION), address.join(Location.REGION, JoinType.LEFT).get(Region.NAME), address.join(Location.DISTRICT, JoinType.LEFT).get(District.NAME), address.join(Location.COMMUNITY, JoinType.LEFT).get(Community.NAME), address.get(Location.CITY), address.get(Location.STREET), address.get(Location.HOUSE_NUMBER), address.get(Location.ADDITIONAL_INFORMATION), address.get(Location.POSTAL_CODE), person.get(Person.PHONE), resultingCase.get(Case.UUID)); Predicate filter = eventParticipantService.buildCriteriaFilter(eventParticipantCriteria, cb, eventParticipant); cq.where(filter); List<EventParticipantExportDto> eventParticipantResultList = em.createQuery(cq).setFirstResult(first).setMaxResults(max).getResultList(); if (!eventParticipantResultList.isEmpty()) { Map<Long, Location> personAddresses = null; List<Location> personAddressesList = null; CriteriaQuery<Location> personAddressesCq = cb.createQuery(Location.class); Root<Location> personAddressesRoot = personAddressesCq.from(Location.class); Expression<String> personAddressesIdsExpr = personAddressesRoot.get(Location.ID); personAddressesCq.where( personAddressesIdsExpr .in(eventParticipantResultList.stream().map(EventParticipantExportDto::getPersonAddressId).collect(Collectors.toList()))); personAddressesList = em.createQuery(personAddressesCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList(); personAddresses = personAddressesList.stream().collect(Collectors.toMap(Location::getId, Function.identity())); Map<Long, List<Sample>> samples = null; List<Sample> samplesList = null; CriteriaQuery<Sample> samplesCq = cb.createQuery(Sample.class); Root<Sample> samplesRoot = samplesCq.from(Sample.class); Join<Sample, EventParticipant> samplesEventParticipantJoin = samplesRoot.join(Sample.ASSOCIATED_EVENT_PARTICIPANT, JoinType.LEFT); Expression<String> eventParticipantIdsExpr = samplesEventParticipantJoin.get(EventParticipant.ID); samplesCq.where( eventParticipantIdsExpr.in(eventParticipantResultList.stream().map(EventParticipantExportDto::getId).collect(Collectors.toList()))); samplesList = em.createQuery(samplesCq).setHint(ModelConstants.HINT_HIBERNATE_READ_ONLY, true).getResultList(); samples = samplesList.stream().collect(Collectors.groupingBy(s -> s.getAssociatedEventParticipant().getId())); Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue)); for (EventParticipantExportDto exportDto : eventParticipantResultList) { final boolean inJurisdiction = eventParticipantJurisdictionChecker.isInJurisdictionOrOwned(exportDto.getJurisdiction()); if (personAddresses != null) { Optional.ofNullable(personAddresses.get(exportDto.getPersonAddressId())) .ifPresent(personAddress -> exportDto.setAddressGpsCoordinates(personAddress.buildGpsCoordinatesCaption())); } if (samples != null) { Optional.ofNullable(samples.get(exportDto.getId())).ifPresent(eventParticipantSamples -> { int count = 0; for (Sample sample : eventParticipantSamples) { EmbeddedSampleExportDto sampleDto = new EmbeddedSampleExportDto( sample.getSampleDateTime(), sample.getLab() != null ? FacilityHelper.buildFacilityString(sample.getLab().getUuid(), sample.getLab().getName(), sample.getLabDetails()) : null, sample.getPathogenTestResult()); exportDto.addEventParticipantSample(sampleDto); } }); } pseudonymizer.pseudonymizeDto(EventParticipantExportDto.class, exportDto, inJurisdiction, (c) -> { pseudonymizer.pseudonymizeDto(BirthDateDto.class, c.getBirthdate(), inJurisdiction, null); pseudonymizer.pseudonymizeDtoCollection(EmbeddedSampleExportDto.class, c.getEventParticipantSamples(), s -> inJurisdiction, null); pseudonymizer.pseudonymizeDto(BurialInfoDto.class, c.getBurialInfo(), inJurisdiction, null); }); } } return eventParticipantResultList; }  @Override List<EventParticipantDto> getAllEventParticipantsByEventAfter(Date date, String eventUuid); @Override List<String> getAllActiveUuids(); @Override List<EventParticipantDto> getAllActiveEventParticipantsAfter(Date date); @Override List<String> getDeletedUuidsSince(Date since); @Override List<EventParticipantDto> getByUuids(List<String> uuids); @Override EventParticipantDto getEventParticipantByUuid(String uuid); @Override EventParticipantDto saveEventParticipant(EventParticipantDto dto); @Override void validate(EventParticipantDto eventParticipant); @Override void deleteEventParticipant(EventParticipantReferenceDto eventParticipantRef); @Override List<EventParticipantIndexDto> getIndexList(
		EventParticipantCriteria eventParticipantCriteria,
		Integer first,
		Integer max,
		List<SortProperty> sortProperties); @Override List<EventParticipantExportDto> getExportList(
		EventParticipantCriteria eventParticipantCriteria,
		int first,
		int max,
		Language userLanguage); @Override long count(EventParticipantCriteria eventParticipantCriteria); @Override boolean exists(String uuid); @Override EventParticipantReferenceDto getReferenceByUuid(String uuid); @Override boolean isEventParticipantEditAllowed(String uuid); EventParticipant fromDto(@NotNull EventParticipantDto source); static EventParticipantReferenceDto toReferenceDto(EventParticipant entity); static EventParticipantDto toDto(EventParticipant source); @Override List<EventParticipantDto> getAllActiveEventParticipantsByEvent(String eventUuid);  }
@Test public void testGetExportList() { TestDataCreator.RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility"); UserDto user = creator .createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR); EventDto event = creator.createEvent( EventStatus.SIGNAL, "Title", "Description", "First", "Name", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 1), new Date(), user.toReference(), user.toReference(), Disease.EVD, rdcf.district); PersonDto eventPerson = creator.createPerson("Event", "Organizer"); creator.createEventParticipant(event.toReference(), eventPerson, "event Director", user.toReference()); PersonDto eventPerson1 = creator.createPerson("Event", "Participant"); creator.createEventParticipant(event.toReference(), eventPerson1, "event fan", user.toReference()); EventParticipantCriteria eventParticipantCriteria = new EventParticipantCriteria(); eventParticipantCriteria.event(event.toReference()); List<EventParticipantExportDto> results = getEventParticipantFacade().getExportList(eventParticipantCriteria, 0, 100, Language.EN); assertThat(results, Matchers.hasSize(2)); }