Search in sources :

Example 1 with ErrorMessage

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

the class FormComponentState method copyFieldMessages.

private void copyFieldMessages(final EntityMessagesHolder messagesHolder) {
    for (Map.Entry<String, FieldComponentState> fieldComponentEntry : getFieldComponents().entrySet()) {
        ErrorMessage message = messagesHolder.getError(fieldComponentEntry.getKey());
        copyMessage(fieldComponentEntry.getValue(), message);
    }
}
Also used : FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ErrorMessage

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

the class FormComponentState method copyEntityToFields.

private void copyEntityToFields(final Entity entity, final boolean requestUpdateState) {
    for (Map.Entry<String, FieldComponentState> field : getFieldComponents().entrySet()) {
        ErrorMessage message = entity.getError(field.getKey());
        copyMessage(field.getValue(), message);
        if (fieldIsGridCorrespondingLookup(field.getValue(), field.getKey(), entity)) {
            continue;
        }
        if (fieldIsDetachedEntityTree(field.getValue(), field.getKey(), entity)) {
            EntityTree tree = entity.getTreeField(field.getKey());
            if (tree != null) {
                ((TreeComponentState) field.getValue()).setRootNode(tree.getRoot());
            }
        }
        field.getValue().setFieldValue(convertFieldToString(entity.getField(field.getKey()), field.getKey()));
        if (requestUpdateState) {
            field.getValue().requestComponentUpdateState();
        }
    }
}
Also used : FieldComponentState(com.qcadoo.view.internal.components.FieldComponentState) TreeComponentState(com.qcadoo.view.internal.components.tree.TreeComponentState) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) HashMap(java.util.HashMap) Map(java.util.Map) EntityTree(com.qcadoo.model.api.EntityTree)

Example 3 with ErrorMessage

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

the class FormComponentStateTest method shouldNotDeleteFormEntity.

@Test
public void shouldNotDeleteFormEntity() throws Exception {
    // given
    EntityMessagesHolder messagesHolder = mock(EntityMessagesHolder.class);
    final String message = "some.message";
    ErrorMessage errorMessage = new ErrorMessage(message);
    given(messagesHolder.getGlobalErrors()).willReturn(Lists.newArrayList(errorMessage));
    Map<String, ErrorMessage> fieldErrors = Maps.newHashMap();
    fieldErrors.put("name", errorMessage);
    given(messagesHolder.getErrors()).willReturn(fieldErrors);
    EntityOpResult result = EntityOpResult.failure(messagesHolder);
    given(dataDefinition.delete(13L)).willReturn(result);
    name.setFieldValue("text");
    form.setFieldValue(13L);
    // when
    form.performEvent(viewDefinitionState, "delete", new String[0]);
    // then
    assertNotNull(name.getFieldValue());
    verify(dataDefinition).delete(13L);
    assertEquals(13L, form.getFieldValue());
}
Also used : EntityOpResult(com.qcadoo.model.api.EntityOpResult) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) EntityMessagesHolder(com.qcadoo.model.api.EntityMessagesHolder) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 4 with ErrorMessage

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

the class CustomValidatorTest method shouldNotAddDefaultMessageIfValidationFailAndThereIsAlreadyMessageAssignedToField.

@Test
public final void shouldNotAddDefaultMessageIfValidationFailAndThereIsAlreadyMessageAssignedToField() {
    // given
    Map<String, ErrorMessage> errors = Maps.newHashMap();
    errors.put(FIELD_NAME, new ErrorMessage(CUSTOM_MSG));
    stubFieldHookDef(false, errors);
    // when
    boolean isValid = customValidator.call(entity, oldValue, newValue);
    // then
    assertFalse(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());
}
Also used : ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Test(org.junit.Test)

Example 5 with ErrorMessage

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

the class CustomValidatorTest method shouldAddDefaultMessageIfValidationFailAndThereIsAlreadyMessageAssignedToOtherField.

@Test
public final void shouldAddDefaultMessageIfValidationFailAndThereIsAlreadyMessageAssignedToOtherField() {
    // given
    Map<String, ErrorMessage> errors = Maps.newHashMap();
    errors.put("another" + FIELD_NAME, new ErrorMessage(CUSTOM_MSG));
    stubFieldHookDef(false, errors);
    // when
    boolean isValid = customValidator.call(entity, oldValue, newValue);
    // then
    assertFalse(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(DEFAULT_MSG, argCaptor.getValue());
}
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