Search in sources :

Example 51 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class FieldHelperTest method shouldCreateAndSetMetadataForManyToManyRelationship.

@Test
public void shouldCreateAndSetMetadataForManyToManyRelationship() {
    Entity entity = new Entity("SampleEntity");
    Field field = new Field(entity, "sampleField", "Display Name", true, false, false, false, false, "default", "tooltip", "placeholder", new HashSet<Lookup>());
    FieldHelper.createMetadataForManyToManyRelationship(field, "org.motechproject.sample.Test", "java.util.Set", "relatedField", true);
    assertEquals(field.getMetadata().size(), 4);
    assertEquals(field.getMetadataValue(Constants.MetadataKeys.OWNING_SIDE), "true");
    assertEquals(field.getMetadataValue(Constants.MetadataKeys.RELATED_FIELD), "relatedField");
    assertEquals(field.getMetadataValue(Constants.MetadataKeys.RELATED_CLASS), "org.motechproject.sample.Test");
    assertEquals(field.getMetadataValue(Constants.MetadataKeys.RELATIONSHIP_COLLECTION_TYPE), "java.util.Set");
}
Also used : Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) Lookup(org.motechproject.mds.domain.Lookup) Test(org.junit.Test)

Example 52 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class InstancesWriter method writeInstance.

public void writeInstance(Object instance) throws IOException {
    jsonWriter.beginObject();
    writeInstanceReferenceId(instance);
    for (Field field : entity.getFields()) {
        if (!field.isAutoGenerated()) {
            writeProperty(instance, field);
        }
    }
    jsonWriter.endObject();
}
Also used : Field(org.motechproject.mds.domain.Field)

Example 53 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class FieldReader method readField.

public void readField() throws IOException {
    Field field = new Field();
    field.setEntity(entity);
    jsonReader.beginObject();
    field.setName(objectReader.readString("name"));
    field.setDisplayName(objectReader.readString("displayName"));
    field.setRequired(objectReader.readBoolean("required"));
    field.setUnique(objectReader.readBoolean("unique"));
    field.setDefaultValue(objectReader.readString("defaultValue"));
    field.setTooltip(objectReader.readString("tooltip"));
    field.setPlaceholder(objectReader.readString("placeholder"));
    field.setNonEditable(objectReader.readBoolean("nonEditable"));
    field.setNonDisplayable(objectReader.readBoolean("nonDisplayable"));
    field.setType(importContext.getType(objectReader.readString("type")));
    readMetadata(field);
    readValidations(field);
    readSettings(field);
    jsonReader.endObject();
    Field existingField = entity.getField(field.getName());
    if (null == existingField || !existingField.isReadOnly()) {
        entity.addField(field);
    } else {
        throw new FieldReadOnlyException(entity.getName(), existingField.getName());
    }
}
Also used : Field(org.motechproject.mds.domain.Field) FieldReadOnlyException(org.motechproject.mds.exception.field.FieldReadOnlyException)

Example 54 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class FieldWriter method writeFieldNamesArray.

public void writeFieldNamesArray(String name, List<Field> fields) throws IOException {
    jsonWriter.name(name);
    jsonWriter.beginArray();
    for (Field field : fields) {
        jsonWriter.value(field.getName());
    }
    jsonWriter.endArray();
}
Also used : Field(org.motechproject.mds.domain.Field)

Example 55 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class LookupReader method readFields.

private List<Field> readFields() throws IOException {
    List<Field> fields = new ArrayList<>();
    objectReader.expect("fields");
    jsonReader.beginArray();
    while (jsonReader.hasNext()) {
        String fieldName = jsonReader.nextString();
        Field field = entity.getField(fieldName);
        if (null != field) {
            fields.add(field);
        } else {
            throw new FieldNotFoundException(entity.getClassName(), fieldName);
        }
    }
    jsonReader.endArray();
    return fields;
}
Also used : Field(org.motechproject.mds.domain.Field) ArrayList(java.util.ArrayList) FieldNotFoundException(org.motechproject.mds.exception.field.FieldNotFoundException)

Aggregations

Field (org.motechproject.mds.domain.Field)73 Entity (org.motechproject.mds.domain.Entity)33 Test (org.junit.Test)24 Lookup (org.motechproject.mds.domain.Lookup)16 MdsEntity (org.motechproject.mds.domain.MdsEntity)15 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)15 Type (org.motechproject.mds.domain.Type)14 ArrayList (java.util.ArrayList)13 Transactional (org.springframework.transaction.annotation.Transactional)13 FieldDto (org.motechproject.mds.dto.FieldDto)12 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)12 HashSet (java.util.HashSet)8 Matchers.anyString (org.mockito.Matchers.anyString)6 FieldSetting (org.motechproject.mds.domain.FieldSetting)6 TypeSetting (org.motechproject.mds.domain.TypeSetting)6 UserPreferences (org.motechproject.mds.domain.UserPreferences)5 EntityDto (org.motechproject.mds.dto.EntityDto)5 AllUserPreferences (org.motechproject.mds.repository.internal.AllUserPreferences)5 FieldMetadata (org.motechproject.mds.domain.FieldMetadata)4 LookupDto (org.motechproject.mds.dto.LookupDto)4