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;
}
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;
}
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);
}
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());
}
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);
}
Aggregations