labelingsystem-server  Version 0.1.0.0
ValidateJSONObject Class Reference

Static Public Member Functions

static void validateAgent (String json) throws ParseException, ValidateJSONObjectException
 
static void validateVocabulary (String json) throws ParseException, ValidateJSONObjectException
 
static void validateLabel (String json) throws ParseException, ValidateJSONObjectException
 

Member Function Documentation

◆ validateAgent()

static void validateAgent ( String  json) throws ParseException, ValidateJSONObjectException
static
10  {
11  JSONObject jsonObject = (JSONObject) new JSONParser().parse(json);
12  // MENDATORY KEYS
13  if (!jsonObject.containsKey("id")) {
14  throw new ValidateJSONObjectException("id missing");
15  }
16  if (!jsonObject.containsKey("firstName")) {
17  throw new ValidateJSONObjectException("firstName missing");
18  }
19  if (!jsonObject.containsKey("lastName")) {
20  throw new ValidateJSONObjectException("lastName missing");
21  }
22  if (!jsonObject.containsKey("orcid")) {
23  throw new ValidateJSONObjectException("orcid missing");
24  }
25  if (!jsonObject.containsKey("affiliation")) {
26  throw new ValidateJSONObjectException("affiliation missing");
27  }
28  // GET UNSUPPORTED KEYS
29  // MENDATORY
30  if (jsonObject.containsKey("id")) {
31  jsonObject.remove("id");
32  }
33  if (jsonObject.containsKey("firstName")) {
34  jsonObject.remove("firstName");
35  }
36  if (jsonObject.containsKey("lastName")) {
37  jsonObject.remove("lastName");
38  }
39  if (jsonObject.containsKey("orcid")) {
40  jsonObject.remove("orcid");
41  }
42  if (jsonObject.containsKey("affiliation")) {
43  jsonObject.remove("affiliation");
44  }
45  // OPTIONAL
46  if (jsonObject.containsKey("title")) {
47  jsonObject.remove("title");
48  }
49  if (jsonObject.containsKey("pwd")) {
50  jsonObject.remove("pwd");
51  }
52  if (jsonObject.containsKey("status")) {
53  jsonObject.remove("status");
54  }
55  if (jsonObject.containsKey("role")) {
56  jsonObject.remove("role");
57  }
58  if (!jsonObject.isEmpty()) {
59  throw new ValidateJSONObjectException("found unsupported key");
60  }
61  }

Referenced by AgentsResource.postAgent(), and AgentsResource.updateAgent().

◆ validateLabel()

static void validateLabel ( String  json) throws ParseException, ValidateJSONObjectException
static
125  {
126  JSONObject jsonObject = (JSONObject) new JSONParser().parse(json);
127  // MENDATORY KEYS
128  if (!jsonObject.containsKey("creator")) {
129  throw new ValidateJSONObjectException("creator missing");
130  }
131  if (!jsonObject.containsKey("vocabID")) {
132  throw new ValidateJSONObjectException("vocabID missing");
133  }
134  if (!jsonObject.containsKey("thumbnail")) {
135  throw new ValidateJSONObjectException("thumbnail missing");
136  }
137  if (!jsonObject.containsKey("language")) {
138  throw new ValidateJSONObjectException("language missing");
139  }
140  // GET UNSUPPORTED KEYS
141  // MENDATORY
142  if (jsonObject.containsKey("id")) {
143  jsonObject.remove("id");
144  }
145  if (jsonObject.containsKey("creator")) {
146  jsonObject.remove("creator");
147  }
148  if (jsonObject.containsKey("vocabID")) {
149  jsonObject.remove("vocabID");
150  }
151  if (jsonObject.containsKey("thumbnail")) {
152  jsonObject.remove("thumbnail");
153  }
154  if (jsonObject.containsKey("language")) {
155  jsonObject.remove("language");
156  }
157  if (jsonObject.containsKey("license")) {
158  jsonObject.remove("license");
159  }
160  // OPTIONAL
161  if (jsonObject.containsKey("description")) {
162  jsonObject.remove("description");
163  }
164  if (jsonObject.containsKey("translations")) {
165  jsonObject.remove("translations");
166  }
167  if (jsonObject.containsKey("broader")) {
168  jsonObject.remove("broader");
169  }
170  if (jsonObject.containsKey("narrower")) {
171  jsonObject.remove("narrower");
172  }
173  if (jsonObject.containsKey("related")) {
174  jsonObject.remove("related");
175  }
176  if (jsonObject.containsKey("broadMatch")) {
177  jsonObject.remove("broadMatch");
178  }
179  if (jsonObject.containsKey("narrowMatch")) {
180  jsonObject.remove("narrowMatch");
181  }
182  if (jsonObject.containsKey("relatedMatch")) {
183  jsonObject.remove("relatedMatch");
184  }
185  if (jsonObject.containsKey("closeMatch")) {
186  jsonObject.remove("closeMatch");
187  }
188  if (jsonObject.containsKey("exactMatch")) {
189  jsonObject.remove("exactMatch");
190  }
191  if (jsonObject.containsKey("seeAlso")) {
192  jsonObject.remove("seeAlso");
193  }
194  if (jsonObject.containsKey("created")) {
195  jsonObject.remove("created");
196  }
197  if (jsonObject.containsKey("released")) {
198  jsonObject.remove("released");
199  }
200  if (jsonObject.containsKey("lastModified")) {
201  jsonObject.remove("lastModified");
202  }
203  if (jsonObject.containsKey("revisions")) {
204  jsonObject.remove("revisions");
205  }
206  if (jsonObject.containsKey("equalConcepts")) {
207  jsonObject.remove("equalConcepts");
208  }
209  if (jsonObject.containsKey("creatorInfo")) {
210  jsonObject.remove("creatorInfo");
211  }
212  if (jsonObject.containsKey("releaseType")) {
213  jsonObject.remove("releaseType");
214  }
215  if (!jsonObject.isEmpty()) {
216  throw new ValidateJSONObjectException("found unsupported key");
217  }
218  }

Referenced by LabelsResource.postLabel(), and LabelsResource.updateLabel().

◆ validateVocabulary()

static void validateVocabulary ( String  json) throws ParseException, ValidateJSONObjectException
static
63  {
64  JSONObject jsonObject = (JSONObject) new JSONParser().parse(json);
65  // MENDATORY KEYS
66  if (!jsonObject.containsKey("creator")) {
67  throw new ValidateJSONObjectException("creator missing");
68  }
69  if (!jsonObject.containsKey("title")) {
70  throw new ValidateJSONObjectException("title missing");
71  }
72  if (!jsonObject.containsKey("description")) {
73  throw new ValidateJSONObjectException("description missing");
74  }
75  if (!jsonObject.containsKey("language")) {
76  throw new ValidateJSONObjectException("language missing");
77  }
78  if (!jsonObject.containsKey("license")) {
79  throw new ValidateJSONObjectException("license missing");
80  }
81  // GET UNSUPPORTED KEYS
82  // MENDATORY
83  if (jsonObject.containsKey("id")) {
84  jsonObject.remove("id");
85  }
86  if (jsonObject.containsKey("creator")) {
87  jsonObject.remove("creator");
88  }
89  if (jsonObject.containsKey("title")) {
90  jsonObject.remove("title");
91  }
92  if (jsonObject.containsKey("description")) {
93  jsonObject.remove("description");
94  }
95  if (jsonObject.containsKey("language")) {
96  jsonObject.remove("language");
97  }
98  if (jsonObject.containsKey("license")) {
99  jsonObject.remove("license");
100  }
101  // OPTIONAL
102  if (jsonObject.containsKey("created")) {
103  jsonObject.remove("created");
104  }
105  if (jsonObject.containsKey("released")) {
106  jsonObject.remove("released");
107  }
108  if (jsonObject.containsKey("lastModified")) {
109  jsonObject.remove("lastModified");
110  }
111  if (jsonObject.containsKey("statistics")) {
112  jsonObject.remove("statistics");
113  }
114  if (jsonObject.containsKey("creatorInfo")) {
115  jsonObject.remove("creatorInfo");
116  }
117  if (jsonObject.containsKey("releaseType")) {
118  jsonObject.remove("releaseType");
119  }
120  if (!jsonObject.isEmpty()) {
121  throw new ValidateJSONObjectException("found unsupported key");
122  }
123  }

Referenced by VocabsResource.postVocabulary(), and VocabsResource.updateVocabulary().