use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class TechnologyProductionLineCriteriaModifiers method filterByTechnologyAndDivision.
public void filterByTechnologyAndDivision(final SearchCriteriaBuilder scb, final FilterValueHolder filterValueHolder) {
scb.add(SearchRestrictions.eq(ProductionLineFields.PRODUCTION, true));
if (filterValueHolder.has(L_TECHNOLOGY_ID)) {
SearchCriteriaBuilder subCriteria = getTechnologyDD().findWithAlias(TechnologiesConstants.MODEL_TECHNOLOGY).add(SearchRestrictions.idEq(filterValueHolder.getLong(L_TECHNOLOGY_ID))).createAlias(TechnologyFields.PRODUCTION_LINES, TechnologyFields.PRODUCTION_LINES, JoinType.INNER).createAlias(TechnologyFields.PRODUCTION_LINES + L_DOT + TechnologyProductionLineFields.PRODUCTION_LINE, TechnologyProductionLineFields.PRODUCTION_LINE, JoinType.INNER).add(SearchRestrictions.eqField(TechnologyProductionLineFields.PRODUCTION_LINE + L_DOT + L_ID, L_THIS_ID)).setProjection(SearchProjections.id());
scb.add(SearchSubqueries.notExists(subCriteria));
}
if (filterValueHolder.has(L_DIVISION_ID)) {
Long divisionId = filterValueHolder.getLong(L_DIVISION_ID);
Entity division = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_DIVISION).get(divisionId);
List<Long> productionLinesIds = division.getHasManyField(DivisionFieldsPL.PRODUCTION_LINES).stream().map(Entity::getId).collect(Collectors.toList());
if (!productionLinesIds.isEmpty()) {
scb.add(SearchRestrictions.in(L_ID, productionLinesIds));
}
}
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class DeliveryStatePFTDService method findStorageLocationForProduct.
public Optional<Entity> findStorageLocationForProduct(final Entity product, final Entity location) {
SearchCriteriaBuilder scb = getStorageLocationDD().find();
scb.add(SearchRestrictions.belongsTo(StorageLocationFields.PRODUCT, product));
scb.add(SearchRestrictions.belongsTo(StorageLocationFields.LOCATION, location));
return Optional.ofNullable(scb.setMaxResults(1).uniqueResult());
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class BatchModelValidators method existsAnyBatchMatchingCriterion.
private boolean existsAnyBatchMatchingCriterion(final DataDefinition batchDD, final SearchCriterion criterion) {
SearchCriteriaBuilder scb = batchDD.find();
scb.add(criterion);
scb.setProjection(alias(id(), "id"));
return scb.setMaxResults(1).uniqueResult() != null;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class AssignmentToShiftXlsHelper method getStaffsList.
public List<Entity> getStaffsList(final Entity assignmentToShift, final String occupationType, final Entity productionLine) {
List<Entity> staffs = Lists.newArrayList();
if (assignmentToShift == null) {
return staffs;
}
SearchCriterion criterion = SearchRestrictions.eq(StaffAssignmentToShiftFields.OCCUPATION_TYPE, occupationType);
SearchCriteriaBuilder builder = assignmentToShift.getHasManyField(AssignmentToShiftFields.STAFF_ASSIGNMENT_TO_SHIFTS).find().add(criterion).add(SearchRestrictions.belongsTo(StaffAssignmentToShiftFields.PRODUCTION_LINE, productionLine));
String assignmentState = assignmentToShift.getStringField(AssignmentToShiftFields.STATE);
if (AssignmentToShiftState.CORRECTED.getStringValue().equals(assignmentState)) {
staffs = builder.add(SearchRestrictions.eq(StaffAssignmentToShiftFields.STATE, StaffAssignmentToShiftState.CORRECTED.getStringValue())).list().getEntities();
} else if (!AssignmentToShiftState.DRAFT.getStringValue().equals(assignmentState)) {
staffs = builder.add(SearchRestrictions.eq(StaffAssignmentToShiftFields.STATE, StaffAssignmentToShiftState.ACCEPTED.getStringValue())).list().getEntities();
}
return staffs;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class ProductionCountingQuantitySetService method fillSetField.
public Entity fillSetField(final Entity productionCountingQuantity) {
String typeOfMaterial = productionCountingQuantity.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL);
String role = productionCountingQuantity.getStringField(ProductionCountingQuantityFields.ROLE);
if (GlobalTypeOfMaterial.COMPONENT.getStringValue().equals(typeOfMaterial) && ProductionCountingQuantityRole.USED.getStringValue().equals(role)) {
Entity product = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.PRODUCT);
if (product != null) {
Entity technology = getTechnologyDD().find().add(SearchRestrictions.eq(TechnologyFields.MASTER, true)).add(SearchRestrictions.belongsTo(TechnologyFields.PRODUCT, product)).uniqueResult();
if (technology != null) {
EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
Entity operationProductOutComponent = operationComponents.getRoot().getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0);
boolean isSet = operationProductOutComponent.getBooleanField("set");
if (isSet) {
productionCountingQuantity.setField(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.SET.getStringValue());
}
}
}
} else if (GlobalTypeOfMaterial.FINAL_PRODUCT.getStringValue().equals(typeOfMaterial) && ProductionCountingQuantityRole.PRODUCED.getStringValue().equals(role)) {
Entity order = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.ORDER);
Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
Entity operationProductOutComponent = operationComponents.getRoot().getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0);
boolean isSet = operationProductOutComponent.getBooleanField("set");
if (isSet) {
productionCountingQuantity.setField(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.SET.getStringValue());
SearchCriteriaBuilder findProductionCountingQuantity = productionCountingQuantity.getDataDefinition().find();
List<Entity> entities = findProductionCountingQuantity.add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).list().getEntities();
markIntermediateInProductionCountingQuantities(entities, true);
}
} else if (GlobalTypeOfMaterial.INTERMEDIATE.getStringValue().equals(typeOfMaterial) && ProductionCountingQuantityRole.USED.getStringValue().equals(role)) {
Entity order = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.ORDER);
SearchCriteriaBuilder findProductionCountingQuantity = productionCountingQuantity.getDataDefinition().find();
List<Entity> entities = findProductionCountingQuantity.add(SearchRestrictions.and(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order), SearchRestrictions.eq(ProductionCountingQuantityFields.TYPE_OF_MATERIAL, GlobalTypeOfMaterial.FINAL_PRODUCT.getStringValue()), SearchRestrictions.eq(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.SET.getStringValue()))).list().getEntities();
Entity technologyOperationComponent = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT);
if (technologyOperationComponent != null) {
Entity operation = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
long count = entities.stream().filter(entity -> {
Entity entityTechnologyOperationComponent = entity.getBelongsToField(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT);
Entity entityOperation = entityTechnologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
return "1.".equals(entityTechnologyOperationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER)) && operation.getId().equals(entityOperation.getId());
}).count();
if (count > 0) {
productionCountingQuantity.setField(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.INTERMEDIATE.getStringValue());
}
}
}
return productionCountingQuantity;
}
Aggregations