Search in sources :

Example 31 with SearchCriteriaBuilder

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

the class ProductionLinesServiceImpl method getWorkstationTypesSumProjection.

private Entity getWorkstationTypesSumProjection(final Long productionLineId, final String workstationTypeNumber) {
    SearchCriteriaBuilder scb = getWorkstationTypeComponentDD().find();
    scb.createCriteria(WorkstationTypeComponentFields.PRODUCTIONLINE, "pl").add(idEq(productionLineId));
    scb.createCriteria(WorkstationTypeComponentFields.WORKSTATIONTYPE, "wt").add(eq(WorkstationTypeFields.NUMBER, workstationTypeNumber));
    scb.setProjection(list().add(alias(sum(WorkstationTypeComponentFields.QUANTITY), "sum")).add(rowCount()));
    scb.addOrder(asc("sum"));
    return scb.setMaxResults(1).uniqueResult();
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 32 with SearchCriteriaBuilder

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

the class TechnologyService method isTechnologyUsedInActiveOrder.

public boolean isTechnologyUsedInActiveOrder(final Entity technology) {
    if (!ordersPluginIsEnabled()) {
        return false;
    }
    SearchCriteriaBuilder searchCriteria = getOrderDD().find();
    searchCriteria.add(SearchRestrictions.belongsTo("technology", technology));
    searchCriteria.add(SearchRestrictions.in("state", Lists.newArrayList("01pending", "02accepted", "03inProgress", "06interrupted")));
    searchCriteria.setMaxResults(1);
    return Objects.nonNull(searchCriteria.uniqueResult());
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 33 with SearchCriteriaBuilder

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

the class TechnologyModelHooks method setNewMasterTechnology.

private void setNewMasterTechnology(final DataDefinition technologyDD, final Entity technology) {
    if (technology.getStringField(TechnologyFields.STATE).equals(TechnologyState.OUTDATED.getStringValue()) && technology.getBooleanField(MASTER)) {
        technology.setField(MASTER, false);
        return;
    }
    if (!technology.getStringField(TechnologyFields.STATE).equals(TechnologyState.ACCEPTED.getStringValue()) || technology.getStringField(TechnologyFields.TECHNOLOGY_TYPE) != null) {
        return;
    }
    SearchCriteriaBuilder searchCriteries = technologyDD.find();
    searchCriteries.add(SearchRestrictions.eq(MASTER, true));
    searchCriteries.add(SearchRestrictions.belongsTo(PRODUCT, technology.getBelongsToField(PRODUCT)));
    Entity defaultTechnology = searchCriteries.uniqueResult();
    if (defaultTechnology != null && defaultTechnology.getId().equals(technology.getId())) {
        return;
    }
    if (defaultTechnology == null && technology.getStringField(TechnologyFields.STATE).equals(TechnologyState.ACCEPTED.getStringValue())) {
        technology.setField(MASTER, true);
        return;
    }
    if (defaultTechnology == null || !technology.getBooleanField(MASTER)) {
        return;
    }
    defaultTechnology.setField(MASTER, false);
    technologyDD.save(defaultTechnology);
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 34 with SearchCriteriaBuilder

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

the class ProductionLineTechnologyGroupHooks method checkIfIsUnique.

private boolean checkIfIsUnique(DataDefinition productionLineTechnologyGroupDD, Entity productionLineTechnologyGroup) {
    SearchCriteriaBuilder scb = productionLineTechnologyGroupDD.find().add(SearchRestrictions.belongsTo(L_PRODUCTION_LINE, productionLineTechnologyGroup.getBelongsToField(L_PRODUCTION_LINE)));
    if (Objects.nonNull(productionLineTechnologyGroup.getBelongsToField(L_TECHNOLOGY_GROUP))) {
        scb.add(SearchRestrictions.belongsTo(L_TECHNOLOGY_GROUP, productionLineTechnologyGroup.getBelongsToField(L_TECHNOLOGY_GROUP)));
    } else {
        scb.add(SearchRestrictions.isNull(L_TECHNOLOGY_GROUP));
    }
    if (Objects.nonNull(productionLineTechnologyGroup.getId())) {
        scb.add(SearchRestrictions.idNe(productionLineTechnologyGroup.getId()));
    }
    boolean empty = scb.list().getEntities().isEmpty();
    if (!empty) {
        productionLineTechnologyGroup.addGlobalError("technologies.productionLineTechnologyGroup.error.notUnique");
    }
    return empty;
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder)

Example 35 with SearchCriteriaBuilder

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

the class SkillCriteriaModifiersT method filterBySkill.

public void filterBySkill(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
    if (filterValueHolder.has(L_SKILL_ID)) {
        SearchCriteriaBuilder subCriteria = getSkillDD().findWithAlias(BasicConstants.MODEL_SKILL).add(SearchRestrictions.idEq(filterValueHolder.getLong(L_SKILL_ID))).createAlias(OperationFields.OPERATION_SKILLS, OperationFields.OPERATION_SKILLS, JoinType.INNER).createAlias(OperationFields.OPERATION_SKILLS + L_DOT + OperationSkillFields.OPERATION, OperationSkillFields.OPERATION, JoinType.INNER).add(SearchRestrictions.eqField(OperationSkillFields.OPERATION + L_DOT + L_ID, L_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