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(OLECheckedOutItems.class,"message");
34 xstream.omitField(OLEHolds.class,"message");
35 xstream.omitField(OLEItemFines.class,"message");
36 xstream.omitField(OLECheckedOutItems.class,"code");
37 xstream.omitField(OLEHolds.class,"code");
38 xstream.omitField(OLEItemFines.class,"code");
39 xstream.aliasField("userPrivileges", OLELookupUser.class, "oleUserPrivileges");
40 xstream.alias("holds",OLEHolds.class);
41 xstream.aliasField("holdsList",OLEHolds.class,"oleHoldsList");
42 xstream.alias("fines",OLEItemFines.class);
43 xstream.aliasField("finesList",OLEItemFines.class,"oleItemFineList");
44 String response =xstream.toXML(lookupUser);
45 if (LOG.isDebugEnabled())
46 LOG.debug(response);
47 return response;
48 }
49
50
51
52 public OLELookupUser getLookupUser(String xml){
53 XStream xstream = new XStream();
54 xstream.alias("lookupUser",OLELookupUser.class);
55 xstream.alias("userPrivilege",OLEUserPrivilege.class);
56 xstream.alias("hold",OLEHold.class);
57 xstream.alias("checkedOutItem",OLECheckedOutItem.class);
58 xstream.alias("fine",OLEItemFine.class);
59 xstream.omitField(OLECheckedOutItems.class,"message");
60 xstream.omitField(OLECheckedOutItems.class,"code");
61 xstream.omitField(OLEHolds.class,"message");
62 xstream.omitField(OLEHolds.class,"code");
63 xstream.omitField(OLEItemFines.class,"message");
64 xstream.omitField(OLEItemFines.class,"code");
65 xstream.alias("patronName",OlePatronNameBo.class);
66 xstream.alias("patronEmail",OlePatronEmailBo.class);
67 xstream.alias("patronAddress",OlePatronAddressBo.class);
68 xstream.alias("patronPhone",OlePatronPhoneBo.class);
69 xstream.aliasField("userPrivileges", OLELookupUser.class, "oleUserPrivileges");
70 xstream.alias("holds",OLEHolds.class);
71 xstream.aliasField("holdsList",OLEHolds.class,"oleHoldsList");
72 xstream.alias("fines",OLEItemFines.class);
73 xstream.aliasField("finesList",OLEItemFines.class,"oleItemFineList");
74 OLELookupUser oleLookupUser =(OLELookupUser)xstream.fromXML(xml);
75 return oleLookupUser;
76 }
77
78 public String generateLookupUserJson(String xml) {
79 OLELookupUser oleLookupUser = (OLELookupUser)getLookupUser(xml);
80 OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
81 try{
82 return xmlContentHandler.marshalToJSON(oleLookupUser);
83 }catch(Exception e){
84 LOG.error(e,e);
85 }
86 return null;
87 }
88 }