Search in sources :

Example 76 with FieldDefinition

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion)

Example 77 with FieldDefinition

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) EntityList(com.qcadoo.model.api.EntityList)

Example 78 with FieldDefinition

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) EntityList(com.qcadoo.model.api.EntityList)

Example 79 with FieldDefinition

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));
}
Also used : BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 80 with FieldDefinition

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;
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition)

Aggregations

FieldDefinition (com.qcadoo.model.api.FieldDefinition)142 Test (org.junit.Test)92 DataDefinition (com.qcadoo.model.api.DataDefinition)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)48 Entity (com.qcadoo.model.api.Entity)32 BelongsToType (com.qcadoo.model.api.types.BelongsToType)19 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)15 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)13 InternalFieldDefinition (com.qcadoo.model.internal.api.InternalFieldDefinition)12 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)11 HasManyType (com.qcadoo.model.api.types.HasManyType)9 StringType (com.qcadoo.model.internal.types.StringType)9 JSONObject (org.json.JSONObject)8 Map (java.util.Map)7 Matchers.anyString (org.mockito.Matchers.anyString)7 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)6 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)6 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)6 Before (org.junit.Before)6 EntityList (com.qcadoo.model.api.EntityList)5