Search in sources :

Example 11 with SearchCriteriaBuilder

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

the class UseReplacementCriteriaModifiers method filter.

public void filter(final SearchCriteriaBuilder scb, final FilterValueHolder filterValue) {
    if (filterValue.has("BASIC_PRODUCT_ID")) {
        Entity basicProduct = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(filterValue.getLong("BASIC_PRODUCT_ID"));
        List<Entity> replacements = basicProduct.getHasManyField(ProductFields.SUBSTITUTE_COMPONENTS);
        List<Long> ids = replacements.stream().filter(r -> Objects.nonNull(r.getBelongsToField(SubstituteComponentFields.PRODUCT))).map(r -> r.getBelongsToField(SubstituteComponentFields.PRODUCT).getId()).collect(Collectors.toList());
        scb.add(SearchRestrictions.in("id", ids));
    } else {
        scb.add(SearchRestrictions.idEq(-1));
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) Autowired(org.springframework.beans.factory.annotation.Autowired) SubstituteComponentFields(com.qcadoo.mes.basic.constants.SubstituteComponentFields) Collectors(java.util.stream.Collectors) FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) Objects(java.util.Objects) Entity(com.qcadoo.model.api.Entity) List(java.util.List) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Service(org.springframework.stereotype.Service) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) Entity(com.qcadoo.model.api.Entity)

Example 12 with SearchCriteriaBuilder

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

the class ProductionTrackingListenerService method getInProductionCountingQuantities.

private List<Entity> getInProductionCountingQuantities(Entity trackingOperationProductComponent, Entity order, Entity technologyOperationComponent, boolean isForEach) {
    Entity product = trackingOperationProductComponent.getBelongsToField(L_PRODUCT);
    SearchCriteriaBuilder scb = order.getHasManyField(OrderFieldsBPC.PRODUCTION_COUNTING_QUANTITIES).find().add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.USED.getStringValue())).add(SearchRestrictions.in(ProductionCountingQuantityFields.TYPE_OF_MATERIAL, Lists.newArrayList(ProductionCountingQuantityTypeOfMaterial.COMPONENT.getStringValue(), ProductionCountingQuantityTypeOfMaterial.INTERMEDIATE.getStringValue()))).add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.PRODUCT, product));
    if (isForEach && Objects.nonNull(technologyOperationComponent)) {
        Entity toc = technologyOperationComponent.getDataDefinition().get(technologyOperationComponent.getId());
        scb = scb.add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT, toc));
    }
    return scb.list().getEntities();
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 13 with SearchCriteriaBuilder

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

the class ProductionTrackingListenerService method checkIfUsedOrWastesQuantitiesWereNotFilled.

public boolean checkIfUsedOrWastesQuantitiesWereNotFilled(final Entity productionTracking) {
    Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
    final SearchCriteriaBuilder searchBuilder = productionTracking.getHasManyField(ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_OUT_COMPONENTS).find().add(SearchRestrictions.or(SearchRestrictions.isNotNull(TrackingOperationProductOutComponentFields.USED_QUANTITY), SearchRestrictions.isNotNull(TrackingOperationProductOutComponentFields.WASTES_QUANTITY))).setProjection(SearchProjections.alias(SearchProjections.rowCount(), L_COUNT)).addOrder(asc(L_COUNT));
    return (order.getBooleanField(OrderFieldsPC.REGISTER_QUANTITY_OUT_PRODUCT) && ((Long) searchBuilder.setMaxResults(1).uniqueResult().getField(L_COUNT) <= 0));
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 14 with SearchCriteriaBuilder

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

the class ProductionTrackingListenerService method checkIfExistsFinalRecord.

private void checkIfExistsFinalRecord(final Entity productionTracking) {
    if (productionTracking.getBooleanField(ProductionTrackingFields.IS_CORRECTION) && !productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING)) {
        return;
    }
    final Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
    final String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);
    final SearchCriteriaBuilder searchBuilder = productionTracking.getDataDefinition().find();
    searchBuilder.add(SearchRestrictions.eq(ProductionTrackingFields.STATE, ProductionTrackingStateStringValues.ACCEPTED));
    searchBuilder.add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order));
    searchBuilder.add(SearchRestrictions.eq(ProductionTrackingFields.LAST_TRACKING, true));
    if (productionCountingService.isTypeOfProductionRecordingForEach(typeOfProductionRecording)) {
        searchBuilder.add(SearchRestrictions.belongsTo(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT, productionTracking.getBelongsToField(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT)));
    }
    if (searchBuilder.list().getTotalNumberOfEntities() != 0) {
        productionTracking.addGlobalError("productionCounting.productionTracking.messages.error.finalExists");
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 15 with SearchCriteriaBuilder

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

the class ProductionTrackingDocumentsHelper method groupAndFilterInProducts.

public Multimap<Long, Entity> groupAndFilterInProducts(final Entity order, final List<Entity> trackingOperationProductInComponents) {
    Multimap<Long, Entity> groupedRecordInProducts = ArrayListMultimap.create();
    SearchCriteriaBuilder scb = getProductionCountingQuantityDD().find().add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.USED.getStringValue()));
    List<Entity> productionCountingQuantities = scb.list().getEntities();
    for (Entity topic : trackingOperationProductInComponents) {
        BigDecimal usedQuantity = topic.getDecimalField(L_USED_QUANTITY);
        if (Objects.nonNull(usedQuantity) && BigDecimal.ZERO.compareTo(usedQuantity) < 0) {
            Entity product = topic.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCT);
            Entity productionTracking = topic.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCTION_TRACKING);
            Entity toc = productionTracking.getBelongsToField(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT);
            Either<Boolean, Entity> eitherWarehouse = getWarehouseForProduct(productionCountingQuantities, toc, product);
            if (eitherWarehouse.isRight()) {
                Entity warehouse = eitherWarehouse.getRight();
                if (Objects.isNull(warehouse)) {
                    DocumentBuilder documentBuilder = documentManagementService.getDocumentBuilder();
                    Entity emptyDocumentForErrorHandling = documentBuilder.createDocument(userService.getCurrentUserEntity());
                    emptyDocumentForErrorHandling.setNotValid();
                    emptyDocumentForErrorHandling.addGlobalError("productFlowThruDivision.productionCountingQuantity.productionCountingQuantityError.warehouseNotSet", product.getStringField(ProductFields.NUMBER));
                    throw new DocumentBuildException(emptyDocumentForErrorHandling, Lists.newArrayList());
                }
                groupedRecordInProducts.put(warehouse.getId(), topic);
            }
        }
    }
    return groupedRecordInProducts;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) DocumentBuilder(com.qcadoo.mes.materialFlowResources.service.DocumentBuilder) BigDecimal(java.math.BigDecimal) DocumentBuildException(com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException)

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