1 package org.kuali.ole.systemintegration.rest.service;
2
3 import com.thoughtworks.xstream.XStream;
4 import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
5 import org.kuali.ole.docstore.common.document.content.instance.*;
6
7 import org.kuali.ole.systemintegration.rest.bo.*;
8
9
10
11
12
13
14
15
16
17 public class InstanceXmlConverterService {
18
19
20
21
22
23
24 public String generateInstanceCollectionsXml(InstanceCollection instanceCollection) {
25 XStream stream = new XStream();
26 stream = generateInstanceCollectionXml(stream);
27 String xml = stream.toXML(instanceCollection);
28 xml = xml.replace("<string>", "");
29 xml = xml.replace("</string>", "");
30 String output = xml.replace("<ole:instanceCollection>", "<ole:instanceCollection xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
31 " xsi:schemaLocation=\"http://ole.kuali.org/standards/ole-instance instance9.1.1-circulation.xsd\"\n" +
32 " xmlns:circ=\"http://ole.kuali.org/standards/ole-instance-circulation\"\n" +
33 " xmlns:ole=\"http://ole.kuali.org/standards/ole-instance\">");
34 return output;
35 }
36
37
38
39
40
41 public String generateInstanceCollectionsJSON(InstanceCollection instanceCollection) {
42 XStream stream = new XStream(new JettisonMappedXmlDriver());
43 stream.autodetectAnnotations(true);
44 stream.processAnnotations(InstanceCollection.class);
45 stream.setMode(XStream.NO_REFERENCES);
46 stream = generateInstanceCollectionXml(stream);
47
48 String jsonContent = stream.toXML(instanceCollection);
49 return jsonContent;
50
51 }
52
53
54
55
56
57 private XStream generateLocationXml(XStream xstream) {
58 xstream.alias("ole:location", Location.class);
59 xstream.aliasField("ole:primary", Location.class, "primary");
60 xstream.aliasField("ole:status", Location.class, "status");
61 xstream.aliasField("circ:locationLevel", Location.class, "locationLevel");
62 xstream = generateLocationLevelXml(xstream);
63 return xstream;
64 }
65
66
67
68
69
70 private XStream generateLocationLevelXml(XStream xstream) {
71 xstream.alias("circ:locationLevel", LocationLevel.class);
72 xstream.aliasField("ole:name", LocationLevel.class, "name");
73 xstream.aliasField("ole:level", LocationLevel.class, "level");
74 xstream.aliasField("circ:locationLevel", LocationLevel.class, "locationLevel");
75 return xstream;
76 }
77
78
79
80
81
82 private XStream generateNoteXml(XStream xstream) {
83 xstream.alias("ole:note", Note.class);
84 xstream.aliasField("ole:value", Note.class, "value");
85
86 return xstream;
87 }
88
89
90
91
92
93 private XStream generateUriXml(XStream xstream) {
94 xstream.alias("ole:uri", Uri.class);
95 xstream.aliasField("ole:value", Uri.class, "value");
96 xstream.aliasField("ole:resolvable", Uri.class, "resolvable");
97 return xstream;
98 }
99
100
101
102
103
104 private XStream generateHighDensityStorageXml(XStream xstream) {
105 xstream.alias("ole:highDensityStorage", HighDensityStorage.class);
106 xstream.aliasField("ole:row", HighDensityStorage.class, "row");
107 xstream.omitField(HighDensityStorage.class, "module");
108 xstream.omitField(HighDensityStorage.class, "shelf");
109 xstream.omitField(HighDensityStorage.class, "tray");
110 xstream.aliasField("ole:module", HighDensityStorage.class, "module");
111 xstream.aliasField("ole:shelf", HighDensityStorage.class, "shelf");
112 xstream.aliasField("ole:tray", HighDensityStorage.class, "tray");
113 return xstream;
114 }
115
116
117
118
119
120 private XStream generateItemTypeXml(XStream xstream) {
121 xstream.alias("ole:itemType", ItemType.class);
122 xstream.aliasField("ole:codeValue", ItemType.class, "codeValue");
123 xstream.omitField(ItemType.class, "fullValue");
124 xstream.aliasField("ole:fullValue", ItemType.class, "fullValue");
125 xstream.aliasField("ole:typeOrSource", ItemType.class, "typeOrSource");
126 xstream = generateTypeOrSourceXml(xstream);
127 return xstream;
128 }
129
130
131
132
133
134 private XStream generateTypeOrSourceXml(XStream xstream) {
135 xstream.alias("typeOrSource", TypeOrSource.class);
136 xstream.aliasField("ole:pointer", TypeOrSource.class, "pointer");
137 xstream.aliasField("ole:text", TypeOrSource.class, "text");
138 return xstream;
139 }
140
141
142
143
144
145 private XStream generateStatisticalSearchingCodeXml(XStream xstream) {
146 xstream.alias("ole:statisticalSearchingCode", StatisticalSearchingCode.class);
147 xstream.aliasField("ole:codeValue", StatisticalSearchingCode.class, "codeValue");
148 xstream.aliasField("ole:fullValue", StatisticalSearchingCode.class, "fullValue");
149 xstream.aliasField("ole:typeOrSource", StatisticalSearchingCode.class, "typeOrSource");
150 return xstream;
151 }
152
153
154
155
156
157 private XStream generateIdentifierXml(XStream xstream) {
158 xstream.alias("ole:identifier", Identifier.class);
159 xstream.aliasField("ole:identifierValue", Identifier.class, "identifierValue");
160 xstream.aliasField("ole:source", Identifier.class, "source");
161 return xstream;
162 }
163
164
165
166
167
168 private XStream generateAccessInformationXml(XStream xstream) {
169 xstream.alias("ole:accessInformation", AccessInformation.class);
170 xstream.aliasField("ole:barcode", AccessInformation.class, "barcode");
171 xstream.aliasField("ole:uri", AccessInformation.class, "uri");
172 xstream = generateUriXml(xstream);
173 return xstream;
174 }
175
176
177
178
179
180 private XStream generateSourceHoldingsXml(XStream xstream) {
181 xstream.alias("ole:sourceHoldings", SourceHoldings.class);
182 xstream.aliasField("ole:holdingsIdentifier", SourceHoldings.class, "holdingsIdentifier");
183 xstream.aliasField("ole:name", SourceHoldings.class, "name");
184
185 xstream.aliasField("ole:primary", SourceHoldings.class, "primary");
186 xstream.aliasField("ole:extension", SourceHoldings.class, "extension");
187 xstream.aliasField("ole:holdings", SourceHoldings.class, "holdings");
188 return xstream;
189 }
190
191
192
193
194
195 private XStream generateShelvingOrderXml(XStream xstream) {
196 xstream.alias("ole:shelvingOrder", ShelvingOrder.class);
197 xstream.aliasField("ole:codeValue", ShelvingOrder.class, "codeValue");
198 xstream.aliasField("ole:fullValue", ShelvingOrder.class, "fullValue");
199 xstream.aliasField("ole:typeOrSource", ShelvingOrder.class, "typeOrSource");
200 xstream.omitField(ShelvingOrder.class, "fullValue");
201 xstream.omitField(ShelvingOrder.class, "typeOrSource");
202 return xstream;
203 }
204
205
206
207
208
209 private XStream generateShelvingSchemeXml(XStream xstream) {
210 xstream.alias("ole:shelvingScheme", ShelvingScheme.class);
211 xstream.aliasField("ole:codeValue", ShelvingScheme.class, "codeValue");
212 xstream.aliasField("ole:fullValue", ShelvingScheme.class, "fullValue");
213 xstream.aliasField("ole:typeOrSource", ShelvingScheme.class, "typeOrSource");
214 xstream.omitField(ShelvingScheme.class, "fullValue");
215 xstream.omitField(ShelvingScheme.class, "typeOrSource");
216 return xstream;
217 }
218
219
220
221
222
223 private XStream generateCallNumberXml(XStream xstream) {
224 xstream.alias("ole:callNumber", CallNumber.class);
225 xstream.aliasField("ole:type", CallNumber.class, "type");
226 xstream.aliasField("ole:prefix", CallNumber.class, "prefix");
227 xstream.aliasField("ole:number", CallNumber.class, "number");
228 xstream.aliasField("ole:classificationPart", CallNumber.class, "classificationPart");
229 xstream.aliasField("ole:itemPart", CallNumber.class, "itemPart");
230 xstream.omitField(CallNumber.class, "classificationPart");
231 xstream.omitField(CallNumber.class, "itemPart");
232 xstream.aliasField("ole:shelvingScheme", CallNumber.class, "shelvingScheme");
233 xstream.aliasField("ole:shelvingOrder", CallNumber.class, "shelvingOrder");
234 xstream = generateShelvingOrderXml(xstream);
235 xstream = generateShelvingSchemeXml(xstream);
236 return xstream;
237 }
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274 private XStream generateExtentOfOwnershipXml(XStream xstream) {
275 xstream.alias("ole:extentOfOwnership", ExtentOfOwnership.class);
276 xstream.aliasField("ole:textualHoldings", ExtentOfOwnership.class, "textualHoldings");
277 xstream.aliasField("ole:type", ExtentOfOwnership.class, "type");
278 xstream.aliasField("ole:notes", ExtentOfOwnership.class, "note");
279 xstream.aliasAttribute(Note.class, "type", "type");
280 xstream.addImplicitCollection(ExtentOfOwnership.class, "note", Note.class);
281 xstream = generateNoteXml(xstream);
282 return xstream;
283 }
284
285
286
287
288
289 private XStream generateFormerIdentifierXml(XStream xstream) {
290 xstream.alias("ole:formerIdentifier", FormerIdentifier.class);
291 xstream.aliasField("ole:identifierType", FormerIdentifier.class, "identifierType");
292 xstream.aliasField("ole:identifier", FormerIdentifier.class, "identifier");
293 xstream = generateIdentifierXml(xstream);
294 return xstream;
295 }
296
297
298
299
300
301 private XStream generateOleHoldingsXml(XStream xstream) {
302 xstream.alias("ole:oleHoldings", OleHoldings.class);
303 xstream.aliasField("ole:holdingsIdentifier", OleHoldings.class, "holdingsIdentifier");
304 xstream.aliasField("ole:receiptStatus", OleHoldings.class, "receiptStatus");
305
306 xstream.addImplicitCollection(OleHoldings.class, "extentOfOwnership", ExtentOfOwnership.class);
307 xstream.addImplicitCollection(OleHoldings.class, "uri", Uri.class);
308 xstream.addImplicitCollection(OleHoldings.class, "note", Note.class);
309 xstream.aliasField("ole:extension", OleHoldings.class, "extension");
310 xstream.aliasField("ole:callNumber", OleHoldings.class, "callNumber");
311 xstream.aliasField("ole:location", OleHoldings.class, "location");
312 xstream = generateLocationXml(xstream);
313 xstream = generateExtentOfOwnershipXml(xstream);
314 xstream = generateHoldingsSerialReceivingXml(xstream);
315 return xstream;
316 }
317
318
319
320
321
322 private XStream generateItemXml(XStream xstream) {
323 xstream.alias("ole:item", Item.class);
324 xstream.aliasField("ole:itemIdentifier", Item.class, "itemIdentifier");
325 xstream.aliasField("ole:purchaseOrderLineItemIdentifier", Item.class, "purchaseOrderLineItemIdentifier");
326 xstream.aliasField("ole:vendorLineItemIdentifier", Item.class, "vendorLineItemIdentifier");
327 xstream.aliasField("ole:accessInformation", Item.class, "accessInformation");
328
329 xstream = generateAccessInformationXml(xstream);
330 xstream.aliasField("circ:itemType", Item.class, "itemType");
331 xstream = generateItemTypeXml(xstream);
332 xstream.aliasField("ole:location", Item.class, "location");
333 xstream = generateLocationXml(xstream);
334 xstream.aliasField("ole:note", Item.class, "note");
335 xstream = generateNoteXml(xstream);
336 xstream.aliasField("ole:highDensityStorage", Item.class, "highDensityStorage");
337 xstream = generateHighDensityStorageXml(xstream);
338 xstream.aliasField("circ:temporaryItemType", Item.class, "temporaryItemType");
339 xstream = generateItemTypeXml(xstream);
340 xstream.aliasField("ole:callNumber", Item.class, "callNumber");
341 xstream = generateCallNumberXml(xstream);
342 xstream.aliasField("ole:extension", Item.class, "extension");
343
344 xstream = generateStatisticalSearchingCodeXml(xstream);
345
346 xstream.aliasField("ole:additionalAttributes", Item.class, "content");
347 xstream.aliasField("ole:barcodeARSL", Item.class, "barcodeARSL");
348 xstream.aliasField("ole:copyNumber", Item.class, "copyNumber");
349 xstream.aliasField("ole:copyNumberLabel", Item.class, "copyNumberLabel");
350 xstream.aliasField("ole:volumeNumber", Item.class, "volumeNumber");
351 xstream.aliasField("ole:volumeNumberLabel", Item.class, "volumeNumberLabel");
352 xstream.aliasField("ole:enumeration", Item.class, "enumeration");
353 xstream.aliasField("ole:chronology", Item.class, "chronology");
354 xstream.aliasField("ole:fund", Item.class, "fund");
355 xstream.aliasField("ole:donorPublicDisplay", Item.class, "donorPublicDisplay");
356 xstream.aliasField("ole:donorNote", Item.class, "donorNote");
357 xstream.aliasField("ole:price", Item.class, "price");
358 xstream.aliasField("ole:numberOfPieces", Item.class, "numberOfPieces");
359 xstream.aliasField("circ:itemStatus", Item.class, "itemStatus");
360 xstream.aliasField("ole:itemStatusEffectiveDate", Item.class, "itemStatusEffectiveDate");
361 xstream.aliasField("ole:checkinNote", Item.class, "checkinNote");
362 xstream.aliasField("ole:staffOnlyFlag", Item.class, "staffOnlyFlag");
363 xstream.aliasField("ole:fastAddFlag", Item.class, "fastAddFlag");
364 xstream.omitField(Item.class, "analytic");
365 xstream.omitField(Item.class, "resourceIdentifier");
366 xstream.aliasField("ole:analytic", Item.class, "analytic");
367 xstream.aliasField("ole:resourceIdentifier", Item.class, "resourceIdentifier");
368 xstream.aliasField("ole:formerIdentifiers", Item.class, "formerIdentifier");
369 xstream.aliasField("ole:statisticalSearchingCodes", Item.class, "statisticalSearchingCode");
370 xstream.addImplicitCollection(Item.class, "formerIdentifier", FormerIdentifier.class);
371 xstream.addImplicitCollection(Item.class, "statisticalSearchingCode", StatisticalSearchingCode.class);
372 return xstream;
373 }
374
375
376
377
378
379 public XStream generateItemsXml(XStream xstream) {
380 xstream.alias("ole:items", Items.class);
381 xstream.aliasField("ole:items", Items.class, "item");
382 xstream = generateItemXml(xstream);
383 xstream.addImplicitCollection(Items.class, "item", Item.class);
384 return xstream;
385 }
386
387
388
389
390
391 public XStream generateInstanceXml(XStream xstream) {
392 xstream.alias("ole:instance", Instance.class);
393 xstream.aliasField("ole:instanceIdentifier", Instance.class, "instanceIdentifier");
394 xstream.aliasField("ole:resourceIdentifier", Instance.class, "resourceIdentifier");
395 xstream.aliasField("ole:oleHoldings", Instance.class, "oleHoldings");
396 xstream.aliasAttribute(OleHoldings.class, "primary", "primary");
397 xstream.aliasField("ole:sourceHoldings", Instance.class, "sourceHoldings");
398 xstream.aliasField("ole:items", Instance.class, "items");
399 xstream.aliasField("ole:extension", Instance.class, "extension");
400 xstream.omitField(Instance.class, "extension");
401 xstream.omitField(Instance.class, "formerResourceIdentifier");
402 xstream.aliasField("ole:formerResourceIdentifiers", Instance.class, "formerResourceIdentifier");
403 xstream = generateItemsXml(xstream);
404 xstream = generateFormerIdentifierXml(xstream);
405 xstream = generateOleHoldingsXml(xstream);
406 xstream = generateSourceHoldingsXml(xstream);
407 xstream.addImplicitCollection(Instance.class, "formerResourceIdentifier", FormerIdentifier.class);
408 return xstream;
409 }
410
411
412
413
414
415 public XStream generateInstanceCollectionXml(XStream xstream) {
416 xstream.alias("ole:instanceCollection", InstanceCollection.class);
417 xstream.aliasField("ole:instances", Instance.class, "instance");
418 xstream.addImplicitCollection(InstanceCollection.class, "instance", Instance.class);
419 xstream = generateInstanceXml(xstream);
420 return xstream;
421 }
422
423
424
425
426
427 private XStream generateHoldingsSerialReceivingXml(XStream xstream) {
428
429 xstream.alias("ole:HoldingsSerialReceiving", HoldingsSerialReceiving.class);
430 xstream.aliasField("ole:serialReceiving", HoldingsSerialReceiving.class, "oleSerialReceiving");
431 xstream.aliasField("ole:callNumber", SerialReceiving.class, "callNumber");
432 xstream.aliasField("ole:unboundLocation", SerialReceiving.class, "unboundLocation");
433 xstream.aliasField("ole:mains", HoldingsSerialHistory.class, "oleSerialReceivingMainList");
434 xstream.aliasField("ole:indexs", HoldingsSerialHistory.class, "oleSerialReceivingIndexList");
435 xstream.aliasField("ole:supplementaries", HoldingsSerialHistory.class, "oleSerialReceivingSupplementList");
436 xstream.aliasField("ole:serialReceivingHistory", SerialReceiving.class, "oleHoldingsSerialHistory");
437 xstream.alias("ole:main", SerialReceivingMain.class);
438 xstream.alias("ole:index", SerialReceivingIndex.class);
439 xstream.alias("ole:supplementary",SerialReceivingSupplement.class);
440 xstream.alias("ole:serialReceivingHistory",HoldingsSerialHistory.class);
441 xstream.aliasField("ole:enumerationCaption",SerialReceivingMain.class, "enumerationCaption");
442 xstream.aliasField("ole:chronologyCaption", SerialReceivingMain.class, "chronologyCaption");
443 xstream.aliasField("ole:publicReceiptNote", SerialReceivingMain.class, "publicReceiptNote");
444 xstream.aliasField("ole:enumerationCaption",SerialReceivingIndex.class, "enumerationCaption");
445 xstream.aliasField("ole:chronologyCaption", SerialReceivingIndex.class, "chronologyCaption");
446 xstream.aliasField("ole:publicReceiptNote", SerialReceivingIndex.class, "publicReceiptNote");
447 xstream.aliasField("ole:enumerationCaption",SerialReceivingSupplement.class, "enumerationCaption");
448 xstream.aliasField("ole:chronologyCaption", SerialReceivingSupplement.class, "chronologyCaption");
449 xstream.aliasField("ole:publicReceiptNote", SerialReceivingSupplement.class, "publicReceiptNote");
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474 return xstream;
475 }
476
477
478 }