use of org.ehrbase.client.classgenerator.shareddefinition.Setting 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.Setting in project openEHR_SDK by ehrbase.
the class EventContextValueInserter method insert.
@Override
public void insert(EventContext rmObject, DefaultValues defaultValues) {
if (RMHelper.isEmpty(rmObject.getStartTime()) && defaultValues.containsDefaultValue(DefaultValuePath.TIME)) {
rmObject.setStartTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.TIME)));
}
if (RMHelper.isEmpty(rmObject.getEndTime()) && defaultValues.containsDefaultValue(DefaultValuePath.END_TIME)) {
rmObject.setEndTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.END_TIME)));
}
if (RMHelper.isEmpty(rmObject.getHealthCareFacility()) && (defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_NAME) || defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_ID))) {
rmObject.setHealthCareFacility(buildPartyIdentified(defaultValues, DefaultValuePath.HEALTHCARE_FACILITY_NAME, DefaultValuePath.HEALTHCARE_FACILITY_ID, rmObject.getHealthCareFacility()));
}
if (RMHelper.isEmpty(rmObject.getLocation()) && defaultValues.containsDefaultValue(DefaultValuePath.LOCATION)) {
rmObject.setLocation(defaultValues.getDefaultValue(DefaultValuePath.LOCATION));
}
if (RMHelper.isEmpty(rmObject.getSetting()) && defaultValues.containsDefaultValue(DefaultValuePath.SETTING)) {
Setting defaultValue = defaultValues.getDefaultValue(DefaultValuePath.SETTING);
rmObject.setSetting(new DvCodedText(defaultValue.getValue(), defaultValue.toCodePhrase()));
}
if (RMHelper.isEmpty(rmObject.getParticipations()) && defaultValues.containsDefaultValue(DefaultValuePath.PARTICIPATION)) {
rmObject.setParticipations(defaultValues.getDefaultValue(DefaultValuePath.PARTICIPATION));
}
if (rmObject.getParticipations() != null) {
rmObject.getParticipations().stream().map(Participation::getPerformer).filter(Objects::nonNull).map(PartyProxy::getExternalRef).filter(Objects::nonNull).filter(ref -> ref.getId() != null).forEach(ref -> {
if (ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_NAMESPACE)) {
ref.setNamespace(defaultValues.getDefaultValue(DefaultValuePath.ID_NAMESPACE));
}
if (ref.getId() instanceof GenericId && ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_SCHEME)) {
((GenericId) ref.getId()).setScheme(defaultValues.getDefaultValue(DefaultValuePath.ID_SCHEME));
}
});
}
}
use of org.ehrbase.client.classgenerator.shareddefinition.Setting 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