use of com.nedap.archie.aom.CComplexObject in project archetype-languageserver by nedap.
the class PartialAOMPathQuery method findLSPPartial.
// TODO: check if/how this is different from AOMPathQuery.findPartial, and potentially remove
public PartialMatch findLSPPartial(CComplexObject root) {
List<ArchetypeModelObject> result = new ArrayList<>();
boolean findThroughDifferentialPaths = true, matchSpecializedNodes = true;
result.add(root);
List<PathSegment> pathSegments = getPathSegments();
for (int i = 0; i < pathSegments.size(); i++) {
List<ArchetypeModelObject> previousResult = result;
PathSegment segment = pathSegments.get(i);
CAttribute differentialAttribute = null;
if (findThroughDifferentialPaths) {
differentialAttribute = findMatchingDifferentialPath(pathSegments.subList(i, pathSegments.size()), result);
}
if (differentialAttribute != null) {
// skip a few pathsegments for this differential path match
i = i + new APathQuery(differentialAttribute.getDifferentialPath()).getPathSegments().size() - 1;
PathSegment lastPathSegment = pathSegments.get(i);
ArchetypeModelObject oneMatchingObject = findOneMatchingObject(differentialAttribute, lastPathSegment, matchSpecializedNodes);
if (oneMatchingObject != null) {
result = Lists.newArrayList(oneMatchingObject);
} else {
result = findOneSegment(segment, result, matchSpecializedNodes);
}
} else {
result = findOneSegment(segment, result, matchSpecializedNodes);
}
List<ArchetypeModelObject> returnValue = previousResult.stream().filter((object) -> object != null).collect(Collectors.toList());
if (result.isEmpty()) {
// we have to return our partial match here
return new PartialMatch(pathSegments, pathSegments.subList(i, pathSegments.size()), returnValue);
}
}
List<ArchetypeModelObject> returnValue = result.stream().filter((object) -> object != null).collect(Collectors.toList());
return new PartialMatch(pathSegments, new ArrayList<>(), returnValue);
}
use of com.nedap.archie.aom.CComplexObject in project archetype-languageserver by nedap.
the class ArchetypeHoverInfo method extractHoverInfo.
private void extractHoverInfo(DocumentInformation documentInformation, CAttribute attribute, Archetype archetypeForTerms) {
for (CObject object : attribute.getChildren()) {
try {
if (object instanceof CComplexObject) {
extractHoverInfo(documentInformation, (CComplexObject) object, archetypeForTerms);
} else if (object instanceof CTerminologyCode) {
extractHoverInfo(documentInformation, (CTerminologyCode) object, archetypeForTerms);
} else if (object instanceof ArchetypeSlot) {
getHoverInfoForCObject(documentInformation, object, archetypeForTerms);
}
// for the other primitives, hovers should not be important
} catch (Exception e) {
// If this fails, fine, continue with the rest of the file!
// TODO: report to client?
e.printStackTrace();
}
}
try {
CAttribute flatAttribute = archetypeForTerms.itemAtPath(attribute.getPath());
if (flatAttribute == null) {
flatAttribute = attribute;
}
Cardinality cardinality = null;
MultiplicityInterval existence = null;
// TODO: do a proper path lookup through the RM model?
CAttribute defaults = new BMMConstraintImposer(metaModels.getSelectedBmmModel()).getDefaultAttribute(flatAttribute.getParent().getRmTypeName(), flatAttribute.getRmAttributeName());
if (flatAttribute.getCardinality() != null) {
cardinality = flatAttribute.getCardinality();
} else {
if (defaults != null) {
cardinality = defaults.getCardinality();
}
}
if (flatAttribute.getExistence() != null) {
existence = flatAttribute.getExistence();
} else {
if (defaults != null) {
existence = flatAttribute.getExistence();
}
}
boolean multiple = flatAttribute.isMultiple();
StringBuilder content = new StringBuilder();
if (cardinality != null) {
content.append("Cardinality: ");
content.append(cardinality.toString());
}
if (existence != null) {
content.append(", existence: " + existence.toString());
}
content.append(multiple ? "\n multiple valued attribute" : "\n single valued attribute");
BmmClass classDefinition = metaModels.getSelectedBmmModel().getClassDefinition(flatAttribute.getParent().getRmTypeName());
if (classDefinition != null) {
BmmProperty bmmProperty = classDefinition.getFlatProperties().get(flatAttribute.getRmAttributeName());
if (bmmProperty != null) {
content.append("\n\nRM type name: *" + bmmProperty.getType().toDisplayString() + "*");
}
}
content.append("\n\n path: " + attribute.getPath());
Hover hover = new Hover();
hover.setContents(new MarkupContent(MARKDOWN, content.toString()));
Range range = getHoverRange(documentInformation, attribute);
if (range != null) {
hoverRanges.addRange(range, hover);
}
} catch (Exception e) {
// TODO: report to client?
e.printStackTrace();
}
}
use of com.nedap.archie.aom.CComplexObject in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilder method build.
@SuppressWarnings("unchecked")
public static <T> T build(WebTemplateNode node, boolean withChildren, Class<T> clazz) {
String rmclass = node.getRmType();
CComplexObject elementConstraint = new CComplexObject();
elementConstraint.setRmTypeName(rmclass);
Object skeleton;
switch(rmclass) {
case "UID_BASED_ID":
skeleton = new HierObjectId();
break;
case "PARTY_PROXY":
skeleton = new PartyIdentified();
break;
case "STRING":
case "LONG":
skeleton = null;
break;
case "BOOLEAN":
skeleton = false;
break;
default:
skeleton = RM_OBJECT_CREATOR.create(elementConstraint);
break;
}
if (withChildren) {
node.getChildren().stream().filter(n -> !List.of("name", "archetype_node_id", "offset").contains(n.getId())).forEach(c -> {
Object childObject = build(c, true, Object.class);
insert(node, (RMObject) skeleton, c, childObject);
});
}
if (skeleton instanceof Locatable) {
Optional<WebTemplateNode> name = node.findChildById("name");
if (name.isPresent()) {
if (name.get().getRmType().equals(RmConstants.DV_CODED_TEXT)) {
((Locatable) skeleton).setName(extractDefault(name.get(), DvCodedText.class).orElseThrow());
} else {
((Locatable) skeleton).setName(extractDefault(name.get(), DvText.class).orElse(new DvText(node.getName())));
}
} else {
((Locatable) skeleton).setName(new DvText(node.getName()));
}
((Locatable) skeleton).setArchetypeNodeId(node.getNodeId());
}
if (skeleton instanceof Entry) {
((Entry) skeleton).setEncoding(new CodePhrase(new TerminologyId("IANA_character-sets"), "UTF-8"));
node.findChildById("subject").map(n -> build(n, false, PartyProxy.class)).ifPresent(((Entry) skeleton)::setSubject);
}
if (skeleton instanceof Composition) {
node.findChildById("category").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((Composition) skeleton)::setCategory);
}
if (skeleton instanceof DvInterval) {
((DvInterval<?>) skeleton).setLowerIncluded(true);
((DvInterval<?>) skeleton).setUpperIncluded(true);
}
if (skeleton instanceof PartyRelated) {
node.findChildById("relationship").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((PartyRelated) skeleton)::setRelationship);
}
if (skeleton == null || clazz.isAssignableFrom(skeleton.getClass())) {
return (T) skeleton;
} else {
throw new SdkException(String.format("%s not assignable from %s", skeleton.getClass(), clazz));
}
}
Aggregations