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