use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class OperationModelValidators method appendErrorToModelField.
private void appendErrorToModelField(final Entity entity, final String fieldName, final String messageKey) {
FieldDefinition productInFieldDef = entity.getDataDefinition().getField(fieldName);
entity.addError(productInFieldDef, messageKey);
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class RegexFailedValidationLoggingAspect method afterReturningCallExecution.
@AfterReturning(pointcut = "callExecution(target, entity, oldValue, newValue)", returning = "result")
public void afterReturningCallExecution(final Object target, final Entity entity, final Object oldValue, final Object newValue, final boolean result) {
if (!result && logger.isInfoEnabled()) {
try {
List<String> messageStatements = Lists.newArrayList();
FieldDefinition fieldDefinition = (FieldDefinition) FieldUtils.readField(target, "fieldDefinition", true);
DataDefinition dataDefinition = fieldDefinition.getDataDefinition();
messageStatements.add("INPUT REJECTED FOR ENTITY: " + dataDefinition.getPluginIdentifier() + "." + dataDefinition.getName());
messageStatements.add("AND FIELD: " + fieldDefinition.getName());
messageStatements.add("OLD VALUE: " + Optional.ofNullable(oldValue).map(Object::toString).orElse(StringUtils.EMPTY));
messageStatements.add("NEW VALUE: " + Optional.ofNullable(newValue).map(Object::toString).orElse(StringUtils.EMPTY));
messageStatements.add("AUTHENTICATION:" + SecurityContextHolder.getContext().getAuthentication());
logger.info(String.join(" ", messageStatements));
} catch (IllegalAccessException iae) {
// ignore
}
}
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class ProductValidatorsTest method shouldCheckEanUniquenessReturnTrueIfThereIsNoExistingProductsWithGivenId.
@Test
public final void shouldCheckEanUniquenessReturnTrueIfThereIsNoExistingProductsWithGivenId() {
// given
String oldVal = "123456";
String newVal = "654321";
ArgumentCaptor<SearchCriterion> criterionCaptor = ArgumentCaptor.forClass(SearchCriterion.class);
stubSearchCriteriaWith(null);
// when
boolean isValid = productValidators.checkEanUniqueness(dataDefinition, fieldDefinition, entity, oldVal, newVal);
// then
assertTrue(isValid);
verify(entity, never()).addError(any(FieldDefinition.class), anyString());
verify(scb).add(criterionCaptor.capture());
assertEquals(SearchRestrictions.eq(ProductFields.EAN, newVal), criterionCaptor.getValue());
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class ProductValidatorsTest method shouldCheckEanUniquenessJustReturnTrueIfNewEanIsNull.
@Test
public final void shouldCheckEanUniquenessJustReturnTrueIfNewEanIsNull() {
// given
String oldVal = "123456";
String newVal = null;
// when
boolean isValid = productValidators.checkEanUniqueness(dataDefinition, fieldDefinition, entity, oldVal, newVal);
// then
assertTrue(isValid);
verify(entity, never()).addError(any(FieldDefinition.class), anyString());
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class DeliveredProductReservationHooks method sumIsNotExceeded.
private boolean sumIsNotExceeded(final Entity deliveredProductReservation) {
Entity deliveredProduct = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.DELIVERED_PRODUCT);
BigDecimal productDeliveredQuantity = deliveredProduct.getDecimalField(DeliveredProductFields.DELIVERED_QUANTITY);
if (Objects.isNull(productDeliveredQuantity)) {
return true;
}
BigDecimal reservationDeliveredQuantity = deliveredProductReservation.getDecimalField(DeliveredProductReservationFields.DELIVERED_QUANTITY);
SearchCriteriaBuilder searchCriteriaBuilder = deliveredProductReservation.getDataDefinition().find();
SearchProjection sumOfQuantityProjection = SearchProjections.alias(SearchProjections.sum(DeliveredProductReservationFields.DELIVERED_QUANTITY), L_SUM_OF_QUANTITY);
searchCriteriaBuilder.setProjection(SearchProjections.list().add(sumOfQuantityProjection).add(SearchProjections.rowCount()));
SearchCriterion criterion;
SearchCriterion criterionDeliveredProduct = SearchRestrictions.belongsTo(DeliveredProductReservationFields.DELIVERED_PRODUCT, deliveredProduct);
Long deliveredProductReservationId = deliveredProductReservation.getId();
if (Objects.isNull(deliveredProductReservationId)) {
criterion = criterionDeliveredProduct;
} else {
SearchCriterion criterionId = SearchRestrictions.idNe(deliveredProductReservationId);
criterion = SearchRestrictions.and(criterionDeliveredProduct, 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);
BigDecimal damagedQuantity = deliveredProduct.getDecimalField(DeliveredProductFields.DAMAGED_QUANTITY);
damagedQuantity = BigDecimalUtils.convertNullToZero(damagedQuantity);
productDeliveredQuantity = productDeliveredQuantity.subtract(damagedQuantity);
boolean sumIsNotExceeded = productDeliveredQuantity.compareTo(reservationDeliveredQuantity.add(sumOfQuantity)) >= 0;
if (!sumIsNotExceeded) {
FieldDefinition deliveredQuantityField = deliveredProductReservation.getDataDefinition().getField(DeliveredProductReservationFields.DELIVERED_QUANTITY);
deliveredProductReservation.addError(deliveredQuantityField, "deliveries.deliveredProductReservation.error.sumIsExceeded");
}
return sumIsNotExceeded;
}
Aggregations