better handling of circular dependencies in snap shot generator
This commit is contained in:
parent
9b562f3489
commit
4d99bcb0c6
|
@ -463,6 +463,9 @@ public class ProfileUtilities extends TranslatingUtilities {
|
||||||
if (derived == null) {
|
if (derived == null) {
|
||||||
throw new DefinitionException("no derived structure provided");
|
throw new DefinitionException("no derived structure provided");
|
||||||
}
|
}
|
||||||
|
checkNotGenerating(base, "Base for generating a snapshot for the profile "+derived.getUrl());
|
||||||
|
checkNotGenerating(derived, "Focus for generating a snapshot");
|
||||||
|
derived.setUserData("profileutils.snapshot.generating", true);
|
||||||
|
|
||||||
if (!base.hasType()) {
|
if (!base.hasType()) {
|
||||||
throw new DefinitionException("Base profile "+base.getUrl()+" has no type");
|
throw new DefinitionException("Base profile "+base.getUrl()+" has no type");
|
||||||
|
@ -622,6 +625,7 @@ public class ProfileUtilities extends TranslatingUtilities {
|
||||||
derived.setSnapshot(null);
|
derived.setSnapshot(null);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
derived.clearUserData("profileutils.snapshot.generating");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkDifferential(List<ElementDefinition> elements, String type, String url) {
|
private void checkDifferential(List<ElementDefinition> elements, String type, String url) {
|
||||||
|
@ -853,10 +857,12 @@ public class ProfileUtilities extends TranslatingUtilities {
|
||||||
CanonicalType p = diffMatches.get(0).getType().get(0).getProfile().get(0);
|
CanonicalType p = diffMatches.get(0).getType().get(0).getProfile().get(0);
|
||||||
StructureDefinition sd = context.fetchResource(StructureDefinition.class, p.getValue());
|
StructureDefinition sd = context.fetchResource(StructureDefinition.class, p.getValue());
|
||||||
if (sd != null) {
|
if (sd != null) {
|
||||||
|
checkNotGenerating(sd, "an extension definition");
|
||||||
if (!sd.hasSnapshot()) {
|
if (!sd.hasSnapshot()) {
|
||||||
StructureDefinition sdb = context.fetchResource(StructureDefinition.class, sd.getBaseDefinition());
|
StructureDefinition sdb = context.fetchResource(StructureDefinition.class, sd.getBaseDefinition());
|
||||||
if (sdb == null)
|
if (sdb == null)
|
||||||
throw new DefinitionException("Unable to find base "+sd.getBaseDefinition()+" for "+sd.getUrl());
|
throw new DefinitionException("Unable to find base "+sd.getBaseDefinition()+" for "+sd.getUrl());
|
||||||
|
checkNotGenerating(sdb, "an extension base");
|
||||||
generateSnapshot(sdb, sd, sd.getUrl(), (sdb.hasUserData("path")) ? Utilities.extractBaseUrl(sdb.getUserString("path")) : webUrl, sd.getName());
|
generateSnapshot(sdb, sd, sd.getUrl(), (sdb.hasUserData("path")) ? Utilities.extractBaseUrl(sdb.getUserString("path")) : webUrl, sd.getName());
|
||||||
}
|
}
|
||||||
ElementDefinition src;
|
ElementDefinition src;
|
||||||
|
@ -1424,7 +1430,7 @@ public class ProfileUtilities extends TranslatingUtilities {
|
||||||
outcome.setSlicing(null);
|
outcome.setSlicing(null);
|
||||||
if (!outcome.getPath().startsWith(resultPathBase))
|
if (!outcome.getPath().startsWith(resultPathBase))
|
||||||
throw new DefinitionException("Adding wrong path");
|
throw new DefinitionException("Adding wrong path");
|
||||||
if (diffpos < diffMatches.size() && diffMatches.get(diffpos).getSliceName().equals(outcome.getSliceName())) {
|
if (diffpos < diffMatches.size() && diffMatches.get(diffpos).hasSliceName() && diffMatches.get(diffpos).getSliceName().equals(outcome.getSliceName())) {
|
||||||
// if there's a diff, we update the outcome with diff
|
// if there's a diff, we update the outcome with diff
|
||||||
// no? updateFromDefinition(outcome, diffMatches.get(diffpos), profileName, closed, url);
|
// no? updateFromDefinition(outcome, diffMatches.get(diffpos), profileName, closed, url);
|
||||||
//then process any children
|
//then process any children
|
||||||
|
@ -1540,6 +1546,12 @@ public class ProfileUtilities extends TranslatingUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void checkNotGenerating(StructureDefinition sd, String role) {
|
||||||
|
if (sd.hasUserData("profileutils.snapshot.generating")) {
|
||||||
|
throw new FHIRException("Attempt to use a snapshot on profile '"+sd.getUrl()+"' as "+role+" before it is generated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isBaseResource(List<TypeRefComponent> types) {
|
private boolean isBaseResource(List<TypeRefComponent> types) {
|
||||||
if (types.isEmpty())
|
if (types.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
@ -2566,7 +2578,7 @@ public class ProfileUtilities extends TranslatingUtilities {
|
||||||
String url = u.getValue();
|
String url = u.getValue();
|
||||||
boolean tgtOk = !td.hasTargetProfile() || td.hasTargetProfile(url);
|
boolean tgtOk = !td.hasTargetProfile() || td.hasTargetProfile(url);
|
||||||
while (url != null && !tgtOk) {
|
while (url != null && !tgtOk) {
|
||||||
StructureDefinition sd = context.fetchResource(StructureDefinition.class, url);
|
StructureDefinition sd = context.fetchRawProfile(url);
|
||||||
if (sd == null) {
|
if (sd == null) {
|
||||||
if (messages != null) {
|
if (messages != null) {
|
||||||
messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.BUSINESSRULE, purl+"#"+derived.getPath(), "Connect check whether the target profile "+url+" is valid constraint on the base because it is not known", IssueSeverity.WARNING));
|
messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.BUSINESSRULE, purl+"#"+derived.getPath(), "Connect check whether the target profile "+url+" is valid constraint on the base because it is not known", IssueSeverity.WARNING));
|
||||||
|
|
|
@ -539,6 +539,7 @@ public interface IWorkerContext {
|
||||||
public void setOverrideVersionNs(String value);
|
public void setOverrideVersionNs(String value);
|
||||||
|
|
||||||
public StructureDefinition fetchTypeDefinition(String typeName);
|
public StructureDefinition fetchTypeDefinition(String typeName);
|
||||||
|
public StructureDefinition fetchRawProfile(String url);
|
||||||
|
|
||||||
public void setUcumService(UcumService ucumService);
|
public void setUcumService(UcumService ucumService);
|
||||||
|
|
||||||
|
|
|
@ -640,6 +640,12 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StructureDefinition fetchRawProfile(String uri) {
|
||||||
|
StructureDefinition r = super.fetchResource(StructureDefinition.class, uri);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateSnapshot(StructureDefinition p) throws DefinitionException, FHIRException {
|
public void generateSnapshot(StructureDefinition p) throws DefinitionException, FHIRException {
|
||||||
generateSnapshot(p, false);
|
generateSnapshot(p, false);
|
||||||
|
|
|
@ -87,6 +87,16 @@ public class PackageClientTests {
|
||||||
for (PackageInfo pi : matches) {
|
for (PackageInfo pi : matches) {
|
||||||
System.out.println(pi.toString());
|
System.out.println(pi.toString());
|
||||||
}
|
}
|
||||||
|
Assert.assertTrue(matches.size() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVersions2A() throws IOException {
|
||||||
|
PackageClient client = new PackageClient("http://local.fhir.org:960/packages");
|
||||||
|
List<PackageInfo> matches = client.getVersions("hl7.fhir.us.core");
|
||||||
|
for (PackageInfo pi : matches) {
|
||||||
|
System.out.println(pi.toString());
|
||||||
|
}
|
||||||
Assert.assertTrue(matches.size() > 0);
|
Assert.assertTrue(matches.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue