1 package org.kuali.ole.ncip.converter;
2
3 import com.thoughtworks.xstream.XStream;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.bo.OLERenewItem;
6 import org.kuali.ole.ncip.bo.OLERenewItemList;
7
8
9
10
11
12
13
14
15 public class OLERenewItemConverter {
16 final Logger LOG = Logger.getLogger(OLEItemFineConverter.class);
17
18 private static XStream xStream = getXstream();
19 private static XStream xStream1 = getXstream1();
20 private static XStream xStreamList = getXstreamList();
21 private static XStream xStreamList1 = getXstreamList1();
22
23 public String generateRenewItemXml(OLERenewItem olePlaceRequest) {
24 return xStream.toXML(olePlaceRequest);
25 }
26
27 public String generateRenewItemXmlForSIP2(OLERenewItem olePlaceRequest) {
28 return xStream1.toXML(olePlaceRequest);
29 }
30
31 public Object generateRenewItemObject(String xml) {
32 return xStream1.fromXML(xml);
33 }
34
35 public String generateRenewItemListXml(OLERenewItemList olePlaceRequest) {
36 return xStreamList.toXML(olePlaceRequest);
37 }
38
39 public String generateRenewItemListXmlForSip2(OLERenewItemList olePlaceRequest) {
40 return xStreamList1.toXML(olePlaceRequest);
41 }
42
43 public Object generateRenewItemListObject(String xml) {
44 return xStreamList1.fromXML(xml);
45 }
46
47 public Object generateRenewItemListObjectForSip2(String xml) {
48 return xStreamList1.fromXML(xml);
49 }
50
51 public String generateRenewItemListJson(String xml) {
52 OLERenewItemList oleRenewItemList = (OLERenewItemList) generateRenewItemListObject(xml);
53 OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
54 if (oleRenewItemList == null) {
55 oleRenewItemList = new OLERenewItemList();
56 }
57 try {
58 return xmlContentHandler.marshalToJSON(oleRenewItemList);
59 } catch (Exception e) {
60 LOG.error(e, e);
61 }
62 return null;
63 }
64 public String generateRenewItemJson(String xml) {
65 OLERenewItem oleRenewItem = (OLERenewItem) generateRenewItemObject(xml);
66 OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
67 if (oleRenewItem == null) {
68 oleRenewItem = new OLERenewItem();
69 }
70 try {
71 return xmlContentHandler.marshalToJSON(oleRenewItem);
72 } catch (Exception e) {
73 LOG.error(e, e);
74 }
75 return null;
76 }
77 private static XStream getXstreamList() {
78 XStream xStream = new XStream();
79 xStream.alias("renewItem", OLERenewItem.class);
80 xStream.alias("renewItemList", OLERenewItemList.class);
81 xStream.omitField(OLERenewItem.class, "patronBarcode");
82 xStream.omitField(OLERenewItem.class, "titleIdentifier");
83 xStream.omitField(OLERenewItem.class, "itemBarcode");
84 xStream.omitField(OLERenewItem.class, "feeAmount");
85 xStream.omitField(OLERenewItem.class, "feeType");
86 xStream.omitField(OLERenewItem.class, "mediaType");
87 xStream.omitField(OLERenewItem.class, "transactionId");
88 xStream.omitField(OLERenewItem.class, "itemProperties");
89 xStream.addImplicitCollection(OLERenewItemList.class, "renewItemList", OLERenewItem.class);
90 return xStream;
91 }
92
93 private static XStream getXstreamList1() {
94 XStream xStream = new XStream();
95 xStream.alias("renewItem", OLERenewItem.class);
96 xStream.alias("renewItemList", OLERenewItemList.class);
97 xStream.addImplicitCollection(OLERenewItemList.class, "renewItemList", OLERenewItem.class);
98 return xStream;
99 }
100
101 private static XStream getXstream() {
102 XStream xStream = new XStream();
103 xStream.alias("renewItem", OLERenewItem.class);
104 xStream.omitField(OLERenewItem.class, "patronBarcode");
105 xStream.omitField(OLERenewItem.class, "titleIdentifier");
106 xStream.omitField(OLERenewItem.class, "itemBarcode");
107 xStream.omitField(OLERenewItem.class, "feeAmount");
108 xStream.omitField(OLERenewItem.class, "feeType");
109 xStream.omitField(OLERenewItem.class, "mediaType");
110 xStream.omitField(OLERenewItem.class, "transactionId");
111 xStream.omitField(OLERenewItem.class, "itemProperties");
112 return xStream;
113 }
114
115 private static XStream getXstream1() {
116 XStream xStream = new XStream();
117 xStream.alias("renewItem", OLERenewItem.class);
118 return xStream;
119 }
120
121
122 }