use of com.nedap.archie.rminfo.RMAttributeInfo in project openEHR_SDK by ehrbase.
the class DtoToCompositionWalker method handleSingleValue.
private void handleSingleValue(Object value, String childName, Object child, Object parent) {
if (value == null) {
// NOP
} else if (EnumValueSet.class.isAssignableFrom(value.getClass()) && DvCodedText.class.isAssignableFrom(parent.getClass())) {
EnumValueSet valueSet = (EnumValueSet) value;
DvCodedText dvCodedText = (DvCodedText) parent;
dvCodedText.setValue(valueSet.getValue());
dvCodedText.setDefiningCode(new CodePhrase(new TerminologyId(valueSet.getTerminologyId()), valueSet.getCode()));
} else if (EnumValueSet.class.isAssignableFrom(value.getClass()) && DvCodedText.class.isAssignableFrom(ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName).getType())) {
EnumValueSet valueSet = (EnumValueSet) value;
DvCodedText dvCodedText = new DvCodedText();
dvCodedText.setValue(valueSet.getValue());
dvCodedText.setDefiningCode(new CodePhrase(new TerminologyId(valueSet.getTerminologyId()), valueSet.getCode()));
RM_OBJECT_CREATOR.set(parent, childName, Collections.singletonList(dvCodedText));
} else if (EnumValueSet.class.isAssignableFrom(value.getClass())) {
EnumValueSet valueSet = (EnumValueSet) value;
CodePhrase codePhrase = new CodePhrase(new TerminologyId(valueSet.getTerminologyId()), valueSet.getCode());
RM_OBJECT_CREATOR.set(parent, childName, Collections.singletonList(codePhrase));
} else if (ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName).getTypeInCollection().isAssignableFrom(value.getClass()) || (ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName).getTypeInCollection().isAssignableFrom(boolean.class) && value.getClass().isAssignableFrom(Boolean.class))) {
RMAttributeInfo attributeInfo = ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parent.getClass(), childName);
if (attributeInfo.isMultipleValued()) {
try {
Object invoke = attributeInfo.getGetMethod().invoke(parent);
if (Collection.class.isAssignableFrom(invoke.getClass()) && child != null) {
((Collection) invoke).remove(child);
}
} catch (IllegalAccessException | InvocationTargetException e) {
logger.warn(e.getMessage(), e);
}
}
RM_OBJECT_CREATOR.addElementToListOrSetSingleValues(parent, childName, Collections.singletonList(value));
} else {
logger.warn("Unhandled child {} in {}", childName, parent);
}
}
use of com.nedap.archie.rminfo.RMAttributeInfo in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilder method remove.
public static void remove(WebTemplateNode parentNode, RMObject parentObject, WebTemplateNode childNode, Object removeChildObject) {
String attributeName = FlatPath.removeStart(new FlatPath(childNode.getAqlPath(true)), new FlatPath(parentNode.getAqlPath(true))).getLast().getName();
RMAttributeInfo attributeInfo = ARCHIE_RM_INFO_LOOKUP.getAttributeInfo(parentObject.getClass(), attributeName);
try {
Object actualChild = attributeInfo.getGetMethod().invoke(parentObject);
if (actualChild instanceof Collection) {
((Collection<?>) actualChild).remove(removeChildObject);
} else if (Objects.equals(actualChild, removeChildObject)) {
attributeInfo.getSetMethod().invoke(parentObject, (Object) null);
}
} catch (IllegalAccessException | InvocationTargetException e) {
throw new SdkException(e.getMessage());
}
}
Aggregations