Use JsonNodeUtils to manage array nodes
This commit is contained in:
parent
543a2c5bdb
commit
40b34cce13
@ -7,6 +7,7 @@ import java.util.stream.Collectors;
|
|||||||
import org.oneedtech.inspect.schema.Catalog;
|
import org.oneedtech.inspect.schema.Catalog;
|
||||||
import org.oneedtech.inspect.schema.SchemaKey;
|
import org.oneedtech.inspect.schema.SchemaKey;
|
||||||
import org.oneedtech.inspect.util.resource.Resource;
|
import org.oneedtech.inspect.util.resource.Resource;
|
||||||
|
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
@ -69,9 +70,11 @@ public class Assertion extends Credential {
|
|||||||
|
|
||||||
public static Assertion.Type valueOf (JsonNode typeNode) {
|
public static Assertion.Type valueOf (JsonNode typeNode) {
|
||||||
if(typeNode != null) {
|
if(typeNode != null) {
|
||||||
String value = typeNode.asText();
|
List<String> values = JsonNodeUtil.asStringList(typeNode);
|
||||||
|
for (String value : values) {
|
||||||
if(value.equals("Assertion")) {
|
if(value.equals("Assertion")) {
|
||||||
return Assertion;
|
return Assertion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Unknown;
|
return Unknown;
|
||||||
|
@ -5,7 +5,6 @@ import static org.oneedtech.inspect.vc.VerifiableCredential.Type.ClrCredential;
|
|||||||
import static org.oneedtech.inspect.vc.VerifiableCredential.Type.EndorsementCredential;
|
import static org.oneedtech.inspect.vc.VerifiableCredential.Type.EndorsementCredential;
|
||||||
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.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -14,9 +13,9 @@ import java.util.stream.Collectors;
|
|||||||
import org.oneedtech.inspect.schema.Catalog;
|
import org.oneedtech.inspect.schema.Catalog;
|
||||||
import org.oneedtech.inspect.schema.SchemaKey;
|
import org.oneedtech.inspect.schema.SchemaKey;
|
||||||
import org.oneedtech.inspect.util.resource.Resource;
|
import org.oneedtech.inspect.util.resource.Resource;
|
||||||
|
import org.oneedtech.inspect.vc.util.JsonNodeUtil;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ public class VerifiableCredential extends Credential {
|
|||||||
protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map<String, SchemaKey> schemas) {
|
protected VerifiableCredential(Resource resource, JsonNode data, String jwt, Map<String, SchemaKey> schemas) {
|
||||||
super(ID, resource, data, jwt, schemas);
|
super(ID, resource, data, jwt, schemas);
|
||||||
|
|
||||||
ArrayNode typeNode = (ArrayNode)jsonData.get("type");
|
JsonNode typeNode = jsonData.get("type");
|
||||||
this.credentialType = VerifiableCredential.Type.valueOf(typeNode);
|
this.credentialType = VerifiableCredential.Type.valueOf(typeNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,11 +81,10 @@ public class VerifiableCredential extends Credential {
|
|||||||
VerifiableCredential, //this is an underspecifier in our context
|
VerifiableCredential, //this is an underspecifier in our context
|
||||||
Unknown;
|
Unknown;
|
||||||
|
|
||||||
public static VerifiableCredential.Type valueOf (ArrayNode typeArray) {
|
public static VerifiableCredential.Type valueOf (JsonNode typeNode) {
|
||||||
if(typeArray != null) {
|
if(typeNode != null) {
|
||||||
Iterator<JsonNode> iter = typeArray.iterator();
|
List<String> values = JsonNodeUtil.asStringList(typeNode);
|
||||||
while(iter.hasNext()) {
|
for (String value : values) {
|
||||||
String value = iter.next().asText();
|
|
||||||
if(value.equals("AchievementCredential") || value.equals("OpenBadgeCredential")) {
|
if(value.equals("AchievementCredential") || value.equals("OpenBadgeCredential")) {
|
||||||
return AchievementCredential;
|
return AchievementCredential;
|
||||||
} else if(value.equals("ClrCredential")) {
|
} else if(value.equals("ClrCredential")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user