Search in sources :

Example 16 with FieldType

use of com.qcadoo.model.api.types.FieldType in project qcadoo by qcadoo.

the class ExpressionServiceImpl method getValuesForEntity.

private Map<String, Object> getValuesForEntity(final Entity entity, final Locale locale, final int level) {
    if (entity == null) {
        return null;
    }
    Map<String, Object> values = new HashMap<>();
    values.put("id", entity.getId());
    if (level == 0) {
        values.putAll(entity.getFields());
        return values;
    }
    for (Map.Entry<String, Object> entry : entity.getFields().entrySet()) {
        if (entry.getValue() instanceof Collection) {
            values.put(entry.getKey(), entry.getValue());
        } else {
            FieldType type = entity.getDataDefinition().getField(entry.getKey()).getType();
            if (type instanceof BelongsToType) {
                Entity belongsToEntity = getBelongsToEntity(entry.getValue(), (BelongsToType) type);
                values.put(entry.getKey(), getValuesForEntity(belongsToEntity, locale, level - 1));
            } else {
                String value = null;
                if (entry.getValue() != null) {
                    value = type.toString(entry.getValue(), locale);
                }
                values.put(entry.getKey(), value);
            }
        }
    }
    return values;
}
Also used : Entity(com.qcadoo.model.api.Entity) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldType(com.qcadoo.model.api.types.FieldType)

Example 17 with FieldType

use of com.qcadoo.model.api.types.FieldType in project qcadoo by qcadoo.

the class ModelXmlToDefinitionConverterImpl method createFieldElement.

private FieldHookDefinition createFieldElement(final XMLStreamReader reader, final FieldDefinition fieldDefinition, final String tag) throws HookInitializationException, ModelXmlParsingException {
    FieldHookDefinition fieldHookDefinition;
    switch(FieldTag.valueOf(tag.toUpperCase(Locale.ENGLISH))) {
        case VALIDATESLENGTH:
            fieldHookDefinition = getValidatorDefinition(reader, new LengthValidator(getIntegerAttribute(reader, "min"), getIntegerAttribute(reader, "is"), getIntegerAttribute(reader, "max")));
            break;
        case VALIDATESUNSCALEDVALUE:
            fieldHookDefinition = getValidatorDefinition(reader, new UnscaledValueValidator(getIntegerAttribute(reader, "min"), getIntegerAttribute(reader, "is"), getIntegerAttribute(reader, "max")));
            break;
        case VALIDATESSCALE:
            fieldHookDefinition = getValidatorDefinition(reader, new ScaleValidator(getIntegerAttribute(reader, "min"), getIntegerAttribute(reader, "is"), getIntegerAttribute(reader, "max")));
            break;
        case VALIDATESRANGE:
            FieldType type = fieldDefinition.getType();
            Object from = getRangeForType(getStringAttribute(reader, "from"), type);
            Object to = getRangeForType(getStringAttribute(reader, "to"), type);
            boolean exclusively = getBooleanAttribute(reader, "exclusively", false);
            fieldHookDefinition = getValidatorDefinition(reader, new RangeValidator(from, to, exclusively));
            break;
        case VALIDATESWITH:
            fieldHookDefinition = getValidatorDefinition(reader, new CustomValidator(getFieldHookDefinition(reader)));
            break;
        case VALIDATESREGEX:
            fieldHookDefinition = getValidatorDefinition(reader, new RegexValidator(getStringAttribute(reader, "pattern")));
            break;
        default:
            throw new ModelXmlParsingException("Illegal type of field's validator '" + tag + "'");
    }
    return fieldHookDefinition;
}
Also used : FieldType(com.qcadoo.model.api.types.FieldType)

Example 18 with FieldType

use of com.qcadoo.model.api.types.FieldType in project qcadoo by qcadoo.

the class GridComponentFilterUtilsTest method mockFieldDefinition.

@SuppressWarnings("unchecked")
private FieldDefinition mockFieldDefinition(final String fieldName, @SuppressWarnings("rawtypes") final Class typeClass, final DataDefinition dataDefinition) {
    final FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getName()).willReturn(fieldName);
    final FieldType fieldType = mock(FieldType.class);
    given(fieldType.getType()).willReturn(typeClass);
    given(fieldDefinition.getType()).willReturn(fieldType);
    DataDefinition ddMock = this.dataDefinition;
    if (dataDefinition != null) {
        ddMock = dataDefinition;
    }
    given(ddMock.getField(fieldName)).willReturn(fieldDefinition);
    return fieldDefinition;
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) FieldType(com.qcadoo.model.api.types.FieldType)

Example 19 with FieldType

use of com.qcadoo.model.api.types.FieldType in project qcadoo by qcadoo.

the class InitializationTest method shouldInitializeAllComponents.

@Test
public void shouldInitializeAllComponents() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    DataDefinition hasManyDataDefinition = mock(DataDefinition.class);
    DataDefinition belongsToDataDefinition = mock(DataDefinition.class);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    FieldType fieldType = mock(FieldType.class);
    BelongsToType belongsToType = mock(BelongsToType.class);
    HasManyType hasManyType = mock(HasManyType.class);
    given(dataDefinition.getField("hasMany")).willReturn(hasManyFieldDefinition);
    given(belongsToDataDefinition.getField("hasMany")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("belongsTo")).willReturn(belongsToFieldDefinition);
    given(dataDefinition.getField("field")).willReturn(fieldDefinition);
    given(fieldDefinition.getType()).willReturn(fieldType);
    given(hasManyFieldDefinition.getType()).willReturn(hasManyType);
    given(belongsToFieldDefinition.getType()).willReturn(belongsToType);
    given(hasManyType.getDataDefinition()).willReturn(hasManyDataDefinition);
    given(belongsToType.getDataDefinition()).willReturn(belongsToDataDefinition);
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("view", "plugin", dataDefinition, true, null);
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("parent", viewDefinition));
    AbstractContainerPattern form = new FormComponentPattern(getComponentDefinition(QcadooViewConstants.L_FORM, null, null, parent, viewDefinition));
    AbstractComponentPattern input = new TextInputComponentPattern(getComponentDefinition("input", "field", null, form, viewDefinition));
    AbstractComponentPattern select = new TextInputComponentPattern(getComponentDefinition("select", "belongsTo", null, form, viewDefinition));
    AbstractComponentPattern subselect = new TextInputComponentPattern(getComponentDefinition("subselect", "#{parent.form}.hasMany", "#{parent.form.select}.hasMany", form, viewDefinition));
    AbstractComponentPattern grid = new TextInputComponentPattern(getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{parent.form}.hasMany", parent, viewDefinition));
    parent.addChild(form);
    parent.addChild(grid);
    form.addChild(input);
    form.addChild(select);
    form.addChild(subselect);
    viewDefinition.addComponentPattern(parent);
    // when
    viewDefinition.initialize();
    // then
    assertEquals(dataDefinition, getField(parent, "dataDefinition"));
    assertEquals(dataDefinition, getField(form, "dataDefinition"));
    assertEquals(dataDefinition, getField(input, "dataDefinition"));
    assertEquals(belongsToDataDefinition, getField(select, "dataDefinition"));
    assertEquals(hasManyDataDefinition, getField(subselect, "dataDefinition"));
    assertEquals(hasManyDataDefinition, getField(grid, "dataDefinition"));
    assertNull(getField(parent, "scopeFieldDefinition"));
    assertNull(getField(form, "scopeFieldDefinition"));
    assertNull(getField(input, "scopeFieldDefinition"));
    assertNull(getField(select, "scopeFieldDefinition"));
    assertEquals(hasManyFieldDefinition, getField(subselect, "scopeFieldDefinition"));
    assertEquals(hasManyFieldDefinition, getField(grid, "scopeFieldDefinition"));
    assertNull(getField(parent, "fieldDefinition"));
    assertNull(getField(form, "fieldDefinition"));
    assertEquals(fieldDefinition, getField(input, "fieldDefinition"));
    assertEquals(belongsToFieldDefinition, getField(select, "fieldDefinition"));
    assertEquals(hasManyFieldDefinition, getField(subselect, "fieldDefinition"));
    assertNull(getField(grid, "fieldDefinition"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) FieldType(com.qcadoo.model.api.types.FieldType) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Aggregations

FieldType (com.qcadoo.model.api.types.FieldType)19 Test (org.junit.Test)15 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)11 FieldDefinition (com.qcadoo.model.api.FieldDefinition)4 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)3 DataDefinition (com.qcadoo.model.api.DataDefinition)2 Entity (com.qcadoo.model.api.Entity)2 BelongsToType (com.qcadoo.model.api.types.BelongsToType)2 FieldDefinitionImpl (com.qcadoo.model.internal.FieldDefinitionImpl)2 Date (java.util.Date)2 HasManyType (com.qcadoo.model.api.types.HasManyType)1 BelongsToEntityType (com.qcadoo.model.internal.types.BelongsToEntityType)1 BooleanType (com.qcadoo.model.internal.types.BooleanType)1 DateTimeType (com.qcadoo.model.internal.types.DateTimeType)1 DateType (com.qcadoo.model.internal.types.DateType)1 DecimalType (com.qcadoo.model.internal.types.DecimalType)1 IntegerType (com.qcadoo.model.internal.types.IntegerType)1 ManyToManyEntitiesType (com.qcadoo.model.internal.types.ManyToManyEntitiesType)1 PasswordType (com.qcadoo.model.internal.types.PasswordType)1 PriorityType (com.qcadoo.model.internal.types.PriorityType)1