use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class DeliveriesServiceImpl method getSelectedOrderedProducts.
public List<Entity> getSelectedOrderedProducts(final GridComponent orderedProductGrid) {
List<Entity> result = Lists.newArrayList();
Set<Long> ids = orderedProductGrid.getSelectedEntitiesIds();
if (Objects.nonNull(ids) && !ids.isEmpty()) {
final SearchCriteriaBuilder searchCriteria = getOrderedProductDD().find();
searchCriteria.add(SearchRestrictions.in("id", ids));
result = searchCriteria.list().getEntities();
}
return result;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class ReservationService method findPresentDeliveredProductForProductReservations.
private List<Entity> findPresentDeliveredProductForProductReservations(final Entity deliveredProduct) {
Entity delivery = deliveredProduct.getBelongsToField(DeliveredProductFields.DELIVERY);
Entity additionalCode = deliveredProduct.getBelongsToField(DeliveredProductFields.ADDITIONAL_CODE);
Entity batch = deliveredProduct.getBelongsToField(DeliveredProductFields.BATCH);
SearchCriteriaBuilder findDeliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS).find();
findDeliveredProducts.add(SearchRestrictions.belongsTo(DeliveredProductFields.PRODUCT, deliveredProduct.getBelongsToField(DeliveredProductFields.PRODUCT)));
if (Objects.isNull(batch)) {
findDeliveredProducts.add(SearchRestrictions.isNull(DeliveredProductFields.BATCH));
} else {
findDeliveredProducts.add(SearchRestrictions.belongsTo(DeliveredProductFields.BATCH, batch));
}
if (Objects.isNull(additionalCode)) {
findDeliveredProducts.add(SearchRestrictions.isNull(DeliveredProductFields.ADDITIONAL_CODE));
} else {
findDeliveredProducts.add(SearchRestrictions.belongsTo(DeliveredProductFields.ADDITIONAL_CODE, additionalCode));
}
if (PluginUtils.isEnabled("supplyNegotiations")) {
findDeliveredProducts.add(SearchRestrictions.belongsTo(OFFER, deliveredProduct.getBelongsToField(OFFER)));
}
List<Entity> deliveredProducts = findDeliveredProducts.list().getEntities();
List<Entity> allReservationsFromDeliveredProducts = deliveredProducts.stream().flatMap(p -> p.getHasManyField(DeliveredProductFields.RESERVATIONS).stream()).collect(Collectors.toList());
return allReservationsFromDeliveredProducts;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class LineChangeoverNormsHooks method checkUniqueNorms.
public boolean checkUniqueNorms(final DataDefinition changeoverNormDD, final Entity changeoverNorm) {
SearchCriteriaBuilder searchCriteriaBuilder = dataDefinitionService.get(LineChangeoverNormsConstants.PLUGIN_IDENTIFIER, LineChangeoverNormsConstants.MODEL_LINE_CHANGEOVER_NORMS).find().add(SearchRestrictions.belongsTo(FROM_TECHNOLOGY, changeoverNorm.getBelongsToField(FROM_TECHNOLOGY))).add(SearchRestrictions.belongsTo(TO_TECHNOLOGY, changeoverNorm.getBelongsToField(TO_TECHNOLOGY))).add(SearchRestrictions.belongsTo(FROM_TECHNOLOGY_GROUP, changeoverNorm.getBelongsToField(FROM_TECHNOLOGY_GROUP))).add(SearchRestrictions.belongsTo(TO_TECHNOLOGY_GROUP, changeoverNorm.getBelongsToField(TO_TECHNOLOGY_GROUP))).add(SearchRestrictions.belongsTo(PRODUCTION_LINE, changeoverNorm.getBelongsToField(PRODUCTION_LINE)));
if (changeoverNorm.getId() != null) {
searchCriteriaBuilder.add(SearchRestrictions.ne("id", changeoverNorm.getId()));
}
Entity existingChangeoverNorm = searchCriteriaBuilder.uniqueResult();
if (existingChangeoverNorm != null) {
changeoverNorm.addGlobalError(L_LINE_CHANGEOVER_NORMS_LINE_CHANGEOVER_NORM_NOT_UNIQUE, existingChangeoverNorm.getStringField(NUMBER));
return false;
}
return true;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class SalesPlanProductValidators method checkIfEntityAlreadyExistsForProductAndSalesPlan.
private boolean checkIfEntityAlreadyExistsForProductAndSalesPlan(final DataDefinition salesPlanDD, final Entity salesPlanProduct) {
SearchCriteriaBuilder searchCriteriaBuilder = salesPlanDD.find().add(SearchRestrictions.belongsTo(SalesPlanProductFields.SALES_PLAN, salesPlanProduct.getBelongsToField(SalesPlanProductFields.SALES_PLAN))).add(SearchRestrictions.belongsTo(SalesPlanProductFields.PRODUCT, salesPlanProduct.getBelongsToField(SalesPlanProductFields.PRODUCT)));
// It decreases unnecessary mapping overhead
searchCriteriaBuilder.setProjection(SearchProjections.alias(SearchProjections.id(), "id"));
Long salesPlanProductId = salesPlanProduct.getId();
if (salesPlanProductId != null) {
searchCriteriaBuilder.add(SearchRestrictions.ne("id", salesPlanProductId));
}
if (searchCriteriaBuilder.setMaxResults(1).uniqueResult() == null) {
return true;
}
salesPlanProduct.addError(salesPlanDD.getField(SalesPlanProductFields.PRODUCT), "masterOrders.salesPlanProduct.alreadyExistsForProductAndSalesPlan");
return false;
}
use of com.qcadoo.model.api.search.SearchCriteriaBuilder in project mes by qcadoo.
the class MasterOrderProductValidators method checkIfEntityAlreadyExistsForProductAndMasterOrder.
private boolean checkIfEntityAlreadyExistsForProductAndMasterOrder(final DataDefinition masterOrderProductDD, final Entity masterOrderProduct) {
SearchCriteriaBuilder searchCriteriaBuilder = masterOrderProductDD.find().add(SearchRestrictions.belongsTo(MasterOrderProductFields.MASTER_ORDER, masterOrderProduct.getBelongsToField(MasterOrderProductFields.MASTER_ORDER))).add(SearchRestrictions.belongsTo(MasterOrderProductFields.PRODUCT, masterOrderProduct.getBelongsToField(MasterOrderProductFields.PRODUCT)));
// It decreases unnecessary mapping overhead
searchCriteriaBuilder.setProjection(SearchProjections.alias(SearchProjections.id(), "id"));
Long masterOrderProductId = masterOrderProduct.getId();
if (masterOrderProductId != null) {
searchCriteriaBuilder.add(SearchRestrictions.ne("id", masterOrderProductId));
}
if (searchCriteriaBuilder.setMaxResults(1).uniqueResult() == null) {
return true;
}
masterOrderProduct.addError(masterOrderProductDD.getField(MasterOrderProductFields.PRODUCT), "masterOrders.masterOrderProduct.alreadyExistsForProductAndMasterOrder");
return false;
}
Aggregations