Search in sources :

Example 16 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class ProgressPerShiftViewSaver method showValidationErrors.

private void showValidationErrors(final ViewDefinitionState view, final Iterable<ErrorMessage> errorMessages) {
    FormComponent form = getFormComponent(view);
    form.addMessage("qcadooView.message.saveFailedMessage", ComponentState.MessageType.FAILURE);
    for (ErrorMessage errorMessage : errorMessages) {
        form.addMessage(errorMessage.getMessage(), ComponentState.MessageType.FAILURE, errorMessage.getVars());
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

Example 17 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class StateChangeContextTest method shouldMarkExistingDatabaseEntityAsInvalidIfConstructorGetInvalidStateChangeEntity.

@Test
public final void shouldMarkExistingDatabaseEntityAsInvalidIfConstructorGetInvalidStateChangeEntity() {
    // given
    final Entity existingStateChangeEntity = mock(Entity.class);
    given(stateChangeEntity.isValid()).willReturn(false);
    given(stateChangeEntity.getId()).willReturn(1L);
    given(stateChangeDD.get(Mockito.any(Long.class))).willReturn(existingStateChangeEntity);
    given(existingStateChangeEntity.isValid()).willReturn(true);
    final Map<String, ErrorMessage> fieldErrorsMap = Maps.newHashMap();
    final ErrorMessage fieldErrorMessage = buildErrorMessage(FIELD_1_MESSAGE_1);
    fieldErrorsMap.put(FIELD_1_NAME, fieldErrorMessage);
    given(stateChangeEntity.getErrors()).willReturn(fieldErrorsMap);
    final List<ErrorMessage> globalErrors = Lists.newArrayList();
    final ErrorMessage globalErrorMessage = buildErrorMessage(GLOBAL_MESSAGE_1);
    globalErrors.add(globalErrorMessage);
    given(stateChangeEntity.getGlobalErrors()).willReturn(globalErrors);
    // when
    new StateChangeContextImpl(stateChangeEntity, describer, messageService);
    // then
    verify(messageService).addValidationError(Mockito.any(StateChangeContext.class), Mockito.eq(FIELD_1_NAME), Mockito.eq(FIELD_1_MESSAGE_1));
    verify(messageService).addValidationError(Mockito.any(StateChangeContext.class), Mockito.eq((String) null), Mockito.eq(GLOBAL_MESSAGE_1));
    verify(existingStateChangeEntity).setField(describer.getStatusFieldName(), FAILURE.getStringValue());
}
Also used : Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Test(org.junit.Test)

Example 18 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class StateChangeContextTest method shouldNotSaveAndSetAlreadyInvalidOwnerEntity.

@Test
public final void shouldNotSaveAndSetAlreadyInvalidOwnerEntity() {
    // given
    given(owner.isValid()).willReturn(false);
    given(ownerDD.save(owner)).willReturn(owner);
    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(ownerDD, never()).save(owner);
    verify(stateChangeEntity, never()).setField(describer.getOwnerFieldName(), owner);
    verify(stateChangeEntity, never()).setField(describer.getOwnerFieldName(), savedOwner);
    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);
    verify(stateChangeEntity).setField(describer.getStatusFieldName(), StateChangeStatus.FAILURE.getStringValue());
}
Also used : ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Test(org.junit.Test)

Example 19 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class StateChangeContextTest method shouldMarkEntityAsInvalidAndSetStateToFailureIfStateChangeEntityIsInvalidAfterSave.

@Test
public final void shouldMarkEntityAsInvalidAndSetStateToFailureIfStateChangeEntityIsInvalidAfterSave() {
    // given
    final Entity savedStateChangeEntity = mock(Entity.class);
    given(stateChangeEntity.isValid()).willReturn(true);
    given(savedStateChangeEntity.isValid()).willReturn(true, false);
    given(stateChangeDD.save(stateChangeEntity)).willReturn(savedStateChangeEntity);
    final Map<String, ErrorMessage> fieldErrorsMap = Maps.newHashMap();
    final ErrorMessage fieldErrorMessage = buildErrorMessage(FIELD_1_MESSAGE_1);
    fieldErrorsMap.put(FIELD_1_NAME, fieldErrorMessage);
    given(savedStateChangeEntity.getErrors()).willReturn(fieldErrorsMap);
    final List<ErrorMessage> globalErrors = Lists.newArrayList();
    final ErrorMessage globalErrorMessage = buildErrorMessage(GLOBAL_MESSAGE_1);
    globalErrors.add(globalErrorMessage);
    given(savedStateChangeEntity.getGlobalErrors()).willReturn(globalErrors);
    // when
    stateChangeContext.save();
    // 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);
    verify(stateChangeEntity).setField(describer.getStatusFieldName(), FAILURE.getStringValue());
}
Also used : Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Test(org.junit.Test)

Example 20 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class StateChangeContextTest method shouldSaveButNotSetJustInvalidateOwnerEntity.

@Test
public final void shouldSaveButNotSetJustInvalidateOwnerEntity() {
    // given
    given(owner.isValid()).willReturn(true);
    given(ownerDD.save(owner)).willReturn(savedOwner);
    given(savedOwner.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(savedOwner.getErrors()).willReturn(fieldErrorsMap);
    final List<ErrorMessage> globalErrors = Lists.newArrayList();
    final ErrorMessage globalErrorMessage = buildErrorMessage(GLOBAL_MESSAGE_1);
    globalErrors.add(globalErrorMessage);
    given(savedOwner.getGlobalErrors()).willReturn(globalErrors);
    // when
    stateChangeContext.setOwner(owner);
    // then
    verify(ownerDD).save(owner);
    verify(stateChangeEntity, never()).setField(describer.getOwnerFieldName(), owner);
    verify(stateChangeEntity, never()).setField(describer.getOwnerFieldName(), savedOwner);
    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);
    verify(stateChangeEntity).setField(describer.getStatusFieldName(), StateChangeStatus.FAILURE.getStringValue());
}
Also used : ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Test(org.junit.Test)

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