Add warning about resources not linked to in bundles
This commit is contained in:
parent
f508f7279a
commit
1e69909466
|
@ -32,6 +32,7 @@ public class I18nConstants {
|
||||||
public static final String BUNDLE_BUNDLE_ENTRY_MULTIPLE_PROFILES = "BUNDLE_BUNDLE_ENTRY_MULTIPLE_PROFILES";
|
public static final String BUNDLE_BUNDLE_ENTRY_MULTIPLE_PROFILES = "BUNDLE_BUNDLE_ENTRY_MULTIPLE_PROFILES";
|
||||||
public static final String BUNDLE_BUNDLE_ENTRY_NOTFOUND = "Bundle_BUNDLE_Entry_NotFound";
|
public static final String BUNDLE_BUNDLE_ENTRY_NOTFOUND = "Bundle_BUNDLE_Entry_NotFound";
|
||||||
public static final String BUNDLE_BUNDLE_ENTRY_ORPHAN = "Bundle_BUNDLE_Entry_Orphan";
|
public static final String BUNDLE_BUNDLE_ENTRY_ORPHAN = "Bundle_BUNDLE_Entry_Orphan";
|
||||||
|
public static final String BUNDLE_BUNDLE_ENTRY_REVERSE = "BUNDLE_BUNDLE_ENTRY_REVERSE";
|
||||||
public static final String BUNDLE_BUNDLE_ENTRY_TYPE = "Bundle_BUNDLE_Entry_Type";
|
public static final String BUNDLE_BUNDLE_ENTRY_TYPE = "Bundle_BUNDLE_Entry_Type";
|
||||||
public static final String BUNDLE_BUNDLE_ENTRY_TYPE2 = "Bundle_BUNDLE_Entry_Type2";
|
public static final String BUNDLE_BUNDLE_ENTRY_TYPE2 = "Bundle_BUNDLE_Entry_Type2";
|
||||||
public static final String BUNDLE_BUNDLE_ENTRY_TYPE3 = "Bundle_BUNDLE_Entry_Type3";
|
public static final String BUNDLE_BUNDLE_ENTRY_TYPE3 = "Bundle_BUNDLE_Entry_Type3";
|
||||||
|
|
|
@ -11,6 +11,7 @@ BUNDLE_BUNDLE_ENTRY_FULLURL_REQUIRED = Except for transactions and batches, each
|
||||||
Bundle_BUNDLE_Entry_NoProfile = No profile found for contained resource of type ''{0}''
|
Bundle_BUNDLE_Entry_NoProfile = No profile found for contained resource of type ''{0}''
|
||||||
Bundle_BUNDLE_Entry_NotFound = Can''t find ''{0}'' in the bundle ({1})
|
Bundle_BUNDLE_Entry_NotFound = Can''t find ''{0}'' in the bundle ({1})
|
||||||
Bundle_BUNDLE_Entry_Orphan = Entry {0} isn''t reachable by traversing from first Bundle entry
|
Bundle_BUNDLE_Entry_Orphan = Entry {0} isn''t reachable by traversing from first Bundle entry
|
||||||
|
BUNDLE_BUNDLE_ENTRY_REVERSE = Entry {0} isn''t reachable by traversing forwards from first Bundle entry, and isn''t a resource type that is typically used that way - check this is not missed somewhere
|
||||||
Bundle_BUNDLE_Entry_Type = The type ''{0}'' is not valid - no resources allowed here (allowed = {1})
|
Bundle_BUNDLE_Entry_Type = The type ''{0}'' is not valid - no resources allowed here (allowed = {1})
|
||||||
Bundle_BUNDLE_Entry_Type2 = The type ''{0}'' is not valid - must be {1} (allowed = {2})
|
Bundle_BUNDLE_Entry_Type2 = The type ''{0}'' is not valid - must be {1} (allowed = {2})
|
||||||
Bundle_BUNDLE_Entry_Type3 = The type ''{0}'' is not valid - must be one of {1}
|
Bundle_BUNDLE_Entry_Type3 = The type ''{0}'' is not valid - must be one of {1}
|
||||||
|
|
|
@ -396,20 +396,30 @@ public class BundleValidator extends BaseValidator{
|
||||||
|
|
||||||
private void checkAllInterlinked(List<ValidationMessage> errors, List<Element> entries, NodeStack stack, Element bundle, boolean isError) {
|
private void checkAllInterlinked(List<ValidationMessage> errors, List<Element> entries, NodeStack stack, Element bundle, boolean isError) {
|
||||||
List<EntrySummary> entryList = new ArrayList<>();
|
List<EntrySummary> entryList = new ArrayList<>();
|
||||||
|
int i = 0;
|
||||||
for (Element entry : entries) {
|
for (Element entry : entries) {
|
||||||
Element r = entry.getNamedChild(RESOURCE);
|
Element r = entry.getNamedChild(RESOURCE);
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
entryList.add(new EntrySummary(entry, r));
|
EntrySummary e = new EntrySummary(i, entry, r);
|
||||||
|
entryList.add(e);
|
||||||
|
System.out.println("Found entry "+e.dbg());
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (EntrySummary e : entryList) {
|
for (EntrySummary e : entryList) {
|
||||||
Set<String> references = findReferences(e.getEntry());
|
Set<String> references = findReferences(e.getEntry());
|
||||||
for (String ref : references) {
|
for (String ref : references) {
|
||||||
Element tgt = resolveInBundle(entries, ref, e.getEntry().getChildValue(FULL_URL), e.getResource().fhirType(), e.getResource().getIdBase());
|
Element tgt = resolveInBundle(entries, ref, e.getEntry().getChildValue(FULL_URL), e.getResource().fhirType(), e.getResource().getIdBase());
|
||||||
if (tgt != null) {
|
if (tgt != null) {
|
||||||
EntrySummary t = entryForTarget(entryList, tgt);
|
EntrySummary t = entryForTarget(entryList, tgt);
|
||||||
if (t != null) {
|
if (t != null ) {
|
||||||
e.getTargets().add(t);
|
if (t != e) {
|
||||||
|
System.out.println("Entry "+e.getIndex()+" refers to "+t.getIndex()+" by ref '"+ref+"'");
|
||||||
|
e.getTargets().add(t);
|
||||||
|
} else {
|
||||||
|
System.out.println("Entry "+e.getIndex()+" refers to itself by '"+ref+"'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -422,6 +432,7 @@ public class BundleValidator extends BaseValidator{
|
||||||
foundRevLinks = false;
|
foundRevLinks = false;
|
||||||
for (EntrySummary e : entryList) {
|
for (EntrySummary e : entryList) {
|
||||||
if (!visited.contains(e)) {
|
if (!visited.contains(e)) {
|
||||||
|
System.out.println("Not visited "+e.getIndex()+" - check for reverse links");
|
||||||
boolean add = false;
|
boolean add = false;
|
||||||
for (EntrySummary t : e.getTargets()) {
|
for (EntrySummary t : e.getTargets()) {
|
||||||
if (visited.contains(t)) {
|
if (visited.contains(t)) {
|
||||||
|
@ -429,6 +440,10 @@ public class BundleValidator extends BaseValidator{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (add) {
|
if (add) {
|
||||||
|
warning(errors, IssueType.INFORMATIONAL, e.getEntry().line(), e.getEntry().col(),
|
||||||
|
stack.addToLiteralPath(ENTRY + '[' + (i + 1) + ']'), isExpectedToBeReverse(e.getResource().fhirType()),
|
||||||
|
I18nConstants.BUNDLE_BUNDLE_ENTRY_REVERSE, (e.getEntry().getChildValue(FULL_URL) != null ? "'" + e.getEntry().getChildValue(FULL_URL) + "'" : ""));
|
||||||
|
System.out.println("Found reverse links for "+e.getIndex());
|
||||||
foundRevLinks = true;
|
foundRevLinks = true;
|
||||||
visitLinked(visited, e);
|
visitLinked(visited, e);
|
||||||
}
|
}
|
||||||
|
@ -436,7 +451,7 @@ public class BundleValidator extends BaseValidator{
|
||||||
}
|
}
|
||||||
} while (foundRevLinks);
|
} while (foundRevLinks);
|
||||||
|
|
||||||
int i = 0;
|
i = 0;
|
||||||
for (EntrySummary e : entryList) {
|
for (EntrySummary e : entryList) {
|
||||||
Element entry = e.getEntry();
|
Element entry = e.getEntry();
|
||||||
if (isError) {
|
if (isError) {
|
||||||
|
@ -450,6 +465,10 @@ public class BundleValidator extends BaseValidator{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isExpectedToBeReverse(String fhirType) {
|
||||||
|
return Utilities.existsInList(fhirType, "Provenance");
|
||||||
|
}
|
||||||
|
|
||||||
private String uriRegexForVersion() {
|
private String uriRegexForVersion() {
|
||||||
if (VersionUtilities.isR3Ver(context.getVersion()))
|
if (VersionUtilities.isR3Ver(context.getVersion()))
|
||||||
return URI_REGEX3;
|
return URI_REGEX3;
|
||||||
|
|
|
@ -10,6 +10,7 @@ public class EntrySummary {
|
||||||
Element entry;
|
Element entry;
|
||||||
Element resource;
|
Element resource;
|
||||||
List<EntrySummary> targets = new ArrayList<>();
|
List<EntrySummary> targets = new ArrayList<>();
|
||||||
|
private int index;
|
||||||
|
|
||||||
public Element getEntry() {
|
public Element getEntry() {
|
||||||
return entry;
|
return entry;
|
||||||
|
@ -38,8 +39,17 @@ public class EntrySummary {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntrySummary(Element entry, Element resource) {
|
public EntrySummary(int i, Element entry, Element resource) {
|
||||||
this.entry = entry;
|
this.index = i;
|
||||||
this.resource = resource;
|
this.entry = entry;
|
||||||
|
this.resource = resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String dbg() {
|
||||||
|
return ""+index+"="+ entry.getChildValue("fullUrl")+" | "+resource.getIdBase() + "("+resource.fhirType()+")";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIndex() {
|
||||||
|
return Integer.toString(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue