use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class SwaggerFieldConverter method toComboboxProperty.
private static Property toComboboxProperty(Field field) {
if (field.getType().isCombobox()) {
ComboboxHolder cbHolder = new ComboboxHolder(field);
Property itemProperty = new Property(STRING_TYPE);
// user-supplied comoboxes are actually strings or list of strings
if (!cbHolder.isAllowUserSupplied()) {
itemProperty.setEnumValues(Arrays.asList(cbHolder.getValues()));
}
if (cbHolder.isAllowMultipleSelections()) {
return new Property(ARRAY_TYPE, itemProperty);
} else {
return itemProperty;
}
} else {
return null;
}
}
use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class EntityServiceImpl method getAllComboboxValues.
private List<String> getAllComboboxValues(Entity entity, Field field) {
ServiceReference<ComboboxValueService> ref = bundleContext.getServiceReference(ComboboxValueService.class);
if (ref == null) {
LOGGER.warn("Combobox value service unavailable, ignoring user supplied values");
ComboboxHolder cbHolder = new ComboboxHolder(field);
return Arrays.asList(cbHolder.getValues());
} else {
ComboboxValueService cbValueService = bundleContext.getService(ref);
return cbValueService.getAllValuesForCombobox(entity.toDto(), field.toDto());
}
}
use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class EntityBuilderImpl method createField.
private CtField createField(CtClass declaring, EntityDto entity, FieldDto field, EntityType entityType) throws IllegalAccessException, InstantiationException, CannotCompileException, ClassNotFoundException {
TypeDto fieldType = field.getType();
String genericSignature = null;
CtClass type = null;
if (fieldType.isCombobox()) {
ComboboxHolder holder = new ComboboxHolder(entity, field);
if (holder.isEnum() || holder.isEnumCollection()) {
type = classPool.getOrNull(holder.getEnumName());
if (holder.isEnumCollection()) {
genericSignature = JavassistUtil.genericSignature(holder.getTypeClassName(), holder.getEnumName());
type = classPool.getOrNull(holder.getTypeClassName());
}
} else if (holder.isStringCollection()) {
genericSignature = JavassistUtil.genericSignature(holder.getTypeClassName(), holder.getUnderlyingType());
type = classPool.getOrNull(holder.getTypeClassName());
} else if (holder.isString()) {
type = classPool.getOrNull(holder.getUnderlyingType());
}
} else if (fieldType.isRelationship()) {
Class fieldClass = getClass().getClassLoader().loadClass(fieldType.getTypeClass());
Relationship relationshipType = (Relationship) fieldClass.newInstance();
genericSignature = relationshipType.getGenericSignature(field, entityType);
type = classPool.getOrNull(relationshipType.getFieldType(field, entityType));
} else {
type = classPool.getOrNull(fieldType.getTypeClass());
}
return JavassistBuilder.createField(declaring, type, field.getBasic().getName(), genericSignature);
}
use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class EntityMetadataBuilderImpl method setComboboxMetadata.
private FieldMetadata setComboboxMetadata(ClassMetadata cmd, EntityDto entity, FieldDto field, Class<?> definition, EntityType entityType) {
ComboboxHolder holder = new ComboboxHolder(entity, field);
String fieldName = getNameForMetadata(field);
FieldMetadata fmd = cmd.newFieldMetadata(fieldName);
if (holder.isCollection()) {
addDefaultFetchGroupMetadata(fmd, definition);
fmd.setTable(ClassTableName.getTableName(cmd.getTable(), fieldName));
JoinMetadata jm = fmd.newJoinMetadata();
ForeignKeyMetadata fkmd = getOrCreateFkMetadata(jm);
fkmd.setName(KeyNames.cbForeignKeyName(entity.getName(), entity.getId(), fieldName, entityType));
jm.setDeleteAction(ForeignKeyAction.CASCADE);
jm.newColumnMetadata().setName(fieldName + "_OID");
}
return fmd;
}
use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class LookupBuilder method body.
private String body() {
StringBuilder body = new StringBuilder();
body.append("java.util.List properties = new java.util.ArrayList();");
Map<String, String> jdoQueryVariables = new HashMap<>();
for (String lookupFieldName : lookup.getFieldsOrder()) {
boolean appendJdoVariableName = false;
FieldDto field = getLookupField(lookupFieldName);
// don't use lookupFieldName for fetching fields, as it can contain dots, etc.
LookupFieldDto lookupField = lookup.getLookupField(field.getBasic().getName());
FieldDto relationField = null;
if (lookupFieldName.contains(".")) {
EntityDto relatedEntity = schemaHolder.getEntityByClassName(new RelationshipHolder(field).getRelatedClass());
relationField = schemaHolder.getFieldByName(relatedEntity, LookupName.getRelatedFieldName(lookupFieldName));
}
TypeDto type = field.getType();
String typeClassName = resolveClassName(type, relationField);
body.append("properties.add(");
if (type.isCombobox()) {
ComboboxHolder holder = new ComboboxHolder(entity, field);
typeClassName = holder.getUnderlyingType();
body.append(resolvePropertyForCombobox(holder, type));
} else if (relationField != null && relationField.getType().isCombobox()) {
RelationshipHolder relationshipHolder = new RelationshipHolder(field);
EntityDto relatedEntity = schemaHolder.getEntityByClassName(relationshipHolder.getRelatedClass());
ComboboxHolder holder = new ComboboxHolder(relatedEntity, relationField);
typeClassName = holder.getUnderlyingType();
body.append(resolvePropertyForCombobox(holder, type));
addJdoVariableName(jdoQueryVariables, lookupFieldName);
appendJdoVariableName = needsJdoVariable(type);
} else if (relationField != null && (type.getTypeClass().equals(TypeDto.MANY_TO_MANY_RELATIONSHIP.getTypeClass()) || type.getTypeClass().equals(TypeDto.ONE_TO_MANY_RELATIONSHIP.getTypeClass()))) {
// related class collection
body.append(PropertyBuilder.class.getName());
body.append(".createRelationProperty");
addJdoVariableName(jdoQueryVariables, lookupFieldName);
appendJdoVariableName = true;
} else {
body.append(PropertyBuilder.class.getName());
body.append(".create");
}
body.append(buildPropertyParameters(appendJdoVariableName, lookupFieldName, lookupField, typeClassName, jdoQueryVariables));
}
body.append(buildReturn());
return body.toString();
}
Aggregations