Skip to content

Commit d76a0a0

Browse files
committed
feat: Add support for BitstringStatusList
1 parent b01f5fe commit d76a0a0

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
package com.danubetech.verifiablecredentials.credentialstatus;
2+
3+
import com.apicatalog.jsonld.loader.DocumentLoader;
4+
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
5+
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
6+
import com.fasterxml.jackson.annotation.JsonCreator;
7+
import foundation.identity.jsonld.JsonLDObject;
8+
import foundation.identity.jsonld.JsonLDUtils;
9+
10+
import java.io.Reader;
11+
import java.net.URI;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
public class BitstringStatusListEntry extends CredentialStatus {
16+
17+
public static final URI[] DEFAULT_JSONLD_CONTEXTS = { VerifiableCredentialContexts.JSONLD_CONTEXT_W3C_CREDENTIALS_V2 };
18+
public static final String[] DEFAULT_JSONLD_TYPES = { VerifiableCredentialKeywords.JSONLD_TERM_BITSTRING_STATUS_LIST_ENTRY };
19+
public static final String DEFAULT_JSONLD_PREDICATE = VerifiableCredentialKeywords.JSONLD_TERM_CREDENTIALSTATUS;
20+
public static final DocumentLoader DEFAULT_DOCUMENT_LOADER = VerifiableCredentialContexts.DOCUMENT_LOADER;
21+
22+
@JsonCreator
23+
public BitstringStatusListEntry() {
24+
super();
25+
}
26+
27+
protected BitstringStatusListEntry(Map<String, Object> jsonObject) {
28+
super(jsonObject);
29+
}
30+
31+
/*
32+
* Factory methods
33+
*/
34+
35+
public static class Builder<B extends BitstringStatusListEntry.Builder<B>> extends CredentialStatus.Builder<B> {
36+
37+
private String statusListIndex;
38+
private URI statusListCredential;
39+
private String statusPurpose;
40+
private Integer statusSize = 1;
41+
private List<StatusMessage> statusMessage;
42+
private URI statusReference;
43+
44+
45+
46+
public Builder(BitstringStatusListEntry jsonLdObject) {
47+
super(jsonLdObject);
48+
this.defaultTypes(true);
49+
}
50+
51+
@Override
52+
public BitstringStatusListEntry build() {
53+
54+
super.build();
55+
56+
// add JSON-LD properties
57+
if (this.statusListIndex != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_STATUSLISTINDEX, this.statusListIndex);
58+
if (this.statusListCredential != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_STATUSLISTCREDENTIAL, JsonLDUtils.uriToString(this.statusListCredential));
59+
if (this.statusPurpose != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_STATUSPURPOSE, this.statusPurpose);
60+
if (this.statusSize != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_STATUSSIZE, this.statusSize);
61+
if (this.statusMessage != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_STATUSMESSAGE, this.statusMessage);
62+
if (this.statusReference != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_STATUSREFERENCE, JsonLDUtils.uriToString(this.statusReference));
63+
64+
return (BitstringStatusListEntry) this.jsonLdObject;
65+
}
66+
67+
public B statusListIndex(String statusListIndex) {
68+
this.statusListIndex = statusListIndex;
69+
return (B) this;
70+
}
71+
72+
public B statusListCredential(URI statusListCredential) {
73+
this.statusListCredential = statusListCredential;
74+
return (B) this;
75+
}
76+
77+
public B statusPurpose(String statusPurpose) {
78+
this.statusPurpose = statusPurpose;
79+
return (B) this;
80+
}
81+
82+
public B statusSize(Integer statusSize) {
83+
this.statusSize = statusSize;
84+
return (B) this;
85+
}
86+
87+
public B statusMessage(List<StatusMessage> statusMessage) {
88+
this.statusMessage = statusMessage;
89+
return (B) this;
90+
}
91+
public B statusReference(URI statusReference) {
92+
this.statusReference = statusReference;
93+
return (B) this;
94+
}
95+
}
96+
97+
public static Builder<? extends Builder<?>> builder() {
98+
return new Builder<>(new BitstringStatusListEntry());
99+
}
100+
101+
public static BitstringStatusListEntry fromJsonObject(Map<String, Object> jsonObject) {
102+
return new BitstringStatusListEntry(jsonObject);
103+
}
104+
105+
public static BitstringStatusListEntry fromJsonLDObject(JsonLDObject jsonLDObject) { return fromJsonObject(jsonLDObject.getJsonObject()); }
106+
107+
public static BitstringStatusListEntry fromJson(Reader reader) {
108+
return new BitstringStatusListEntry(readJson(reader));
109+
}
110+
111+
public static BitstringStatusListEntry fromJson(String json) {
112+
return new BitstringStatusListEntry(readJson(json));
113+
}
114+
115+
/*
116+
* Adding, getting, and removing the JSON-LD object
117+
*/
118+
119+
public static BitstringStatusListEntry getFromJsonLDObject(JsonLDObject jsonLdObject) {
120+
return JsonLDObject.getFromJsonLDObject(BitstringStatusListEntry.class, jsonLdObject);
121+
}
122+
123+
public static void removeFromJsonLdObject(JsonLDObject jsonLdObject) {
124+
JsonLDObject.removeFromJsonLdObject(BitstringStatusListEntry.class, jsonLdObject);
125+
}
126+
127+
/*
128+
* Getters
129+
*/
130+
131+
public String getStatusListIndex() {
132+
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_STATUSLISTINDEX);
133+
}
134+
135+
public URI getStatusListCredential() {
136+
return JsonLDUtils.stringToUri(JsonLDUtils.jsonLdGetString(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_STATUSLISTCREDENTIAL));
137+
}
138+
139+
public String getStatusPurpose(){
140+
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_STATUSPURPOSE);
141+
}
142+
143+
public String getStatusSize() {
144+
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_STATUSSIZE);
145+
}
146+
public List<Object> getStatusMessage() {
147+
return JsonLDUtils.jsonLdGetJsonArray(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_STATUSMESSAGE);
148+
}
149+
150+
public URI getStatusReference() {
151+
return JsonLDUtils.stringToUri(JsonLDUtils.jsonLdGetString(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_STATUSREFERENCE));
152+
}
153+
154+
public static class StatusMessage{
155+
private String status;
156+
private String message;
157+
158+
public StatusMessage(String status, String message) {
159+
this.status = status;
160+
this.message = message;
161+
}
162+
163+
public StatusMessage() {
164+
}
165+
166+
public String getStatus() {
167+
return status;
168+
}
169+
170+
public void setStatus(String status) {
171+
this.status = status;
172+
}
173+
174+
public String getMessage() {
175+
return message;
176+
}
177+
178+
public void setMessage(String message) {
179+
this.message = message;
180+
}
181+
}
182+
}

src/main/java/com/danubetech/verifiablecredentials/jsonld/VerifiableCredentialKeywords.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public class VerifiableCredentialKeywords {
4444
public static final String JSONLD_TERM_STATUSLISTCREDENTIAL = "statusListCredential";
4545
public static final String JSONLD_TERM_STATUSPURPOSE = "statusPurpose";
4646

47+
public static final String JSONLD_TERM_BITSTRING_STATUS_LIST_ENTRY = "BitstringStatusListEntry";
48+
public static final String JSONLD_TERM_STATUSSIZE = "statusSize";
49+
public static final String JSONLD_TERM_STATUSMESSAGE = "statusMessage";
50+
public static final String JSONLD_TERM_STATUSREFERENCE = "statusReference";
4751
/*
4852
* https://www.w3.org/ns/credentials/v2
4953
*/

0 commit comments

Comments
 (0)