use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class InstanceServiceImpl method getSingleTrashRecord.
@Override
public EntityRecord getSingleTrashRecord(Long entityId, Long instanceId) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
MotechDataService service = getServiceForEntity(entity);
List<FieldDto> fields = entityService.getEntityFieldsForUI(entityId);
Object instance = trashService.findTrashById(instanceId, entity.getClassName());
Map<String, List<FieldDto>> relatedEntitiesFields = getRelatedEntitiesFields(fields);
return instanceToRecord(instance, entity, fields, service, EntityType.TRASH, relatedEntitiesFields);
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class InstanceServiceImpl method convertToBasicHistoryRecord.
private BasicHistoryRecord convertToBasicHistoryRecord(Object object, EntityDto entity, Long instanceId, MotechDataService service) {
Long entityId = entity.getId();
List<FieldDto> fields = getEntityFields(entityId);
Map<String, List<FieldDto>> relatedEntitiesFields = getRelatedEntitiesFields(fields);
BasicEntityRecord entityRecord = instanceToBasicRecord(object, entity, entityService.getEntityFields(entityId), service, EntityType.HISTORY, relatedEntitiesFields);
Long historyInstanceSchemaVersion = (Long) PropertyUtil.safeGetProperty(object, HistoryTrashClassHelper.historySchemaVersion(object.getClass()));
Long currentSchemaVersion = entityService.getCurrentSchemaVersion(entity.getClassName());
return new BasicHistoryRecord(entityRecord.getId(), instanceId, historyInstanceSchemaVersion.equals(currentSchemaVersion), entityRecord.getFields());
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class ExampleData method getFields.
public List<FieldDto> getFields(Long entityId) {
List<FieldDto> list = new ArrayList<>();
for (FieldDto field : draftFields) {
if (field.getEntityId().equals(entityId)) {
list.add(field);
}
}
if (fieldsHistory.containsKey(entityId)) {
for (Map.Entry<Long, FieldDto> entry : fieldsHistory.get(entityId).entrySet()) {
boolean found = false;
for (int i = list.size() - 1; i >= 0; --i) {
FieldDto field = list.get(i);
if (field.getId().equals(entry.getKey())) {
list.remove(i);
if (null != entry.getValue()) {
list.add(i, entry.getValue());
}
found = true;
break;
}
}
if (!found && null != entry.getValue()) {
list.add(entry.getValue());
}
}
}
Collections.sort(list, new Comparator<FieldDto>() {
@Override
public int compare(FieldDto one, FieldDto two) {
return one.getId().compareTo(two.getId());
}
});
return list;
}
use of org.motechproject.mds.dto.FieldDto 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.FieldDto 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;
}
Aggregations