Search in sources :

Example 1 with BatchNumberUniqueness

use of com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness in project mes by qcadoo.

the class OrderedProductHooks method createBatch.

private void createBatch(final Entity orderedProduct) {
    String batchNumber = orderedProduct.getStringField(OrderedProductFields.BATCH_NUMBER);
    Entity product = orderedProduct.getBelongsToField(OrderedProductFields.PRODUCT);
    Entity delivery = orderedProduct.getBelongsToField(OrderedProductFields.DELIVERY);
    if (Objects.nonNull(batchNumber) && Objects.nonNull(product)) {
        Entity supplier = delivery.getBelongsToField(DeliveryFields.SUPPLIER);
        Entity batch = advancedGenealogyService.createOrGetBatch(batchNumber, product, supplier);
        if (batch.isValid()) {
            orderedProduct.setField(OrderedProductFields.BATCH_NUMBER, null);
            orderedProduct.setField(OrderedProductFields.BATCH, batch);
        } else {
            BatchNumberUniqueness batchNumberUniqueness = batchModelValidators.getBatchNumberUniqueness();
            String errorMessage = batchModelValidators.getBatchNumberErrorMessage(batchNumberUniqueness);
            orderedProduct.addGlobalError(errorMessage);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) BatchNumberUniqueness(com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness)

Example 2 with BatchNumberUniqueness

use of com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness in project mes by qcadoo.

the class BatchModelValidators method checkIfBatchNumberIsUnique.

public boolean checkIfBatchNumberIsUnique(final DataDefinition batchDD, final Entity batch) {
    BatchNumberUniqueness batchNumberUniqueness = getBatchNumberUniqueness();
    if (batchNumberUniqueness == null) {
        return true;
    }
    SearchCriterion criterion = batchNumberUniqueness.buildCriterionFor(batch);
    if (existsAnyBatchMatchingCriterion(batchDD, criterion)) {
        String errorMessage = getBatchNumberErrorMessage(batchNumberUniqueness);
        batch.addError(batchDD.getField(BatchFields.NUMBER), errorMessage);
        return false;
    }
    return true;
}
Also used : SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) BatchNumberUniqueness(com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness)

Example 3 with BatchNumberUniqueness

use of com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness in project mes by qcadoo.

the class DeliveredProductHooks method createBatch.

private void createBatch(final Entity deliveredProduct) {
    String batchNumber = deliveredProduct.getStringField(DeliveredProductFields.BATCH_NUMBER);
    Entity product = deliveredProduct.getBelongsToField(DeliveredProductFields.PRODUCT);
    Entity delivery = deliveredProduct.getBelongsToField(DeliveredProductFields.DELIVERY);
    if (Objects.nonNull(batchNumber) && Objects.nonNull(product) && Objects.nonNull(delivery)) {
        Entity supplier = delivery.getBelongsToField(DeliveryFields.SUPPLIER);
        Entity batch = advancedGenealogyService.createOrGetBatch(batchNumber, product, supplier);
        if (batch.isValid()) {
            deliveredProduct.setField(DeliveredProductFields.BATCH_NUMBER, null);
            deliveredProduct.setField(DeliveredProductFields.BATCH, batch);
        } else {
            BatchNumberUniqueness batchNumberUniqueness = batchModelValidators.getBatchNumberUniqueness();
            String errorMessage = batchModelValidators.getBatchNumberErrorMessage(batchNumberUniqueness);
            deliveredProduct.addGlobalError(errorMessage);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) BatchNumberUniqueness(com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness)

Aggregations

BatchNumberUniqueness (com.qcadoo.mes.advancedGenealogy.constants.BatchNumberUniqueness)3 Entity (com.qcadoo.model.api.Entity)2 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)1