Search in sources :

Example 21 with ErrorMessage

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);
}
Also used : ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Test(org.junit.Test)

Example 22 with ErrorMessage

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());
    }
}
Also used : ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

Example 23 with ErrorMessage

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());
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

Example 24 with ErrorMessage

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);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with ErrorMessage

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));
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent) ArrayList(java.util.ArrayList) EntityOpResult(com.qcadoo.model.api.EntityOpResult) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

Aggregations

ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)50 Entity (com.qcadoo.model.api.Entity)30 BigDecimal (java.math.BigDecimal)11 Test (org.junit.Test)11 Transactional (org.springframework.transaction.annotation.Transactional)8 Map (java.util.Map)7 DataDefinition (com.qcadoo.model.api.DataDefinition)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 FormComponent (com.qcadoo.view.api.components.FormComponent)5 TranslationService (com.qcadoo.localization.api.TranslationService)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 LocaleContextHolder (org.springframework.context.i18n.LocaleContextHolder)4 Lists (com.google.common.collect.Lists)3 OrderFields (com.qcadoo.mes.orders.constants.OrderFields)3 ProductFlowThruDivisionConstants (com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants)3 WarehouseIssueParameterService (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService)3 ProductsToIssueFields (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields)3 WarehouseIssueFields (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields)3 StateChangeContext (com.qcadoo.mes.states.StateChangeContext)3