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);
}
}
}
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;
}
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);
}
}
}
Aggregations