use of org.motechproject.mds.dto.MetadataDto in project motech by motech.
the class InstanceServiceTest method mockAnotherEntityFields.
private void mockAnotherEntityFields() {
FieldDto relatedField = FieldTestHelper.fieldDto(2L, "testClasses", OneToManyRelationship.class.getName(), "Test Classes", null);
relatedField.addMetadata(new MetadataDto(Constants.MetadataKeys.RELATED_CLASS, TestClass.class.getName()));
when(entityService.getEntityFieldsForUI(ANOTHER_ENTITY_ID)).thenReturn(asList(FieldTestHelper.fieldDto(1L, "id", Long.class.getName(), "Id", null), relatedField));
}
use of org.motechproject.mds.dto.MetadataDto in project motech by motech.
the class RelationshipDisplayUtilTest method prepareFieldDefinitionsForManufacturer.
private List<FieldDto> prepareFieldDefinitionsForManufacturer() {
List<FieldDto> fields = new ArrayList<>();
FieldDto name = new FieldDto("name", "Name", null);
FieldDto factories = new FieldDto("factories", "Factories", null);
factories.addMetadata(new MetadataDto(Constants.MetadataKeys.RELATED_CLASS, "Factory"));
FieldDto safetyPolicy = new FieldDto("safetyPolicy", "Safety policy", null);
safetyPolicy.addMetadata(new MetadataDto(Constants.MetadataKeys.RELATED_CLASS, "SafetyPolicy"));
fields.add(name);
fields.add(factories);
fields.add(safetyPolicy);
return fields;
}
use of org.motechproject.mds.dto.MetadataDto in project motech by motech.
the class RelationshipDisplayUtilTest method prepareFieldDefinitionsForFactory.
private List<FieldDto> prepareFieldDefinitionsForFactory() {
List<FieldDto> fields = new ArrayList<>();
FieldDto name = new FieldDto("name", "Name", null);
FieldDto location = new FieldDto("location", "Location", null);
location.addMetadata(new MetadataDto(Constants.MetadataKeys.RELATED_CLASS, "Location"));
fields.add(name);
fields.add(location);
return fields;
}
use of org.motechproject.mds.dto.MetadataDto in project motech by motech.
the class EntityDefaultFieldsHelper method defaultFields.
public static List<FieldDto> defaultFields(SchemaHolder schemaHolder) {
TypeDto longType = schemaHolder.getType(Long.class);
TypeDto stringType = schemaHolder.getType(String.class);
TypeDto dateTimeType = schemaHolder.getType(DateTime.class);
FieldDto idField = new FieldDto(Constants.Util.ID_FIELD_NAME, Constants.Util.ID_DISPLAY_FIELD_NAME, longType, true, true);
idField.setReadOnly(true);
idField.setMetadata(Collections.singletonList(new MetadataDto(AUTO_GENERATED, TRUE)));
FieldDto creatorField = new FieldDto(Constants.Util.CREATOR_FIELD_NAME, Constants.Util.CREATOR_DISPLAY_FIELD_NAME, stringType, true, false);
creatorField.setReadOnly(true);
creatorField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));
FieldDto ownerField = new FieldDto(Constants.Util.OWNER_FIELD_NAME, Constants.Util.OWNER_DISPLAY_FIELD_NAME, stringType, false, false);
ownerField.setReadOnly(true);
ownerField.addMetadata(new MetadataDto(AUTO_GENERATED_EDITABLE, TRUE));
FieldDto modifiedByField = new FieldDto(Constants.Util.MODIFIED_BY_FIELD_NAME, Constants.Util.MODIFIED_BY_DISPLAY_FIELD_NAME, stringType, true, false);
modifiedByField.setReadOnly(true);
modifiedByField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));
FieldDto modificationDateField = new FieldDto(Constants.Util.MODIFICATION_DATE_FIELD_NAME, Constants.Util.MODIFICATION_DATE_DISPLAY_FIELD_NAME, dateTimeType, true, false);
modificationDateField.setReadOnly(true);
modificationDateField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));
FieldDto creationDateField = new FieldDto(Constants.Util.CREATION_DATE_FIELD_NAME, Constants.Util.CREATION_DATE_DISPLAY_FIELD_NAME, dateTimeType, true, false);
creationDateField.setReadOnly(true);
creationDateField.addMetadata(new MetadataDto(AUTO_GENERATED, TRUE));
return Arrays.asList(idField, creatorField, ownerField, modifiedByField, modificationDateField, creationDateField);
}
use of org.motechproject.mds.dto.MetadataDto in project motech by motech.
the class Field method updateMetadata.
private void updateMetadata(List<MetadataDto> metadataList) {
Iterator<FieldMetadata> it = getMetadata().iterator();
while (it.hasNext()) {
FieldMetadata meta = it.next();
boolean inNewList = false;
for (MetadataDto metadataDto : metadataList) {
if (StringUtils.equals(metadataDto.getKey(), meta.getKey())) {
inNewList = true;
break;
}
}
if (!inNewList) {
it.remove();
}
}
for (MetadataDto metadataDto : metadataList) {
FieldMetadata meta = getMetadata(metadataDto.getKey());
if (null == meta) {
FieldMetadata newMetadata = new FieldMetadata(metadataDto);
addMetadata(newMetadata);
} else {
meta.update(metadataDto);
}
}
}
Aggregations