Two type of generic property probes, depending of the type of validations
This commit is contained in:
parent
521cce5dd4
commit
7cd9103001
@ -13,13 +13,13 @@ import org.oneedtech.inspect.vc.Credential.CredentialEnum;
|
||||
*
|
||||
* @author mgylling
|
||||
*/
|
||||
public class ContextPropertyProbe extends PropertyProbe {
|
||||
public class ContextPropertyProbe extends StringValuePropertyProbe {
|
||||
private final CredentialEnum type;
|
||||
|
||||
public ContextPropertyProbe(CredentialEnum type) {
|
||||
super(ID, "@context");
|
||||
this.type = checkNotNull(type);
|
||||
setValidations(this::validate);
|
||||
setValueValidations(this::validate);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
public class PropertyProbe extends Probe<JsonNode> {
|
||||
private final String propertyName;
|
||||
private BiFunction<List<String>, RunContext, ReportItems> validations;
|
||||
private BiFunction<JsonNode, RunContext, ReportItems> validations;
|
||||
|
||||
public PropertyProbe(String id, String propertyName) {
|
||||
super(id);
|
||||
@ -20,7 +20,7 @@ public class PropertyProbe extends Probe<JsonNode> {
|
||||
this.validations = this::defaultValidation;
|
||||
}
|
||||
|
||||
public void setValidations(BiFunction<List<String>, RunContext, ReportItems> validations) {
|
||||
public void setValidations(BiFunction<JsonNode, RunContext, ReportItems> validations) {
|
||||
this.validations = validations;
|
||||
}
|
||||
|
||||
@ -30,14 +30,16 @@ public class PropertyProbe extends Probe<JsonNode> {
|
||||
if (propertyNode == null) {
|
||||
return reportForNonExistentProperty(ctx);
|
||||
}
|
||||
|
||||
List<String> values = JsonNodeUtil.asStringList(propertyNode);
|
||||
return validations.apply(values, ctx);
|
||||
return validations.apply(propertyNode, ctx);
|
||||
}
|
||||
|
||||
protected ReportItems reportForNonExistentProperty(RunContext ctx) {
|
||||
return fatal("No " + propertyName + " property", ctx);
|
||||
}
|
||||
|
||||
private ReportItems defaultValidation(List<String> nodeValues, RunContext ctx) {
|
||||
private ReportItems defaultValidation(JsonNode node, RunContext ctx) {
|
||||
return notRun("Not additional validations run", ctx);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package org.oneedtech.inspect.vc.probe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.oneedtech.inspect.core.probe.RunContext;
|
||||
import org.oneedtech.inspect.core.report.ReportItems;
|
||||
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||
|
||||
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);
|
||||
this.valueValidations = this::defaultValidation;
|
||||
super.setValidations(this::nodeValidation);
|
||||
}
|
||||
|
||||
public void setValueValidations(BiFunction<List<String>, RunContext, ReportItems> validations) {
|
||||
this.valueValidations = validations;
|
||||
}
|
||||
|
||||
private ReportItems nodeValidation(JsonNode node, RunContext ctx) {
|
||||
List<String> values = JsonNodeUtil.asStringList(node);
|
||||
return valueValidations.apply(values, ctx);
|
||||
}
|
||||
|
||||
private ReportItems defaultValidation(List<String> nodeValues, RunContext ctx) {
|
||||
return notRun("Not additional validations run", ctx);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -14,13 +14,13 @@ import org.oneedtech.inspect.vc.Credential.CredentialEnum;
|
||||
*
|
||||
* @author mgylling
|
||||
*/
|
||||
public class TypePropertyProbe extends PropertyProbe {
|
||||
public class TypePropertyProbe extends StringValuePropertyProbe {
|
||||
private final CredentialEnum expected;
|
||||
|
||||
public TypePropertyProbe(CredentialEnum expected) {
|
||||
super(ID, "type");
|
||||
this.expected = checkNotNull(expected);
|
||||
this.setValidations(this::validate);
|
||||
this.setValueValidations(this::validate);
|
||||
}
|
||||
|
||||
public ReportItems validate(List<String> values, RunContext ctx) {
|
||||
|
Loading…
Reference in New Issue
Block a user