use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class UseReplacementCriteriaModifiers method filter.
public void filter(final SearchCriteriaBuilder scb, final FilterValueHolder filterValue) {
if (filterValue.has("BASIC_PRODUCT_ID")) {
Entity basicProduct = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(filterValue.getLong("BASIC_PRODUCT_ID"));
List<Entity> replacements = basicProduct.getHasManyField(ProductFields.SUBSTITUTE_COMPONENTS);
List<Long> ids = replacements.stream().filter(r -> Objects.nonNull(r.getBelongsToField(SubstituteComponentFields.PRODUCT))).map(r -> r.getBelongsToField(SubstituteComponentFields.PRODUCT).getId()).collect(Collectors.toList());
scb.add(SearchRestrictions.in("id", ids));
} else {
scb.add(SearchRestrictions.idEq(-1));
}
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class ProductionTrackingListenerService method getInProductionCountingQuantities.
private List<Entity> getInProductionCountingQuantities(Entity trackingOperationProductComponent, Entity order, Entity technologyOperationComponent, boolean isForEach) {
Entity product = trackingOperationProductComponent.getBelongsToField(L_PRODUCT);
SearchCriteriaBuilder scb = order.getHasManyField(OrderFieldsBPC.PRODUCTION_COUNTING_QUANTITIES).find().add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.USED.getStringValue())).add(SearchRestrictions.in(ProductionCountingQuantityFields.TYPE_OF_MATERIAL, Lists.newArrayList(ProductionCountingQuantityTypeOfMaterial.COMPONENT.getStringValue(), ProductionCountingQuantityTypeOfMaterial.INTERMEDIATE.getStringValue()))).add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.PRODUCT, product));
if (isForEach && Objects.nonNull(technologyOperationComponent)) {
Entity toc = technologyOperationComponent.getDataDefinition().get(technologyOperationComponent.getId());
scb = scb.add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT, toc));
}
return scb.list().getEntities();
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class ProductionTrackingListenerService method checkIfUsedOrWastesQuantitiesWereNotFilled.
public boolean checkIfUsedOrWastesQuantitiesWereNotFilled(final Entity productionTracking) {
Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
final SearchCriteriaBuilder searchBuilder = productionTracking.getHasManyField(ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_OUT_COMPONENTS).find().add(SearchRestrictions.or(SearchRestrictions.isNotNull(TrackingOperationProductOutComponentFields.USED_QUANTITY), SearchRestrictions.isNotNull(TrackingOperationProductOutComponentFields.WASTES_QUANTITY))).setProjection(SearchProjections.alias(SearchProjections.rowCount(), L_COUNT)).addOrder(asc(L_COUNT));
return (order.getBooleanField(OrderFieldsPC.REGISTER_QUANTITY_OUT_PRODUCT) && ((Long) searchBuilder.setMaxResults(1).uniqueResult().getField(L_COUNT) <= 0));
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class ProductionTrackingListenerService method checkIfExistsFinalRecord.
private void checkIfExistsFinalRecord(final Entity productionTracking) {
if (productionTracking.getBooleanField(ProductionTrackingFields.IS_CORRECTION) && !productionTracking.getBooleanField(ProductionTrackingFields.LAST_TRACKING)) {
return;
}
final Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
final String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);
final SearchCriteriaBuilder searchBuilder = productionTracking.getDataDefinition().find();
searchBuilder.add(SearchRestrictions.eq(ProductionTrackingFields.STATE, ProductionTrackingStateStringValues.ACCEPTED));
searchBuilder.add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order));
searchBuilder.add(SearchRestrictions.eq(ProductionTrackingFields.LAST_TRACKING, true));
if (productionCountingService.isTypeOfProductionRecordingForEach(typeOfProductionRecording)) {
searchBuilder.add(SearchRestrictions.belongsTo(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT, productionTracking.getBelongsToField(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT)));
}
if (searchBuilder.list().getTotalNumberOfEntities() != 0) {
productionTracking.addGlobalError("productionCounting.productionTracking.messages.error.finalExists");
}
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class ProductionTrackingDocumentsHelper method groupAndFilterInProducts.
public Multimap<Long, Entity> groupAndFilterInProducts(final Entity order, final List<Entity> trackingOperationProductInComponents) {
Multimap<Long, Entity> groupedRecordInProducts = ArrayListMultimap.create();
SearchCriteriaBuilder scb = getProductionCountingQuantityDD().find().add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.USED.getStringValue()));
List<Entity> productionCountingQuantities = scb.list().getEntities();
for (Entity topic : trackingOperationProductInComponents) {
BigDecimal usedQuantity = topic.getDecimalField(L_USED_QUANTITY);
if (Objects.nonNull(usedQuantity) && BigDecimal.ZERO.compareTo(usedQuantity) < 0) {
Entity product = topic.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCT);
Entity productionTracking = topic.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCTION_TRACKING);
Entity toc = productionTracking.getBelongsToField(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT);
Either<Boolean, Entity> eitherWarehouse = getWarehouseForProduct(productionCountingQuantities, toc, product);
if (eitherWarehouse.isRight()) {
Entity warehouse = eitherWarehouse.getRight();
if (Objects.isNull(warehouse)) {
DocumentBuilder documentBuilder = documentManagementService.getDocumentBuilder();
Entity emptyDocumentForErrorHandling = documentBuilder.createDocument(userService.getCurrentUserEntity());
emptyDocumentForErrorHandling.setNotValid();
emptyDocumentForErrorHandling.addGlobalError("productFlowThruDivision.productionCountingQuantity.productionCountingQuantityError.warehouseNotSet", product.getStringField(ProductFields.NUMBER));
throw new DocumentBuildException(emptyDocumentForErrorHandling, Lists.newArrayList());
}
groupedRecordInProducts.put(warehouse.getId(), topic);
}
}
}
return groupedRecordInProducts;
}
Aggregations