From 256028142045dbb77205f15f1ad55b26069635e0 Mon Sep 17 00:00:00 2001 From: Xavi Aracil Date: Fri, 25 Nov 2022 13:56:19 +0100 Subject: [PATCH] Moved getContext to CredentialEnum --- .../org/oneedtech/inspect/vc/Assertion.java | 10 +++++----- .../org/oneedtech/inspect/vc/Credential.java | 3 +-- .../inspect/vc/VerifiableCredential.java | 20 +++++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java index cfa452e..5650e2f 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java @@ -35,11 +35,6 @@ public class Assertion extends Credential { return assertionType; } - @Override - public List getContext() { - return List.of("https://w3id.org/openbadges/v2"); - } - @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -97,6 +92,11 @@ public class Assertion extends Credential { public List getAllowedTypeValues() { return allowedTypeValues; } + + @Override + public List getContextUris() { + return List.of("https://w3id.org/openbadges/v2") ; + } } public static final String ID = Assertion.class.getCanonicalName(); diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java index 7600c6d..83c19b8 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java @@ -62,8 +62,6 @@ public abstract class Credential extends GeneratedObject { public abstract CredentialEnum getCredentialType(); - public abstract List getContext(); - @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -80,6 +78,7 @@ public abstract class Credential extends GeneratedObject { public interface CredentialEnum { List getRequiredTypeValues(); List getAllowedTypeValues(); + List getContextUris(); } public abstract static class Builder { diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java index ba1d045..e062432 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java @@ -39,15 +39,6 @@ public class VerifiableCredential extends Credential { return credentialType; } - @Override - public List getContext() { - return values.get(values.keySet() - .stream() - .filter(s->s.contains(credentialType)) - .findFirst() - .orElseThrow(()-> new IllegalArgumentException(credentialType.name() + " not recognized"))); - } - public ProofType getProofType() { return jwt == null ? ProofType.EMBEDDED : ProofType.EXTERNAL; } @@ -59,7 +50,7 @@ public class VerifiableCredential extends Credential { .put(EndorsementCredential, Catalog.OB_30_ENDORSEMENTCREDENTIAL_JSON) .build(); - private static final Map, List> values = new ImmutableMap.Builder, List>() + private static final Map, List> contextMap = new ImmutableMap.Builder, List>() .put(Set.of(Type.OpenBadgeCredential, AchievementCredential, EndorsementCredential), List.of("https://www.w3.org/2018/credentials/v1", //"https://purl.imsglobal.org/spec/ob/v3p0/context.json")) //dev legacy @@ -115,6 +106,15 @@ public class VerifiableCredential extends Credential { public List getAllowedTypeValues() { return allowedTypeValues; } + + @Override + public List getContextUris() { + return contextMap.get(contextMap.keySet() + .stream() + .filter(s->s.contains(this)) + .findFirst() + .orElseThrow(()-> new IllegalArgumentException(this.name() + " not recognized"))); + } } public enum ProofType {