Better report messages

This commit is contained in:
Xavi Aracil 2022-12-15 13:32:26 +01:00
parent 766228bbad
commit 682c9d9d4d
12 changed files with 41 additions and 38 deletions

View File

@ -92,6 +92,7 @@ public abstract class Credential extends GeneratedObject {
List<String> getAllowedTypeValues(); List<String> getAllowedTypeValues();
boolean isAllowedTypeValuesRequired(); boolean isAllowedTypeValuesRequired();
List<String> getContextUris(); List<String> getContextUris();
String toString();
} }
public abstract static class Builder<B extends Credential> { public abstract static class Builder<B extends Credential> {

View File

@ -136,7 +136,7 @@ public class OB20Inspector extends VCInspector {
List<Validation> validations = assertion.getValidations(); List<Validation> validations = assertion.getValidations();
for (Validation validation : validations) { for (Validation validation : validations) {
probeCount++; probeCount++;
accumulator.add(ValidationPropertyProbeFactory.of(validation).run(assertionNode, ctx)); accumulator.add(ValidationPropertyProbeFactory.of(assertion.getCredentialType().toString(), validation).run(assertionNode, ctx));
if(broken(accumulator)) return abort(ctx, accumulator, probeCount); if(broken(accumulator)) return abort(ctx, accumulator, probeCount);
} }

View File

@ -51,7 +51,7 @@ public class JsonLDCompactionProve extends Probe<Credential> {
return success(this, ctx); return success(this, ctx);
} catch (Exception e) { } catch (Exception e) {
return fatal("Error while parsing credential: " + e.getMessage(), ctx); return fatal("Error while compacting JSON-LD: " + crd.getJson() + ". Caused by: " + e.getMessage(), ctx);
} }
} }

View File

@ -19,7 +19,7 @@ public class ContextPropertyProbe extends StringValuePropertyProbe {
private final CredentialEnum type; private final CredentialEnum type;
public ContextPropertyProbe(CredentialEnum type) { public ContextPropertyProbe(CredentialEnum type) {
super(ID, "@context"); super(ID, type.toString(), "@context");
this.type = checkNotNull(type); this.type = checkNotNull(type);
setValueValidations(this::validate); setValueValidations(this::validate);
} }

View File

@ -12,8 +12,8 @@ public class PropertyProbe extends Probe<JsonNode> {
private final String propertyName; private final String propertyName;
private BiFunction<JsonNode, RunContext, ReportItems> validations; private BiFunction<JsonNode, RunContext, ReportItems> validations;
public PropertyProbe(String id, String propertyName) { public PropertyProbe(String id, String typeName, String propertyName) {
super(id); super(id, typeName, propertyName);
this.propertyName = propertyName; this.propertyName = propertyName;
this.validations = this::defaultValidation; this.validations = this::defaultValidation;
} }

View File

@ -12,8 +12,8 @@ import com.fasterxml.jackson.databind.JsonNode;
public class StringValuePropertyProbe extends PropertyProbe { public class StringValuePropertyProbe extends PropertyProbe {
private BiFunction<List<String>, RunContext, ReportItems> valueValidations; private BiFunction<List<String>, RunContext, ReportItems> valueValidations;
public StringValuePropertyProbe(String id, String propertyName) { public StringValuePropertyProbe(String id, String credentialType, String propertyName) {
super(id, propertyName); super(id, credentialType, propertyName);
this.valueValidations = this::defaultValidation; this.valueValidations = this::defaultValidation;
super.setValidations(this::nodeValidation); super.setValidations(this::nodeValidation);
} }

View File

@ -18,7 +18,7 @@ public class TypePropertyProbe extends StringValuePropertyProbe {
private final CredentialEnum expected; private final CredentialEnum expected;
public TypePropertyProbe(CredentialEnum expected) { public TypePropertyProbe(CredentialEnum expected) {
super(ID, "type"); super(ID, expected.toString(), "type");
this.expected = checkNotNull(expected); this.expected = checkNotNull(expected);
this.setValueValidations(this::validate); this.setValueValidations(this::validate);
} }

View File

@ -20,12 +20,12 @@ import com.fasterxml.jackson.databind.JsonNode;
*/ */
public class ValidationImagePropertyProbe extends ValidationPropertyProbe { public class ValidationImagePropertyProbe extends ValidationPropertyProbe {
public ValidationImagePropertyProbe(Validation validation) { public ValidationImagePropertyProbe(String credentialType, Validation validation) {
super(ID, validation); this(credentialType, validation, true);
} }
public ValidationImagePropertyProbe(Validation validation, boolean fullValidate) { public ValidationImagePropertyProbe(String credentialType, Validation validation, boolean fullValidate) {
super(ID, validation, fullValidate); super(ID, credentialType, validation, fullValidate);
} }
@Override @Override

View File

@ -16,12 +16,12 @@ import com.fasterxml.jackson.databind.JsonNode;
*/ */
public class ValidationIssuerPropertyProbe extends ValidationPropertyProbe { public class ValidationIssuerPropertyProbe extends ValidationPropertyProbe {
public ValidationIssuerPropertyProbe(Validation validation) { public ValidationIssuerPropertyProbe(String credentialType, Validation validation) {
super(ID, validation); this(credentialType, validation, true);
} }
public ValidationIssuerPropertyProbe(Validation validation, boolean fullValidate) { public ValidationIssuerPropertyProbe(String credentialType, Validation validation, boolean fullValidate) {
super(ID, validation, fullValidate); super(ID, credentialType, validation, fullValidate);
} }
@Override @Override

View File

@ -37,22 +37,22 @@ import foundation.identity.jsonld.ConfigurableDocumentLoader;
*/ */
public class ValidationPropertyProbe extends PropertyProbe { public class ValidationPropertyProbe extends PropertyProbe {
protected final Validation validation; protected final Validation validation;
protected final boolean fullValidate; // TODO: fullValidate protected final boolean fullValidate;
public ValidationPropertyProbe(Validation validation) { public ValidationPropertyProbe(String credentialType, Validation validation) {
this(ID, validation, true); this(ID, credentialType, validation, true);
} }
public ValidationPropertyProbe(String id, Validation validation) { public ValidationPropertyProbe(String id, String credentialType, Validation validation) {
this(id, validation, true); this(id, credentialType, validation, true);
} }
public ValidationPropertyProbe(Validation validation, boolean fullValidate) { public ValidationPropertyProbe(String credentialType, Validation validation, boolean fullValidate) {
this(ID, validation, fullValidate); this(ID, credentialType, validation, fullValidate);
} }
public ValidationPropertyProbe(String id, Validation validation, boolean fullValidate) { public ValidationPropertyProbe(String id, String credentialType, Validation validation, boolean fullValidate) {
super(id + "<" + validation.getName() + ">", validation.getName()); super(id, credentialType, validation.getName());
this.validation = validation; this.validation = validation;
this.fullValidate = fullValidate; this.fullValidate = fullValidate;
setValidations(this::validate); setValidations(this::validate);
@ -170,7 +170,7 @@ public class ValidationPropertyProbe extends PropertyProbe {
private ReportItems validatePrerequisites(JsonNode node, RunContext ctx) { private ReportItems validatePrerequisites(JsonNode node, RunContext ctx) {
List<ReportItems> results = validation.getPrerequisites().stream() List<ReportItems> results = validation.getPrerequisites().stream()
.map(v -> ValidationPropertyProbeFactory.of(v, validation.isFullValidate())) .map(v -> ValidationPropertyProbeFactory.of(validation.getName(), v, validation.isFullValidate()))
.map(probe -> { .map(probe -> {
try { try {
return probe.run(node, ctx); return probe.run(node, ctx);
@ -186,7 +186,7 @@ public class ValidationPropertyProbe extends PropertyProbe {
private ReportItems validateExpectedTypes(JsonNode node, RunContext ctx) { private ReportItems validateExpectedTypes(JsonNode node, RunContext ctx) {
List<ReportItems> results = validation.getExpectedTypes().stream() List<ReportItems> results = validation.getExpectedTypes().stream()
.flatMap(type -> type.getValidations().stream()) .flatMap(type -> type.getValidations().stream())
.map(v -> ValidationPropertyProbeFactory.of(v, validation.isFullValidate())) .map(v -> ValidationPropertyProbeFactory.of(validation.getName(), v, validation.isFullValidate()))
.map(probe -> { .map(probe -> {
try { try {
return probe.run(node, ctx); return probe.run(node, ctx);

View File

@ -3,6 +3,8 @@ package org.oneedtech.inspect.vc.probe.validation;
import static org.oneedtech.inspect.util.code.Defensives.checkNotNull; import static org.oneedtech.inspect.util.code.Defensives.checkNotNull;
import org.oneedtech.inspect.vc.Assertion.ValueType; import org.oneedtech.inspect.vc.Assertion.ValueType;
import org.oneedtech.inspect.vc.Credential.CredentialEnum;
import org.oneedtech.inspect.vc.Assertion;
import org.oneedtech.inspect.vc.Validation; import org.oneedtech.inspect.vc.Validation;
/** /**
@ -10,21 +12,21 @@ import org.oneedtech.inspect.vc.Validation;
* @author xaracil * @author xaracil
*/ */
public class ValidationPropertyProbeFactory { public class ValidationPropertyProbeFactory {
public static ValidationPropertyProbe of(Validation validation) { public static ValidationPropertyProbe of(String type, Validation validation) {
return of(validation, true); return of(type, validation, true);
} }
public static ValidationPropertyProbe of(Validation validation, boolean fullValidate) { public static ValidationPropertyProbe of(String type, Validation validation, boolean fullValidate) {
checkNotNull(validation.getType()); checkNotNull(validation.getType());
if (validation.getType() == ValueType.RDF_TYPE) { if (validation.getType() == ValueType.RDF_TYPE) {
return new ValidationRdfTypePropertyProbe(validation, fullValidate); return new ValidationRdfTypePropertyProbe(type, validation, fullValidate);
} }
if (validation.getType() == ValueType.IMAGE) { if (validation.getType() == ValueType.IMAGE) {
return new ValidationImagePropertyProbe(validation); return new ValidationImagePropertyProbe(type, validation);
} }
if (validation.getType() == ValueType.ISSUER) { if (validation.getType() == ValueType.ISSUER) {
return new ValidationIssuerPropertyProbe(validation); return new ValidationIssuerPropertyProbe(type, validation);
} }
return new ValidationPropertyProbe(validation, fullValidate); return new ValidationPropertyProbe(type, validation, fullValidate);
} }
} }

View File

@ -19,12 +19,12 @@ import com.fasterxml.jackson.databind.node.TextNode;
* @author xaracil * @author xaracil
*/ */
public class ValidationRdfTypePropertyProbe extends ValidationPropertyProbe { public class ValidationRdfTypePropertyProbe extends ValidationPropertyProbe {
public ValidationRdfTypePropertyProbe(Validation validation) { public ValidationRdfTypePropertyProbe(String credentialType, Validation validation ) {
super(ID, validation); this(credentialType, validation, true);
} }
public ValidationRdfTypePropertyProbe(Validation validation, boolean fullValidate) { public ValidationRdfTypePropertyProbe(String credentialType, Validation validation, boolean fullValidate) {
super(ID, validation, fullValidate); super(ID, credentialType, validation, fullValidate);
} }
@Override @Override