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();
}
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());
}
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);
}
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;
}
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));
}
}
Aggregations