Search in sources :

Example 76 with SearchCriteriaBuilder

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

the class ScheduleOrderCriteriaModifiers 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_FOR_EACH));
    if (filterValueHolder.has(SCHEDULE_PARAMETER)) {
        SearchCriteriaBuilder subCriteria = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_SCHEDULE).findWithAlias(OrdersConstants.MODEL_SCHEDULE).add(SearchRestrictions.idEq(filterValueHolder.getLong(SCHEDULE_PARAMETER))).createAlias(ScheduleFields.ORDERS, ScheduleFields.ORDERS, JoinType.INNER).add(SearchRestrictions.eqField(ScheduleFields.ORDERS + ".id", "this.id")).setProjection(SearchProjections.id());
        scb.add(SearchSubqueries.notExists(subCriteria));
    }
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 77 with SearchCriteriaBuilder

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

the class OperationalTaskValidators method checkIfAlreadyExists.

private boolean checkIfAlreadyExists(DataDefinition operationalTaskDD, Entity operationalTask) {
    String type = operationalTask.getStringField(OperationalTaskFields.TYPE);
    if (OperationalTaskType.EXECUTION_OPERATION_IN_ORDER.getStringValue().equalsIgnoreCase(type)) {
        Entity order = operationalTask.getBelongsToField(OperationalTaskFields.ORDER);
        Entity toc = operationalTask.getBelongsToField(OperationalTaskFields.TECHNOLOGY_OPERATION_COMPONENT);
        SearchCriteriaBuilder scb = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_OPERATIONAL_TASK).find().add(SearchRestrictions.belongsTo(OperationalTaskFields.ORDER, order)).add(SearchRestrictions.belongsTo(OperationalTaskFields.TECHNOLOGY_OPERATION_COMPONENT, toc)).add(SearchRestrictions.in(OperationalTaskFields.STATE, Lists.newArrayList(OperationalTaskStateStringValues.PENDING, OperationalTaskStateStringValues.STARTED, OperationalTaskStateStringValues.FINISHED)));
        if (Objects.nonNull(operationalTask.getId())) {
            scb.add(SearchRestrictions.idNe(operationalTask.getId()));
        }
        scb.setProjection(alias(rowCount(), L_COUNT));
        scb.addOrder(asc(L_COUNT));
        Entity countProjection = scb.setMaxResults(1).uniqueResult();
        boolean isValid = ((countProjection == null) || ((Long) countProjection.getField(L_COUNT) == 0));
        if (!isValid) {
            operationalTask.addGlobalError("orders.operationalTask.error.notUnique");
        }
        return isValid;
    }
    return true;
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 78 with SearchCriteriaBuilder

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

the class ProductCatalogNumbersHooks method checkIfExistsCatalogNumberWithNumberAndCompany.

public boolean checkIfExistsCatalogNumberWithNumberAndCompany(final DataDefinition dataDefinition, final Entity entity) {
    SearchCriteriaBuilder criteria = dataDefinitionService.get(ProductCatalogNumbersConstants.PLUGIN_IDENTIFIER, ProductCatalogNumbersConstants.MODEL_PRODUCT_CATALOG_NUMBERS).find().add(SearchRestrictions.eq(CATALOG_NUMBER, entity.getStringField(CATALOG_NUMBER))).add(SearchRestrictions.belongsTo(COMPANY, entity.getBelongsToField(COMPANY)));
    if (entity.getId() != null) {
        criteria.add(SearchRestrictions.ne("id", entity.getId()));
    }
    List<Entity> catalogsNumbers = criteria.list().getEntities();
    if (catalogsNumbers.isEmpty()) {
        return true;
    } else {
        entity.addGlobalError("productCatalogNumbers.productCatalogNumber.validationError.alreadyExistsCatalogNumerForCompany");
        return false;
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 79 with SearchCriteriaBuilder

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

the class CommonReasonTypeModelHooksTest method stubFindResults.

private void stubFindResults(final boolean existsMatchingEntity) {
    SearchCriteriaBuilder scb = mock(SearchCriteriaBuilder.class);
    given(reasonDD.find()).willReturn(scb);
    given(scb.setMaxResults(anyInt())).willReturn(scb);
    given(scb.add(any(SearchCriterion.class))).willReturn(scb);
    given(scb.setProjection(any(SearchProjection.class))).willReturn(scb);
    SearchResult searchResult = mock(SearchResult.class);
    given(scb.list()).willReturn(searchResult);
    given(searchResult.getTotalNumberOfEntities()).willReturn(existsMatchingEntity ? 1 : 0);
}
Also used : 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 80 with SearchCriteriaBuilder

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

the class StaffCriteriaModifierPFTD method filterByProductionLine.

public void filterByProductionLine(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
    if (filterValueHolder.has(L_ORDER_ID)) {
        SearchCriteriaBuilder subCriteria = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).findWithAlias(OrdersConstants.MODEL_ORDER).add(SearchRestrictions.idEq(filterValueHolder.getLong(L_ORDER_ID))).createAlias(OrderFields.STAFF, OrderFields.STAFF, JoinType.INNER).add(SearchRestrictions.eqField(OrderFields.STAFF + L_DOT + L_ID, L_THIS_ID)).setProjection(SearchProjections.id());
        scb.add(SearchSubqueries.notExists(subCriteria));
    }
    if (filterValueHolder.has(L_PRODUCTION_LINE_ID)) {
        scb.add(SearchRestrictions.or(SearchRestrictions.belongsTo(StaffFields.PRODUCTION_LINE, ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE, filterValueHolder.getLong(L_PRODUCTION_LINE_ID)), SearchRestrictions.isNull(StaffFields.PRODUCTION_LINE)));
    } else {
        scb.add(SearchRestrictions.isNull(StaffFields.PRODUCTION_LINE));
    }
}
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