Search in sources :

Example 1 with LabMessageIndexDto

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);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) User(de.symeda.sormas.backend.user.User) ArrayList(java.util.ArrayList) LabMessageIndexDto(de.symeda.sormas.api.labmessage.LabMessageIndexDto) Predicate(javax.persistence.criteria.Predicate) SortProperty(de.symeda.sormas.api.utils.SortProperty) Expression(javax.persistence.criteria.Expression)

Example 2 with LabMessageIndexDto

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));
}
Also used : LabMessageIndexDto(de.symeda.sormas.api.labmessage.LabMessageIndexDto) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer)

Example 3 with LabMessageIndexDto

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

Example 4 with LabMessageIndexDto

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);
}
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

LabMessageIndexDto (de.symeda.sormas.api.labmessage.LabMessageIndexDto)4 SortProperty (de.symeda.sormas.api.utils.SortProperty)3 LabMessageCriteria (de.symeda.sormas.api.labmessage.LabMessageCriteria)2 ArrayList (java.util.ArrayList)2 HtmlRenderer (com.vaadin.ui.renderers.HtmlRenderer)1 User (de.symeda.sormas.backend.user.User)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Expression (javax.persistence.criteria.Expression)1 Order (javax.persistence.criteria.Order)1 Predicate (javax.persistence.criteria.Predicate)1 Test (org.junit.Test)1