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);
}
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;
}
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());
}
}
}
}
}
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);
}
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;
}
Aggregations