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