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();
boolean isAllowedTypeValuesRequired();
List<String> getContextUris();
String toString();
}
public abstract static class Builder<B extends Credential> {

View File

@ -136,7 +136,7 @@ public class OB20Inspector extends VCInspector {
List<Validation> validations = assertion.getValidations();
for (Validation validation : validations) {
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);
}

View File

@ -51,7 +51,7 @@ public class JsonLDCompactionProve extends Probe<Credential> {
return success(this, ctx);
} 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;
public ContextPropertyProbe(CredentialEnum type) {
super(ID, "@context");
super(ID, type.toString(), "@context");
this.type = checkNotNull(type);
setValueValidations(this::validate);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,22 +37,22 @@ import foundation.identity.jsonld.ConfigurableDocumentLoader;
*/
public class ValidationPropertyProbe extends PropertyProbe {
protected final Validation validation;
protected final boolean fullValidate; // TODO: fullValidate
protected final boolean fullValidate;
public ValidationPropertyProbe(Validation validation) {
this(ID, validation, true);
public ValidationPropertyProbe(String credentialType, Validation validation) {
this(ID, credentialType, validation, true);
}
public ValidationPropertyProbe(String id, Validation validation) {
this(id, validation, true);
public ValidationPropertyProbe(String id, String credentialType, Validation validation) {
this(id, credentialType, validation, true);
}
public ValidationPropertyProbe(Validation validation, boolean fullValidate) {
this(ID, validation, fullValidate);
public ValidationPropertyProbe(String credentialType, Validation validation, boolean fullValidate) {
this(ID, credentialType, validation, fullValidate);
}
public ValidationPropertyProbe(String id, Validation validation, boolean fullValidate) {
super(id + "<" + validation.getName() + ">", validation.getName());
public ValidationPropertyProbe(String id, String credentialType, Validation validation, boolean fullValidate) {
super(id, credentialType, validation.getName());
this.validation = validation;
this.fullValidate = fullValidate;
setValidations(this::validate);
@ -170,7 +170,7 @@ public class ValidationPropertyProbe extends PropertyProbe {
private ReportItems validatePrerequisites(JsonNode node, RunContext ctx) {
List<ReportItems> results = validation.getPrerequisites().stream()
.map(v -> ValidationPropertyProbeFactory.of(v, validation.isFullValidate()))
.map(v -> ValidationPropertyProbeFactory.of(validation.getName(), v, validation.isFullValidate()))
.map(probe -> {
try {
return probe.run(node, ctx);
@ -186,7 +186,7 @@ public class ValidationPropertyProbe extends PropertyProbe {
private ReportItems validateExpectedTypes(JsonNode node, RunContext ctx) {
List<ReportItems> results = validation.getExpectedTypes().stream()
.flatMap(type -> type.getValidations().stream())
.map(v -> ValidationPropertyProbeFactory.of(v, validation.isFullValidate()))
.map(v -> ValidationPropertyProbeFactory.of(validation.getName(), v, validation.isFullValidate()))
.map(probe -> {
try {
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 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;
/**
@ -10,21 +12,21 @@ import org.oneedtech.inspect.vc.Validation;
* @author xaracil
*/
public class ValidationPropertyProbeFactory {
public static ValidationPropertyProbe of(Validation validation) {
return of(validation, true);
public static ValidationPropertyProbe of(String type, Validation validation) {
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());
if (validation.getType() == ValueType.RDF_TYPE) {
return new ValidationRdfTypePropertyProbe(validation, fullValidate);
return new ValidationRdfTypePropertyProbe(type, validation, fullValidate);
}
if (validation.getType() == ValueType.IMAGE) {
return new ValidationImagePropertyProbe(validation);
return new ValidationImagePropertyProbe(type, validation);
}
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
*/
public class ValidationRdfTypePropertyProbe extends ValidationPropertyProbe {
public ValidationRdfTypePropertyProbe(Validation validation) {
super(ID, validation);
public ValidationRdfTypePropertyProbe(String credentialType, Validation validation ) {
this(credentialType, validation, true);
}
public ValidationRdfTypePropertyProbe(Validation validation, boolean fullValidate) {
super(ID, validation, fullValidate);
public ValidationRdfTypePropertyProbe(String credentialType, Validation validation, boolean fullValidate) {
super(ID, credentialType, validation, fullValidate);
}
@Override