Search in sources :

Example 1 with TypeDto

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

the class MdsDummyDataGeneratorImpl method prepareDummyEntity.

private void prepareDummyEntity(int number, int fieldsPerEntity, int lookupsPerEntity) throws IOException {
    EntityDto entityDto = new EntityDto(Long.valueOf(number), entityPrefix.concat(String.valueOf(number)));
    entityDto = entityService.createEntity(entityDto);
    List<FieldDto> fields = new ArrayList<>();
    for (int i = 0; i < fieldsPerEntity; i++) {
        TypeDto type = pickRandomFieldType();
        fields.add(new FieldDto(null, entityDto.getId(), type, new FieldBasicDto(fieldPrefix.concat(String.valueOf(i)), fieldPrefix.concat(String.valueOf(i))), false, null, null, settingsFor(type), null));
    }
    entityService.addFields(entityDto, fields);
    List<LookupDto> lookups = new ArrayList<>();
    for (int i = 0; i < lookupsPerEntity; i++) {
        List<LookupFieldDto> lookupFields = new ArrayList<>();
        List<FieldDto> entityFields = entityService.getFields(entityDto.getId());
        int amountOfFields = RAND.nextInt(entityFields.size());
        for (int j = 0; j < amountOfFields; j++) {
            lookupFields.add(new LookupFieldDto(null, entityFields.get(j).getBasic().getName(), LookupFieldType.VALUE));
        }
        lookups.add(new LookupDto(lookupPrefix.concat(String.valueOf(i)), RAND.nextBoolean(), RAND.nextBoolean(), lookupFields, false));
    }
    entityService.addLookups(entityDto.getId(), lookups);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) 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 2 with TypeDto

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

the class MdsController method textAreaUIType.

protected TypeDto textAreaUIType() {
    TypeDto textAreaType = new TypeDto();
    textAreaType.setDefaultName("textArea");
    textAreaType.setDisplayName("mds.field.textArea");
    textAreaType.setDescription("mds.field.description.textArea");
    textAreaType.setTypeClass("textArea");
    return textAreaType;
}
Also used : TypeDto(org.motechproject.mds.dto.TypeDto)

Example 3 with TypeDto

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

the class LookupProcessor method verifyLookupParameters.

private void verifyLookupParameters(Method method, String entityClassName, String lookupName, List<LookupFieldDto> lookupFields, Class<?>[] parameterTypes) {
    List<String> parametersNames = findParametersNames(method);
    for (LookupFieldDto lookupFieldDto : lookupFields) {
        if (lookupFieldDto.getType() == LookupFieldType.VALUE) {
            FieldDto fieldDto = findEntityFieldByName(entityClassName, lookupFieldDto.getLookupFieldName());
            int position = parametersNames.indexOf(lookupFieldDto.getLookupFieldName());
            if (fieldDto != null && fieldDto.getType() != null) {
                TypeDto type = fieldDto.getType();
                // check if field is a Combobox or a TextArea
                if (type.isCombobox() || (type.isTextArea() && "java.lang.String".equals(parameterTypes[position].getName()))) {
                    continue;
                }
                if (!parameterTypes[position].getName().equals(type.getTypeClass())) {
                    StringBuilder sb = new StringBuilder("Wrong type of argument ");
                    sb.append(position).append(" \"").append(parametersNames.get(position));
                    sb.append("\" in lookup \"").append(lookupName);
                    sb.append("\" - should be ").append(type.getTypeClass());
                    sb.append(" but is ").append(parameterTypes[position].getName());
                    throw new LookupWrongParameterTypeException(sb.toString());
                }
            }
        }
    }
}
Also used : LookupWrongParameterTypeException(org.motechproject.mds.exception.lookup.LookupWrongParameterTypeException) TypeDto(org.motechproject.mds.dto.TypeDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 4 with TypeDto

use of org.motechproject.mds.dto.TypeDto 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);
}
Also used : TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 5 with TypeDto

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

the class EntityBuilderImpl method createInitializer.

private CtField.Initializer createInitializer(EntityDto entity, FieldDto field) {
    TypeDto type = field.getType();
    CtField.Initializer initializer = null;
    if (type.isCombobox()) {
        ComboboxHolder holder = new ComboboxHolder(entity, field);
        if (holder.isStringCollection()) {
            initializer = JavassistBuilder.createCollectionInitializer(holder.getUnderlyingType(), field.getBasic().getDefaultValue());
        } else if (holder.isEnumCollection()) {
            Object defaultValue = field.getBasic().getDefaultValue();
            initializer = JavassistBuilder.createCollectionInitializer(holder.getEnumName(), EnumHelper.prefixEnumValues((Collection) defaultValue));
        } else if (holder.isString()) {
            initializer = JavassistBuilder.createInitializer(holder.getUnderlyingType(), field.getBasic().getDefaultValue().toString());
        } else if (holder.isEnum()) {
            initializer = JavassistBuilder.createEnumInitializer(holder.getEnumName(), EnumHelper.prefixEnumValue(field.getBasic().getDefaultValue().toString()));
        }
    } else if (!type.isRelationship()) {
        initializer = JavassistBuilder.createInitializer(type.getTypeClass(), field.getBasic().getDefaultValue());
    }
    return initializer;
}
Also used : CtField(javassist.CtField) ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) Collection(java.util.Collection) TypeDto(org.motechproject.mds.dto.TypeDto)

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