use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class WarehouseIssueDetailsListeners method fillProductsToIssue.
public void fillProductsToIssue(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent issueForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
FieldComponent collectionProductsField = (FieldComponent) view.getComponentByReference(WarehouseIssueFields.COLLECTION_PRODUCTS);
LookupComponent operation = (LookupComponent) view.getComponentByReference(WarehouseIssueFields.TECHNOLOGY_OPERATION_COMPONENT);
LookupComponent division = (LookupComponent) view.getComponentByReference(WarehouseIssueFields.DIVISION);
Long warehouseIssueId = issueForm.getEntityId();
Entity toc = operation.getEntity();
Entity divisionEntity = division.getEntity();
List<Entity> createdProducts = warehouseIssueService.fillProductsToIssue(warehouseIssueId, CollectionProducts.fromStringValue(collectionProductsField.getFieldValue().toString()), toc, divisionEntity);
if (createdProducts != null) {
List<Entity> invalidProducts = createdProducts.stream().filter(productToIssue -> !productToIssue.isValid()).collect(Collectors.toList());
if (invalidProducts.isEmpty()) {
view.addMessage("productFlowThruDivision.issue.downloadedProducts", ComponentState.MessageType.SUCCESS);
} else {
Multimap<String, String> errors = ArrayListMultimap.create();
for (Entity productToIssue : invalidProducts) {
String number = productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT).getStringField(ProductFields.NUMBER);
Map<String, ErrorMessage> errorMessages = productToIssue.getErrors();
errorMessages.entrySet().stream().forEach(entry -> errors.put(entry.getValue().getMessage(), number));
productToIssue.getGlobalErrors().stream().forEach(error -> errors.put(error.getMessage(), number));
}
view.addMessage("productFlowThruDivision.issue.downloadedProductsError", ComponentState.MessageType.INFO, false);
for (String message : errors.keySet()) {
String translatedMessage = translationService.translate(message, LocaleContextHolder.getLocale());
String products = errors.get(message).stream().collect(Collectors.joining(", "));
if ((translatedMessage + products).length() < 255) {
view.addMessage("productFlowThruDivision.issue.downloadedProductsErrorMessages", ComponentState.MessageType.FAILURE, false, translatedMessage, products);
}
}
}
} else {
view.addMessage("productFlowThruDivision.issue.noProductsToDownload", ComponentState.MessageType.INFO);
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class TechnologyValidationService method createMessageForValidationErrors.
private String createMessageForValidationErrors(final String message, final Entity entity) {
List<ErrorMessage> errors = Lists.newArrayList();
if (!entity.getErrors().isEmpty()) {
errors.addAll(entity.getErrors().values());
}
if (!entity.getGlobalErrors().isEmpty()) {
errors.addAll(entity.getGlobalErrors());
}
StringBuilder errorMessages = new StringBuilder();
errorMessages.append(message).append("\n");
for (ErrorMessage error : errors) {
if (!error.getMessage().equals("qcadooView.validate.global.error.custom")) {
String translatedErrorMessage = translationService.translate(error.getMessage(), Locale.getDefault(), error.getVars());
errorMessages.append("- ").append(translatedErrorMessage);
errorMessages.append(",\n ");
}
}
String msg = errorMessages.toString();
int length = msg.length();
String lastSign = msg.substring(length - 3);
if (",\n ".equals(lastSign)) {
msg = msg.substring(0, length - 3);
}
return msg;
}
use of com.qcadoo.model.api.validators.ErrorMessage in project qcadoo by qcadoo.
the class DataAccessServiceImpl method logEntityErrors.
private void logEntityErrors(final Entity entity, final String msg) {
if (!LOG.isInfoEnabled()) {
return;
}
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotEmpty(msg)) {
sb.append(msg);
sb.append('\n');
}
for (ErrorMessage error : entity.getGlobalErrors()) {
sb.append(" --- " + error.getMessage());
sb.append('\n');
}
for (Map.Entry<String, ErrorMessage> error : entity.getErrors().entrySet()) {
sb.append(" --- " + error.getKey() + ": " + error.getValue().getMessage());
sb.append('\n');
}
LOG.info(sb.toString());
}
use of com.qcadoo.model.api.validators.ErrorMessage in project qcadoo by qcadoo.
the class CustomValidatorTest method shouldNotAddDefaultMessageIfValidationSuccessAndThereIsAlreadyMessageAssignedToField.
@Test
public final void shouldNotAddDefaultMessageIfValidationSuccessAndThereIsAlreadyMessageAssignedToField() {
// given
Map<String, ErrorMessage> errors = Maps.newHashMap();
errors.put("another" + FIELD_NAME, new ErrorMessage(CUSTOM_MSG));
stubFieldHookDef(true, errors);
// when
boolean isValid = customValidator.call(entity, oldValue, newValue);
// then
assertTrue(isValid);
verify(fieldHookDef, times(1)).call(entity, oldValue, newValue);
verify(entity, never()).addError(Mockito.eq(fieldDefinition), Mockito.eq(CUSTOM_MSG), Mockito.<String>anyVararg());
verify(entity, never()).addError(Mockito.eq(fieldDefinition), Mockito.eq(DEFAULT_MSG), Mockito.<String>anyVararg());
}
use of com.qcadoo.model.api.validators.ErrorMessage in project qcadoo by qcadoo.
the class CustomValidatorTest method shouldNotAddDefaultMessageIfValidationSuccessAndThereIsAlreadyMessageAssignedToOtherField.
@Test
public final void shouldNotAddDefaultMessageIfValidationSuccessAndThereIsAlreadyMessageAssignedToOtherField() {
// given
Map<String, ErrorMessage> errors = Maps.newHashMap();
errors.put(FIELD_NAME, new ErrorMessage(CUSTOM_MSG));
stubFieldHookDef(true, errors);
// when
boolean isValid = customValidator.call(entity, oldValue, newValue);
// then
assertTrue(isValid);
verify(fieldHookDef, times(1)).call(entity, oldValue, newValue);
ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class);
verify(entity, times(1)).addError(Mockito.eq(fieldDefinition), argCaptor.capture(), Mockito.<String>anyVararg());
assertEquals(CUSTOM_MSG, argCaptor.getValue());
}
Aggregations