use of de.symeda.sormas.api.labmessage.LabMessageCriteria 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.LabMessageCriteria in project SORMAS-Project by hzi-braunschweig.
the class LabMessageService method getForSample.
public List<LabMessage> getForSample(SampleReferenceDto sample) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<LabMessage> cq = cb.createQuery(LabMessage.class);
Root<LabMessage> labMessageRoot = cq.from(LabMessage.class);
LabMessageCriteria criteria = new LabMessageCriteria();
criteria.setSample(sample);
Predicate filter = buildCriteriaFilter(cb, labMessageRoot, criteria);
cq.where(filter);
cq.distinct(true);
cq.orderBy(cb.desc(labMessageRoot.get(LabMessage.CREATION_DATE)));
return em.createQuery(cq).getResultList();
}
use of de.symeda.sormas.api.labmessage.LabMessageCriteria in project SORMAS-Project by hzi-braunschweig.
the class LabMessageFacadeEjbUnitTest method testCount.
@Test
public void testCount() {
when(em.getCriteriaBuilder()).thenReturn(criteriaBuilder);
when(criteriaBuilder.createQuery(Long.class)).thenReturn(longCriteriaQuery);
when(longCriteriaQuery.from(LabMessage.class)).thenReturn(labMessage);
when(criteriaBuilder.countDistinct(labMessage)).thenReturn(longExpression);
when(em.createQuery(longCriteriaQuery)).thenReturn(longTypedQuery);
long expected = 1L;
when(longTypedQuery.getSingleResult()).thenReturn(expected);
long result = sut.count(new LabMessageCriteria());
assertEquals(expected, result);
}
use of de.symeda.sormas.api.labmessage.LabMessageCriteria 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