track issues with sorting diffs into qa.html

This commit is contained in:
Grahame Grieve 2020-01-21 11:37:01 +11:00
parent 21768851f9
commit d4701a2cad
3 changed files with 30 additions and 7 deletions

View File

@ -2583,7 +2583,7 @@ public class ProfileUtilities extends TranslatingUtilities {
}
}
}
sortDifferential(base, derived, derived.getName(), new ArrayList<String>());
sortDifferential(base, derived, derived.getName(), new ArrayList<String>(), false);
}
private void closeChildren(StructureDefinition base, ElementDefinition edb, StructureDefinition derived, ElementDefinition edm) {
@ -4350,7 +4350,9 @@ public class ProfileUtilities extends TranslatingUtilities {
}
public void sortDifferential(StructureDefinition base, StructureDefinition diff, String name, List<String> errors) throws FHIRException {
public void sortDifferential(StructureDefinition base, StructureDefinition diff, String name, List<String> errors, boolean errorIfChanges) throws FHIRException {
List<ElementDefinition> original = new ArrayList<>();
original.addAll(diff.getDifferential().getElement());
final List<ElementDefinition> diffList = diff.getDifferential().getElement();
int lastCount = diffList.size();
// first, we move the differential elements into a tree
@ -4390,13 +4392,34 @@ public class ProfileUtilities extends TranslatingUtilities {
sortElements(edh, cmp, errors);
// now, we serialise them back to a list
List<ElementDefinition> newDiff = new ArrayList<>();
writeElements(edh, newDiff);
if (errorIfChanges) {
compareDiffs(original, newDiff, errors);
}
diffList.clear();
writeElements(edh, diffList);
diffList.addAll(newDiff);
if (lastCount != diffList.size())
errors.add("Sort failed: counts differ; at least one of the paths in the differential is illegal");
}
private void compareDiffs(List<ElementDefinition> diffList, List<ElementDefinition> newDiff, List<String> errors) {
if (diffList.size() != newDiff.size()) {
errors.add("The diff list size changed when sorting - was "+diffList.size()+" is now "+newDiff.size());
} else {
for (int i = 0; i < Integer.min(diffList.size(), newDiff.size()); i++) {
ElementDefinition e = diffList.get(i);
ElementDefinition n = newDiff.get(i);
if (!n.getPath().equals(e.getPath())) {
errors.add("The element "+e.getPath()+" is out of order (and maybe others after it)");
return;
}
}
}
}
private int processElementsIntoTree(ElementDefinitionHolder edh, int i, List<ElementDefinition> list) {
String path = edh.getSelf().getPath();
final String prefix = path + ".";

View File

@ -662,7 +662,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
pu.setThrowException(false);
if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT) {
pu.sortDifferential(sd, p, p.getUrl(), errors);
pu.sortDifferential(sd, p, p.getUrl(), errors, true);
}
pu.setDebug(false);
for (String err : errors)

View File

@ -458,7 +458,7 @@ public class SnapShotGenerationTests {
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), null, null);
pu.setIds(test.getSource(), false);
List<String> errors = new ArrayList<String>();
pu.sortDifferential(base, test.getOutput(), test.getOutput().getUrl(), errors);
pu.sortDifferential(base, test.getOutput(), test.getOutput().getUrl(), errors, false);
if (!errors.isEmpty())
throw new FHIRException(errors.get(0));
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", test.getId()+"-expected.xml"), new FileOutputStream(TestingUtilities.tempFile("snapshot", test.getId()+"-expected.xml")));
@ -490,7 +490,7 @@ public class SnapShotGenerationTests {
if (test.isSort()) {
List<String> errors = new ArrayList<String>();
int lastCount = output.getDifferential().getElement().size();
pu.sortDifferential(base, output, test.getSource().getName(), errors);
pu.sortDifferential(base, output, test.getSource().getName(), errors, false);
if (errors.size() > 0)
throw new FHIRException("Sort failed: "+errors.toString());
}
@ -537,7 +537,7 @@ public class SnapShotGenerationTests {
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), messages , new TestPKP());
pu.setNewSlicingProcessing(true);
List<String> errors = new ArrayList<String>();
pu.sortDifferential(base, sd, url, errors);
pu.sortDifferential(base, sd, url, errors, false);
if (!errors.isEmpty())
throw new FHIRException(errors.get(0));
pu.setIds(sd, false);