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