Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rm visibility #346

Merged
merged 15 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ target/
out/
test-output/
grammars/gen
grammars/src/main/antlr/gen/
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.nedap.archie.adlparser.antlr.AdlBaseListener;
import com.nedap.archie.adlparser.antlr.AdlParser;
import com.nedap.archie.adlparser.antlr.AdlParser.*;
import com.nedap.archie.aom.rmoverlay.RmOverlay;
import com.nedap.archie.rminfo.MetaModels;
import com.nedap.archie.serializer.odin.OdinObjectParser;
import com.nedap.archie.serializer.odin.AdlOdinToJsonConverter;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void exitTemplate(TemplateContext ctx) {
}

@Override
public void enterTemplate_overlay(Template_overlayContext ctx) {
public void enterTemplateOverlay(TemplateOverlayContext ctx) {
TemplateOverlay overlay = new TemplateOverlay();
overlay.setDifferential(true);
if(rootArchetype != null) {
Expand All @@ -88,7 +89,7 @@ public void enterTemplate_overlay(Template_overlayContext ctx) {
}

@Override
public void enterOperational_template(Operational_templateContext ctx) {
public void enterOperationalTemplate(OperationalTemplateContext ctx) {
rootArchetype = new OperationalTemplate();
rootArchetype.setDifferential(false);//operational templates are flat by definition
setArchetype(rootArchetype);
Expand All @@ -105,7 +106,7 @@ private void parseArchetypeHRID(TerminalNode hrId) {
}
}

public void enterMeta_data_item(AdlParser.Meta_data_itemContext ctx) {
public void enterMetaDataItem(AdlParser.MetaDataItemContext ctx) {
/*
SYM_ADL_VERSION '=' VERSION_ID
| SYM_UID '=' GUID
Expand All @@ -119,26 +120,26 @@ public void enterMeta_data_item(AdlParser.Meta_data_itemContext ctx) {
if(archetype instanceof AuthoredArchetype) {
AuthoredArchetype authoredArchetype = (AuthoredArchetype) archetype;

if(ctx.meta_data_tag_adl_version() != null) {
if(ctx.metaDataTagAdlVersion() != null) {
authoredArchetype.setAdlVersion(ctx.VERSION_ID().getText());
}
if(ctx.meta_data_tag_build_uid() != null) {
if(ctx.metaDataTagBuildUid() != null) {
authoredArchetype.setBuildUid(ctx.GUID().getText());
}
if(ctx.meta_data_tag_rm_release() != null) {
if(ctx.metaDataTagRmRelease() != null) {
authoredArchetype.setRmRelease(ctx.VERSION_ID().getText());
}
if(ctx.meta_data_tag_is_controlled() != null) {
if(ctx.metaDataTagIsControlled() != null) {
authoredArchetype.setControlled(true);
}
if(ctx.meta_data_tag_is_generated() != null) {
if(ctx.metaDataTagIsGenerated() != null) {
authoredArchetype.setGenerated(true);
}
if(ctx.meta_data_tag_uid() != null) {
if(ctx.metaDataTagUid() != null) {
authoredArchetype.setUid(ctx.GUID().getText());
}
else if(ctx.identifier() != null) {
authoredArchetype.addOtherMetadata(ctx.identifier().getText(), ctx.meta_data_value() == null ? null : ctx.meta_data_value().getText());
authoredArchetype.addOtherMetadata(ctx.identifier().getText(), ctx.metaDataValue() == null ? null : ctx.metaDataValue().getText());
}
}

Expand All @@ -148,43 +149,49 @@ else if(ctx.identifier() != null) {
* one level below: definition, language, etc.
*/
@Override
public void enterDefinition_section(Definition_sectionContext ctx) {
public void enterDefinitionSection(DefinitionSectionContext ctx) {
CComplexObject definition = cComplexObjectParser.parseComplexObject(ctx.c_complex_object());
archetype.setDefinition(definition);
}

@Override
public void enterLanguage_section(Language_sectionContext ctx) {
public void enterLanguageSection(LanguageSectionContext ctx) {
archetype.setAuthoredResourceContent(OdinObjectParser.convert(ctx.odin_text(), LanguageSection.class));
}

@Override
public void enterTerminology_section(Terminology_sectionContext ctx) {
public void enterTerminologySection(TerminologySectionContext ctx) {
archetype.setTerminology(terminologyParser.parseTerminology(ctx));
}

@Override
public void enterDescription_section(AdlParser.Description_sectionContext ctx) {
public void enterDescriptionSection(AdlParser.DescriptionSectionContext ctx) {
archetype.setDescription(OdinObjectParser.convert(ctx.odin_text(), ResourceDescription.class));
}

@Override
public void enterSpecialization_section(Specialization_sectionContext ctx) {
public void enterSpecializationSection(SpecializationSectionContext ctx) {
if(ctx != null && ctx.archetype_ref() != null) {
archetype.setParentArchetypeId(ctx.archetype_ref().getText());
}
}

public void enterRules_section(Rules_sectionContext ctx) {
@Override
public void enterRulesSection(RulesSectionContext ctx) {
archetype.setRules(cComplexObjectParser.parseRules(ctx));
}


public void enterAnnotations_section(AdlParser.Annotations_sectionContext ctx) {
@Override
public void enterAnnotationsSection(AdlParser.AnnotationsSectionContext ctx) {
archetype.setAnnotations(OdinObjectParser.convert(ctx.odin_text(), ResourceAnnotations.class));
}

public void enterComponent_terminologies_section(AdlParser.Component_terminologies_sectionContext ctx) {
@Override
public void enterRmOverlaySection(AdlParser.RmOverlaySectionContext ctx) {
archetype.setRmOverlay(OdinObjectParser.convert(ctx.odin_text(), RmOverlay.class));
}

public void enterComponentTerminologiesSection(AdlParser.ComponentTerminologiesSectionContext ctx) {
if (!(archetype instanceof OperationalTemplate)) {
throw new IllegalArgumentException("cannot add component terminologies to anything but an operational template");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CComplexObjectParser(ANTLRParserErrors errors, MetaModels metaModels) {
this.metaModels = metaModels;
}

public RulesSection parseRules(Rules_sectionContext context) {
public RulesSection parseRules(RulesSectionContext context) {
RulesSection result = new RulesSection();

result.setContent(context.getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public TerminologyParser(ANTLRParserErrors errors) {
super(errors);
}

public ArchetypeTerminology parseTerminology(Terminology_sectionContext context) {
public ArchetypeTerminology parseTerminology(TerminologySectionContext context) {
ArchetypeTerminology terminology = OdinObjectParser.convert(context.odin_text(), ArchetypeTerminology.class);
return terminology;
}
Expand Down
25 changes: 24 additions & 1 deletion aom/src/main/java/com/nedap/archie/aom/Archetype.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nedap.archie.aom.primitives.CTerminologyCode;
import com.nedap.archie.aom.rmoverlay.RmAttributeVisibility;
import com.nedap.archie.aom.rmoverlay.RmOverlay;
import com.nedap.archie.aom.terminology.ArchetypeTerm;
import com.nedap.archie.aom.terminology.ArchetypeTerminology;
import com.nedap.archie.aom.terminology.ValueSet;
Expand All @@ -10,6 +12,7 @@
import com.nedap.archie.definitions.AdlCodeDefinitions;
import com.nedap.archie.query.AOMPathQuery;
import com.nedap.archie.xml.adapters.ArchetypeTerminologyAdapter;
import com.nedap.archie.xml.adapters.RMOverlayXmlAdapter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
Expand Down Expand Up @@ -46,7 +49,8 @@
"buildUid",
"rmRelease",
"generated",
"otherMetaData"
"otherMetaData",
"rmOverlay"
})
public class Archetype extends AuthoredResource {

Expand Down Expand Up @@ -75,6 +79,10 @@ public class Archetype extends AuthoredResource {
//TODO: this probably requires a custom XmlAdapter
private Map<String, String> otherMetaData = new LinkedHashMap<>();

@XmlElement(name="rm_overlay")
@XmlJavaTypeAdapter(RMOverlayXmlAdapter.class)
private RmOverlay rmOverlay;

public String getParentArchetypeId() {
return parentArchetypeId;
}
Expand Down Expand Up @@ -274,6 +282,13 @@ public Set<String> getAllUsedCodes() {

}
}
if(rmOverlay != null && rmOverlay.getRmVisibility() != null) {
for (RmAttributeVisibility value : rmOverlay.getRmVisibility().values()) {
if(value.getAlias() != null) {
result.add(value.getAlias().getCodeString());
}
}
}

return result;
}
Expand Down Expand Up @@ -333,4 +348,12 @@ public String generateNextSpecializedIdCode(String nodeId) {
return nodeId + AdlCodeDefinitions.SPECIALIZATION_SEPARATOR + generateSpecializationDepthCodePrefix(specializationDepth-nodeIdSpecializationDepth-1) + (maximumIdCode+1);

}

public RmOverlay getRmOverlay() {
return rmOverlay;
}

public void setRmOverlay(RmOverlay rmOverlay) {
this.rmOverlay = rmOverlay;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.nedap.archie.aom.rmoverlay;

import com.nedap.archie.aom.ArchetypeModelObject;
import com.nedap.archie.base.terminology.TerminologyCode;

import javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlType;
import java.util.Objects;

public class RmAttributeVisibility extends ArchetypeModelObject {

@Nullable
private VisibilityType visibility;
@Nullable
private TerminologyCode alias;

public RmAttributeVisibility() {
}

public RmAttributeVisibility(VisibilityType visibility, TerminologyCode alias) {
this.visibility = visibility;
this.alias = alias;
}

public VisibilityType getVisibility() {
return visibility;
}

public void setVisibility(VisibilityType visibility) {
this.visibility = visibility;
}

public TerminologyCode getAlias() {
return alias;
}

public void setAlias(TerminologyCode alias) {
this.alias = alias;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RmAttributeVisibility that = (RmAttributeVisibility) o;
return visibility == that.visibility &&
Objects.equals(alias, that.alias);
}

@Override
public int hashCode() {
return Objects.hash(visibility, alias);
}
}
42 changes: 42 additions & 0 deletions aom/src/main/java/com/nedap/archie/aom/rmoverlay/RmOverlay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.nedap.archie.aom.rmoverlay;

import com.nedap.archie.aom.ArchetypeModelObject;

import javax.annotation.Nullable;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

public class RmOverlay extends ArchetypeModelObject {

@Nullable
Map<String, RmAttributeVisibility> rmVisibility = new LinkedHashMap<>();

public RmOverlay() {
}

public RmOverlay(Map<String, RmAttributeVisibility> rmVisibility) {
this.rmVisibility = rmVisibility;
}

public Map<String, RmAttributeVisibility> getRmVisibility() {
return rmVisibility;
}

public void setRmVisibility(Map<String, RmAttributeVisibility> rmVisibility) {
this.rmVisibility = rmVisibility;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RmOverlay rmOverlay = (RmOverlay) o;
return Objects.equals(rmVisibility, rmOverlay.rmVisibility);
}

@Override
public int hashCode() {
return Objects.hash(rmVisibility);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.nedap.archie.aom.rmoverlay;

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;

public enum VisibilityType {
@JsonProperty("hide")
@XmlEnumValue("hide")
HIDE,
@JsonProperty("show")
@XmlEnumValue("show")
SHOW;
}
35 changes: 35 additions & 0 deletions aom/src/main/java/com/nedap/archie/aom/utils/AOMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import com.nedap.archie.definitions.AdlCodeDefinitions;
import com.nedap.archie.paths.PathSegment;
import com.nedap.archie.paths.PathUtil;
import com.nedap.archie.query.AOMPathQuery;
import com.nedap.archie.query.APathQuery;
import com.nedap.archie.query.PartialMatch;
import com.nedap.archie.rminfo.MetaModel;
import com.nedap.archie.rminfo.ModelInfoLookup;
import com.nedap.archie.rminfo.RMAttributeInfo;
import com.nedap.archie.rminfo.RMTypeInfo;
Expand Down Expand Up @@ -338,6 +341,38 @@ public static int getMaximumIdCode(int specializationDepth, String prefix, Colle
return maximumIdCode;
}

public static boolean isPathInArchetypeOrRm(MetaModel metaModel, String path, Archetype template) {
AOMPathQuery aomPathQuery = new AOMPathQuery(path);
PartialMatch partial = aomPathQuery.findPartial(template.getDefinition());
if(partial.isFullMatch()) {
return true;
} else {
if(isArchetypePath(partial.getRemainingPath())) {
// the remaining path is an archetype path, so cannot be found purely in the RM without
//further constraints
return false;
}
//we have a partial match left, search for it in the RM
//in case there is no match at all, getFoundObjects() will contain the root node, so this is safe
for (ArchetypeModelObject archetypeModelObject : partial.getFoundObjects()) {
if (archetypeModelObject instanceof CObject) {
if (metaModel.hasReferenceModelPath(((CObject) archetypeModelObject).getRmTypeName(), partial.getRemainingPath())) {
return true;
}
} else if (archetypeModelObject instanceof CAttribute) {
CAttribute attribute = (CAttribute) archetypeModelObject;
//matched an attribute. So if even one object matches, return true
for(CObject child:attribute.getChildren()) {
if (metaModel.hasReferenceModelPath(child.getRmTypeName(), partial.getRemainingPath())) {
return true;
}
}
}
}
}
return false;
}

/**
* Given a code such as 'id4.1.0.0.1', return the nearest code that exists in a parent. In this example,
* returns id4.1, so removes all zeros.
Expand Down
Loading