Search in sources :

Example 21 with FieldDto

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);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) List(java.util.List) MotechDataService(org.motechproject.mds.service.MotechDataService) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 22 with FieldDto

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());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BasicHistoryRecord(org.motechproject.mds.web.domain.BasicHistoryRecord) BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 23 with FieldDto

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;
}
Also used : ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 24 with FieldDto

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;
}
Also used : ArrayList(java.util.ArrayList) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 25 with FieldDto

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;
}
Also used : ArrayList(java.util.ArrayList) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

FieldDto (org.motechproject.mds.dto.FieldDto)158 Test (org.junit.Test)61 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)60 EntityDto (org.motechproject.mds.dto.EntityDto)53 ArrayList (java.util.ArrayList)47 LookupDto (org.motechproject.mds.dto.LookupDto)29 List (java.util.List)23 MetadataDto (org.motechproject.mds.dto.MetadataDto)22 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)19 TypeDto (org.motechproject.mds.dto.TypeDto)17 Method (java.lang.reflect.Method)14 MotechDataService (org.motechproject.mds.service.MotechDataService)14 HashMap (java.util.HashMap)12 Field (org.motechproject.mds.domain.Field)12 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)12 Arrays.asList (java.util.Arrays.asList)11 SettingDto (org.motechproject.mds.dto.SettingDto)11 Before (org.junit.Before)7 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)7