|
| 1 | +package com.danubetech.verifiablecredentials.jsonld.credentialstatus; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.LinkedHashMap; |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +import com.github.jsonldjava.core.JsonLdConsts; |
| 8 | + |
| 9 | +public class RevocationQuery2020Status { |
| 10 | + |
| 11 | + public static final LinkedHashMap<String, Object> JSONLD_CONTEXT; |
| 12 | + |
| 13 | + public static final String JSONLD_TERM_CREDENTIALSTATUS = "credentialStatus"; |
| 14 | + public static final String JSONLD_TERM_TYPE = "type"; |
| 15 | + public static final String JSONLD_TERM_REVOCATIONQUERY2020STATUS = "RevocationQuery2020Status"; |
| 16 | + public static final String JSONLD_TERM_CREDENTIALREFERENCE = "credentialReference"; |
| 17 | + public static final String JSONLD_TERM_REVOCATIONSERVICE = "revocationService"; |
| 18 | + |
| 19 | + private final LinkedHashMap<String, Object> jsonLdCredentialStatusObject; |
| 20 | + |
| 21 | + static { |
| 22 | + |
| 23 | + JSONLD_CONTEXT = new LinkedHashMap<String, Object> (); |
| 24 | + JSONLD_CONTEXT.put(JSONLD_TERM_REVOCATIONQUERY2020STATUS, "https://danubetech.com/schema/2020/proofs/v1#RevocationQuery2020Status"); |
| 25 | + JSONLD_CONTEXT.put(JSONLD_TERM_CREDENTIALREFERENCE, "https://danubetech.com/schema/2020/proofs/v1#credentialReference"); |
| 26 | + JSONLD_CONTEXT.put(JSONLD_TERM_REVOCATIONSERVICE, "https://danubetech.com/schema/2020/proofs/v1#revocationService"); |
| 27 | + } |
| 28 | + |
| 29 | + protected RevocationQuery2020Status(LinkedHashMap<String, Object> jsonLdCredentialStatusObject) { |
| 30 | + |
| 31 | + this.jsonLdCredentialStatusObject = jsonLdCredentialStatusObject; |
| 32 | + } |
| 33 | + |
| 34 | + public RevocationQuery2020Status() { |
| 35 | + |
| 36 | + this.jsonLdCredentialStatusObject = new LinkedHashMap<String, Object> (); |
| 37 | + } |
| 38 | + |
| 39 | + public static RevocationQuery2020Status fromJsonLdObject(LinkedHashMap<String, Object> jsonLdCredentialStatusObject) { |
| 40 | + |
| 41 | + return new RevocationQuery2020Status(jsonLdCredentialStatusObject); |
| 42 | + } |
| 43 | + |
| 44 | + public LinkedHashMap<String, Object> getJsonLdCredentialStatusObject() { |
| 45 | + |
| 46 | + return this.jsonLdCredentialStatusObject; |
| 47 | + } |
| 48 | + |
| 49 | + @SuppressWarnings("unchecked") |
| 50 | + public static void addContextToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { |
| 51 | + |
| 52 | + Object context = jsonLdObject.get(JsonLdConsts.CONTEXT); |
| 53 | + ArrayList<Object> contexts; |
| 54 | + |
| 55 | + // add as single value |
| 56 | + |
| 57 | + if (context == null) { |
| 58 | + |
| 59 | + jsonLdObject.put(JsonLdConsts.CONTEXT, JSONLD_CONTEXT); |
| 60 | + return; |
| 61 | + } |
| 62 | + |
| 63 | + // add as array member |
| 64 | + |
| 65 | + if (context instanceof ArrayList<?>) { |
| 66 | + |
| 67 | + contexts = (ArrayList<Object>) context; |
| 68 | + } else { |
| 69 | + |
| 70 | + contexts = new ArrayList<Object> (); |
| 71 | + contexts.add(context); |
| 72 | + jsonLdObject.put(JsonLdConsts.CONTEXT, contexts); |
| 73 | + } |
| 74 | + |
| 75 | + if (! contexts.contains(JSONLD_CONTEXT)) { |
| 76 | + |
| 77 | + contexts.add(JSONLD_CONTEXT); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + public static void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject, LinkedHashMap<String, Object> jsonLdCredentialStatusObject) { |
| 82 | + |
| 83 | + Object credentialStatus = jsonLdObject.get(JSONLD_TERM_CREDENTIALSTATUS); |
| 84 | + |
| 85 | + // add as single value |
| 86 | + |
| 87 | + if (credentialStatus == null) { |
| 88 | + |
| 89 | + jsonLdObject.put(JSONLD_TERM_CREDENTIALSTATUS, jsonLdCredentialStatusObject); |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + // add as array member |
| 94 | + |
| 95 | + ArrayList<Object> proofs; |
| 96 | + |
| 97 | + if (credentialStatus instanceof ArrayList<?>) { |
| 98 | + |
| 99 | + proofs = (ArrayList<Object>) credentialStatus; |
| 100 | + } else { |
| 101 | + |
| 102 | + proofs = new ArrayList<Object> (); |
| 103 | + proofs.add(credentialStatus); |
| 104 | + jsonLdObject.put(JSONLD_TERM_CREDENTIALSTATUS, jsonLdCredentialStatusObject); |
| 105 | + } |
| 106 | + |
| 107 | + if (! proofs.contains(jsonLdCredentialStatusObject)) { |
| 108 | + |
| 109 | + proofs.add(jsonLdCredentialStatusObject); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject, boolean addContext) { |
| 114 | + |
| 115 | + if (addContext) addContextToJsonLdObject(jsonLdObject); |
| 116 | + |
| 117 | + addToJsonLdObject(jsonLdObject, this.getJsonLdCredentialStatusObject()); |
| 118 | + } |
| 119 | + |
| 120 | + public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { |
| 121 | + |
| 122 | + this.addToJsonLdObject(jsonLdObject, false); |
| 123 | + } |
| 124 | + |
| 125 | + public static void removeFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { |
| 126 | + |
| 127 | + jsonLdObject.remove(JSONLD_TERM_CREDENTIALSTATUS); |
| 128 | + } |
| 129 | + |
| 130 | + @SuppressWarnings("unchecked") |
| 131 | + public static RevocationQuery2020Status getFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { |
| 132 | + |
| 133 | + Object jsonLdProofObjectEntry = jsonLdObject.get(JSONLD_TERM_CREDENTIALSTATUS); |
| 134 | + |
| 135 | + if (jsonLdProofObjectEntry instanceof List) { |
| 136 | + |
| 137 | + List<LinkedHashMap<String, Object>> jsonLdProofObjectList = (List<LinkedHashMap<String, Object>>) jsonLdProofObjectEntry; |
| 138 | + |
| 139 | + for (LinkedHashMap<String, Object> jsonLdProofObject : jsonLdProofObjectList) { |
| 140 | + |
| 141 | + if (JSONLD_TERM_REVOCATIONQUERY2020STATUS.equals(jsonLdProofObject.get("type"))) return RevocationQuery2020Status.fromJsonLdObject(jsonLdProofObject); |
| 142 | + } |
| 143 | + } else if (jsonLdProofObjectEntry instanceof LinkedHashMap) { |
| 144 | + |
| 145 | + LinkedHashMap<String, Object> jsonLdProofObject = (LinkedHashMap<String, Object>) jsonLdProofObjectEntry; |
| 146 | + |
| 147 | + if (JSONLD_TERM_REVOCATIONQUERY2020STATUS.equals(jsonLdProofObject.get("type"))) return RevocationQuery2020Status.fromJsonLdObject(jsonLdProofObject); |
| 148 | + } |
| 149 | + |
| 150 | + return null; |
| 151 | + } |
| 152 | + |
| 153 | + public String getType() { |
| 154 | + return (String) this.jsonLdCredentialStatusObject.get(JSONLD_TERM_TYPE); |
| 155 | + } |
| 156 | + |
| 157 | + public void setType(String type) { |
| 158 | + this.jsonLdCredentialStatusObject.put(JSONLD_TERM_TYPE, type); |
| 159 | + } |
| 160 | + |
| 161 | + public String getCredentialReference() { |
| 162 | + return (String) this.jsonLdCredentialStatusObject.get(JSONLD_TERM_CREDENTIALREFERENCE); |
| 163 | + } |
| 164 | + |
| 165 | + public void setCredentialReference(String credentialReference) { |
| 166 | + this.jsonLdCredentialStatusObject.put(JSONLD_TERM_CREDENTIALREFERENCE, credentialReference); |
| 167 | + } |
| 168 | + |
| 169 | + public String getRevocationService() { |
| 170 | + return (String) this.jsonLdCredentialStatusObject.get(JSONLD_TERM_REVOCATIONSERVICE); |
| 171 | + } |
| 172 | + |
| 173 | + public void setRevocationService(String revocationService) { |
| 174 | + this.jsonLdCredentialStatusObject.put(JSONLD_TERM_REVOCATIONSERVICE, revocationService); |
| 175 | + } |
| 176 | + |
| 177 | + @Override |
| 178 | + public int hashCode() { |
| 179 | + final int prime = 31; |
| 180 | + int result = 1; |
| 181 | + result = prime * result + ((jsonLdCredentialStatusObject == null) ? 0 : jsonLdCredentialStatusObject.hashCode()); |
| 182 | + return result; |
| 183 | + } |
| 184 | + |
| 185 | + @Override |
| 186 | + public boolean equals(Object obj) { |
| 187 | + if (this == obj) |
| 188 | + return true; |
| 189 | + if (obj == null) |
| 190 | + return false; |
| 191 | + if (getClass() != obj.getClass()) |
| 192 | + return false; |
| 193 | + RevocationQuery2020Status other = (RevocationQuery2020Status) obj; |
| 194 | + if (jsonLdCredentialStatusObject == null) { |
| 195 | + if (other.jsonLdCredentialStatusObject != null) |
| 196 | + return false; |
| 197 | + } else if (!jsonLdCredentialStatusObject.equals(other.jsonLdCredentialStatusObject)) |
| 198 | + return false; |
| 199 | + return true; |
| 200 | + } |
| 201 | + |
| 202 | + @Override |
| 203 | + public String toString() { |
| 204 | + return "RevocationQuery2020Status [jsonLdObject=" + jsonLdCredentialStatusObject + "]"; |
| 205 | + } |
| 206 | +} |
0 commit comments