Search in sources :

Example 1 with LabMessageCriteria

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);
    }
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) LabMessageIndexDto(de.symeda.sormas.api.labmessage.LabMessageIndexDto) LabMessageCriteria(de.symeda.sormas.api.labmessage.LabMessageCriteria)

Example 2 with LabMessageCriteria

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) LabMessageCriteria(de.symeda.sormas.api.labmessage.LabMessageCriteria) Predicate(javax.persistence.criteria.Predicate)

Example 3 with LabMessageCriteria

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);
}
Also used : LabMessageCriteria(de.symeda.sormas.api.labmessage.LabMessageCriteria) Test(org.junit.Test)

Example 4 with LabMessageCriteria

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);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) ArrayList(java.util.ArrayList) LabMessageIndexDto(de.symeda.sormas.api.labmessage.LabMessageIndexDto) LabMessageCriteria(de.symeda.sormas.api.labmessage.LabMessageCriteria) Test(org.junit.Test)

Aggregations

LabMessageCriteria (de.symeda.sormas.api.labmessage.LabMessageCriteria)4 LabMessageIndexDto (de.symeda.sormas.api.labmessage.LabMessageIndexDto)2 SortProperty (de.symeda.sormas.api.utils.SortProperty)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1