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.ncip.bo.*;
6 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
7 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
8 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
9 import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
10 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
11
12
13
14
15
16
17
18
19 public class OLELookupUserConverter {
20 final Logger LOG = Logger.getLogger(OLELookupUserConverter.class);
21
22 public String generateLookupUserResponseXml(OLELookupUser lookupUser){
23 XStream xstream = new XStream();
24 xstream.alias("lookupUser",OLELookupUser.class);
25 xstream.alias("userPrivilege",OLEUserPrivilege.class);
26 xstream.alias("hold",OLEHold.class);
27 xstream.alias("checkedOutItem",OLECheckedOutItem.class);
28 xstream.alias("fine",OLEItemFine.class);
29 xstream.alias("patronName",OlePatronNameBo.class);
30 xstream.alias("patronEmail",OlePatronEmailBo.class);
31 xstream.alias("patronAddress",OlePatronAddressBo.class);
32 xstream.alias("patronPhone", OlePatronPhoneBo.class);
33 xstream.omitField(OlePatronPhoneBo.class,"isValidPatron");
34 xstream.omitField(OLECheckedOutItems.class,"message");
35 xstream.omitField(OLEHolds.class,"message");
36 xstream.omitField(OLEItemFines.class,"message");
37 xstream.omitField(OLECheckedOutItems.class,"code");
38 xstream.omitField(OLEHolds.class,"code");
39 xstream.omitField(OLEItemFines.class,"code");
40 xstream.aliasField("userPrivileges", OLELookupUser.class, "oleUserPrivileges");
41 xstream.alias("holds",OLEHolds.class);
42 xstream.aliasField("holdsList",OLEHolds.class,"oleHoldsList");
43 xstream.alias("fines",OLEItemFines.class);
44 xstream.aliasField("finesList",OLEItemFines.class,"oleItemFineList");
45 String response =xstream.toXML(lookupUser);
46 if (LOG.isDebugEnabled())
47 LOG.debug(response);
48 return response;
49 }
50
51 public String generateLookupUserResponseXmlForSip2(OLELookupUser lookupUser){
52 XStream xstream = new XStream();
53 xstream.alias("lookupUser",OLELookupUser.class);
54 xstream.alias("userPrivilege",OLEUserPrivilege.class);
55 xstream.alias("hold",OLEHold.class);
56 xstream.alias("checkedOutItem",OLECheckedOutItem.class);
57 xstream.alias("fine",OLEItemFine.class);
58 xstream.alias("patronName",OlePatronNameBo.class);
59 xstream.alias("patronEmail",OlePatronEmailBo.class);
60 xstream.alias("patronAddress",OlePatronAddressBo.class);
61 xstream.alias("patronPhone", OlePatronPhoneBo.class);
62 xstream.omitField(OLECheckedOutItems.class,"message");
63 xstream.omitField(OLEHolds.class,"message");
64 xstream.omitField(OLEItemFines.class,"message");
65 xstream.omitField(OLECheckedOutItems.class,"code");
66 xstream.omitField(OLEHolds.class,"code");
67 xstream.omitField(OLEItemFines.class,"code");
68 xstream.aliasField("userPrivileges", OLELookupUser.class, "oleUserPrivileges");
69 xstream.alias("holds",OLEHolds.class);
70 xstream.aliasField("holdsList",OLEHolds.class,"oleHoldsList");
71 xstream.alias("fines",OLEItemFines.class);
72 xstream.aliasField("finesList",OLEItemFines.class,"oleItemFineList");
73 String response =xstream.toXML(lookupUser);
74 if (LOG.isDebugEnabled())
75 LOG.debug(response);
76 return response;
77 }
78
79
80
81 public OLELookupUser getLookupUser(String xml){
82 XStream xstream = new XStream();
83 xstream.alias("lookupUser",OLELookupUser.class);
84 xstream.alias("userPrivilege",OLEUserPrivilege.class);
85 xstream.alias("hold",OLEHold.class);
86 xstream.alias("checkedOutItem",OLECheckedOutItem.class);
87 xstream.alias("fine",OLEItemFine.class);
88 xstream.omitField(OLECheckedOutItems.class,"message");
89 xstream.omitField(OLECheckedOutItems.class,"code");
90 xstream.omitField(OLEHolds.class,"message");
91 xstream.omitField(OLEHolds.class,"code");
92 xstream.omitField(OLEItemFines.class,"message");
93 xstream.omitField(OLEItemFines.class,"code");
94 xstream.alias("patronName",OlePatronNameBo.class);
95 xstream.alias("patronEmail",OlePatronEmailBo.class);
96 xstream.alias("patronAddress",OlePatronAddressBo.class);
97 xstream.alias("patronPhone",OlePatronPhoneBo.class);
98 xstream.aliasField("userPrivileges", OLELookupUser.class, "oleUserPrivileges");
99 xstream.alias("holds",OLEHolds.class);
100 xstream.aliasField("holdsList",OLEHolds.class,"oleHoldsList");
101 xstream.alias("fines",OLEItemFines.class);
102 xstream.aliasField("finesList",OLEItemFines.class,"oleItemFineList");
103 OLELookupUser oleLookupUser =(OLELookupUser)xstream.fromXML(xml);
104 return oleLookupUser;
105 }
106
107 public String generateLookupUserJson(String xml) {
108 OLELookupUser oleLookupUser = (OLELookupUser)getLookupUser(xml);
109 OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
110 try{
111 return xmlContentHandler.marshalToJSON(oleLookupUser);
112 }catch(Exception e){
113 LOG.error(e,e);
114 }
115 return null;
116 }
117 }