use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class StateChangeContextTest method shouldCopyValidationErrorMessagesFromEntity.
@Test
public final void shouldCopyValidationErrorMessagesFromEntity() {
// given
given(owner.isValid()).willReturn(false);
final Map<String, ErrorMessage> fieldErrorsMap = Maps.newHashMap();
final ErrorMessage fieldErrorMessage = buildErrorMessage(FIELD_1_MESSAGE_1);
fieldErrorsMap.put(FIELD_1_NAME, fieldErrorMessage);
given(owner.getErrors()).willReturn(fieldErrorsMap);
final List<ErrorMessage> globalErrors = Lists.newArrayList();
final ErrorMessage globalErrorMessage = buildErrorMessage(GLOBAL_MESSAGE_1);
globalErrors.add(globalErrorMessage);
given(owner.getGlobalErrors()).willReturn(globalErrors);
// when
stateChangeContext.setOwner(owner);
// then
verify(messageService).addValidationError(stateChangeContext, FIELD_1_NAME, FIELD_1_MESSAGE_1, EMPTY_STRING_ARRAY);
verify(messageService).addValidationError(stateChangeContext, null, GLOBAL_MESSAGE_1, EMPTY_STRING_ARRAY);
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class ValidationMessageHelper method copyErrorsFromEntity.
public static void copyErrorsFromEntity(final StateChangeContext stateChangeContext, final Entity entity) {
for (ErrorMessage globalError : entity.getGlobalErrors()) {
stateChangeContext.addValidationError(globalError.getMessage(), globalError.getVars());
}
for (Entry<String, ErrorMessage> fieldErrorMessageEntry : entity.getErrors().entrySet()) {
final ErrorMessage fieldErrorMessage = fieldErrorMessageEntry.getValue();
stateChangeContext.addFieldValidationError(fieldErrorMessageEntry.getKey(), fieldErrorMessage.getMessage(), fieldErrorMessage.getVars());
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class OperationModelHooks method createOperationOutput.
private void createOperationOutput(final Entity operation) {
if (operation.getBooleanField(OperationFields.CREATE_OPERATION_OUTPUT) && Objects.isNull(operation.getBelongsToField(OperationFields.PRODUCT))) {
Entity product = createProductForOperation(operation);
if (!product.isValid()) {
ErrorMessage errorMessage = product.getError(ProductFields.NUMBER);
if (Objects.nonNull(errorMessage) && errorMessage.getMessage().equals("qcadooView.validate.field.error.duplicated")) {
operation.addGlobalError("technologies.operation.createOperationOutput.failed.productDuplicated", product.getStringField(ProductFields.NUMBER));
}
operation.addGlobalError("technologies.operation.createOperationOutput.failed");
} else {
operation.setField(OperationFields.PRODUCT, product.getId());
}
}
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class WarehouseMinimumStateListListener method createMultiMinimalStates.
@Transactional
public void createMultiMinimalStates(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity state = form.getPersistedEntityWithIncludedFormValues();
if (state.getBelongsToField(WarehouseMinimumStateFields.LOCATION) == null) {
LookupComponent location = (LookupComponent) view.getComponentByReference(WarehouseMinimumStateFields.LOCATION);
location.addMessage(new ErrorMessage(L_QCADOO_VIEW_VALIDATE_FIELD_ERROR_MISSING));
location.requestComponentUpdateState();
return;
}
if (state.getManyToManyField("products") == null || state.getManyToManyField("products").isEmpty()) {
view.addMessage(new ErrorMessage("warehouseMinimalState.warehouseMinimumStateAddMulti.error.productsEmpthy"));
return;
}
state.getManyToManyField("products").forEach(p -> createMinimalStateEntity(state, p));
componentState.addMessage("warehouseMinimalState.warehouseMinimumStateAddMulti.info.generated", ComponentState.MessageType.SUCCESS);
}
use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.
the class DetailedProductionCountingAndProgressListHooks method onRemoveSelectedProductionCountingQuantities.
public void onRemoveSelectedProductionCountingQuantities(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent grid = ((GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID));
List<Entity> selectedEntities = grid.getSelectedEntities();
List<Long> ids = new ArrayList<>();
boolean deleteSuccessful = true;
List<ErrorMessage> errors = Lists.newArrayList();
for (Entity productionCountingQuantity : selectedEntities) {
String typeOfMaterial = productionCountingQuantity.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL);
if (GlobalTypeOfMaterial.FINAL_PRODUCT.getStringValue().equals(typeOfMaterial)) {
state.addMessage("basicProductionCounting.productionCountingQuantity.error.cantDeleteFinal", ComponentState.MessageType.INFO);
} else {
ids.add(productionCountingQuantity.getId());
if (deleteSuccessful) {
EntityOpResult result = productionCountingQuantity.getDataDefinition().delete(productionCountingQuantity.getId());
if (!result.isSuccessfull()) {
deleteSuccessful = false;
errors.addAll(result.getMessagesHolder().getGlobalErrors());
}
}
}
}
if (ids.size() == 1 && deleteSuccessful) {
state.addMessage("qcadooView.message.deleteMessage", ComponentState.MessageType.SUCCESS);
} else if (ids.size() > 1 && deleteSuccessful) {
state.addMessage("qcadooView.message.deleteMessages", ComponentState.MessageType.SUCCESS, String.valueOf(ids.size()));
} else if (!deleteSuccessful) {
errors.stream().forEach(error -> state.addMessage(error));
}
}
Aggregations