Search in sources :

Example 66 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.

the class GridComponentPattern method parseColumnOption.

private void parseColumnOption(final ComponentOption option) {
    GridComponentColumn column = new GridComponentColumn(option.getAttributeValue("name"));
    String fields = option.getAttributeValue("fields");
    if (Objects.nonNull(fields)) {
        for (FieldDefinition field : parseFields(fields, column)) {
            column.addField(field);
        }
    }
    column.setAuthorizationRole(parseColumnAuthorizationRole(option));
    column.setAlign(parseColumnAlignOption(option));
    column.setExpression(option.getAttributeValue("expression"));
    String columnWidth = option.getAttributeValue("width");
    if (Objects.nonNull(columnWidth)) {
        column.setWidth(Integer.valueOf(columnWidth));
    }
    if (Objects.nonNull(option.getAttributeValue("link"))) {
        column.setLink(Boolean.parseBoolean(option.getAttributeValue("link")));
    }
    if (Objects.nonNull(option.getAttributeValue("hidden"))) {
        column.setHidden(Boolean.parseBoolean(option.getAttributeValue("hidden")));
    }
    column.setClassesNames(option.getAttributeValue("classesNames"));
    column.setClassesCondition(option.getAttributeValue("classesCondition"));
    column.setFormatter(option.getAttributeValue("formatter"));
    column.setCorrespondingView(option.getAttributeValue("correspondingView"));
    column.setCorrespondingField(option.getAttributeValue("correspondingField"));
    column.setCorrespondingViewField(option.getAttributeValue("correspondingViewField"));
    if (Objects.nonNull(option.getAttributeValue("attachment"))) {
        column.setAttachment(Boolean.parseBoolean(option.getAttributeValue("attachment")));
    }
    columns.put(column.getName(), column);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition)

Example 67 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.

the class StateChangeViewClientValidationUtilTest method mockFieldDefinition.

private FieldDefinition mockFieldDefinition(final String name) {
    final FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getName()).willReturn(name);
    return fieldDefinition;
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition)

Example 68 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.

the class StateChangeViewClientValidationUtilTest method shouldAddValidationErrorToFormIfFieldIsNull.

@Test
public final void shouldAddValidationErrorToFormIfFieldIsNull() {
    // given
    DataDefinition dataDefinition = mockDataDefinition(Lists.<FieldDefinition>newArrayList());
    given(entity.getDataDefinition()).willReturn(dataDefinition);
    given(formComponent.getEntity()).willReturn(entity);
    Entity message = mockValidationErrorMsg(null, false, TRANSLATION_KEY);
    given(messagesHolder.getAllMessages()).willReturn(Lists.newArrayList(message));
    // when
    validationUtil.addValidationErrorMessages(formComponent, entity, messagesHolder);
    // then
    verify(entity, Mockito.never()).addError(Mockito.any(FieldDefinition.class), Mockito.eq(TRANSLATION_KEY));
    verify(formComponent).addTranslatedMessage(Mockito.any(String.class), Mockito.eq(convertViewMessageType(VALIDATION_ERROR)), Mockito.any(Boolean.class));
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 69 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.

the class StateChangeViewClientValidationUtilTest method shouldAddValidationErrorToFormIfFieldDoesNotExist.

@Test
public final void shouldAddValidationErrorToFormIfFieldDoesNotExist() {
    // given
    DataDefinition dataDefinition = mockDataDefinition(Lists.<FieldDefinition>newArrayList());
    given(entity.getDataDefinition()).willReturn(dataDefinition);
    given(formComponent.getEntity()).willReturn(entity);
    Entity message = mockValidationErrorMsg("notExistingField", false, TRANSLATION_KEY);
    given(messagesHolder.getAllMessages()).willReturn(Lists.newArrayList(message));
    // when
    validationUtil.addValidationErrorMessages(formComponent, entity, messagesHolder);
    // then
    verify(entity, Mockito.never()).addError(Mockito.any(FieldDefinition.class), Mockito.eq(TRANSLATION_KEY));
    verify(formComponent).addTranslatedMessage(Mockito.any(String.class), Mockito.eq(convertViewMessageType(VALIDATION_ERROR)), Mockito.any(Boolean.class));
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 70 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.

the class StateChangeViewClientValidationUtilTest method shouldAddValidationErrorToEntityField.

@Test
public final void shouldAddValidationErrorToEntityField() {
    // given
    final String existingFieldName = "existingField";
    FieldDefinition existingField = mockFieldDefinition(existingFieldName);
    DataDefinition dataDefinition = mockDataDefinition(Lists.newArrayList(existingField));
    given(entity.getDataDefinition()).willReturn(dataDefinition);
    given(formComponent.getEntity()).willReturn(entity);
    Entity message = mockValidationErrorMsg(existingFieldName, false, TRANSLATION_KEY);
    given(messagesHolder.getAllMessages()).willReturn(Lists.newArrayList(message));
    // when
    validationUtil.addValidationErrorMessages(formComponent, entity, messagesHolder);
    // then
    verify(entity).addError(existingField, TRANSLATION_KEY);
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Aggregations

FieldDefinition (com.qcadoo.model.api.FieldDefinition)142 Test (org.junit.Test)92 DataDefinition (com.qcadoo.model.api.DataDefinition)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)48 Entity (com.qcadoo.model.api.Entity)32 BelongsToType (com.qcadoo.model.api.types.BelongsToType)19 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)15 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)13 InternalFieldDefinition (com.qcadoo.model.internal.api.InternalFieldDefinition)12 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)11 HasManyType (com.qcadoo.model.api.types.HasManyType)9 StringType (com.qcadoo.model.internal.types.StringType)9 JSONObject (org.json.JSONObject)8 Map (java.util.Map)7 Matchers.anyString (org.mockito.Matchers.anyString)7 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)6 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)6 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)6 Before (org.junit.Before)6 EntityList (com.qcadoo.model.api.EntityList)5