Search in sources :

Example 71 with SearchCriteriaBuilder

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

the class MaterialRequirementCoveragesListHooks method addDiscriminatorRestrictionToGrid.

public final void addDiscriminatorRestrictionToGrid(final ViewDefinitionState view) {
    GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
    grid.setCustomRestriction(new CustomRestriction() {

        @Override
        public void addRestriction(final SearchCriteriaBuilder searchBuilder) {
            searchBuilder.add(SearchRestrictions.eq(MaterialRequirementCoverageFields.SAVED, true));
        }
    });
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) GridComponent(com.qcadoo.view.api.components.GridComponent) CustomRestriction(com.qcadoo.model.api.search.CustomRestriction)

Example 72 with SearchCriteriaBuilder

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

the class OrderPackService method getSumQuantityOrderPacksForOrderWithoutPack.

public BigDecimal getSumQuantityOrderPacksForOrderWithoutPack(Entity order, Long orderPackId) {
    if (order.getHasManyField(OrderFields.ORDER_PACKS).size() == 1 && orderPackId != null || order.getHasManyField(OrderFields.ORDER_PACKS).isEmpty()) {
        return BigDecimal.ZERO;
    }
    SearchCriteriaBuilder scb = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER_PACK).find().add(SearchRestrictions.belongsTo(OrderPackFields.ORDER, order));
    if (orderPackId != null) {
        scb.add(SearchRestrictions.idNe(orderPackId));
    }
    scb.setProjection(alias(sum(OrderPackFields.QUANTITY), QNT_SUM_FIELD_NAME)).addOrder(asc(QNT_SUM_FIELD_NAME));
    return scb.setMaxResults(1).uniqueResult().getDecimalField(QNT_SUM_FIELD_NAME);
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 73 with SearchCriteriaBuilder

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

the class OrdersForSubproductsGenerationListeners method getGeneratingMRC.

private Optional<Entity> getGeneratingMRC() {
    SearchCriteriaBuilder searchCriteriaBuilder = getMaterialRequirementCoverageDD().find();
    searchCriteriaBuilder.add(SearchRestrictions.eq(MaterialRequirementCoverageFields.ORDER_GENERATION_IN_PROGRESS, true));
    List<Entity> entities = searchCriteriaBuilder.list().getEntities();
    if (entities.isEmpty()) {
        return Optional.empty();
    } else {
        return Optional.of(entities.get(0));
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 74 with SearchCriteriaBuilder

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

the class OrdersForSubproductsGenerationService method hasSubOrders.

public boolean hasSubOrders(final Entity order) {
    if (Objects.isNull(order)) {
        return false;
    }
    SearchCriteriaBuilder scb = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).find();
    scb.add(SearchRestrictions.belongsTo(OrderFieldsOFSPG.PARENT, order));
    scb.setProjection(SearchProjections.alias(SearchProjections.countDistinct("id"), COUNT_ALIAS));
    scb.addOrder(SearchOrders.desc(COUNT_ALIAS));
    Entity projectionResult = scb.setMaxResults(1).uniqueResult();
    Long countValue = (Long) projectionResult.getField(COUNT_ALIAS);
    return countValue > 0;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 75 with SearchCriteriaBuilder

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

the class ProductionLineScheduleOrderCriteriaModifiers method filterByState.

public void filterByState(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
    scb.add(SearchRestrictions.in(OrderFields.STATE, Lists.newArrayList(OrderState.ACCEPTED.getStringValue(), OrderState.PENDING.getStringValue())));
    scb.add(SearchRestrictions.eq(L_TYPE_OF_PRODUCTION_RECORDING, L_CUMULATED));
    if (filterValueHolder.has(SCHEDULE_PARAMETER)) {
        SearchCriteriaBuilder subCriteria = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_PRODUCTION_LINE_SCHEDULE).findWithAlias(OrdersConstants.MODEL_PRODUCTION_LINE_SCHEDULE).add(SearchRestrictions.idEq(filterValueHolder.getLong(SCHEDULE_PARAMETER))).createAlias(ProductionLineScheduleFields.ORDERS, ProductionLineScheduleFields.ORDERS, JoinType.INNER).add(SearchRestrictions.eqField(ProductionLineScheduleFields.ORDERS + ".id", "this.id")).setProjection(SearchProjections.id());
        scb.add(SearchSubqueries.notExists(subCriteria));
    }
}
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