Search in sources :

Example 21 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.

the class WorkPlanServiceImplTest method shouldReturnEmptyListIfOrdersWithGivenIdDoesNotExist.

@Test
public final void shouldReturnEmptyListIfOrdersWithGivenIdDoesNotExist() throws Exception {
    // given
    Entity order1 = mock(Entity.class);
    when(order1.getId()).thenReturn(1L);
    Entity order2 = mock(Entity.class);
    when(order2.getId()).thenReturn(2L);
    Entity order3 = mock(Entity.class);
    when(order3.getId()).thenReturn(3L);
    @SuppressWarnings("unchecked") Iterator<Long> iterator = mock(Iterator.class);
    when(iterator.hasNext()).thenReturn(true, true, true, true, false);
    when(iterator.next()).thenReturn(1L, 2L, 3L, 4L);
    @SuppressWarnings("unchecked") Set<Long> selectedOrderIds = mock(Set.class);
    when(selectedOrderIds.iterator()).thenReturn(iterator);
    when(selectedOrderIds.size()).thenReturn(4);
    SearchCriteriaBuilder criteria = mock(SearchCriteriaBuilder.class);
    when(criteria.add(Mockito.any(SearchCriterion.class))).thenReturn(criteria);
    SearchResult result = mock(SearchResult.class);
    when(criteria.list()).thenReturn(result);
    when(result.getTotalNumberOfEntities()).thenReturn(0);
    DataDefinition orderDD = mock(DataDefinition.class);
    when(orderDD.find()).thenReturn(criteria);
    when(dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER)).thenReturn(orderDD);
    // when
    List<Entity> resultList = workPlanService.getSelectedOrders(selectedOrderIds);
    // then
    Assert.assertEquals(0, resultList.size());
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) SearchResult(com.qcadoo.model.api.search.SearchResult) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 22 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.

the class DocumentPositionParametersItemModelValidators method validate.

public boolean validate(final DataDefinition itemDD, final Entity item) {
    if (!item.getBooleanField("checked")) {
        String name = item.getStringField("name");
        switch(name) {
            case DocumentPositionParametersItemValues.PRICE:
            case DocumentPositionParametersItemValues.BATCH:
            case DocumentPositionParametersItemValues.PRODUCTION_DATE:
            case DocumentPositionParametersItemValues.EXPIRATION_DATE:
                DataDefinition locationDD = dataDefinitionService.get(MaterialFlowConstants.PLUGIN_IDENTIFIER, MaterialFlowConstants.MODEL_LOCATION);
                String camelCaseName = "require" + name.substring(0, 1).toUpperCase() + name.substring(1);
                SearchResult result = locationDD.find().add(SearchRestrictions.eq(camelCaseName, true)).setMaxResults(1).list();
                if (result.getTotalNumberOfEntities() > 0) {
                    String locationName = result.getEntities().get(0).getStringField(LocationFields.NAME);
                    String fieldTranslatedName = translationService.translate("materialFlowResources.materialFlowResourcesParameters.documentPositionParameters." + name, LocaleContextHolder.getLocale());
                    String errorMessage = translationService.translate("materialFlowResources.error.documentLocationPositionItemCantBeHidden", LocaleContextHolder.getLocale());
                    errorMessage = String.format(errorMessage, fieldTranslatedName, locationName);
                    item.addError(itemDD.getField("checked"), errorMessage);
                    return false;
                }
        }
    }
    return true;
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 23 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.

the class ProductionCountingOrderStatesListenerService method checkIfOrderHasFinalProductionTrackings.

private boolean checkIfOrderHasFinalProductionTrackings(final Entity order, final Entity technologyOperationComponent) {
    final SearchCriteriaBuilder searchCriteriaBuilder = productionCountingService.getProductionTrackingDD().find().add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order)).add(SearchRestrictions.eq(ProductionTrackingFields.LAST_TRACKING, true));
    if (Objects.nonNull(technologyOperationComponent)) {
        searchCriteriaBuilder.add(SearchRestrictions.belongsTo(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT, technologyOperationComponent));
    }
    SearchResult searchResult = searchCriteriaBuilder.list();
    return (searchResult.getTotalNumberOfEntities() > 0);
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult)

Example 24 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.

the class MessageServiceImpl method messageAlreadyExists.

@Override
public boolean messageAlreadyExists(final Entity message) {
    final SearchCriteriaBuilder criteriaBuilder = getDataDefinition().find();
    criteriaBuilder.add(SearchRestrictions.allEq(message.getFields()));
    final SearchResult result = criteriaBuilder.list();
    return result.getTotalNumberOfEntities() > 0;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchResult(com.qcadoo.model.api.search.SearchResult)

Example 25 with SearchResult

use of com.qcadoo.model.api.search.SearchResult in project mes by qcadoo.

the class TSFOrderSuppliesOrderStateValidationService method areSubcontracedOperations.

private boolean areSubcontracedOperations(final Entity order) {
    Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
    SearchResult searchResult = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT).find().add(SearchRestrictions.belongsTo(TechnologyOperationComponentFields.TECHNOLOGY, technology)).add(SearchRestrictions.eq(TechnologyOperationComponentFieldsTS.IS_SUBCONTRACTING, true)).list();
    return !searchResult.getEntities().isEmpty();
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchResult(com.qcadoo.model.api.search.SearchResult)

Aggregations

SearchResult (com.qcadoo.model.api.search.SearchResult)35 Entity (com.qcadoo.model.api.Entity)18 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 DataDefinition (com.qcadoo.model.api.DataDefinition)10 Test (org.junit.Test)10 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)7 SearchProjection (com.qcadoo.model.api.search.SearchProjection)4 FieldEntityIdChangeListener (com.qcadoo.view.internal.FieldEntityIdChangeListener)4 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)4 BigDecimal (java.math.BigDecimal)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 SearchQueryBuilder (com.qcadoo.model.api.search.SearchQueryBuilder)2 Date (java.util.Date)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ImmutableList (com.google.common.collect.ImmutableList)1 ProductWithQuantityAndCost (com.qcadoo.mes.costNormsForMaterials.orderRawMaterialCosts.domain.ProductWithQuantityAndCost)1 Monitorable (com.qcadoo.model.api.aop.Monitorable)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)1 LocalDate (java.time.LocalDate)1