Added new method for getting context uris
This commit is contained in:
parent
677caf6f21
commit
579e19a929
@ -1,6 +1,6 @@
|
|||||||
package org.oneedtech.inspect.vc;
|
package org.oneedtech.inspect.vc;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -9,7 +9,6 @@ import org.oneedtech.inspect.schema.SchemaKey;
|
|||||||
import org.oneedtech.inspect.util.resource.Resource;
|
import org.oneedtech.inspect.util.resource.Resource;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
@ -34,6 +33,11 @@ public class Assertion extends Credential {
|
|||||||
return assertionType.toString();
|
return assertionType.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getContext() {
|
||||||
|
return List.of("https://w3id.org/openbadges/v2");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MoreObjects.toStringHelper(this)
|
return MoreObjects.toStringHelper(this)
|
||||||
|
@ -59,6 +59,8 @@ public abstract class Credential extends GeneratedObject {
|
|||||||
|
|
||||||
public abstract String getCredentialType();
|
public abstract String getCredentialType();
|
||||||
|
|
||||||
|
public abstract List<String> getContext();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MoreObjects.toStringHelper(this)
|
return MoreObjects.toStringHelper(this)
|
||||||
|
@ -6,7 +6,9 @@ import static org.oneedtech.inspect.vc.VerifiableCredential.Type.EndorsementCred
|
|||||||
import static org.oneedtech.inspect.vc.VerifiableCredential.Type.VerifiablePresentation;
|
import static org.oneedtech.inspect.vc.VerifiableCredential.Type.VerifiablePresentation;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.oneedtech.inspect.schema.Catalog;
|
import org.oneedtech.inspect.schema.Catalog;
|
||||||
@ -37,6 +39,15 @@ public class VerifiableCredential extends Credential {
|
|||||||
return credentialType.toString();
|
return credentialType.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getContext() {
|
||||||
|
return values.get(values.keySet()
|
||||||
|
.stream()
|
||||||
|
.filter(s->s.contains(credentialType))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(()-> new IllegalArgumentException(credentialType.name() + " not recognized")));
|
||||||
|
}
|
||||||
|
|
||||||
public ProofType getProofType() {
|
public ProofType getProofType() {
|
||||||
return jwt == null ? ProofType.EMBEDDED : ProofType.EXTERNAL;
|
return jwt == null ? ProofType.EMBEDDED : ProofType.EXTERNAL;
|
||||||
}
|
}
|
||||||
@ -48,6 +59,19 @@ public class VerifiableCredential extends Credential {
|
|||||||
.put(EndorsementCredential, Catalog.OB_30_ENDORSEMENTCREDENTIAL_JSON)
|
.put(EndorsementCredential, Catalog.OB_30_ENDORSEMENTCREDENTIAL_JSON)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
private static final Map<Set<VerifiableCredential.Type>, List<String>> values = new ImmutableMap.Builder<Set<VerifiableCredential.Type>, List<String>>()
|
||||||
|
.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
|
||||||
|
"https://purl.imsglobal.org/spec/ob/v3p0/context.json"))
|
||||||
|
.put(Set.of(ClrCredential),
|
||||||
|
List.of("https://www.w3.org/2018/credentials/v1",
|
||||||
|
// "https://dc.imsglobal.org/draft/clr/v2p0/context", //dev legacy
|
||||||
|
// "https://purl.imsglobal.org/spec/ob/v3p0/context.json")) //dev legacy
|
||||||
|
"https://purl.imsglobal.org/spec/clr/v2p0/context.json",
|
||||||
|
"https://purl.imsglobal.org/spec/ob/v3p0/context.json"))
|
||||||
|
|
||||||
|
.build();
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
AchievementCredential,
|
AchievementCredential,
|
||||||
@ -104,5 +128,4 @@ public class VerifiableCredential extends Credential {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final String ID = VerifiableCredential.class.getCanonicalName();
|
public static final String ID = VerifiableCredential.class.getCanonicalName();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user