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