Search in sources :

Example 31 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class MDSConstructorImpl method buildClasses.

private Map<String, ClassData> buildClasses(List<EntityDto> entities, SchemaHolder schemaHolder) {
    Map<String, ClassData> classDataMap = new LinkedHashMap<>();
    // We build classes for all entities
    for (EntityDto entity : entities) {
        List<FieldDto> fields = schemaHolder.getFields(entity);
        ClassData classData = buildClass(entity, fields);
        ClassData historyClassData = null;
        if (entity.isRecordHistory()) {
            historyClassData = entityBuilder.buildHistory(entity, fields);
        }
        ClassData trashClassData = entityBuilder.buildTrash(entity, fields);
        String className = entity.getClassName();
        classDataMap.put(className, classData);
        if (historyClassData != null) {
            classDataMap.put(ClassName.getHistoryClassName(className), historyClassData);
        }
        classDataMap.put(ClassName.getTrashClassName(className), trashClassData);
    }
    return classDataMap;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ClassData(org.motechproject.mds.domain.ClassData) LinkedHashMap(java.util.LinkedHashMap) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 32 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class Field method toDto.

public FieldDto toDto() {
    FieldBasicDto basic = new FieldBasicDto(displayName, name, required, unique, parseDefaultValue(), tooltip, placeholder);
    TypeDto typeDto = null;
    List<MetadataDto> metaDto = new ArrayList<>();
    for (FieldMetadata meta : metadata) {
        metaDto.add(meta.toDto());
    }
    FieldValidationDto validationDto = null;
    if (CollectionUtils.isNotEmpty(validations)) {
        validationDto = new FieldValidationDto();
        for (FieldValidation validation : validations) {
            validationDto.addCriterion(validation.toDto());
        }
    }
    List<SettingDto> settingsDto = new ArrayList<>();
    for (FieldSetting setting : settings) {
        settingsDto.add(setting.toDto());
    }
    List<LookupDto> lookupDtos = new ArrayList<>();
    for (Lookup lookup : getLookups()) {
        lookupDtos.add(lookup.toDto());
    }
    if (typeDto == null && type != null) {
        typeDto = type.toDto();
    }
    return new FieldDto(id, entity == null ? null : entity.getId(), typeDto, basic, readOnly, nonEditable, nonDisplayable, uiFilterable, uiChanged, metaDto, validationDto, settingsDto, lookupDtos);
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) TypeDto(org.motechproject.mds.dto.TypeDto) SettingDto(org.motechproject.mds.dto.SettingDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 33 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class EntityServiceImpl method getLookupFieldsMapping.

@Override
@Transactional
public Map<String, FieldDto> getLookupFieldsMapping(Long entityId, String lookupName) {
    Entity entity = allEntities.retrieveById(entityId);
    assertEntityExists(entity, entityId);
    Lookup lookup = entity.getLookupByName(lookupName);
    if (lookup == null) {
        throw new LookupNotFoundException(entity.getName(), lookupName);
    }
    Map<String, FieldDto> fieldMap = new HashMap<>();
    for (String lookupFieldName : lookup.getFieldsOrder()) {
        Field field = lookup.getLookupFieldByName(LookupName.getFieldName(lookupFieldName));
        if (lookupFieldName.contains(".")) {
            Entity relatedEntity = allEntities.retrieveByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
            field = relatedEntity.getField(LookupName.getRelatedFieldName(lookupFieldName));
        }
        fieldMap.put(lookupFieldName, field.toDto());
    }
    return fieldMap;
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) LookupNotFoundException(org.motechproject.mds.exception.lookup.LookupNotFoundException) Field(org.motechproject.mds.domain.Field) HashMap(java.util.HashMap) Lookup(org.motechproject.mds.domain.Lookup) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class EntityServiceImpl method removeFields.

private void removeFields(Entity entity, Collection<FieldDto> fields) {
    Iterator<Field> iterator = entity.getFields().iterator();
    while (iterator.hasNext()) {
        Field field = iterator.next();
        // don't remove user defined fields
        if (!field.isReadOnly() || field.getMetadata(AUTO_GENERATED) != null || field.getMetadata(AUTO_GENERATED_EDITABLE) != null) {
            continue;
        }
        boolean found = false;
        for (FieldDto fieldDto : fields) {
            if (field.getName().equalsIgnoreCase(fieldDto.getBasic().getName())) {
                found = true;
                break;
            }
        }
        if (!found) {
            iterator.remove();
        }
    }
}
Also used : Field(org.motechproject.mds.domain.Field) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 35 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class EntityServiceImpl method getFields.

private List<FieldDto> getFields(Long entityId, boolean forDraft, boolean forUi) {
    Entity entity = (forDraft) ? getEntityDraft(entityId) : allEntities.retrieveById(entityId);
    assertEntityExists(entity, entityId);
    // the returned collection is unmodifiable
    List<Field> fields = new ArrayList<>(entity.getFields());
    // for data browser purposes, we sort the fields by their ui display order
    if (!forDraft) {
        Collections.sort(fields, new UIDisplayFieldComparator());
    }
    // if it's for the UI, then we add combobox options
    List<FieldDto> fieldDtos = toFieldDtos(entity, fields, forUi);
    return addNonPersistentFieldsData(fieldDtos, entity);
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Field(org.motechproject.mds.domain.Field) ArrayList(java.util.ArrayList) UIDisplayFieldComparator(org.motechproject.mds.domain.UIDisplayFieldComparator) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) 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