use of org.ehrbase.client.classgenerator.shareddefinition.Category in project openEHR_SDK by ehrbase.
the class ClassGenerator method addSimpleField.
private void addSimpleField(ClassGeneratorContext context, TypeSpec.Builder classBuilder, String path, WebTemplateNode endNode) {
Class<?> clazz = extractClass(endNode);
if (clazz == null) {
logger.warn("No class for path {} ", path);
return;
}
ValueSet valueSet = buildValueSet(endNode);
RmClassGeneratorConfig classGeneratorConfig = configMap.get(clazz);
if (classGeneratorConfig == null && !clazz.getName().contains("java.lang")) {
logger.debug("No ClassGenerator for {}", clazz);
}
boolean expand = classGeneratorConfig != null && classGeneratorConfig.isExpandField();
if (endNode.getRmType().equals("DV_CODED_TEXT") && !List.of("transition", "language", "setting", "category", "territory", "math_function", "null_flavour").contains(endNode.getId(false))) {
expand = expand && endNode.getInputs().stream().filter(i -> i.getType().equals("CODED_TEXT")).map(WebTemplateInput::getList).flatMap(List::stream).findAny().isPresent();
}
if (!expand) {
TypeName className = Optional.ofNullable(clazz).map(ClassName::get).orElse(ClassName.get(Object.class));
if (endNode.isMulti() && !context.nodeDeque.peek().getRmType().equals("ELEMENT")) {
className = ParameterizedTypeName.get(ClassName.get(List.class), className);
}
addField(context, classBuilder, path, endNode, className, valueSet, false);
} else {
Map<String, Field> fieldMap = Arrays.stream(FieldUtils.getAllFields(clazz)).filter(f -> !f.isSynthetic()).collect(Collectors.toMap(Field::getName, f -> f));
Set<String> expandFields = classGeneratorConfig.getExpandFields();
expandFields.forEach(fieldName -> addField(context, classBuilder, path + "|" + new SnakeCase(fieldName).camelToSnake(), endNode, ClassName.get(fieldMap.get(fieldName).getType()), valueSet, false));
}
}
use of org.ehrbase.client.classgenerator.shareddefinition.Category in project openEHR_SDK by ehrbase.
the class ClassGenerator method addField.
private void addField(ClassGeneratorContext context, TypeSpec.Builder classBuilder, String path, WebTemplateNode node, TypeName className, ValueSet valueSet, boolean addChoiceAnnotation) {
if (CodePhrase.class.getName().equals(className.toString()))
switch(node.getName()) {
case "language":
className = ClassName.get(Language.class);
break;
case "setting":
className = ClassName.get(Setting.class);
break;
case "category":
className = ClassName.get(Category.class);
break;
case "territory":
className = ClassName.get(Territory.class);
break;
case "math_function":
className = ClassName.get(MathFunction.class);
break;
case "transition":
className = ClassName.get(Transition.class);
break;
case "null_flavour":
className = ClassName.get(NullFlavour.class);
break;
default:
if (CollectionUtils.isNotEmpty(valueSet.getTherms())) {
final TypeSpec enumValueSet = context.currentEnums.computeIfAbsent(valueSet, vs -> buildEnumValueSet(context, node, vs));
String enumPackage = context.currentPackageName + "." + context.currentMainClass.toLowerCase() + DEFINITION_PACKAGE;
context.classes.put(enumPackage, enumValueSet);
className = ClassName.get(enumPackage, enumValueSet.name);
}
}
String fieldName = defaultNamingStrategy.buildFieldName(context, path, node);
FieldSpec.Builder builder = FieldSpec.builder(className, fieldName).addAnnotation(AnnotationSpec.builder(Path.class).addMember(Path.VALUE, "$S", path).build()).addModifiers(Modifier.PRIVATE).addJavadoc(defaultNamingStrategy.buildFieldJavadoc(context, node));
if (addChoiceAnnotation) {
builder.addAnnotation(Choice.class);
}
FieldSpec fieldSpec = builder.build();
classBuilder.addField(fieldSpec);
classBuilder.addMethod(buildSetter(fieldSpec, false));
classBuilder.addMethod(buildGetter(fieldSpec, false));
}
Aggregations