Search in sources :

Example 16 with SearchCriteriaBuilder

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

the class ProductionTrackingDocumentsHelper method fillFromBPCProductIn.

public final Multimap<Long, Entity> fillFromBPCProductIn(final List<Entity> trackingOperationProductInComponents, final Entity order, final Entity technologyOperationComponent, final boolean withComponents) {
    SearchCriteriaBuilder scb = getProductionCountingQuantityDD().find().add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.USED.getStringValue()));
    if (Objects.nonNull(technologyOperationComponent)) {
        scb = scb.add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT, technologyOperationComponent));
    }
    List<Entity> productionCountingQuantities = scb.list().getEntities();
    Multimap<Long, Entity> groupedRecordInProducts = ArrayListMultimap.create();
    for (Entity productionCountingQuantity : productionCountingQuantities) {
        Entity warehouse;
        if (withComponents && ProductionCountingQuantityTypeOfMaterial.COMPONENT.getStringValue().equals(productionCountingQuantity.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL))) {
            warehouse = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.COMPONENTS_LOCATION);
        } else if (ProductionCountingQuantityTypeOfMaterial.INTERMEDIATE.getStringValue().equals(productionCountingQuantity.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL)) && L_WAREHOUSE.equals(productionCountingQuantity.getStringField(ProductionCountingQuantityFields.PRODUCTION_FLOW))) {
            warehouse = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_FLOW_LOCATION);
        } else {
            continue;
        }
        Entity product = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.PRODUCT);
        Entity trackingOperationProductInComponent = findProductionRecordByProduct(trackingOperationProductInComponents, product);
        if (Objects.nonNull(trackingOperationProductInComponent)) {
            if (!checkIfProductExists(groupedRecordInProducts, warehouse, product)) {
                groupedRecordInProducts.put(warehouse.getId(), trackingOperationProductInComponent);
            }
        }
    }
    return groupedRecordInProducts;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 17 with SearchCriteriaBuilder

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

the class BalanceContextsCleanUpService method getContextIds.

private Collection<Long> getContextIds() {
    DataDefinition dataDef = getDataDefinition();
    SearchCriteriaBuilder scb = dataDef.find();
    scb.setProjection(SearchProjections.alias(SearchProjections.id(), "id"));
    List<Long> ids = Lists.newLinkedList();
    for (Entity idProjection : scb.list().getEntities()) {
        ids.add((Long) idProjection.getField("id"));
    }
    return ids;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 18 with SearchCriteriaBuilder

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

the class ProductionTrackingStatesHelper method findStateChangeEntity.

private Entity findStateChangeEntity(final Entity productionTracking) {
    DataDefinition stateChangeDD = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_TRACKING_STATE_CHANGE);
    SearchCriteriaBuilder scb = stateChangeDD.find();
    scb.add(SearchRestrictions.belongsTo(ProductionTrackingStateChangeFields.PRODUCTION_TRACKING, productionTracking));
    scb.add(SearchRestrictions.eq(ProductionTrackingStateChangeFields.STATUS, StateChangeStatus.SUCCESSFUL.getStringValue()));
    return scb.setMaxResults(1).uniqueResult();
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 19 with SearchCriteriaBuilder

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

the class OrderClosingHelperTest method stubSearchCriteriaResults.

private void stubSearchCriteriaResults(final Long... ids) {
    SearchCriteriaBuilder scb = mock(SearchCriteriaBuilder.class);
    // blind mock of fluent interface
    given(scb.add(any(SearchCriterion.class))).willReturn(scb);
    given(scb.setProjection(any(SearchProjection.class))).willReturn(scb);
    List<Entity> entities = Lists.newArrayList();
    for (Long id : ids) {
        Entity entity = mock(Entity.class);
        given(entity.getField("id")).willReturn(id);
        entities.add(entity);
    }
    SearchResult result = mock(SearchResult.class);
    given(result.getEntities()).willReturn(entities);
    given(scb.list()).willReturn(result);
    given(productionTrackingDD.find()).willReturn(scb);
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchProjection(com.qcadoo.model.api.search.SearchProjection) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) SearchResult(com.qcadoo.model.api.search.SearchResult)

Example 20 with SearchCriteriaBuilder

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

the class ProductionLinesSearchServiceImpl method findProjections.

private List<Entity> findProjections(final LineSearchMode searchMode, final Long techOrTechGroupId) {
    SearchCriteriaBuilder scb = getProductionLineDataDef().find();
    scb.setProjection(alias(id(), "id"));
    searchMode.appendCriteria(scb, techOrTechGroupId);
    return scb.list().getEntities();
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Aggregations

SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)176 Entity (com.qcadoo.model.api.Entity)82 DataDefinition (com.qcadoo.model.api.DataDefinition)26 Autowired (org.springframework.beans.factory.annotation.Autowired)19 Service (org.springframework.stereotype.Service)19 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)18 EntityList (com.qcadoo.model.api.EntityList)17 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)17 Collectors (java.util.stream.Collectors)17 SearchResult (com.qcadoo.model.api.search.SearchResult)16 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)14 Objects (java.util.Objects)14 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)11 BigDecimal (java.math.BigDecimal)11 Set (java.util.Set)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 CustomRestriction (com.qcadoo.model.api.search.CustomRestriction)8