credentialType now is of the interface type

This commit is contained in:
Xavi Aracil 2022-11-25 12:54:17 +01:00
parent cc33dd4068
commit bf3f93e59e
3 changed files with 19 additions and 24 deletions

View File

@ -23,7 +23,7 @@ public class Assertion extends Credential {
final Assertion.Type assertionType;
protected Assertion(Resource resource, JsonNode data, String jwt, Map<String, SchemaKey> schemas) {
protected Assertion(Resource resource, JsonNode data, String jwt, Map<CredentialEnum, SchemaKey> 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<Assertion.Type, SchemaKey> schemas = new ImmutableMap.Builder<Assertion.Type, SchemaKey>()
private static final Map<CredentialEnum, SchemaKey> schemas = new ImmutableMap.Builder<CredentialEnum, SchemaKey>()
.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);
}
}

View File

@ -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<String, SchemaKey> schemas;
final Map<CredentialEnum, SchemaKey> schemas;
protected Credential(String id, Resource resource, JsonNode data, String jwt, Map<String, SchemaKey> schemas) {
protected Credential(String id, Resource resource, JsonNode data, String jwt, Map<CredentialEnum, SchemaKey> 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<String> getContext();

View File

@ -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<String, SchemaKey> schemas) {
protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map<CredentialEnum, SchemaKey> 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<VerifiableCredential.Type, SchemaKey> schemas = new ImmutableMap.Builder<VerifiableCredential.Type, SchemaKey>()
private static final Map<CredentialEnum, SchemaKey> schemas = new ImmutableMap.Builder<CredentialEnum, SchemaKey>()
.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<VerifiableCredential> {
@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);
}
}