SHCParser file cleanup (#640)
* Use File.createTempFile to manage SHCParser payload writing * Undo auto-reorg imports * Remove JsonTrackingParser.write
This commit is contained in:
parent
52cbe69651
commit
83b1702cc5
|
@ -97,7 +97,7 @@ public class SHCParser extends ParserBase {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
map = jwt.map;
|
map = jwt.map;
|
||||||
JsonTrackingParser.write(jwt.payload, "c:\\temp\\payload.json");
|
|
||||||
checkNamedProperties(jwt.getPayload(), prefix+"payload", "iss", "nbf", "vc");
|
checkNamedProperties(jwt.getPayload(), prefix+"payload", "iss", "nbf", "vc");
|
||||||
checkProperty(jwt.getPayload(), prefix+"payload", "iss", true, "String");
|
checkProperty(jwt.getPayload(), prefix+"payload", "iss", true, "String");
|
||||||
logError(1, 1, prefix+"JWT", IssueType.INFORMATIONAL, "The FHIR Validator does not check the JWT signature "+
|
logError(1, 1, prefix+"JWT", IssueType.INFORMATIONAL, "The FHIR Validator does not check the JWT signature "+
|
||||||
|
@ -105,43 +105,43 @@ public class SHCParser extends ParserBase {
|
||||||
checkProperty(jwt.getPayload(), prefix+"payload", "nbf", true, "Number");
|
checkProperty(jwt.getPayload(), prefix+"payload", "nbf", true, "Number");
|
||||||
JsonObject vc = jwt.getPayload().getAsJsonObject("vc");
|
JsonObject vc = jwt.getPayload().getAsJsonObject("vc");
|
||||||
if (vc == null) {
|
if (vc == null) {
|
||||||
logError(1, 1, "JWT", IssueType.STRUCTURE, "Unable to find property 'vc' in the payload", IssueSeverity.ERROR);
|
logError(1, 1, "JWT", IssueType.STRUCTURE, "Unable to find property 'vc' in the payload", IssueSeverity.ERROR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
String path = prefix+"payload.vc";
|
String path = prefix+"payload.vc";
|
||||||
checkNamedProperties(vc, path, "type", "credentialSubject");
|
checkNamedProperties(vc, path, "type", "credentialSubject");
|
||||||
if (!checkProperty(vc, path, "type", true, "Array")) {
|
if (!checkProperty(vc, path, "type", true, "Array")) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
JsonArray type = vc.getAsJsonArray("type");
|
JsonArray type = vc.getAsJsonArray("type");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (JsonElement e : type) {
|
for (JsonElement e : type) {
|
||||||
if (!(e instanceof JsonPrimitive)) {
|
if (!(e instanceof JsonPrimitive)) {
|
||||||
logError(line(e), col(e), path+".type["+i+"]", IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : String but found "+JSONUtil.type(e), IssueSeverity.ERROR);
|
logError(line(e), col(e), path+".type["+i+"]", IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : String but found "+JSONUtil.type(e), IssueSeverity.ERROR);
|
||||||
} else {
|
} else {
|
||||||
types.add(e.getAsString());
|
types.add(e.getAsString());
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (!types.contains("https://smarthealth.cards#health-card")) {
|
if (!types.contains("https://smarthealth.cards#health-card")) {
|
||||||
logError(line(vc), col(vc), path, IssueType.STRUCTURE, "Card does not claim to be of type https://smarthealth.cards#health-card, cannot validate", IssueSeverity.ERROR);
|
logError(line(vc), col(vc), path, IssueType.STRUCTURE, "Card does not claim to be of type https://smarthealth.cards#health-card, cannot validate", IssueSeverity.ERROR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if (!checkProperty(vc, path, "credentialSubject", true, "Object")) {
|
if (!checkProperty(vc, path, "credentialSubject", true, "Object")) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
JsonObject cs = vc.getAsJsonObject("credentialSubject");
|
JsonObject cs = vc.getAsJsonObject("credentialSubject");
|
||||||
path = path+".credentialSubject";
|
path = path+".credentialSubject";
|
||||||
if (!checkProperty(cs, path, "fhirVersion", true, "String")) {
|
if (!checkProperty(cs, path, "fhirVersion", true, "String")) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
JsonElement fv = cs.get("fhirVersion");
|
JsonElement fv = cs.get("fhirVersion");
|
||||||
if (!VersionUtilities.versionsCompatible(context.getVersion(), fv.getAsString())) {
|
if (!VersionUtilities.versionsCompatible(context.getVersion(), fv.getAsString())) {
|
||||||
logError(line(fv), col(fv), path+".fhirVersion", IssueType.STRUCTURE, "Card claims to be of version "+fv.getAsString()+", cannot be validated against version "+context.getVersion(), IssueSeverity.ERROR);
|
logError(line(fv), col(fv), path+".fhirVersion", IssueType.STRUCTURE, "Card claims to be of version "+fv.getAsString()+", cannot be validated against version "+context.getVersion(), IssueSeverity.ERROR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if (!checkProperty(cs, path, "fhirBundle", true, "Object")) {
|
if (!checkProperty(cs, path, "fhirBundle", true, "Object")) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
// ok. all checks passed, we can now validate the bundle
|
// ok. all checks passed, we can now validate the bundle
|
||||||
Element e = jsonParser.parse(cs.getAsJsonObject("fhirBundle"), map);
|
Element e = jsonParser.parse(cs.getAsJsonObject("fhirBundle"), map);
|
||||||
|
|
Loading…
Reference in New Issue