Search in sources :

Example 6 with TypeDto

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

the class EntityMetadataBuilderImpl method setFieldMetadata.

private FieldMetadata setFieldMetadata(ClassMetadata cmd, ClassData classData, EntityDto entity, EntityType entityType, FieldDto field, Class<?> definition) {
    String name = getNameForMetadata(field);
    TypeDto type = field.getType();
    Class<?> typeClass = type.getClassObjectForType();
    if (ArrayUtils.contains(FIELD_VALUE_GENERATOR, name)) {
        return setAutoGenerationMetadata(cmd, name);
    } else if (type.isCombobox()) {
        return setComboboxMetadata(cmd, entity, field, definition, entityType);
    } else if (type.isRelationship()) {
        return setRelationshipMetadata(cmd, classData, entity, field, entityType, definition);
    } else if (Map.class.isAssignableFrom(typeClass)) {
        return setMapMetadata(cmd, entity, field, definition, entityType);
    } else if (Time.class.isAssignableFrom(typeClass)) {
        return setTimeMetadata(cmd, name);
    }
    return cmd.newFieldMetadata(name);
}
Also used : TypeDto(org.motechproject.mds.dto.TypeDto) Map(java.util.Map)

Example 7 with TypeDto

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

the class LookupBuilder method buildGenericSignature.

private String buildGenericSignature() throws NotFoundException {
    // we must build generic signatures for lookup methods
    // an example signature for the method signature
    // List<org.motechproject.mds.Test> method(String p1, Integer p2)
    // is
    // cmt -- (Ljava/lang/String;Ljava/lang/Integer;)Ljava/util/List<Lorg/motechproject/mds/Test;>;
    StringBuilder sb = new StringBuilder();
    sb.append('(');
    List<String> fieldsOrder = lookup.getFieldsOrder();
    for (int i = 0; i < fieldsOrder.size(); ++i) {
        String fieldName = fieldsOrder.get(i);
        FieldDto field = getLookupField(fieldName);
        // don't use fieldName for fetching fields, as it can contain dots, etc.
        LookupFieldDto lookupField = lookup.getLookupField(field.getBasic().getName());
        FieldDto relationField = null;
        EntityDto relatedEntity = null;
        if (fieldsOrder.get(i).contains(".")) {
            relatedEntity = schemaHolder.getEntityByClassName(new RelationshipHolder(field).getRelatedClass());
            relationField = schemaHolder.getFieldByName(relatedEntity, LookupName.getRelatedFieldName(fieldsOrder.get(i)));
        }
        String paramType = getTypeForParam(i, resolveEntity(entity, relatedEntity), resolveField(field, relationField), lookupField);
        String genericType;
        TypeDto type = resolveField(field, relationField).getType();
        if (type.isCombobox()) {
            ComboboxHolder holder = new ComboboxHolder(resolveEntity(entity, relatedEntity), resolveField(field, relationField));
            genericType = holder.getUnderlyingType();
        } else {
            genericType = type.getTypeClass();
        }
        if (StringUtils.equals(paramType, genericType) || TypeHelper.isPrimitive(paramType)) {
            // simple parameter
            sb.append(JavassistUtil.toGenericParam(paramType));
        } else {
            // we wrap in a range/set or a different wrapper
            sb.append(JavassistUtil.genericSignature(paramType, genericType));
        }
    }
    sb.append(')');
    if (lookup.isSingleObjectReturn()) {
        sb.append(JavassistUtil.toGenericParam(className));
    } else {
        sb.append(JavassistUtil.genericSignature(List.class.getName(), className));
    }
    return sb.toString();
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) RelationshipHolder(org.motechproject.mds.domain.RelationshipHolder) ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) TypeDto(org.motechproject.mds.dto.TypeDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 8 with TypeDto

use of org.motechproject.mds.dto.TypeDto 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 9 with TypeDto

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

the class EntityServiceImpl method getSchema.

@Override
@Transactional
public SchemaHolder getSchema() {
    StopWatch stopWatch = new StopWatch();
    SchemaHolder entitiesHolder = new SchemaHolder();
    LOGGER.debug("Retrieving entities for processing");
    stopWatch.start();
    List<Entity> entities = allEntities.getActualEntities();
    stopWatch.stop();
    LOGGER.debug("{} entities retrieved in {} ms", entities.size(), stopWatch.getTime());
    StopWatchHelper.restart(stopWatch);
    for (Entity entity : entities) {
        LOGGER.debug("Preparing entity: {}", entity.getClassName());
        StopWatchHelper.restart(stopWatch);
        EntityDto entityDto = entity.toDto();
        stopWatch.stop();
        LOGGER.debug("Entity dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        AdvancedSettingsDto advSettingsDto = entity.advancedSettingsDto();
        stopWatch.stop();
        LOGGER.debug("Advanced settings dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        List<FieldDto> fieldDtos = entity.getFieldDtos();
        stopWatch.stop();
        LOGGER.debug("Field dtos created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        entitiesHolder.addEntity(entityDto, advSettingsDto, fieldDtos);
        stopWatch.stop();
        LOGGER.debug("Result stored in {} ms", stopWatch.getTime());
    }
    LOGGER.debug("Retrieving types for processing");
    List<Type> types = allTypes.retrieveAll();
    for (Type type : types) {
        TypeDto typeDto = type.toDto();
        entitiesHolder.addType(typeDto);
        entitiesHolder.addTypeValidation(typeDto, type.getTypeValidationDtos());
    }
    LOGGER.debug("Entities holder ready");
    return entitiesHolder;
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) EntityDto(org.motechproject.mds.dto.EntityDto) Type(org.motechproject.mds.domain.Type) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TypeDto(org.motechproject.mds.dto.TypeDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) StopWatch(org.apache.commons.lang.time.StopWatch) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with TypeDto

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

the class FieldHelperTest method fieldDto.

private FieldDto fieldDto() {
    TypeDto type = new TypeDto("typeDispName", "typeDesc", "typeDefaultName", "typeClass");
    FieldBasicDto basic = new FieldBasicDto("fieldDispName", "fieldName", true, false, "defVal", "tooltip", "placeholder");
    MetadataDto metadata = new MetadataDto("key", "val");
    ValidationCriterionDto criterion = new ValidationCriterionDto("criterionDispName", type);
    FieldValidationDto validation = new FieldValidationDto(criterion);
    return new FieldDto(1L, 100L, type, basic, false, new ArrayList<>(asList(metadata)), validation, null, null);
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

TypeDto (org.motechproject.mds.dto.TypeDto)30 FieldDto (org.motechproject.mds.dto.FieldDto)17 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)9 EntityDto (org.motechproject.mds.dto.EntityDto)7 MetadataDto (org.motechproject.mds.dto.MetadataDto)7 ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)6 CtClass (javassist.CtClass)3 FieldValidationDto (org.motechproject.mds.dto.FieldValidationDto)3 LookupDto (org.motechproject.mds.dto.LookupDto)3 IOException (java.io.IOException)2 AccessibleObject (java.lang.reflect.AccessibleObject)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 CannotCompileException (javassist.CannotCompileException)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ClassData (org.motechproject.mds.domain.ClassData)2 Field (org.motechproject.mds.domain.Field)2