use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class TechnologicalProcessRateItemHooks method checkIfRateForGivenTimeExists.
public boolean checkIfRateForGivenTimeExists(final Entity technologicalProcessRateItem) {
Entity technologicalProcessRate = technologicalProcessRateItem.getBelongsToField("technologicalProcessRate");
Date dateFrom = technologicalProcessRateItem.getDateField(L_DATE_FROM);
Date dateTo = technologicalProcessRateItem.getDateField(L_DATE_TO);
SearchCriterion scb = SearchRestrictions.belongsTo("technologicalProcessRate", technologicalProcessRate);
if (dateTo == null) {
scb = SearchRestrictions.and(scb, SearchRestrictions.or(SearchRestrictions.ge(L_DATE_FROM, dateFrom), SearchRestrictions.and(SearchRestrictions.le(L_DATE_FROM, dateFrom), SearchRestrictions.gt(L_DATE_TO, dateFrom))));
} else {
scb = SearchRestrictions.and(scb, SearchRestrictions.and(SearchRestrictions.le(L_DATE_FROM, dateFrom), SearchRestrictions.gt(L_DATE_TO, dateFrom)));
}
if (technologicalProcessRateItem.getId() != null) {
scb = SearchRestrictions.and(scb, SearchRestrictions.ne("id", technologicalProcessRateItem.getId()));
}
long count = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, "technologicalProcessRateItem").count(scb);
return count != 0;
}
use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class SubassemblyValidators method validateUniquenessOfWorkstationAndType.
public void validateUniquenessOfWorkstationAndType(final DataDefinition subassemblyDD, final Entity subassembly) {
Entity workstationEntity = subassembly.getBelongsToField(SubassemblyFields.WORKSTATION);
if (workstationEntity != null) {
SearchCriterion criterionWorkstation = SearchRestrictions.belongsTo(SubassemblyFields.WORKSTATION, workstationEntity);
SearchCriterion criterionType = SearchRestrictions.eq(SubassemblyFields.TYPE, subassembly.getStringField(SubassemblyFields.TYPE));
SearchCriterion criterionId = subassembly.getId() == null ? null : SearchRestrictions.idNe(subassembly.getId());
Long count = criterionId == null ? subassemblyDD.count(SearchRestrictions.and(criterionWorkstation, criterionType)) : subassemblyDD.count(SearchRestrictions.and(criterionWorkstation, criterionType, criterionId));
if (count > 0) {
subassembly.addError(subassemblyDD.getField(SubassemblyFields.WORKSTATION), "basic.validate.global.error.uniquenessOfWorkstationAndType");
}
}
}
use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class DeliveredProductReservationHooks method locationUnique.
private boolean locationUnique(final Entity deliveredProductReservation) {
Entity location = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.LOCATION);
Entity deliveredProduct = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.DELIVERED_PRODUCT);
if (Objects.nonNull(location)) {
SearchCriterion criterion;
SearchCriterion criterionLocation = SearchRestrictions.belongsTo(DeliveredProductReservationFields.LOCATION, location);
SearchCriterion criterionDeliveredProduct = SearchRestrictions.belongsTo(DeliveredProductReservationFields.DELIVERED_PRODUCT, deliveredProduct);
Long deliveredProductReservationId = deliveredProductReservation.getId();
if (Objects.isNull(deliveredProductReservationId)) {
criterion = SearchRestrictions.and(criterionLocation, criterionDeliveredProduct);
} else {
SearchCriterion criterionId = SearchRestrictions.idNe(deliveredProductReservationId);
criterion = SearchRestrictions.and(criterionLocation, criterionDeliveredProduct, criterionId);
}
boolean locationUnique = deliveredProductReservation.getDataDefinition().count(criterion) == 0;
if (!locationUnique) {
FieldDefinition locationField = deliveredProductReservation.getDataDefinition().getField(DeliveredProductReservationFields.LOCATION);
deliveredProductReservation.addError(locationField, "deliveries.deliveredProductReservation.error.locationNotUnique");
}
return locationUnique;
}
return true;
}
use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class OrderedProductReservationHooks method sumIsNotExceeded.
private boolean sumIsNotExceeded(final Entity orderedProductReservation) {
Entity orderedProduct = orderedProductReservation.getBelongsToField(OrderedProductReservationFields.ORDERED_PRODUCT);
BigDecimal productOrderedQuantity = orderedProduct.getDecimalField(OrderedProductReservationFields.ORDERED_QUANTITY);
BigDecimal reservationOrderedQuantity = orderedProductReservation.getDecimalField(OrderedProductReservationFields.ORDERED_QUANTITY);
SearchCriteriaBuilder searchCriteriaBuilder = orderedProductReservation.getDataDefinition().find();
SearchProjection sumOfQuantityProjection = SearchProjections.alias(SearchProjections.sum(OrderedProductReservationFields.ORDERED_QUANTITY), L_SUM_OF_QUANTITY);
searchCriteriaBuilder.setProjection(SearchProjections.list().add(sumOfQuantityProjection).add(SearchProjections.rowCount()));
SearchCriterion criterion;
SearchCriterion criterionOrderedProduct = SearchRestrictions.belongsTo(OrderedProductReservationFields.ORDERED_PRODUCT, orderedProduct);
Long orderedProductReservationId = orderedProductReservation.getId();
if (Objects.isNull(orderedProductReservationId)) {
criterion = criterionOrderedProduct;
} else {
SearchCriterion criterionId = SearchRestrictions.idNe(orderedProductReservationId);
criterion = SearchRestrictions.and(criterionOrderedProduct, criterionId);
}
searchCriteriaBuilder.add(criterion);
searchCriteriaBuilder.addOrder(SearchOrders.asc(L_SUM_OF_QUANTITY));
SearchResult resList = searchCriteriaBuilder.setMaxResults(1).list();
BigDecimal sumOfQuantity = resList.getTotalNumberOfEntities() == 0 ? BigDecimal.ZERO : resList.getEntities().get(0).getDecimalField(L_SUM_OF_QUANTITY);
sumOfQuantity = BigDecimalUtils.convertNullToZero(sumOfQuantity);
boolean sumIsNotExceeded = productOrderedQuantity.compareTo(reservationOrderedQuantity.add(sumOfQuantity)) >= 0;
if (!sumIsNotExceeded) {
FieldDefinition orderedQuantityField = orderedProductReservation.getDataDefinition().getField(OrderedProductReservationFields.ORDERED_QUANTITY);
orderedProductReservation.addError(orderedQuantityField, "deliveries.deliveredProductReservation.error.sumIsExceeded");
}
return sumIsNotExceeded;
}
use of com.qcadoo.model.api.search.SearchCriterion in project mes by qcadoo.
the class ChangeoverNormsSearchServiceImpl method getTechnologiesRestrictions.
private SearchCriterion getTechnologiesRestrictions(final Long fromTechnologyId, final Long fromTechnologyGroupId, final Long toTechnologyId, final Long toTechnologyGroupId) {
SearchCriterion matchTechnologies = getPairRestriction(LineChangeoverNormsFields.FROM_TECHNOLOGY, fromTechnologyId, LineChangeoverNormsFields.TO_TECHNOLOGY, toTechnologyId);
SearchCriterion matchTechnologyGroups = getPairRestriction(LineChangeoverNormsFields.FROM_TECHNOLOGY_GROUP, fromTechnologyGroupId, LineChangeoverNormsFields.TO_TECHNOLOGY_GROUP, toTechnologyGroupId);
Preconditions.checkArgument(matchTechnologies != null || matchTechnologyGroups != null, "you have to provide pair of technologies or pair of technology groups.");
SearchDisjunction disjunction = SearchRestrictions.disjunction();
if (matchTechnologies != null) {
disjunction.add(matchTechnologies);
}
if (matchTechnologyGroups != null) {
disjunction.add(matchTechnologyGroups);
}
return disjunction;
}
Aggregations