use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class OrderedProductReservationHooks method locationUnique.
private boolean locationUnique(final Entity orderedProductReservation) {
Entity location = orderedProductReservation.getBelongsToField(OrderedProductReservationFields.LOCATION);
Entity orderedProduct = orderedProductReservation.getBelongsToField(OrderedProductReservationFields.ORDERED_PRODUCT);
if (Objects.nonNull(location)) {
SearchCriterion criterion;
SearchCriterion criterionLocation = SearchRestrictions.belongsTo(OrderedProductReservationFields.LOCATION, location);
SearchCriterion criterionOrderedProduct = SearchRestrictions.belongsTo(OrderedProductReservationFields.ORDERED_PRODUCT, orderedProduct);
Long orderedProductReservationId = orderedProductReservation.getId();
if (Objects.isNull(orderedProductReservationId)) {
criterion = SearchRestrictions.and(criterionLocation, criterionOrderedProduct);
} else {
SearchCriterion criterionId = SearchRestrictions.idNe(orderedProductReservationId);
criterion = SearchRestrictions.and(criterionLocation, criterionOrderedProduct, criterionId);
}
boolean locationUnique = orderedProductReservation.getDataDefinition().count(criterion) == 0;
if (!locationUnique) {
FieldDefinition locationField = orderedProductReservation.getDataDefinition().getField(OrderedProductReservationFields.LOCATION);
orderedProductReservation.addError(locationField, "deliveries.deliveredProductReservation.error.locationNotUnique");
}
return locationUnique;
}
return true;
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class ReservationService method validateDeliveryOrderedProductsAgainstReservations.
private boolean validateDeliveryOrderedProductsAgainstReservations(final Entity delivery) {
Entity deliveryLocation = delivery.getBelongsToField(DeliveryFields.LOCATION);
EntityList orderedProducts = delivery.getHasManyField(DeliveryFields.ORDERED_PRODUCTS);
if (Objects.nonNull(orderedProducts) && Objects.nonNull(deliveryLocation)) {
for (Entity orderedProduct : orderedProducts) {
EntityList reservations = orderedProduct.getHasManyField(OrderedProductFields.RESERVATIONS);
if (Objects.nonNull(reservations)) {
for (Entity reservation : reservations) {
Entity reservationLocation = reservation.getBelongsToField(OrderedProductReservationFields.LOCATION);
if (deliveryLocation.getId().equals(reservationLocation.getId())) {
FieldDefinition locationField = delivery.getDataDefinition().getField(DeliveryFields.LOCATION);
delivery.addError(locationField, "deliveries.delivery.error.locationNotUniqueToDelivery", deliveryLocation.getStringField(LocationFields.NUMBER));
return false;
}
}
}
}
}
return true;
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class ReservationService method validateDeliveryDeliveredProductsAgainstReservations.
private boolean validateDeliveryDeliveredProductsAgainstReservations(final Entity delivery) {
Entity deliveryLocation = delivery.getBelongsToField(DeliveryFields.LOCATION);
EntityList deliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS);
if (Objects.nonNull(deliveredProducts) && Objects.nonNull(deliveryLocation)) {
for (Entity deliveredProduct : deliveredProducts) {
EntityList reservations = deliveredProduct.getHasManyField(DeliveredProductFields.RESERVATIONS);
if (Objects.nonNull(reservations)) {
for (Entity reservation : reservations) {
Entity reservationLocation = reservation.getBelongsToField(DeliveredProductReservationFields.LOCATION);
if (deliveryLocation.getId().equals(reservationLocation.getId())) {
FieldDefinition locationField = delivery.getDataDefinition().getField(DeliveryFields.LOCATION);
delivery.addError(locationField, "deliveries.delivery.error.locationNotUniqueToDelivery", deliveryLocation.getStringField(LocationFields.NUMBER));
return false;
}
}
}
}
}
return true;
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class BatchUtil method checkField.
private static void checkField(final DataDefinition dataDef, final String fieldName) {
FieldDefinition fd = dataDef.getField(fieldName);
if (fd.getType() instanceof BelongsToType) {
BelongsToType btType = (BelongsToType) fd.getType();
DataDefinition dd = btType.getDataDefinition();
if (AdvancedGenealogyConstants.PLUGIN_IDENTIFIER.equals(dd.getPluginIdentifier()) && AdvancedGenealogyConstants.MODEL_BATCH.equals(dd.getName())) {
return;
}
}
throw new IllegalArgumentException(String.format("Field '%s' should be of type belongsTo, pointing to the advanced genealogy's batch entity!", fieldName));
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class DeliveredProductReservationHooks method locationUniqueToDelivery.
private boolean locationUniqueToDelivery(final Entity deliveredProductReservation) {
Entity deliveredProduct = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.DELIVERED_PRODUCT);
Entity delivery = deliveredProduct.getBelongsToField(DeliveredProductFields.DELIVERY);
Entity deliveryLocation = delivery.getBelongsToField(DeliveryFields.LOCATION);
Entity reservationLocation = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.LOCATION);
boolean locationOtherThenDelivery = Objects.isNull(deliveryLocation) || !deliveryLocation.getId().equals(reservationLocation.getId());
if (!locationOtherThenDelivery) {
FieldDefinition locationField = deliveredProductReservation.getDataDefinition().getField(DeliveredProductReservationFields.LOCATION);
deliveredProductReservation.addError(locationField, "deliveries.deliveredProductReservation.error.locationNotUniqueToDelivery");
}
return locationOtherThenDelivery;
}
Aggregations