EventFacadeEjb implements EventFacade { @Override public List<EventIndexDto> getIndexList(EventCriteria eventCriteria, Integer first, Integer max, List<SortProperty> sortProperties) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<EventIndexDto> cq = cb.createQuery(EventIndexDto.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.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), 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_MEDIA_WEBSITE), event.get(Event.SRC_MEDIA_NAME), 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 = null; if (eventCriteria.getUserFilterIncluded()) { eventService.createUserFilter(cb, cq, event); } if (eventCriteria != null) { Predicate criteriaFilter = eventService.buildCriteriaFilter(eventCriteria, cb, event); filter = AbstractAdoService.and(cb, filter, criteriaFilter); } cq.where(filter); if (sortProperties != null && sortProperties.size() > 0) { List<Order> order = new ArrayList<Order>(sortProperties.size()); for (SortProperty sortProperty : sortProperties) { Expression<?> expression; switch (sortProperty.propertyName) { case EventIndexDto.UUID: case EventIndexDto.EVENT_STATUS: case EventIndexDto.DISEASE: case EventIndexDto.DISEASE_DETAILS: case EventIndexDto.START_DATE: case EventIndexDto.EVENT_TITLE: case EventIndexDto.SRC_FIRST_NAME: case EventIndexDto.SRC_LAST_NAME: case EventIndexDto.SRC_TEL_NO: case EventIndexDto.SRC_TYPE: case EventIndexDto.REPORT_DATE_TIME: expression = event.get(sortProperty.propertyName); break; case EventIndexDto.EVENT_LOCATION: expression = region.get(Region.NAME); order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression)); expression = district.get(District.NAME); order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression)); expression = community.get(Community.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.desc(event.get(Contact.CHANGE_DATE))); } List<EventIndexDto> indexList; if (first != null && max != null) { indexList = em.createQuery(cq).setFirstResult(first).setMaxResults(max).getResultList(); } else { indexList = em.createQuery(cq).getResultList(); } return indexList; }  @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 testGetIndexList() { 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); creator.createEvent( EventStatus.SIGNAL, "TitleEv1", "DescriptionEv1", "First", "Name", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 1), new Date(), user.toReference(), user.toReference(), Disease.EVD, rdcf.district); creator.createEvent( EventStatus.EVENT, "TitleEv2", "DescriptionEv2", "First", "Name", "12345", TypeOfPlace.HOSPITAL, DateHelper.subtractDays(new Date(), 1), new Date(), user.toReference(), user.toReference(), Disease.EVD, rdcf.district); EventCriteria eventCriteria = new EventCriteria(); List<EventIndexDto> results = getEventFacade().getIndexList(eventCriteria, 0, 100, null); assertEquals(2, results.size()); eventCriteria.eventStatus(EventStatus.SIGNAL); results = getEventFacade().getIndexList(eventCriteria, 0, 100, null); assertEquals(1, results.size()); assertEquals("TitleEv1", results.get(0).getEventTitle()); eventCriteria.eventStatus(null); eventCriteria.setTypeOfPlace(TypeOfPlace.HOSPITAL); results = getEventFacade().getIndexList(eventCriteria, 0, 100, null); assertEquals(1, results.size()); assertEquals("TitleEv2", results.get(0).getEventTitle()); }