EventFacadeEjb implements EventFacade { @Override public List<EventExportDto> getExportList(EventCriteria eventCriteria, Integer first, Integer max) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<EventExportDto> cq = cb.createQuery(EventExportDto.class); Root<Event> event = cq.from(Event.class); Join<Event, Location> location = event.join(Event.EVENT_LOCATION, JoinType.LEFT); Join<Location, Region> region = location.join(Location.REGION, JoinType.LEFT); Join<Location, District> district = location.join(Location.DISTRICT, JoinType.LEFT); Join<Location, Community> community = location.join(Location.COMMUNITY, JoinType.LEFT); Subquery<Long> participantCount = cq.subquery(Long.class); Root<EventParticipant> eventParticipantRoot = participantCount.from(EventParticipant.class); Predicate assignedToEvent = cb.equal(eventParticipantRoot.get(EventParticipant.EVENT), event.get(AbstractDomainObject.ID)); Predicate notDeleted = cb.isFalse(eventParticipantRoot.get(EventParticipant.DELETED)); participantCount.select(cb.count(eventParticipantRoot)); participantCount.where(assignedToEvent, notDeleted); cq.multiselect( event.get(Event.UUID), event.get(Event.EXTERNAL_ID), event.get(Event.EVENT_STATUS), participantCount, event.get(Event.DISEASE), event.get(Event.DISEASE_DETAILS), event.get(Event.START_DATE), event.get(Event.END_DATE), event.get(Event.EVENT_TITLE), event.get(Event.EVENT_DESC), event.get(Event.NOSOCOMIAL), region.get(Region.UUID), region.get(Region.NAME), district.get(District.UUID), district.get(District.NAME), community.get(Community.UUID), community.get(Community.NAME), location.get(Location.CITY), location.get(Location.STREET), location.get(Location.HOUSE_NUMBER), location.get(Location.ADDITIONAL_INFORMATION), event.get(Event.SRC_TYPE), event.get(Event.SRC_FIRST_NAME), event.get(Event.SRC_LAST_NAME), event.get(Event.SRC_TEL_NO), event.get(Event.SRC_EMAIL), event.get(Event.SRC_MEDIA_WEBSITE), event.get(Event.SRC_MEDIA_NAME), event.get(Event.SRC_MEDIA_DETAILS), event.get(Event.REPORT_DATE_TIME), event.join(Event.REPORTING_USER, JoinType.LEFT).get(User.UUID), event.join(Event.SURVEILLANCE_OFFICER, JoinType.LEFT).get(User.UUID)); Predicate filter = eventService.createUserFilter(cb, cq, event); if (eventCriteria != null) { Predicate criteriaFilter = eventService.buildCriteriaFilter(eventCriteria, cb, event); filter = AbstractAdoService.and(cb, filter, criteriaFilter); } cq.where(filter); cq.orderBy(cb.desc(event.get(Event.REPORT_DATE_TIME))); List<EventExportDto> exportList; if (first != null && max != null) { exportList = em.createQuery(cq).setFirstResult(first).setMaxResults(max).getResultList(); } else { exportList = em.createQuery(cq).getResultList(); } return exportList; }  @Override List<String> getAllActiveUuids(); @Override List<EventDto> getAllActiveEventsAfter(Date date); @Override List<EventDto> getByUuids(List<String> uuids); @Override List<String> getDeletedUuidsSince(Date since); @Override List<DashboardEventDto> getNewEventsForDashboard(EventCriteria eventCriteria); Map<Disease, Long> getEventCountByDisease(EventCriteria eventCriteria); Map<EventStatus, Long> getEventCountByStatus(EventCriteria eventCriteria); @Override EventDto getEventByUuid(String uuid); @Override EventReferenceDto getReferenceByUuid(String uuid); @Override EventDto saveEvent(EventDto dto); @Override void deleteEvent(String eventUuid); @Override long count(EventCriteria eventCriteria); @Override List<EventIndexDto> getIndexList(EventCriteria eventCriteria, Integer first, Integer max, List<SortProperty> sortProperties); @Override List<EventExportDto> getExportList(EventCriteria eventCriteria, Integer first, Integer max); @Override boolean isArchived(String eventUuid); @Override boolean isDeleted(String eventUuid); @Override void archiveOrDearchiveEvent(String eventUuid, boolean archive); @Override List<String> getArchivedUuidsSince(Date since); Event fromDto(@NotNull EventDto source); EventDto convertToDto(Event source, Pseudonymizer pseudonymizer); static EventReferenceDto toReferenceDto(Event entity); static EventDto toDto(Event source); @Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) void archiveAllArchivableEvents(int daysAfterEventGetsArchived); @Override boolean exists(String uuid); @Override String getUuidByCaseUuidOrPersonUuid(String searchTerm); Boolean isEventEditAllowed(String eventUuid);  }
@Test public void testGetExportList() { RDCF rdcf = creator.createRDCF(); UserDto user = creator.createUser(rdcf, UserRole.SURVEILLANCE_SUPERVISOR); 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); EventCriteria eventCriteria = new EventCriteria(); eventCriteria.setDisease(Disease.EVD); List<EventExportDto> results = getEventFacade().getExportList(eventCriteria, 0, 100); assertThat(results, Matchers.hasSize(1)); }