use of de.symeda.sormas.api.labmessage.LabMessageIndexDto in project SORMAS-Project by hzi-braunschweig.
the class LabMessageFacadeEjb method getIndexList.
@Override
public List<LabMessageIndexDto> getIndexList(LabMessageCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<LabMessageIndexDto> cq = cb.createQuery(LabMessageIndexDto.class);
Root<LabMessage> labMessage = cq.from(LabMessage.class);
Join<LabMessage, User> userJoin = labMessage.join(LabMessage.ASSIGNEE, JoinType.LEFT);
cq.multiselect(labMessage.get(LabMessage.UUID), labMessage.get(LabMessage.TYPE), labMessage.get(LabMessage.MESSAGE_DATE_TIME), labMessage.get(LabMessage.LAB_NAME), labMessage.get(LabMessage.LAB_POSTAL_CODE), labMessage.get(LabMessage.TESTED_DISEASE), labMessage.get(LabMessage.SAMPLE_OVERALL_TEST_RESULT), labMessage.get(LabMessage.PERSON_FIRST_NAME), labMessage.get(LabMessage.PERSON_LAST_NAME), labMessage.get(LabMessage.PERSON_BIRTH_DATE_YYYY), labMessage.get(LabMessage.PERSON_BIRTH_DATE_MM), labMessage.get(LabMessage.PERSON_BIRTH_DATE_DD), labMessage.get(LabMessage.PERSON_POSTAL_CODE), labMessage.get(LabMessage.STATUS), userJoin.get(User.UUID), userJoin.get(User.FIRST_NAME), userJoin.get(User.LAST_NAME));
Predicate filter = null;
if (criteria != null) {
filter = labMessageService.buildCriteriaFilter(cb, labMessage, criteria);
}
if (filter != null) {
cq.where(filter);
}
// Distinct is necessary here to avoid duplicate results due to the user role join in taskService.createAssigneeFilter
cq.distinct(true);
List<Order> order = new ArrayList<>();
if (!CollectionUtils.isEmpty(sortProperties)) {
for (SortProperty sortProperty : sortProperties) {
if (LabMessageIndexDto.PERSON_BIRTH_DATE.equals(sortProperty.propertyName)) {
Expression<?> birthdateYYYY = labMessage.get(LabMessage.PERSON_BIRTH_DATE_YYYY);
order.add(sortProperty.ascending ? cb.asc(birthdateYYYY) : cb.desc(birthdateYYYY));
Expression<?> birthdateMM = labMessage.get(LabMessage.PERSON_BIRTH_DATE_MM);
order.add(sortProperty.ascending ? cb.asc(birthdateMM) : cb.desc(birthdateMM));
Expression<?> birthdateDD = labMessage.get(LabMessage.PERSON_BIRTH_DATE_DD);
order.add(sortProperty.ascending ? cb.asc(birthdateDD) : cb.desc(birthdateDD));
} else if (VALID_SORT_PROPERTY_NAMES.contains(sortProperty.propertyName)) {
Expression<?> expression = labMessage.get(sortProperty.propertyName);
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
}
}
}
order.add(cb.desc(labMessage.get(LabMessage.MESSAGE_DATE_TIME)));
cq.orderBy(order);
return QueryHelper.getResultList(em, cq, first, max);
}
use of de.symeda.sormas.api.labmessage.LabMessageIndexDto in project SORMAS-Project by hzi-braunschweig.
the class LabMessageGrid method addShowColumn.
protected void addShowColumn(Consumer<LabMessageIndexDto> handler) {
Column<LabMessageIndexDto, String> editColumn = addColumn(entry -> VaadinIcons.EYE.getHtml(), new HtmlRenderer());
editColumn.setId(SHOW_MESSAGE);
editColumn.setSortable(false);
editColumn.setWidth(20);
addItemClickListener(new ShowDetailsListener<>(SHOW_MESSAGE, handler));
}
use of de.symeda.sormas.api.labmessage.LabMessageIndexDto in project SORMAS-Project by hzi-braunschweig.
the class LabMessageGrid method setLazyDataProvider.
public void setLazyDataProvider() {
DataProvider<LabMessageIndexDto, LabMessageCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getLabMessageFacade().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 -> (int) FacadeProvider.getLabMessageFacade().count(query.getFilter().orElse(null)));
setDataProvider(dataProvider);
setSelectionMode(SelectionMode.NONE);
if (dataProviderListener != null) {
dataProvider.addDataProviderListener(dataProviderListener);
}
}
use of de.symeda.sormas.api.labmessage.LabMessageIndexDto in project SORMAS-Project by hzi-braunschweig.
the class LabMessageFacadeEjbUnitTest method testGetIndexList.
@Test
public void testGetIndexList() {
int first = 1;
int max = 1;
when(em.getCriteriaBuilder()).thenReturn(criteriaBuilder);
when(criteriaBuilder.createQuery(LabMessageIndexDto.class)).thenReturn(labMessageIndexDtoCriteriaQuery);
when(labMessageIndexDtoCriteriaQuery.from(LabMessage.class)).thenReturn(labMessage);
when(em.createQuery(labMessageIndexDtoCriteriaQuery)).thenReturn(labMessageIndexDtoTypedQuery);
when(labMessageIndexDtoTypedQuery.setFirstResult(first)).thenReturn(labMessageIndexDtoTypedQuery);
when(labMessageIndexDtoTypedQuery.setMaxResults(max)).thenReturn(labMessageIndexDtoTypedQuery);
ArrayList<LabMessageIndexDto> expectedResult = new ArrayList<>();
when(labMessageIndexDtoTypedQuery.getResultList()).thenReturn(expectedResult);
when(labMessage.join(LabMessage.ASSIGNEE, JoinType.LEFT)).thenReturn(userJoin);
when(userJoin.get((String) any())).thenReturn(null);
ArrayList<SortProperty> sortProperties = new ArrayList<>();
sortProperties.add(new SortProperty(LabMessageIndexDto.UUID));
sortProperties.add(new SortProperty("No Valid Property"));
List<LabMessageIndexDto> result = sut.getIndexList(new LabMessageCriteria(), first, max, sortProperties);
verify(labMessageIndexDtoCriteriaQuery).orderBy(orderListArgumentCaptor.capture());
assertEquals(2, orderListArgumentCaptor.getValue().size());
assertEquals(expectedResult, result);
}
Aggregations