1 package org.kuali.ole.ingest;
2
3 import com.thoughtworks.xstream.XStream;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.ingest.pojo.*;
6 import org.kuali.ole.deliver.bo.OlePatronDocument;
7 import org.kuali.ole.deliver.bo.OlePatronDocuments;
8
9 import java.io.IOException;
10 import java.net.URISyntaxException;
11 import java.util.List;
12
13
14
15
16
17 public class OlePatronRecordHandler {
18
19 private static final Logger LOG = Logger.getLogger(OlePatronRecordHandler.class);
20
21
22
23
24
25
26
27
28
29 public OlePatronGroup buildPatronFromFileContent(String fileContent) throws URISyntaxException, IOException {
30 XStream xStream = new XStream();
31 xStream.alias("patronGroup", OlePatronGroup.class);
32 xStream.alias("patron", OlePatron.class);
33 xStream.alias("name", OleNameTypes.class);
34 xStream.alias("postalAddress", OlePatronPostalAddress.class);
35 xStream.alias("emailAddress", OlePatronEmailAddress.class);
36 xStream.alias("telephoneNumber", OlePatronTelePhoneNumber.class);
37 xStream.alias("patronLevelPolicies", OlePatronLevelPolicies.class);
38 xStream.alias("addressLine", OleAddressLine.class);
39 xStream.alias("note", OlePatronNote.class);
40 xStream.alias("affiliation", OlePatronAffiliations.class);
41 xStream.alias("employment", OlePatronEmployments.class);
42 xStream.aliasField("default", OlePatronPostalAddress.class, "defaults");
43 xStream.aliasField("default", OlePatronEmailAddress.class,"defaults");
44 xStream.aliasField("default", OlePatronTelePhoneNumber.class,"defaults");
45 xStream.addImplicitCollection(OlePatronGroup.class, "patronGroup");
46 xStream.addImplicitCollection(OlePatronPostalAddress.class, "addressLinesList",OleAddressLine.class);
47
48 xStream.registerConverter(new OlePatronAddressLineConverter());
49 Object object = xStream.fromXML(fileContent);
50 return (OlePatronGroup) object;
51 }
52
53
54
55
56
57
58
59 public String toXML(List<OlePatron> olePatrons) {
60 StringBuffer stringBuffer = new StringBuffer();
61 stringBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><patronGroup xmlns=\"http://ole.kuali.org/standards/ole-patron\">\n" );
62 stringBuffer.append("\n");
63 for(OlePatron olePatron : olePatrons){
64 XStream xStream = new XStream();
65 xStream.alias("patron", OlePatron.class);
66 xStream.alias("name", OleNameTypes.class);
67 xStream.alias("postalAddress", OlePatronPostalAddress.class);
68 xStream.alias("emailAddress", OlePatronEmailAddress.class);
69 xStream.alias("telephoneNumber", OlePatronTelePhoneNumber.class);
70 xStream.alias("patronLevelPolicies", OlePatronLevelPolicies.class);
71 xStream.alias("addressLine", OleAddressLine.class);
72 xStream.alias("note", OlePatronNote.class);
73 xStream.alias("affiliation", OlePatronAffiliations.class);
74 xStream.alias("employment", OlePatronEmployments.class);
75 xStream.aliasField("default", OlePatronPostalAddress.class,"defaults");
76 xStream.aliasField("default", OlePatronEmailAddress.class,"defaults");
77 xStream.aliasField("default", OlePatronTelePhoneNumber.class,"defaults");
78 xStream.addImplicitCollection(OlePatronGroup.class, "patronGroup");
79 xStream.addImplicitCollection(OlePatronPostalAddress.class, "addressLinesList",OleAddressLine.class);
80 xStream.registerConverter(new OlePatronAddressLineConverter());
81 String xml = xStream.toXML(olePatron);
82 xml = xml.replaceAll("<patron>","<patron xmlns=\"http://ole.kuali.org/standards/ole-patron\">");
83 stringBuffer.append(xml);
84 stringBuffer.append("\n");
85 }
86 stringBuffer.append("\n");
87 stringBuffer.append("</patronGroup>");
88
89 return stringBuffer.toString();
90 }
91
92 public String generatePatronXML(OlePatronDocuments olePatronDocuments) {
93 StringBuffer stringBuffer = new StringBuffer();
94 XStream xStream = new XStream();
95 xStream.alias("olePatronDocuments", OlePatronDocuments.class);
96 xStream.alias("olePatronDocument", OlePatronDocument.class);
97 xStream.alias("olePatronId", String.class);
98 xStream.alias("barcode",String.class);
99 xStream.alias("borrowerType", String.class);
100 xStream.alias("firstName", String.class);
101 xStream.alias("lastName", String.class);
102
103 xStream.alias("activeIndicator", Boolean.class);
104 xStream.omitField(OlePatronDocument.class, "emailAddress");
105 xStream.omitField(OlePatronDocument.class, "expirationFlag");
106 xStream.omitField(OlePatronDocument.class, "generalBlock");
107 xStream.omitField(OlePatronDocument.class, "generalBlockNotes");
108 xStream.omitField(OlePatronDocument.class, "pagingPrivilege");
109 xStream.omitField(OlePatronDocument.class, "courtesyNotice");
110 xStream.omitField(OlePatronDocument.class, "deliveryPrivilege");
111 xStream.omitField(OlePatronDocument.class, "realPatronCheck");
112 xStream.omitField(OlePatronDocument.class,"selfCheckOut");
113 xStream.omitField(OlePatronDocument.class, "expirationDate");
114 xStream.omitField(OlePatronDocument.class, "activationDate");
115 xStream.omitField(OlePatronDocument.class, "middleName");
116 xStream.omitField(OlePatronDocument.class, "phoneNumber");
117 xStream.omitField(OlePatronDocument.class, "borrowerTypeName");
118 xStream.omitField(OlePatronDocument.class, "processMessage");
119 xStream.omitField(OlePatronDocument.class, "source");
120 xStream.omitField(OlePatronDocument.class, "statisticalCategory");
121 xStream.omitField(OlePatronDocument.class, "oleSourceName");
122 xStream.omitField(OlePatronDocument.class, "oleStatisticalCategoryName");
123 xStream.omitField(OlePatronDocument.class, "patronBillFlag");
124 xStream.omitField(OlePatronDocument.class, "proxyPatronId");
125 xStream.omitField(OlePatronDocument.class, "patronPhotograph");
126 xStream.omitField(OlePatronDocument.class, "loanFlag");
127 xStream.omitField(OlePatronDocument.class, "tempCircHistoryFlag");
128 xStream.omitField(OlePatronDocument.class, "requestFlag");
129 xStream.omitField(OlePatronDocument.class, "upload");
130 xStream.omitField(OlePatronDocument.class, "oleLoanDocuments");
131 xStream.omitField(OlePatronDocument.class, "phones");
132 xStream.omitField(OlePatronDocument.class, "addresses");
133 xStream.omitField(OlePatronDocument.class, "oleEntityAddressBo");
134 xStream.omitField(OlePatronDocument.class, "name");
135 xStream.omitField(OlePatronDocument.class, "oleAddresses");
136 xStream.omitField(OlePatronDocument.class, "emails");
137 xStream.omitField(OlePatronDocument.class, "notes");
138 xStream.omitField(OlePatronDocument.class, "lostBarcodes");
139 xStream.omitField(OlePatronDocument.class, "oleBorrowerType");
140 xStream.omitField(OlePatronDocument.class, "entity");
141 xStream.omitField(OlePatronDocument.class, "sourceBo");
142 xStream.omitField(OlePatronDocument.class, "statisticalCategoryBo");
143 xStream.omitField(OlePatronDocument.class, "patronAffiliations");
144 xStream.omitField(OlePatronDocument.class, "employments");
145 xStream.omitField(OlePatronDocument.class, "oleDeliverRequestBos");
146 xStream.omitField(OlePatronDocument.class, "oleProxyPatronDocuments");
147 xStream.omitField(OlePatronDocument.class, "oleTemporaryCirculationHistoryRecords");
148 xStream.omitField(OlePatronDocument.class, "olePatronLocalIds");
149 xStream.omitField(OlePatronDocument.class, "oleProxyPatronDocumentList");
150 xStream.omitField(OlePatronDocument.class, "patronHomePage");
151 xStream.omitField(OlePatronDocument.class, "pointing");
152 xStream.omitField(OlePatronDocument.class, "startingIndexExecuted");
153 xStream.omitField(OlePatronDocument.class, "activateBarcode");
154 xStream.omitField(OlePatronDocument.class, "deactivateBarcode");
155 xStream.omitField(OlePatronDocument.class, "lostStatus");
156 xStream.omitField(OlePatronDocument.class, "lostDescription");
157 xStream.omitField(OlePatronDocument.class, "invalidateBarcode");
158 xStream.omitField(OlePatronDocument.class, "reinstateBarcode");
159 xStream.omitField(OlePatronDocument.class, "skipBarcodeValidation");
160 xStream.omitField(OlePatronDocument.class, "identityService");
161 xStream.omitField(OlePatronDocument.class, "barcodeChanged");
162 xStream.omitField(OlePatronDocument.class, "barcodeEditable");
163 xStream.omitField(OlePatronDocument.class, "popupDialog");
164 xStream.omitField(OlePatronDocument.class, "uiMessageType");
165 xStream.omitField(OlePatronDocument.class, "patronMessage");
166 xStream.omitField(OlePatronDocument.class, "reinstated");
167 xStream.omitField(OlePatronDocument.class, "patronBillPayments");
168 xStream.omitField(OlePatronDocument.class, "numberOfClaimsReturned");
169 xStream.omitField(OlePatronDocument.class, "olePatronEntityViewBo");
170 xStream.omitField(OlePatronDocument.class, "patronBillFileName");
171 xStream.omitField(OlePatronDocument.class, "viewBillUrl");
172 xStream.omitField(OlePatronDocument.class, "createBillUrl");
173 xStream.omitField(OlePatronDocument.class, "namePrefix");
174 xStream.omitField(OlePatronDocument.class, "nameSuffix");
175 xStream.addImplicitCollection(OlePatronDocuments.class, "olePatronDocuments");
176 xStream.omitField(OlePatronDocument.class, "deletedPhones");
177 xStream.omitField(OlePatronDocument.class, "deletedOleEntityAddressBo");
178 xStream.omitField(OlePatronDocument.class, "deletedEmails");
179 xStream.omitField(OlePatronDocument.class, "deletedNotes");
180 xStream.omitField(OlePatronDocument.class, "deletedPatronAffiliations");
181 xStream.omitField(OlePatronDocument.class, "deletedEmployments");
182 xStream.omitField(OlePatronDocument.class, "deletedOleProxyPatronDocuments");
183 xStream.omitField(OlePatronDocument.class, "deletedOlePatronLocalIds");
184 xStream.omitField(OlePatronDocument.class, "showLoanedRecords");
185 xStream.omitField(OlePatronDocument.class, "showRequestedItems");
186 xStream.omitField(OlePatronDocument.class, "showTemporaryCirculationHistoryRecords");
187 xStream.omitField(OlePatronDocument.class, "realPatronLastName");
188 xStream.omitField(OlePatronDocument.class, "realPatronFirstName");
189 xStream.omitField(OlePatronDocument.class, "errorMessage");
190 xStream.omitField(OlePatronDocument.class, "blockPatron");
191 xStream.omitField(OlePatronDocument.class, "errorsAndPermission");
192 xStream.omitField(OlePatronDocument.class, "loanCount");
193 xStream.omitField(OlePatronDocument.class, "requestedItemRecordsCount");
194 xStream.omitField(OlePatronDocument.class, "tempCirculationHistoryCount");
195 String xml = xStream.toXML(olePatronDocuments);
196 stringBuffer.append(xml);
197 stringBuffer.append("\n");
198 return stringBuffer.toString();
199 }
200 }