use multikeymap
This commit is contained in:
parent
bbcfac14fc
commit
e574c51faf
@ -1,14 +1,18 @@
|
|||||||
package org.oneedtech.inspect.vc.probe;
|
package org.oneedtech.inspect.vc.probe;
|
||||||
|
|
||||||
|
import static org.oneedtech.inspect.vc.Credential.Type.*;
|
||||||
|
|
||||||
import static org.oneedtech.inspect.util.code.Defensives.checkNotNull;
|
import static org.oneedtech.inspect.util.code.Defensives.checkNotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.oneedtech.inspect.core.probe.Probe;
|
import org.oneedtech.inspect.core.probe.Probe;
|
||||||
import org.oneedtech.inspect.core.probe.RunContext;
|
import org.oneedtech.inspect.core.probe.RunContext;
|
||||||
import org.oneedtech.inspect.core.report.ReportItems;
|
import org.oneedtech.inspect.core.report.ReportItems;
|
||||||
import org.oneedtech.inspect.vc.Credential;
|
import org.oneedtech.inspect.vc.Credential;
|
||||||
|
|
||||||
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@ -33,31 +37,33 @@ public class ContextPropertyProbe extends Probe<JsonNode> {
|
|||||||
|
|
||||||
ArrayNode contextNode = (ArrayNode) root.get("@context");
|
ArrayNode contextNode = (ArrayNode) root.get("@context");
|
||||||
if (contextNode == null) {
|
if (contextNode == null) {
|
||||||
return fatal("No @context property", ctx);
|
return fatal("No @context property", ctx);
|
||||||
}
|
|
||||||
|
|
||||||
List<String> expected = values.get(type);
|
|
||||||
if(expected == null) {
|
|
||||||
return fatal(type.name() + " not recognized", ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> expected = values.get(values.keySet()
|
||||||
|
.stream()
|
||||||
|
.filter(s->s.contains(type))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(()-> new IllegalArgumentException(type.name() + " not recognized")));
|
||||||
|
|
||||||
List<String> given = JsonNodeUtil.asStringList(contextNode);
|
List<String> given = JsonNodeUtil.asStringList(contextNode);
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for(String uri : expected) {
|
for (String uri : expected) {
|
||||||
if((given.size() < pos+1) || !given.get(pos).equals(uri)) {
|
if ((given.size() < pos + 1) || !given.get(pos).equals(uri)) {
|
||||||
return error("missing required @context uri " + uri + " at position " + (pos+1), ctx);
|
return error("missing required @context uri " + uri + " at position " + (pos + 1), ctx);
|
||||||
}
|
}
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return success(ctx);
|
return success(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Map<Credential.Type, List<String>> values = new ImmutableMap.Builder<Credential.Type, List<String>>()
|
private final static Map<Set<Credential.Type>, List<String>> values = new ImmutableMap.Builder<Set<Credential.Type>, List<String>>()
|
||||||
.put(Credential.Type.OpenBadgeCredential,
|
.put(Set.of(OpenBadgeCredential, AchievementCredential, EndorsementCredential),
|
||||||
List.of("https://www.w3.org/2018/credentials/v1",
|
List.of("https://www.w3.org/2018/credentials/v1",
|
||||||
"https://imsglobal.github.io/openbadges-specification/context.json")) //TODO will change (https://purl.imsglobal.org/spec/ob/v3p0/context/ob_v3p0.jsonld)
|
"https://imsglobal.github.io/openbadges-specification/context.json")) // TODO will change
|
||||||
.build();
|
// (https://purl.imsglobal.org/spec/ob/v3p0/context/ob_v3p0.jsonld)
|
||||||
|
.build();
|
||||||
|
|
||||||
public static final String ID = ContextPropertyProbe.class.getSimpleName();
|
public static final String ID = ContextPropertyProbe.class.getSimpleName();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user