1515
1616import java .io .Reader ;
1717import java .net .URI ;
18- import java .util .Date ;
19- import java .util .List ;
20- import java .util .Map ;
21- import java .util .Set ;
18+ import java .util .*;
2219
2320public class VerifiableCredentialV2 extends JsonLDObject {
2421
@@ -46,17 +43,17 @@ public static class Builder<B extends Builder<B>> extends JsonLDObject.Builder<B
4643 private Date validFrom ;
4744 private Date validUntil ;
4845 private CredentialSubject credentialSubject ;
49- private Object credentialStatus ;
46+ private List < CredentialStatus > credentialStatus ;
5047 private String name ;
5148 private String description ;
52- private LdProof ldProof ;
49+ private List < LdProof > ldProof ;
5350
5451 //extensions
5552
5653 private List <CredentialSchema > credentialSchema ;
57- private Set <Evidence > evidence ;
58- private TermsOfUse termsOfUse ;
59- private RefreshService refreshService ;
54+ private List <Evidence > evidence ;
55+ private List < TermsOfUse > termsOfUse ;
56+ private List < RefreshService > refreshService ;
6057
6158 public Builder (VerifiableCredentialV2 jsonLdObject ) {
6259 super (jsonLdObject );
@@ -76,16 +73,16 @@ public VerifiableCredentialV2 build() {
7673 if (this .validFrom != null ) JsonLDUtils .jsonLdAdd (this .jsonLdObject , VerifiableCredentialKeywords .JSONLD_TERM_VALIDFROM , JsonLDUtils .dateToString (this .validFrom ));
7774 if (this .validUntil != null ) JsonLDUtils .jsonLdAdd (this .jsonLdObject , VerifiableCredentialKeywords .JSONLD_TERM_VALIDUNTIL , JsonLDUtils .dateToString (this .validUntil ));
7875 if (this .credentialSubject != null ) this .credentialSubject .addToJsonLDObject (this .jsonLdObject );
79- if (this .credentialStatus != null ) JsonLDUtils . jsonLdAdd ( this .jsonLdObject , VerifiableCredentialKeywords . JSONLD_TERM_CREDENTIALSTATUS , this .credentialStatus );
80- if (this .name != null ) JsonLDUtils .jsonLdAdd (this .jsonLdObject , VerifiableCredentialKeywords .JSONLD_TERM_NAME , this .name );
81- if (this .description != null ) JsonLDUtils .jsonLdAdd (this .jsonLdObject , VerifiableCredentialKeywords .JSONLD_TERM_NAME , this .description );
82- if (this .ldProof != null ) this .ldProof .addToJsonLDObject (this .jsonLdObject );
76+ if (this .credentialStatus != null ) this .credentialStatus . forEach ( credentialStatus -> credentialStatus . addToJsonLDObject ( this .jsonLdObject ) );
77+ if (this .name != null ) JsonLDUtils .jsonLdAdd (this .jsonLdObject , VerifiableCredentialKeywords .JSONLD_TERM_NAME , this .name );
78+ if (this .description != null ) JsonLDUtils .jsonLdAdd (this .jsonLdObject , VerifiableCredentialKeywords .JSONLD_TERM_NAME , this .description );
79+ if (this .ldProof != null ) this .ldProof .forEach ( ldProof -> ldProof . addToJsonLDObject (this .jsonLdObject ) );
8380
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 );
81+ // add extensions
82+ if (this .credentialSchema != null ) this .credentialSchema . forEach ( credentialSchema -> credentialSchema . addToJsonLDObject ( this . jsonLdObject ) );
83+ if (this .evidence != null ) this .evidence . forEach ( evidence -> evidence . addToJsonLDObject (this .jsonLdObject ) );
84+ if (this .termsOfUse != null ) this .termsOfUse . forEach ( termsOfUse -> termsOfUse . addToJsonLDObject (this .jsonLdObject ) );
85+ if (this .refreshService != null ) this .refreshService .forEach ( refreshService -> refreshService . addToJsonLDObject (this .jsonLdObject ) );
8986
9087 return (VerifiableCredentialV2 ) this .jsonLdObject ;
9188 }
@@ -116,17 +113,14 @@ public B credentialSubject(CredentialSubject credentialSubject) {
116113 }
117114
118115 public B credentialStatus (CredentialStatus credentialStatus ) {
119- this .credentialStatus = credentialStatus ;
116+ if (this .credentialStatus == null ) this .credentialStatus = new ArrayList <>();
117+ this .credentialStatus .add (credentialStatus );
120118 return (B ) this ;
121119 }
122120
123- public B credentialStatus (List <CredentialStatus > credentialStatus ) {
124- this .credentialStatus = credentialStatus ;
125- return (B ) this ;
126- }
127-
128- public B ldProof (LdProof ldProof ) {
129- this .ldProof = ldProof ;
121+ public B credentialStatus (Collection <CredentialStatus > credentialStatus ) {
122+ if (this .credentialStatus == null ) this .credentialStatus = new ArrayList <>();
123+ this .credentialStatus .addAll (credentialStatus );
130124 return (B ) this ;
131125 }
132126
@@ -140,22 +134,63 @@ public B description(String description) {
140134 return (B ) this ;
141135 }
142136
143- public B evidence (Set <Evidence > evidence ) {
144- this .evidence = evidence ;
137+ public B ldProof (LdProof ldProof ) {
138+ if (this .ldProof == null ) this .ldProof = new ArrayList <>();
139+ this .ldProof .add (ldProof );
140+ return (B ) this ;
141+ }
142+
143+ public B ldProof (Collection <LdProof > ldProof ) {
144+ if (this .ldProof == null ) this .ldProof = new ArrayList <>();
145+ this .ldProof .addAll (ldProof );
146+ return (B ) this ;
147+ }
148+
149+ public B credentialSchema (CredentialSchema credentialSchema ) {
150+ if (this .credentialSchema == null ) this .credentialSchema = new ArrayList <>();
151+ this .credentialSchema .add (credentialSchema );
145152 return (B ) this ;
146153 }
147- public B credentialSchema (List <CredentialSchema > credentialSchema ) {
148- this .credentialSchema = credentialSchema ;
154+
155+ public B credentialSchema (Collection <CredentialSchema > credentialSchema ) {
156+ if (this .credentialSchema == null ) this .credentialSchema = new ArrayList <>();
157+ this .credentialSchema .addAll (credentialSchema );
158+ return (B ) this ;
159+ }
160+
161+ public B evidence (Evidence evidence ) {
162+ if (this .evidence == null ) this .evidence = new ArrayList <>();
163+ this .evidence .add (evidence );
164+ return (B ) this ;
165+ }
166+
167+ public B evidence (Collection <Evidence > evidence ) {
168+ if (this .evidence == null ) this .evidence = new ArrayList <>();
169+ this .evidence .addAll (evidence );
149170 return (B ) this ;
150171 }
151172
152173 public B termsOfUse (TermsOfUse termsOfUse ) {
153- this .termsOfUse = termsOfUse ;
174+ if (this .termsOfUse == null ) this .termsOfUse = new ArrayList <>();
175+ this .termsOfUse .add (termsOfUse );
176+ return (B ) this ;
177+ }
178+
179+ public B termsOfUse (Collection <TermsOfUse > termsOfUse ) {
180+ if (this .termsOfUse == null ) this .termsOfUse = new ArrayList <>();
181+ this .termsOfUse .addAll (termsOfUse );
154182 return (B ) this ;
155183 }
156184
157185 public B refreshService (RefreshService refreshService ) {
158- this .refreshService = refreshService ;
186+ if (this .refreshService == null ) this .refreshService = new ArrayList <>();
187+ this .refreshService .add (refreshService );
188+ return (B ) this ;
189+ }
190+
191+ public B refreshService (Collection <RefreshService > refreshService ) {
192+ if (this .refreshService == null ) this .refreshService = new ArrayList <>();
193+ this .refreshService .addAll (refreshService );
159194 return (B ) this ;
160195 }
161196 }
@@ -190,6 +225,10 @@ public static VerifiableCredentialV2 getFromJsonLDObject(JsonLDObject jsonLdObje
190225 return JsonLDObject .getFromJsonLDObject (VerifiableCredentialV2 .class , jsonLdObject );
191226 }
192227
228+ public static List <VerifiableCredentialV2 > getFromJsonLDObjectAsList (JsonLDObject jsonLdObject ) {
229+ return JsonLDObject .getFromJsonLDObjectAsList (VerifiableCredentialV2 .class , jsonLdObject );
230+ }
231+
193232 public static void removeFromJsonLdObject (JsonLDObject jsonLdObject ) {
194233 JsonLDObject .removeFromJsonLdObject (VerifiableCredentialV2 .class , jsonLdObject );
195234 }
@@ -203,9 +242,7 @@ public Object getIssuer() {
203242 }
204243
205244 public URI getIssuerUri () {
206-
207245 Object issuer = JsonLDUtils .jsonLdGetJsonValue (this .getJsonObject (), VerifiableCredentialKeywords .JSONLD_TERM_ISSUER );
208-
209246 return (issuer instanceof String ) ? URI .create (issuer .toString ()) : URI .create ((((Map <String ,Object >)issuer ).get (VerifiableCredentialKeywords .JSONLD_TERM_ISSUER )).toString ());
210247 }
211248
@@ -221,16 +258,14 @@ public CredentialSubject getCredentialSubject() {
221258 return CredentialSubject .getFromJsonLDObject (this );
222259 }
223260
224- public LdProof getLdProof () {
225- return LdProof .getFromJsonLDObject (this );
261+ public CredentialStatus getCredentialStatus () {
262+ return CredentialStatus .getFromJsonLDObject (this );
226263 }
227264
228- //The object can be either CredentialStatus object or list of CredentialStatus objects
229- public Object getCredentialStatus () {
230- return CredentialStatus .getFromJsonLDObject (this );
265+ public List <CredentialStatus > getCredentialStatusAsList () {
266+ return CredentialStatus .getFromJsonLDObjectAsList (this );
231267 }
232268
233-
234269 public String getName (){
235270 return JsonLDUtils .jsonLdGetString (this .getJsonObject (), VerifiableCredentialKeywords .JSONLD_TERM_NAME );
236271 }
@@ -239,21 +274,43 @@ public String getDescription(){
239274 return JsonLDUtils .jsonLdGetString (this .getJsonObject (), VerifiableCredentialKeywords .JSONLD_TERM_DESCRIPTION );
240275 }
241276
242- public Set <Evidence > getEvidence () {
243- return (Set <Evidence >) JsonLDUtils .jsonLdGetJsonValue (this .getJsonObject (),VerifiableCredentialKeywords .JSONLD_TERM_EVIDENCE );
277+ public LdProof getLdProof () {
278+ return LdProof .getFromJsonLDObject (this );
279+ }
280+
281+ public List <LdProof > getLdProofAsList () {
282+ return LdProof .getFromJsonLDObjectAsList (this );
283+ }
284+
285+ public CredentialSchema getCredentialSchema () {
286+ return CredentialSchema .getFromJsonLDObject (this );
244287 }
245288
246- public List <CredentialSchema > getCredentialSchema () {
247- return (List <CredentialSchema >) JsonLDUtils .jsonLdGetJsonValue (this .getJsonObject (), VerifiableCredentialKeywords .JSONLD_TERM_CREDENTIALSCHEMA );
289+ public List <CredentialSchema > getCredentialSchemaAsList () {
290+ return CredentialSchema .getFromJsonLDObjectAsList (this );
291+ }
292+
293+ public Evidence getEvidence () {
294+ return Evidence .getFromJsonLDObject (this );
295+ }
296+
297+ public List <Evidence > getEvidenceAsList () {
298+ return Evidence .getFromJsonLDObjectAsList (this );
248299 }
249300
250301 public TermsOfUse getTermsOfUse () {
251302 return TermsOfUse .getFromJsonLDObject (this );
252303 }
253304
305+ public List <TermsOfUse > getTermsOfUseAsList () {
306+ return TermsOfUse .getFromJsonLDObjectAsList (this );
307+ }
308+
254309 public RefreshService getRefreshService () {
255310 return RefreshService .getFromJsonLDObject (this );
256311 }
257312
258-
313+ public List <RefreshService > getRefreshServiceAsList () {
314+ return RefreshService .getFromJsonLDObjectAsList (this );
315+ }
259316}
0 commit comments