Search in sources :

Example 56 with SearchCriteriaBuilder

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

the class DeliveriesServiceImpl method getSelectedOrderedProducts.

public List<Entity> getSelectedOrderedProducts(final GridComponent orderedProductGrid) {
    List<Entity> result = Lists.newArrayList();
    Set<Long> ids = orderedProductGrid.getSelectedEntitiesIds();
    if (Objects.nonNull(ids) && !ids.isEmpty()) {
        final SearchCriteriaBuilder searchCriteria = getOrderedProductDD().find();
        searchCriteria.add(SearchRestrictions.in("id", ids));
        result = searchCriteria.list().getEntities();
    }
    return result;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 57 with SearchCriteriaBuilder

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

the class ReservationService method findPresentDeliveredProductForProductReservations.

private List<Entity> findPresentDeliveredProductForProductReservations(final Entity deliveredProduct) {
    Entity delivery = deliveredProduct.getBelongsToField(DeliveredProductFields.DELIVERY);
    Entity additionalCode = deliveredProduct.getBelongsToField(DeliveredProductFields.ADDITIONAL_CODE);
    Entity batch = deliveredProduct.getBelongsToField(DeliveredProductFields.BATCH);
    SearchCriteriaBuilder findDeliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS).find();
    findDeliveredProducts.add(SearchRestrictions.belongsTo(DeliveredProductFields.PRODUCT, deliveredProduct.getBelongsToField(DeliveredProductFields.PRODUCT)));
    if (Objects.isNull(batch)) {
        findDeliveredProducts.add(SearchRestrictions.isNull(DeliveredProductFields.BATCH));
    } else {
        findDeliveredProducts.add(SearchRestrictions.belongsTo(DeliveredProductFields.BATCH, batch));
    }
    if (Objects.isNull(additionalCode)) {
        findDeliveredProducts.add(SearchRestrictions.isNull(DeliveredProductFields.ADDITIONAL_CODE));
    } else {
        findDeliveredProducts.add(SearchRestrictions.belongsTo(DeliveredProductFields.ADDITIONAL_CODE, additionalCode));
    }
    if (PluginUtils.isEnabled("supplyNegotiations")) {
        findDeliveredProducts.add(SearchRestrictions.belongsTo(OFFER, deliveredProduct.getBelongsToField(OFFER)));
    }
    List<Entity> deliveredProducts = findDeliveredProducts.list().getEntities();
    List<Entity> allReservationsFromDeliveredProducts = deliveredProducts.stream().flatMap(p -> p.getHasManyField(DeliveredProductFields.RESERVATIONS).stream()).collect(Collectors.toList());
    return allReservationsFromDeliveredProducts;
}
Also used : Arrays(java.util.Arrays) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) Service(org.springframework.stereotype.Service) PluginUtils(com.qcadoo.plugin.api.PluginUtils) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DeliveredProductReservationFields(com.qcadoo.mes.deliveries.constants.DeliveredProductReservationFields) OrderedProductReservationFields(com.qcadoo.mes.deliveries.constants.OrderedProductReservationFields) DeliveriesConstants(com.qcadoo.mes.deliveries.constants.DeliveriesConstants) DeliveryFields(com.qcadoo.mes.deliveries.constants.DeliveryFields) OrderedProductFields(com.qcadoo.mes.deliveries.constants.OrderedProductFields) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityList(com.qcadoo.model.api.EntityList) Objects(java.util.Objects) DeliveredProductFields(com.qcadoo.mes.deliveries.constants.DeliveredProductFields) List(java.util.List) Entity(com.qcadoo.model.api.Entity) Optional(java.util.Optional) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 58 with SearchCriteriaBuilder

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

the class LineChangeoverNormsHooks method checkUniqueNorms.

public boolean checkUniqueNorms(final DataDefinition changeoverNormDD, final Entity changeoverNorm) {
    SearchCriteriaBuilder searchCriteriaBuilder = dataDefinitionService.get(LineChangeoverNormsConstants.PLUGIN_IDENTIFIER, LineChangeoverNormsConstants.MODEL_LINE_CHANGEOVER_NORMS).find().add(SearchRestrictions.belongsTo(FROM_TECHNOLOGY, changeoverNorm.getBelongsToField(FROM_TECHNOLOGY))).add(SearchRestrictions.belongsTo(TO_TECHNOLOGY, changeoverNorm.getBelongsToField(TO_TECHNOLOGY))).add(SearchRestrictions.belongsTo(FROM_TECHNOLOGY_GROUP, changeoverNorm.getBelongsToField(FROM_TECHNOLOGY_GROUP))).add(SearchRestrictions.belongsTo(TO_TECHNOLOGY_GROUP, changeoverNorm.getBelongsToField(TO_TECHNOLOGY_GROUP))).add(SearchRestrictions.belongsTo(PRODUCTION_LINE, changeoverNorm.getBelongsToField(PRODUCTION_LINE)));
    if (changeoverNorm.getId() != null) {
        searchCriteriaBuilder.add(SearchRestrictions.ne("id", changeoverNorm.getId()));
    }
    Entity existingChangeoverNorm = searchCriteriaBuilder.uniqueResult();
    if (existingChangeoverNorm != null) {
        changeoverNorm.addGlobalError(L_LINE_CHANGEOVER_NORMS_LINE_CHANGEOVER_NORM_NOT_UNIQUE, existingChangeoverNorm.getStringField(NUMBER));
        return false;
    }
    return true;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 59 with SearchCriteriaBuilder

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

the class SalesPlanProductValidators method checkIfEntityAlreadyExistsForProductAndSalesPlan.

private boolean checkIfEntityAlreadyExistsForProductAndSalesPlan(final DataDefinition salesPlanDD, final Entity salesPlanProduct) {
    SearchCriteriaBuilder searchCriteriaBuilder = salesPlanDD.find().add(SearchRestrictions.belongsTo(SalesPlanProductFields.SALES_PLAN, salesPlanProduct.getBelongsToField(SalesPlanProductFields.SALES_PLAN))).add(SearchRestrictions.belongsTo(SalesPlanProductFields.PRODUCT, salesPlanProduct.getBelongsToField(SalesPlanProductFields.PRODUCT)));
    // It decreases unnecessary mapping overhead
    searchCriteriaBuilder.setProjection(SearchProjections.alias(SearchProjections.id(), "id"));
    Long salesPlanProductId = salesPlanProduct.getId();
    if (salesPlanProductId != null) {
        searchCriteriaBuilder.add(SearchRestrictions.ne("id", salesPlanProductId));
    }
    if (searchCriteriaBuilder.setMaxResults(1).uniqueResult() == null) {
        return true;
    }
    salesPlanProduct.addError(salesPlanDD.getField(SalesPlanProductFields.PRODUCT), "masterOrders.salesPlanProduct.alreadyExistsForProductAndSalesPlan");
    return false;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 60 with SearchCriteriaBuilder

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

the class MasterOrderProductValidators method checkIfEntityAlreadyExistsForProductAndMasterOrder.

private boolean checkIfEntityAlreadyExistsForProductAndMasterOrder(final DataDefinition masterOrderProductDD, final Entity masterOrderProduct) {
    SearchCriteriaBuilder searchCriteriaBuilder = masterOrderProductDD.find().add(SearchRestrictions.belongsTo(MasterOrderProductFields.MASTER_ORDER, masterOrderProduct.getBelongsToField(MasterOrderProductFields.MASTER_ORDER))).add(SearchRestrictions.belongsTo(MasterOrderProductFields.PRODUCT, masterOrderProduct.getBelongsToField(MasterOrderProductFields.PRODUCT)));
    // It decreases unnecessary mapping overhead
    searchCriteriaBuilder.setProjection(SearchProjections.alias(SearchProjections.id(), "id"));
    Long masterOrderProductId = masterOrderProduct.getId();
    if (masterOrderProductId != null) {
        searchCriteriaBuilder.add(SearchRestrictions.ne("id", masterOrderProductId));
    }
    if (searchCriteriaBuilder.setMaxResults(1).uniqueResult() == null) {
        return true;
    }
    masterOrderProduct.addError(masterOrderProductDD.getField(MasterOrderProductFields.PRODUCT), "masterOrders.masterOrderProduct.alreadyExistsForProductAndMasterOrder");
    return false;
}
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