Search in sources :

Example 1 with FieldDefinitionImpl

use of com.qcadoo.model.internal.FieldDefinitionImpl in project qcadoo by qcadoo.

the class ModelXmlToDefinitionConverterImpl method getFieldDefinition.

private FieldDefinition getFieldDefinition(final XMLStreamReader reader, final DataDefinitionImpl dataDefinition, final FieldsTag fieldTag) throws XMLStreamException, HookInitializationException, ModelXmlParsingException {
    String fieldType = reader.getLocalName();
    String name = getStringAttribute(reader, "name");
    FieldDefinitionImpl fieldDefinition = new FieldDefinitionImpl(dataDefinition, name);
    fieldDefinition.withReadOnly(getBooleanAttribute(reader, "readonly", false));
    fieldDefinition.withDefaultValue(getStringAttribute(reader, "default"));
    fieldDefinition.setPersistent(getBooleanAttribute(reader, "persistent", true));
    fieldDefinition.setExpression(getStringAttribute(reader, "expression"));
    FieldType type = getFieldType(reader, dataDefinition, name, fieldTag, fieldType);
    fieldDefinition.withType(type);
    if (getBooleanAttribute(reader, "required", false)) {
        fieldDefinition.withValidator(getValidatorDefinition(reader, new RequiredValidator()));
    }
    if (getBooleanAttribute(reader, "unique", false)) {
        if (type.isCopyable() && !fieldDefinition.canBeBothCopyableAndUnique()) {
            String message = String.format("Unique field can not have the copyable attribute set to true. Add 'copyable=\"false\"' to #%s_%s.%s to fix it.", dataDefinition.getPluginIdentifier(), dataDefinition.getName(), name);
            throw new IllegalStateException(message);
        }
        fieldDefinition.withValidator(getValidatorDefinition(reader, new UniqueValidator()));
    }
    parseFieldValidators(reader, fieldType, fieldDefinition).forEach(fieldDefinition::withValidator);
    fieldDefinition.withMissingDefaultValidators();
    return fieldDefinition;
}
Also used : FieldDefinitionImpl(com.qcadoo.model.internal.FieldDefinitionImpl) FieldType(com.qcadoo.model.api.types.FieldType)

Example 2 with FieldDefinitionImpl

use of com.qcadoo.model.internal.FieldDefinitionImpl in project qcadoo by qcadoo.

the class ModelXmlToDefinitionConverterImpl method getAuditFieldDefinition.

private FieldDefinition getAuditFieldDefinition(final DataDefinitionImpl dataDefinition, final String name, final FieldType type) {
    FieldDefinitionImpl fieldDefinition = new FieldDefinitionImpl(dataDefinition, name);
    fieldDefinition.withReadOnly(false);
    fieldDefinition.setPersistent(true);
    fieldDefinition.withType(type);
    return fieldDefinition;
}
Also used : FieldDefinitionImpl(com.qcadoo.model.internal.FieldDefinitionImpl)

Example 3 with FieldDefinitionImpl

use of com.qcadoo.model.internal.FieldDefinitionImpl in project qcadoo by qcadoo.

the class ExpressionUtilTest method shouldReturnJoinedStringRepresentationsOfMultipleFieldWithoutExpression.

@Test
public void shouldReturnJoinedStringRepresentationsOfMultipleFieldWithoutExpression() throws Exception {
    // given
    Entity entity = new DefaultEntity(null, 1L);
    entity.setField("name", "Mr T");
    entity.setField("age", 33);
    entity.setField("sex", "F");
    FieldDefinition fieldDefinitionName = new FieldDefinitionImpl(null, "name").withType(new StringType());
    FieldDefinition fieldDefinitionAge = new FieldDefinitionImpl(null, "age").withType(new IntegerType());
    FieldDefinition fieldDefinitionSex = new FieldDefinitionImpl(null, "sex").withType(new StringType());
    // when
    String value = expressionService.getValue(entity, Lists.newArrayList(fieldDefinitionName, fieldDefinitionAge, fieldDefinitionSex), Locale.ENGLISH);
    // then
    assertEquals("Mr T, 33, F", value);
}
Also used : IntegerType(com.qcadoo.model.internal.types.IntegerType) Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) FieldDefinitionImpl(com.qcadoo.model.internal.FieldDefinitionImpl) Test(org.junit.Test)

Example 4 with FieldDefinitionImpl

use of com.qcadoo.model.internal.FieldDefinitionImpl in project qcadoo by qcadoo.

the class FieldTypeFactoryTest method shouldReturnPriorityType.

@Test
public void shouldReturnPriorityType() throws Exception {
    // given
    FieldDefinition fieldDefinition = new FieldDefinitionImpl(null, "aaa");
    // when
    FieldType fieldType = new PriorityType(fieldDefinition);
    // then
    assertEquals(Integer.class, fieldType.getType());
    assertTrue(fieldType.toObject(fieldDefinition, 1).isValid());
    assertEquals(fieldDefinition, ((PriorityType) fieldType).getScopeFieldDefinition());
}
Also used : PriorityType(com.qcadoo.model.internal.types.PriorityType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) FieldDefinitionImpl(com.qcadoo.model.internal.FieldDefinitionImpl) FieldType(com.qcadoo.model.api.types.FieldType) DataAccessTest(com.qcadoo.model.internal.DataAccessTest) Test(org.junit.Test)

Example 5 with FieldDefinitionImpl

use of com.qcadoo.model.internal.FieldDefinitionImpl in project qcadoo by qcadoo.

the class ExpressionUtilTest method shouldReturnStringRepresentationOfOneFieldWithoutExpression.

@Test
public void shouldReturnStringRepresentationOfOneFieldWithoutExpression() throws Exception {
    // given
    Entity entity = new DefaultEntity(null, 1L);
    entity.setField("name", "Mr T");
    FieldDefinition fieldDefinition = new FieldDefinitionImpl(null, "name").withType(new StringType());
    // when
    String value = expressionService.getValue(entity, Lists.newArrayList(fieldDefinition), null);
    // then
    assertEquals("Mr T", value);
}
Also used : Entity(com.qcadoo.model.api.Entity) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) StringType(com.qcadoo.model.internal.types.StringType) DefaultEntity(com.qcadoo.model.internal.DefaultEntity) FieldDefinition(com.qcadoo.model.api.FieldDefinition) FieldDefinitionImpl(com.qcadoo.model.internal.FieldDefinitionImpl) Test(org.junit.Test)

Aggregations

FieldDefinitionImpl (com.qcadoo.model.internal.FieldDefinitionImpl)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)4 Test (org.junit.Test)3 Entity (com.qcadoo.model.api.Entity)2 FieldType (com.qcadoo.model.api.types.FieldType)2 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)2 StringType (com.qcadoo.model.internal.types.StringType)2 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)1 IntegerType (com.qcadoo.model.internal.types.IntegerType)1 PriorityType (com.qcadoo.model.internal.types.PriorityType)1