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 3ba06f8..cfa452e 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 @@ -23,7 +23,7 @@ public class Assertion extends Credential { final Assertion.Type assertionType; - protected Assertion(Resource resource, JsonNode data, String jwt, Map schemas) { + protected Assertion(Resource resource, JsonNode data, String jwt, Map schemas) { super(ID, resource, data, jwt, schemas); JsonNode typeNode = jsonData.get("type"); @@ -31,8 +31,8 @@ public class Assertion extends Credential { } @Override - public String getCredentialType() { - return assertionType.toString(); + public CredentialEnum getCredentialType() { + return assertionType; } @Override @@ -48,7 +48,7 @@ public class Assertion extends Credential { .toString(); } - private static final Map schemas = new ImmutableMap.Builder() + private static final Map schemas = new ImmutableMap.Builder() .put(Type.Assertion, Catalog.OB_21_ASSERTION_JSON) .build(); @@ -58,10 +58,7 @@ public class Assertion extends Credential { public Assertion build() { // transform key of schemas map to string because the type of the key in the base map is generic // and our specific key is an Enum - return new Assertion(getResource(), getJsonData(), getJwt(), - schemas.entrySet().stream().collect(Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue()))); + return new Assertion(getResource(), getJsonData(), getJwt(), schemas); } } 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 e180ef5..7600c6d 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 @@ -1,7 +1,11 @@ package org.oneedtech.inspect.vc; -import static org.oneedtech.inspect.util.code.Defensives.*; -import static org.oneedtech.inspect.util.resource.ResourceType.*; +import static org.oneedtech.inspect.util.code.Defensives.checkNotNull; +import static org.oneedtech.inspect.util.code.Defensives.checkTrue; +import static org.oneedtech.inspect.util.resource.ResourceType.JSON; +import static org.oneedtech.inspect.util.resource.ResourceType.JWT; +import static org.oneedtech.inspect.util.resource.ResourceType.PNG; +import static org.oneedtech.inspect.util.resource.ResourceType.SVG; import java.util.List; import java.util.Map; @@ -13,7 +17,6 @@ import org.oneedtech.inspect.util.resource.Resource; import org.oneedtech.inspect.util.resource.ResourceType; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; import com.google.common.base.MoreObjects; @@ -26,9 +29,9 @@ public abstract class Credential extends GeneratedObject { final Resource resource; final JsonNode jsonData; final String jwt; - final Map schemas; + final Map schemas; - protected Credential(String id, Resource resource, JsonNode data, String jwt, Map schemas) { + protected Credential(String id, Resource resource, JsonNode data, String jwt, Map schemas) { super(id, GeneratedObject.Type.INTERNAL); this.resource = checkNotNull(resource); this.jsonData = checkNotNull(data); @@ -57,7 +60,7 @@ public abstract class Credential extends GeneratedObject { return Optional.ofNullable(schemas.get(getCredentialType())); } - public abstract String getCredentialType(); + public abstract CredentialEnum getCredentialType(); public abstract List getContext(); 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 c892844..ba1d045 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 @@ -28,15 +28,15 @@ import com.google.common.collect.ImmutableMap; public class VerifiableCredential extends Credential { final VerifiableCredential.Type credentialType; - protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map schemas) { + protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map schemas) { super(ID, resource, data, jwt, schemas); JsonNode typeNode = jsonData.get("type"); this.credentialType = VerifiableCredential.Type.valueOf(typeNode); } - public String getCredentialType() { - return credentialType.toString(); + public CredentialEnum getCredentialType() { + return credentialType; } @Override @@ -52,7 +52,7 @@ public class VerifiableCredential extends Credential { return jwt == null ? ProofType.EMBEDDED : ProofType.EXTERNAL; } - private static final Map schemas = new ImmutableMap.Builder() + private static final Map schemas = new ImmutableMap.Builder() .put(AchievementCredential, Catalog.OB_30_ACHIEVEMENTCREDENTIAL_JSON) .put(ClrCredential, Catalog.CLR_20_CLRCREDENTIAL_JSON) .put(VerifiablePresentation, Catalog.CLR_20_CLRCREDENTIAL_JSON) @@ -133,12 +133,7 @@ public class VerifiableCredential extends Credential { public static class Builder extends Credential.Builder { @Override public VerifiableCredential build() { - // transform key of schemas map to string because the type of the key in the base map is generic - // and our specific key is an Enum - return new VerifiableCredential(getResource(), getJsonData(), getJwt(), - schemas.entrySet().stream().collect(Collectors.toMap( - entry -> entry.getKey().toString(), - entry -> entry.getValue()))); + return new VerifiableCredential(getResource(), getJsonData(), getJwt(), schemas); } }