Skip to content

Commit b8a5cf7

Browse files
committed
fix: Handle issuer and issuer object
1 parent c4c5098 commit b8a5cf7

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

src/main/java/com/danubetech/verifiablecredentials/VerifiableCredentialV2.java

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import com.apicatalog.jsonld.loader.DocumentLoader;
44
import com.danubetech.verifiablecredentials.credentialstatus.CredentialStatus;
5+
import com.danubetech.verifiablecredentials.extensions.CredentialSchema;
6+
import com.danubetech.verifiablecredentials.extensions.Evidence;
7+
import com.danubetech.verifiablecredentials.extensions.RefreshService;
8+
import com.danubetech.verifiablecredentials.extensions.TermsOfUse;
59
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
610
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
711
import com.fasterxml.jackson.annotation.JsonCreator;
@@ -14,6 +18,7 @@
1418
import java.util.Date;
1519
import java.util.List;
1620
import java.util.Map;
21+
import java.util.Set;
1722

1823
public class VerifiableCredentialV2 extends JsonLDObject {
1924

@@ -46,6 +51,13 @@ public static class Builder<B extends Builder<B>> extends JsonLDObject.Builder<B
4651
private String description;
4752
private LdProof ldProof;
4853

54+
//extensions
55+
56+
private List<CredentialSchema> credentialSchema;
57+
private Set<Evidence> evidence;
58+
private TermsOfUse termsOfUse;
59+
private RefreshService refreshService;
60+
4961
public Builder(VerifiableCredentialV2 jsonLdObject) {
5062
super(jsonLdObject);
5163
this.forceContextsArray(true);
@@ -69,6 +81,12 @@ public VerifiableCredentialV2 build() {
6981
if(this.description != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_NAME, this.description);
7082
if (this.ldProof != null) this.ldProof.addToJsonLDObject(this.jsonLdObject);
7183

84+
//add extensions
85+
if (this.credentialSchema != null) JsonLDUtils.jsonLdAddAsJsonArray(this.jsonLdObject,VerifiableCredentialKeywords.JSONLD_TERM_CREDENTIALSCHEMA, credentialSchema);
86+
if (this.termsOfUse != null) this.termsOfUse.addToJsonLDObject(this.jsonLdObject);
87+
if (this.evidence != null && !this.evidence.isEmpty()) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_EVIDENCE, this.evidence);
88+
if (this.refreshService != null) this.refreshService.addToJsonLDObject(this.jsonLdObject);
89+
7290
return (VerifiableCredentialV2) this.jsonLdObject;
7391
}
7492

@@ -77,6 +95,11 @@ public B issuer(URI issuer) {
7795
return (B) this;
7896
}
7997

98+
public B issuer(Map<String,Object> issuer) {
99+
this.issuer = issuer;
100+
return (B) this;
101+
}
102+
80103
public B validFrom(Date validFrom) {
81104
this.validFrom = validFrom;
82105
return (B) this;
@@ -116,6 +139,25 @@ public B description(String description) {
116139
this.description = description;
117140
return (B) this;
118141
}
142+
143+
public B evidence(Set<Evidence> evidence) {
144+
this.evidence = evidence;
145+
return (B) this;
146+
}
147+
public B credentialSchema(List<CredentialSchema> credentialSchema) {
148+
this.credentialSchema = credentialSchema;
149+
return (B) this;
150+
}
151+
152+
public B termsOfUse(TermsOfUse termsOfUse) {
153+
this.termsOfUse = termsOfUse;
154+
return (B) this;
155+
}
156+
157+
public B refreshService(RefreshService refreshService) {
158+
this.refreshService = refreshService;
159+
return (B) this;
160+
}
119161
}
120162

121163
public static Builder<? extends Builder<?>> builder() {
@@ -157,7 +199,14 @@ public static void removeFromJsonLdObject(JsonLDObject jsonLdObject) {
157199
*/
158200

159201
public Object getIssuer() {
160-
return JsonLDUtils.stringToUri(JsonLDUtils.jsonLdGetStringOrObjectId(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_ISSUER));
202+
return JsonLDUtils.jsonLdGetJsonValue(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_ISSUER);
203+
}
204+
205+
public URI getIssuerUri() {
206+
207+
Object issuer = JsonLDUtils.jsonLdGetJsonValue(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_ISSUER);
208+
209+
return (issuer instanceof String) ? URI.create(issuer.toString()) : URI.create((((Map<String,Object>)issuer).get(VerifiableCredentialKeywords.JSONLD_TERM_ISSUER)).toString());
161210
}
162211

163212
public Date getValidFrom() {
@@ -190,5 +239,21 @@ public String getDescription(){
190239
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_DESCRIPTION);
191240
}
192241

242+
public Set<Evidence> getEvidence() {
243+
return (Set<Evidence>) JsonLDUtils.jsonLdGetJsonValue(this.getJsonObject(),VerifiableCredentialKeywords.JSONLD_TERM_EVIDENCE);
244+
}
245+
246+
public List<CredentialSchema> getCredentialSchema() {
247+
return (List<CredentialSchema>) JsonLDUtils.jsonLdGetJsonValue(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_CREDENTIALSCHEMA);
248+
}
249+
250+
public TermsOfUse getTermsOfUse() {
251+
return TermsOfUse.getFromJsonLDObject(this);
252+
}
253+
254+
public RefreshService getRefreshService() {
255+
return RefreshService.getFromJsonLDObject(this);
256+
}
257+
193258

194259
}

0 commit comments

Comments
 (0)