use of com.nedap.archie.rm.archetyped.Pathable in project openEHR_SDK by ehrbase.
the class ItemExtractor method invoke.
public ItemExtractor invoke() {
relativeAql = StringUtils.removeEnd(StringUtils.removeStart(childNode.getAqlPath(), currentNode.getAqlPath()), "/");
FlatPath childPath = new FlatPath(relativeAql);
parentAql = StringUtils.removeEnd(childPath.format(false), childPath.format(false).substring(childPath.format(false).lastIndexOf("/")));
if (StringUtils.isBlank(parentAql)) {
parentAql = "/";
}
if (currentRM instanceof Pathable) {
try {
child = ((Pathable) currentRM).itemsAtPath(childPath.format(false));
if (child == null || ((List) child).isEmpty()) {
child = ((Pathable) currentRM).itemAtPath(childPath.format(false));
}
} catch (RuntimeException e) {
child = null;
}
parent = ((Pathable) currentRM).itemAtPath(parentAql);
} else if (currentRM instanceof DvInterval) {
if (relativeAql.contains("upper_included")) {
child = new RmBoolean(((DvInterval<?>) currentRM).isUpperIncluded());
} else if (relativeAql.contains("lower_included")) {
child = new RmBoolean(((DvInterval<?>) currentRM).isLowerIncluded());
} else if (relativeAql.contains("lower")) {
child = ((DvInterval<?>) currentRM).getLower();
} else if (relativeAql.contains("upper")) {
child = ((DvInterval<?>) currentRM).getUpper();
}
parent = currentRM;
} else {
throw new SdkException(String.format("Can not extract from class %s", currentRM.getClass().getSimpleName()));
}
if (StringUtils.isNotBlank(childPath.findOtherPredicate("name/value")) && child instanceof List && Locatable.class.isAssignableFrom(Walker.ARCHIE_RM_INFO_LOOKUP.getClass(childNode.getRmType()))) {
child = ((List) child).stream().filter(c -> childPath.findOtherPredicate("name/value").equals(((Locatable) c).getNameAsString())).collect(Collectors.toList());
// if name not found return null
if (((List<?>) child).isEmpty()) {
child = null;
}
}
if (isChoice && child instanceof List) {
child = ((List) child).stream().filter(c -> Walker.ARCHIE_RM_INFO_LOOKUP.getTypeInfo(c.getClass()).getRmName().equals(childNode.getRmType())).collect(Collectors.toList());
// if rmType not found return null
if (((List<?>) child).isEmpty()) {
child = null;
}
}
if ((childNode.getMax() == 1 || currentNode.getRmType().equals(RmConstants.ELEMENT)) && child instanceof List) {
if (((List<?>) child).isEmpty()) {
child = null;
} else {
child = ((List) child).get(0);
}
}
if (child instanceof Element && !childNode.getRmType().equals(RmConstants.ELEMENT)) {
child = ((Element) child).getValue();
}
return this;
}
Aggregations