Search in sources :

Example 81 with SearchCriteriaBuilder

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

the class TechnologyProductionLineCriteriaModifiers method filterByTechnologyAndDivision.

public void filterByTechnologyAndDivision(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
    scb.add(SearchRestrictions.eq(ProductionLineFields.PRODUCTION, true));
    if (filterValueHolder.has(L_TECHNOLOGY_ID)) {
        SearchCriteriaBuilder subCriteria = getTechnologyDD().findWithAlias(TechnologiesConstants.MODEL_TECHNOLOGY).add(SearchRestrictions.idEq(filterValueHolder.getLong(L_TECHNOLOGY_ID))).createAlias(TechnologyFields.PRODUCTION_LINES, TechnologyFields.PRODUCTION_LINES, JoinType.INNER).createAlias(TechnologyFields.PRODUCTION_LINES + L_DOT + TechnologyProductionLineFields.PRODUCTION_LINE, TechnologyProductionLineFields.PRODUCTION_LINE, JoinType.INNER).add(SearchRestrictions.eqField(TechnologyProductionLineFields.PRODUCTION_LINE + L_DOT + L_ID, L_THIS_ID)).setProjection(SearchProjections.id());
        scb.add(SearchSubqueries.notExists(subCriteria));
    }
    if (filterValueHolder.has(L_DIVISION_ID)) {
        Long divisionId = filterValueHolder.getLong(L_DIVISION_ID);
        Entity division = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_DIVISION).get(divisionId);
        List<Long> productionLinesIds = division.getHasManyField(DivisionFieldsPL.PRODUCTION_LINES).stream().map(Entity::getId).collect(Collectors.toList());
        if (!productionLinesIds.isEmpty()) {
            scb.add(SearchRestrictions.in(L_ID, productionLinesIds));
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 82 with SearchCriteriaBuilder

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

the class DeliveryStatePFTDService method findStorageLocationForProduct.

public Optional<Entity> findStorageLocationForProduct(final Entity product, final Entity location) {
    SearchCriteriaBuilder scb = getStorageLocationDD().find();
    scb.add(SearchRestrictions.belongsTo(StorageLocationFields.PRODUCT, product));
    scb.add(SearchRestrictions.belongsTo(StorageLocationFields.LOCATION, location));
    return Optional.ofNullable(scb.setMaxResults(1).uniqueResult());
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 83 with SearchCriteriaBuilder

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

the class BatchModelValidators method existsAnyBatchMatchingCriterion.

private boolean existsAnyBatchMatchingCriterion(final DataDefinition batchDD, final SearchCriterion criterion) {
    SearchCriteriaBuilder scb = batchDD.find();
    scb.add(criterion);
    scb.setProjection(alias(id(), "id"));
    return scb.setMaxResults(1).uniqueResult() != null;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 84 with SearchCriteriaBuilder

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

the class AssignmentToShiftXlsHelper method getStaffsList.

public List<Entity> getStaffsList(final Entity assignmentToShift, final String occupationType, final Entity productionLine) {
    List<Entity> staffs = Lists.newArrayList();
    if (assignmentToShift == null) {
        return staffs;
    }
    SearchCriterion criterion = SearchRestrictions.eq(StaffAssignmentToShiftFields.OCCUPATION_TYPE, occupationType);
    SearchCriteriaBuilder builder = assignmentToShift.getHasManyField(AssignmentToShiftFields.STAFF_ASSIGNMENT_TO_SHIFTS).find().add(criterion).add(SearchRestrictions.belongsTo(StaffAssignmentToShiftFields.PRODUCTION_LINE, productionLine));
    String assignmentState = assignmentToShift.getStringField(AssignmentToShiftFields.STATE);
    if (AssignmentToShiftState.CORRECTED.getStringValue().equals(assignmentState)) {
        staffs = builder.add(SearchRestrictions.eq(StaffAssignmentToShiftFields.STATE, StaffAssignmentToShiftState.CORRECTED.getStringValue())).list().getEntities();
    } else if (!AssignmentToShiftState.DRAFT.getStringValue().equals(assignmentState)) {
        staffs = builder.add(SearchRestrictions.eq(StaffAssignmentToShiftFields.STATE, StaffAssignmentToShiftState.ACCEPTED.getStringValue())).list().getEntities();
    }
    return staffs;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 85 with SearchCriteriaBuilder

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

the class ProductionCountingQuantitySetService method fillSetField.

public Entity fillSetField(final Entity productionCountingQuantity) {
    String typeOfMaterial = productionCountingQuantity.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL);
    String role = productionCountingQuantity.getStringField(ProductionCountingQuantityFields.ROLE);
    if (GlobalTypeOfMaterial.COMPONENT.getStringValue().equals(typeOfMaterial) && ProductionCountingQuantityRole.USED.getStringValue().equals(role)) {
        Entity product = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.PRODUCT);
        if (product != null) {
            Entity technology = getTechnologyDD().find().add(SearchRestrictions.eq(TechnologyFields.MASTER, true)).add(SearchRestrictions.belongsTo(TechnologyFields.PRODUCT, product)).uniqueResult();
            if (technology != null) {
                EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
                Entity operationProductOutComponent = operationComponents.getRoot().getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0);
                boolean isSet = operationProductOutComponent.getBooleanField("set");
                if (isSet) {
                    productionCountingQuantity.setField(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.SET.getStringValue());
                }
            }
        }
    } else if (GlobalTypeOfMaterial.FINAL_PRODUCT.getStringValue().equals(typeOfMaterial) && ProductionCountingQuantityRole.PRODUCED.getStringValue().equals(role)) {
        Entity order = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.ORDER);
        Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
        EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
        Entity operationProductOutComponent = operationComponents.getRoot().getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0);
        boolean isSet = operationProductOutComponent.getBooleanField("set");
        if (isSet) {
            productionCountingQuantity.setField(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.SET.getStringValue());
            SearchCriteriaBuilder findProductionCountingQuantity = productionCountingQuantity.getDataDefinition().find();
            List<Entity> entities = findProductionCountingQuantity.add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).list().getEntities();
            markIntermediateInProductionCountingQuantities(entities, true);
        }
    } else if (GlobalTypeOfMaterial.INTERMEDIATE.getStringValue().equals(typeOfMaterial) && ProductionCountingQuantityRole.USED.getStringValue().equals(role)) {
        Entity order = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.ORDER);
        SearchCriteriaBuilder findProductionCountingQuantity = productionCountingQuantity.getDataDefinition().find();
        List<Entity> entities = findProductionCountingQuantity.add(SearchRestrictions.and(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order), SearchRestrictions.eq(ProductionCountingQuantityFields.TYPE_OF_MATERIAL, GlobalTypeOfMaterial.FINAL_PRODUCT.getStringValue()), SearchRestrictions.eq(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.SET.getStringValue()))).list().getEntities();
        Entity technologyOperationComponent = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT);
        if (technologyOperationComponent != null) {
            Entity operation = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
            long count = entities.stream().filter(entity -> {
                Entity entityTechnologyOperationComponent = entity.getBelongsToField(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT);
                Entity entityOperation = entityTechnologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
                return "1.".equals(entityTechnologyOperationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER)) && operation.getId().equals(entityOperation.getId());
            }).count();
            if (count > 0) {
                productionCountingQuantity.setField(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.INTERMEDIATE.getStringValue());
            }
        }
    }
    return productionCountingQuantity;
}
Also used : TechnologyFields(com.qcadoo.mes.technologies.constants.TechnologyFields) ProductionCountingQuantitySet(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantitySet) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) Autowired(org.springframework.beans.factory.annotation.Autowired) TechnologyOperationComponentFields(com.qcadoo.mes.technologies.constants.TechnologyOperationComponentFields) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) ProductionCountingQuantityFields(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityFields) Entity(com.qcadoo.model.api.Entity) List(java.util.List) GlobalTypeOfMaterial(com.qcadoo.mes.basic.constants.GlobalTypeOfMaterial) ProductionCountingQuantityRole(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityRole) Service(org.springframework.stereotype.Service) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) List(java.util.List) EntityTree(com.qcadoo.model.api.EntityTree)

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