1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.batchingest;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.StringTokenizer;
24
25 import javax.xml.parsers.SAXParser;
26 import javax.xml.parsers.SAXParserFactory;
27
28 import org.kuali.ole.select.businessobject.BibInfoBean;
29 import org.kuali.ole.select.service.impl.OleBatchIngestServiceImpl;
30 import org.xml.sax.Attributes;
31 import org.xml.sax.SAXException;
32 import org.xml.sax.helpers.DefaultHandler;
33
34 public class MarcDataFormatTransformer {
35 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MarcDataFormatTransformer.class);
36
37 private BibInfoBean bibInfoBean;
38 StringBuilder defaultValues = null;
39 String requestorSourceType = "";
40
41 Map<String,String> deliverToName = new HashMap<String,String>();
42 Map<String, Map<String, String>> fundCodesForMarcXMLTags = new HashMap<String, Map<String, String>>();
43
44 public MarcDataFormatTransformer() {
45
46
47
48
49 deliverToName.put("JLL", "ole-jolevinson");
50 deliverToName.put("CM", "ole-mschramm");
51 deliverToName.put("AK", "ole-gkrau");
52 deliverToName.put("RB", "ole-mbelton");
53
54 HashMap<String, String> map1 = new HashMap<String, String>();
55 map1.put("2947430", "7112");
56 fundCodesForMarcXMLTags.put("43", map1);
57 HashMap<String, String> map2 = new HashMap<String, String>();
58 map2.put("2947485", "7112");
59 fundCodesForMarcXMLTags.put("13", map2);
60 HashMap<String, String> map3 = new HashMap<String, String>();
61 map3.put("2947483", "7112");
62 fundCodesForMarcXMLTags.put("74", map3);
63 HashMap<String, String> map4 = new HashMap<String, String>();
64 map4.put("2947499", "7112");
65 fundCodesForMarcXMLTags.put("98", map4);
66 HashMap<String, String> map5 = new HashMap<String, String>();
67 map5.put("2947494", "7112");
68 fundCodesForMarcXMLTags.put("65", map5);
69 HashMap<String, String> map6 = new HashMap<String, String>();
70 map6.put("2947486", "7112");
71 fundCodesForMarcXMLTags.put("19", map6);
72 HashMap<String, String> map7 = new HashMap<String, String>();
73 map7.put("2947493", "7112");
74 fundCodesForMarcXMLTags.put("64", map7);
75 HashMap<String, String> map8 = new HashMap<String, String>();
76 map8.put("2947496", "7112");
77 fundCodesForMarcXMLTags.put("93", map8);
78 HashMap<String, String> map9 = new HashMap<String, String>();
79 map9.put("2947497", "7112");
80 fundCodesForMarcXMLTags.put("94", map9);
81 HashMap<String, String> map10 = new HashMap<String, String>();
82 map10.put("2947488", "7112");
83 fundCodesForMarcXMLTags.put("35", map10);
84 HashMap<String, String> map11 = new HashMap<String, String>();
85 map11.put("2947498", "7112");
86 fundCodesForMarcXMLTags.put("95", map11);
87 HashMap<String, String> map12 = new HashMap<String, String>();
88 map12.put("2947487", "7112");
89 fundCodesForMarcXMLTags.put("21", map12);
90 HashMap<String, String> map13 = new HashMap<String, String>();
91 map13.put("2947489", "7112");
92 fundCodesForMarcXMLTags.put("37", map13);
93 HashMap<String, String> map14 = new HashMap<String, String>();
94 map14.put("2947482", "7112");
95 fundCodesForMarcXMLTags.put("27", map14);
96 HashMap<String, String> map15 = new HashMap<String, String>();
97 map15.put("2947490", "7112");
98 fundCodesForMarcXMLTags.put("50", map15);
99 HashMap<String, String> map16 = new HashMap<String, String>();
100 map16.put("2947492", "7112");
101 fundCodesForMarcXMLTags.put("53", map16);
102 HashMap<String, String> map17 = new HashMap<String, String>();
103 map17.put("2947491", "7112");
104 fundCodesForMarcXMLTags.put("51", map17);
105 HashMap<String, String> map18 = new HashMap<String, String>();
106 map18.put("2947495", "7112");
107 fundCodesForMarcXMLTags.put("86", map18);
108 }
109
110
111 public void parseDefaultValues() throws Exception{
112
113
114
115 String path = getClass().getClassLoader().getResource("KualiETLConfig.xml").toString();
116 SAXParserFactory factory = SAXParserFactory.newInstance();
117 SAXParser saxParser = factory.newSAXParser();
118 DefaultHandler handler = new DefaultHandler() {
119
120 boolean deliveryCampusCode = false;
121
122 boolean deliveryBuildingCode = false;
123 boolean deliveryBuildingLine1Address = false;
124 boolean deliveryBuildingRoomNumber = false;
125 boolean deliveryCityName = false;
126 boolean deliveryStateCode = false;
127 boolean deliveryPostalCode = false;
128 boolean deliveryCountryCode = false;
129 boolean purchaseOrderTransmissionMethodCode = false;
130 boolean purchaseOrderCostSourceCode = false;
131 boolean requestorPersonName = false;
132 boolean requestorPersonEmailAddress = false;
133 boolean requestorPersonPhoneNumber = false;
134 boolean requisitionDescription = false;
135 boolean financialYear = false;
136 boolean fundingSource = false;
137 boolean uom = false;
138 boolean chart = false;
139
140 boolean percent = false;
141 boolean chartOfAccountsCode = false;
142 boolean organizationCode = false;
143 boolean documentFundingSourceCode = false;
144 boolean useTaxIndicator = false;
145 boolean deliveryBuildingOtherIndicator = false;
146 boolean organizationAutomaticPurchaseOrderLimit = false;
147 boolean purchaseOrderAutomaticIndicator = false;
148 boolean receivingDocumentRequiredIndicator = false;
149 boolean paymentRequestPositiveApprovalIndicator = false;
150 boolean itemTypeCode = false;
151 boolean billingName = false;
152 boolean billingLine1Address = false;
153 boolean billingCityName = false;
154 boolean billingStateCode = false;
155 boolean billingPostalCode = false;
156 boolean billingCountryCode = false;
157 boolean billingPhoneNumber = false;
158 boolean vendorcustomernumber = false;
159 boolean requestorsource = false;
160
161
162
163 public void startElement(String uri, String localName, String qName,
164 Attributes attributes) throws SAXException {
165
166
167 if (qName.equalsIgnoreCase("CONFIG")) {
168 bibInfoBean = new BibInfoBean();
169 defaultValues = new StringBuilder();
170 }
171 if (qName.equalsIgnoreCase("DELIVERYCAMPUSCODE")) {
172 bibInfoBean = new BibInfoBean();
173 defaultValues = new StringBuilder();
174 deliveryCampusCode = true;
175 }
176
177
178 else if (qName.equalsIgnoreCase("DELIVERYBUILDINGCODE")) {
179 defaultValues = new StringBuilder();
180 deliveryBuildingCode = true;
181 }else if (qName.equalsIgnoreCase("DELIVERYBUILDINGLINE1ADDRESS")) {
182 defaultValues = new StringBuilder();
183 deliveryBuildingLine1Address = true;
184 }else if (qName.equalsIgnoreCase("DELIVERYBUILDINGROOMNUMBER")) {
185 defaultValues = new StringBuilder();
186 deliveryBuildingRoomNumber = true;
187 }else if (qName.equalsIgnoreCase("DELIVERYCITYNAME")) {
188 defaultValues = new StringBuilder();
189 deliveryCityName = true;
190 }else if (qName.equalsIgnoreCase("DELIVERYSTATECODE")) {
191 defaultValues = new StringBuilder();
192 deliveryStateCode = true;
193 }else if (qName.equalsIgnoreCase("DELIVERYPOSTALCODE")) {
194 defaultValues = new StringBuilder();
195 deliveryPostalCode = true;
196 }else if (qName.equalsIgnoreCase("DELIVERYCOUNTRYCODE")) {
197 defaultValues = new StringBuilder();
198 deliveryCountryCode = true;
199 }else if (qName.equalsIgnoreCase("REQUISITIONDESCRIPTION")) {
200 defaultValues = new StringBuilder();
201 requisitionDescription = true;
202 }else if (qName.equalsIgnoreCase("FINANCIALYEAR")) {
203 defaultValues = new StringBuilder();
204 financialYear = true;
205 }else if (qName.equalsIgnoreCase("FUNDINGSOURCE")) {
206 defaultValues = new StringBuilder();
207 fundingSource = true;
208 }else if (qName.equalsIgnoreCase("PURCHASEORDERTRANSMISSIONMETHODCODE")) {
209 defaultValues = new StringBuilder();
210 purchaseOrderTransmissionMethodCode = true;
211 }else if (qName.equalsIgnoreCase("PURCHASEORDERCOSTSOURCECODE")) {
212 defaultValues = new StringBuilder();
213 purchaseOrderCostSourceCode = true;
214 }else if (qName.equalsIgnoreCase("REQUESTORPERSONNAME")) {
215 defaultValues = new StringBuilder();
216 requestorPersonName = true;
217 }else if (qName.equalsIgnoreCase("REQUESTORPERSONEMAILADDRESS")) {
218 defaultValues = new StringBuilder();
219 requestorPersonEmailAddress = true;
220 }else if (qName.equalsIgnoreCase("REQUESTORPERSONPHONENUMBER")) {
221 defaultValues = new StringBuilder();
222 requestorPersonPhoneNumber = true;
223 }else if (qName.equalsIgnoreCase("UOM")) {
224 defaultValues = new StringBuilder();
225 uom = true;
226 }else if (qName.equalsIgnoreCase("CHART")) {
227 defaultValues = new StringBuilder();
228 chart = true;
229 }
230
231
232 else if (qName.equalsIgnoreCase("PERCENT")) {
233 defaultValues = new StringBuilder();
234 percent = true;
235 }else if (qName.equalsIgnoreCase("CHARTOFACCOUNTSCODE")) {
236 defaultValues = new StringBuilder();
237 chartOfAccountsCode = true;
238 }else if (qName.equalsIgnoreCase("ORGANIZATIONCODE")) {
239 defaultValues = new StringBuilder();
240 organizationCode = true;
241 }else if (qName.equalsIgnoreCase("DOCUMENTFUNDINGSOURCECODE")) {
242 defaultValues = new StringBuilder();
243 documentFundingSourceCode = true;
244 }else if (qName.equalsIgnoreCase("USETAXINDICATOR")) {
245 defaultValues = new StringBuilder();
246 useTaxIndicator = true;
247 }else if (qName.equalsIgnoreCase("DELIVERYBUILDINGOTHERINDICATOR")) {
248 defaultValues = new StringBuilder();
249 deliveryBuildingOtherIndicator = true;
250 }else if (qName.equalsIgnoreCase("ORGANIZATIONAUTOMATICPURCHASEORDERLIMIT")) {
251 defaultValues = new StringBuilder();
252 organizationAutomaticPurchaseOrderLimit = true;
253 }else if (qName.equalsIgnoreCase("PURCHASEORDERAUTOMATICINDICATOR")) {
254 defaultValues = new StringBuilder();
255 purchaseOrderAutomaticIndicator = true;
256 }else if (qName.equalsIgnoreCase("RECEIVINGDOCUMENTREQUIREDINDICATOR")) {
257 defaultValues = new StringBuilder();
258 receivingDocumentRequiredIndicator = true;
259 }else if (qName.equalsIgnoreCase("PAYMENTREQUESTPOSITIVEAPPROVALINDICATOR")) {
260 defaultValues = new StringBuilder();
261 paymentRequestPositiveApprovalIndicator = true;
262 }else if (qName.equalsIgnoreCase("ITEMTYPECODE")) {
263 defaultValues = new StringBuilder();
264 itemTypeCode = true;
265 }else if(qName.equalsIgnoreCase("BILLINGNAME")){
266 defaultValues = new StringBuilder();
267 billingName = true;
268 }else if(qName.equalsIgnoreCase("BILLINGLINE1ADDRESS")){
269 defaultValues = new StringBuilder();
270 billingLine1Address = true;
271 } else if(qName.equalsIgnoreCase("BILLINGCITYNAME")){
272 defaultValues = new StringBuilder();
273 billingCityName = true;
274 }else if(qName.equalsIgnoreCase("BILLINGSTATECODE")){
275 defaultValues = new StringBuilder();
276 billingStateCode = true;
277 }else if(qName.equalsIgnoreCase("BILLINGPOSTALCODE")){
278 defaultValues = new StringBuilder();
279 billingPostalCode = true;
280 }else if(qName.equalsIgnoreCase("BILLINGCOUNTRYCODE")){
281 defaultValues = new StringBuilder();
282 billingCountryCode = true;
283 }else if(qName.equalsIgnoreCase("BILLINGPHONENUMBER")){
284 defaultValues = new StringBuilder();
285 billingPhoneNumber = true;
286 }else if(qName.equalsIgnoreCase("VENDORCUSTOMERNUMBER")){
287 defaultValues = new StringBuilder();
288 vendorcustomernumber = true;
289 }else if(qName.equalsIgnoreCase("REQUESTORSOURCE")){
290 defaultValues = new StringBuilder();
291 requestorsource = true;
292 }
293
294 }
295
296
297 public void endElement(String uri, String localName,
298 String qName) throws SAXException {
299
300
301 if (deliveryCampusCode) {
302 bibInfoBean.setDeliveryCampusCode(defaultValues.toString());
303 defaultValues = null;
304 deliveryCampusCode = false;
305 }
306
307
308
309 else if (deliveryBuildingCode) {
310 bibInfoBean.setDeliveryBuildingCode(defaultValues.toString());
311 defaultValues = null;
312 deliveryBuildingCode = false;
313 }else if (deliveryBuildingLine1Address) {
314 bibInfoBean.setDeliveryBuildingLine1Address(defaultValues.toString());
315 defaultValues = null;
316 deliveryBuildingLine1Address = false;
317 }else if (deliveryBuildingRoomNumber) {
318 bibInfoBean.setDeliveryBuildingRoomNumber(defaultValues.toString());
319 defaultValues = null;
320 deliveryBuildingRoomNumber = false;
321 }else if (deliveryCityName) {
322 bibInfoBean.setDeliveryCityName(defaultValues.toString());
323 defaultValues = null;
324 deliveryCityName = false;
325 }else if (deliveryStateCode) {
326 bibInfoBean.setDeliveryStateCode(defaultValues.toString());
327 defaultValues = null;
328 deliveryStateCode = false;
329 }else if (deliveryPostalCode) {
330 bibInfoBean.setDeliveryPostalCode(defaultValues.toString());
331 defaultValues = null;
332 deliveryPostalCode = false;
333 }else if (deliveryCountryCode) {
334 bibInfoBean.setDeliveryCountryCode(defaultValues.toString());
335 defaultValues = null;
336 deliveryCountryCode = false;
337 }else if (purchaseOrderTransmissionMethodCode) {
338 bibInfoBean.setPurchaseOrderTransmissionMethodCode(defaultValues.toString());
339 defaultValues = null;
340 purchaseOrderTransmissionMethodCode = false;
341 }else if (purchaseOrderCostSourceCode) {
342 bibInfoBean.setPurchaseOrderCostSourceCode(defaultValues.toString());
343 defaultValues = null;
344 purchaseOrderCostSourceCode = false;
345 }else if (requestorPersonName) {
346 bibInfoBean.setRequestorPersonName(defaultValues.toString());
347 defaultValues = null;
348 requestorPersonName = false;
349 }else if (requestorPersonEmailAddress) {
350 bibInfoBean.setRequestorPersonEmailAddress(defaultValues.toString());
351 defaultValues = null;
352 requestorPersonEmailAddress = false;
353 }else if (requestorPersonPhoneNumber) {
354 bibInfoBean.setRequestorPersonPhoneNumber(defaultValues.toString());
355 defaultValues = null;
356 requestorPersonPhoneNumber = false;
357 }else if (requisitionDescription) {
358 bibInfoBean.setRequisitionDescription(defaultValues.toString());
359 defaultValues = null;
360 requisitionDescription = false;
361 }else if (financialYear) {
362 bibInfoBean.setFinantialYear(defaultValues.toString());
363 defaultValues = null;
364 financialYear = false;
365 }else if (fundingSource) {
366 bibInfoBean.setFundingSource(defaultValues.toString());
367 defaultValues = null;
368 fundingSource = false;
369 } else if (uom) {
370 bibInfoBean.setUom(defaultValues.toString());
371 defaultValues = null;
372 uom = false;
373 }else if (chart) {
374 bibInfoBean.setChart(defaultValues.toString());
375 defaultValues = null;
376 chart = false;
377 }
378
379
380
381 else if (percent) {
382 if(defaultValues.toString().length()>0){
383 bibInfoBean.setPercent(new Long(defaultValues.toString()));
384 percent = false;
385 }
386 defaultValues = null;
387 }else if (chartOfAccountsCode) {
388 bibInfoBean.setChartOfAccountsCode(defaultValues.toString());
389 defaultValues = null;
390 chartOfAccountsCode = false;
391 }else if (organizationCode) {
392 bibInfoBean.setOrganizationCode(defaultValues.toString());
393 defaultValues = null;
394 organizationCode = false;
395 }else if (documentFundingSourceCode) {
396 bibInfoBean.setDocumentFundingSourceCode(defaultValues.toString());
397 defaultValues = null;
398 documentFundingSourceCode = false;
399 }else if (useTaxIndicator) {
400 bibInfoBean.setUseTaxIndicator(defaultValues.toString().equalsIgnoreCase("TRUE") ? true : false);
401 defaultValues = null;
402 useTaxIndicator = false;
403 }else if (deliveryBuildingOtherIndicator) {
404 bibInfoBean.setDeliveryBuildingOtherIndicator(defaultValues.toString().equalsIgnoreCase("TRUE") ? true : false);
405 defaultValues = null;
406 deliveryBuildingOtherIndicator = false;
407 }else if (organizationAutomaticPurchaseOrderLimit) {
408 bibInfoBean.setOrganizationAutomaticPurchaseOrderLimit(defaultValues.toString());
409 defaultValues = null;
410 organizationAutomaticPurchaseOrderLimit = false;
411 }else if (purchaseOrderAutomaticIndicator) {
412 bibInfoBean.setPurchaseOrderAutomaticIndicator(defaultValues.toString().equalsIgnoreCase("TRUE") ? true : false);
413 defaultValues = null;
414 purchaseOrderAutomaticIndicator = false;
415 }else if (receivingDocumentRequiredIndicator) {
416 bibInfoBean.setReceivingDocumentRequiredIndicator(defaultValues.toString().equalsIgnoreCase("TRUE") ? true : false);
417 defaultValues = null;
418 receivingDocumentRequiredIndicator = false;
419 }else if (paymentRequestPositiveApprovalIndicator) {
420 bibInfoBean.setPaymentRequestPositiveApprovalIndicator(defaultValues.toString().equalsIgnoreCase("TRUE") ? true : false);
421 defaultValues = null;
422 paymentRequestPositiveApprovalIndicator = false;
423 }else if (itemTypeCode) {
424 bibInfoBean.setItemTypeCode(defaultValues.toString());
425 defaultValues = null;
426 itemTypeCode = false;
427 }else if (billingName) {
428 bibInfoBean.setBillingName(defaultValues.toString());
429 defaultValues = null;
430 billingName = false;
431 }else if (billingLine1Address) {
432 bibInfoBean.setBillingLine1Address(defaultValues.toString());
433 defaultValues = null;
434 billingLine1Address = false;
435 }else if (billingCityName) {
436 bibInfoBean.setBillingCityName(defaultValues.toString());
437 defaultValues = null;
438 billingCityName = false;
439 }else if (billingStateCode) {
440 bibInfoBean.setBillingStateCode(defaultValues.toString());
441 defaultValues = null;
442 billingStateCode = false;
443 }else if (billingPostalCode) {
444 bibInfoBean.setBillingPostalCode(defaultValues.toString());
445 defaultValues = null;
446 billingPostalCode = false;
447 }else if (billingCountryCode) {
448 bibInfoBean.setBillingCountryCode(defaultValues.toString());
449 defaultValues = null;
450 billingCountryCode = false;
451 }else if (billingPhoneNumber) {
452 bibInfoBean.setBillingPhoneNumber(defaultValues.toString());
453 defaultValues = null;
454 billingPhoneNumber = false;
455 }else if(vendorcustomernumber){
456 bibInfoBean.setVendorCustomerNumber(defaultValues.toString());
457 defaultValues = null;
458 vendorcustomernumber = false;
459 }else if(requestorsource){
460 requestorSourceType = defaultValues.toString();
461 defaultValues = null;
462 requestorsource = false;
463 }
464
465 }
466
467 public void characters(char ch[], int start, int length)
468 throws SAXException {
469 if(defaultValues != null)
470 defaultValues.append(ch, start, length);
471 }
472
473 };saxParser.parse(path, handler);
474 }
475
476
477
478 public String transformRawDataToXml(String rawData) throws Exception{
479 StringBuilder xmlString = new StringBuilder();
480 parseDefaultValues();
481 boolean rootFlag = false;
482 String urlxsi = "\"http://www.w3.org/2001/XMLSchema-instance\"";
483 String ns = "xsi:noNamespaceSchemaLocation=";
484 String orderType = "firm_fixed_ybp";
485
486 if ( LOG.isDebugEnabled() ) {
487 LOG.debug("Start Checking the Data");
488 LOG.debug(rawData);
489 }
490 xmlString.append("<requisitions ordertype='" + orderType + "' requestorsource='"+requestorSourceType+"' xmlns:xsi=" + urlxsi + " " + ns + "\"requisition.xsd\"" + ">\n");
491 boolean emptyFlag = false;
492 StringTokenizer field = new StringTokenizer(rawData, "=");
493 while (field.hasMoreTokens()) {
494
495 String fieldLine = field.nextToken();
496 if((fieldLine.trim().length()>0)&&(fieldLine.trim().length()>=4) ){
497 String fieldCode = fieldLine.substring(0, 4);
498
499 if (fieldCode.contains("LDR")) {
500 if (rootFlag) {
501 try{
502 if(emptyFlag){
503 parseDefaultValues();
504 xmlString = getDefaultValues(xmlString);
505 }
506 }catch(Exception e){
507 e.printStackTrace();
508 }
509 if(emptyFlag){
510 xmlString.append("</requisition>\n");
511 emptyFlag = false;
512 }
513 }
514 xmlString.append("<requisition>\n");
515 String leader = fieldLine.substring(fieldCode.length(), fieldLine.length());
516 xmlString.append("<leader><![CDATA["+leader.trim()+"]]></leader>\n");
517 emptyFlag = true;
518 rootFlag = true;
519 }else if(fieldCode.contains("008")){
520 String controlField = fieldLine.substring(fieldCode.length(), fieldLine.length());
521 xmlString.append("<controlfield><![CDATA["+controlField.trim()+"]]></controlfield>\n");
522 }else if (fieldCode.contains("020")) {
523 String[] subField = fieldLine.split("\\$");
524 String isbn = "";
525 for (int i = 0; i < subField.length; i++) {
526 String subFieldCode = String.valueOf(subField[i].charAt(0));
527 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
528 isbn = subField[1].substring(1, subField[1].length());
529 xmlString.append("<ISBN><![CDATA["+isbn.trim()+"]]></ISBN>\n");
530 emptyFlag = true;
531 }
532 }
533 } else if (fieldCode.contains("100")) {
534 String[] subField = fieldLine.split("\\$");
535 String author = "";
536 for (int i = 0; i < subField.length; i++) {
537 String subFieldCode = String.valueOf(subField[i].charAt(0));
538 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
539 author = subField[1].substring(1, subField[1].length());
540 xmlString.append("<author><![CDATA["+author.trim()+"]]></author>\n");
541 emptyFlag = true;
542 }
543 }
544 } else if (fieldCode.contains("245")) {
545 String[] subField = fieldLine.split("\\$");
546 String title = "";
547 for (int i = 0; i < subField.length; i++) {
548 String subFieldCode = String.valueOf(subField[i].charAt(0));
549 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
550 title = subField[1].substring(1, subField[1].length());
551 xmlString.append("<title><![CDATA["+title.trim()+"]]></title>\n");
552 emptyFlag = true;
553 }
554 }
555 } else if (fieldCode.contains("250")) {
556 String[] subField = fieldLine.split("\\$");
557 String edition = "";
558 for (int i = 0; i < subField.length; i++) {
559 String subFieldCode = String.valueOf(subField[i].charAt(0));
560 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
561 edition = subField[1].substring(1, subField[1].length());
562 xmlString.append("<edition><![CDATA["+edition.trim()+"]]></edition>\n");
563 emptyFlag = true;
564 }
565 }
566 } else if (fieldCode.contains("260")) {
567 String[] subField = fieldLine.split("\\$");
568 String placeOfPublication = "";
569 String publisher = "";
570 String yearOfPublication = "";
571 xmlString.append("<publicationdetails>\n");
572 for (int i = 0; i < subField.length; i++) {
573 String subFieldCode = String.valueOf(subField[i].charAt(0));
574
575 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
576 placeOfPublication = subField[i].substring(1, subField[i].length());
577 xmlString.append("<placeofpublication><![CDATA["+placeOfPublication.trim()+"]]></placeofpublication>\n");
578 emptyFlag = true;
579 }
580
581 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("b")) {
582 publisher = subField[i].substring(1, subField[i].length());
583 xmlString.append("<publisher><![CDATA["+publisher.trim()+"]]></publisher>\n");
584 emptyFlag = true;
585 }
586
587 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("c")) {
588 yearOfPublication = subField[i].substring(1, subField[i].length());
589 xmlString.append("<yearofpublication><![CDATA["+yearOfPublication.trim()+"]]></yearofpublication>\n");
590 emptyFlag = true;
591 }
592 }
593 xmlString.append("</publicationdetails>\n");
594 } else if (fieldCode.contains("490")) {
595 String[] subField = fieldLine.split("\\$");
596 for (int i = 0; i < subField.length; i++) {
597 String subFieldCode = String.valueOf(subField[i].charAt(0));
598 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
599 String series = subField[1].substring(1, subField[1].length());
600 xmlString.append("<seriesstatement><![CDATA["+series.replaceAll("&", "&").trim()+"]]></seriesstatement>\n");
601 emptyFlag = true;
602 }
603 }
604 } else if (fieldCode.contains("960")) {
605 String[] subField = fieldLine.split("\\$");
606 String accountNumber = "";
607 String location = "";
608 xmlString.append("<funddetails>\n");
609 for (int i = 0; i < subField.length; i++) {
610 String subFieldCode = String.valueOf(subField[i].charAt(0));
611
612 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
613 accountNumber = subField[i].substring(1, subField[i].length());
614 HashMap<String, String> map = fundCodesForMarcXMLTags.get(accountNumber.trim()) != null?(HashMap<String, String>)fundCodesForMarcXMLTags.get(accountNumber.trim()):null;
615
616 String account="";
617 String fundCode="";
618 if(map != null){
619 for (Iterator key = map.keySet().iterator(); key.hasNext();) {
620 account = (String)key.next();
621 fundCode = (String)map.get(account);
622 }
623 }
624
625
626 xmlString.append("<accountno>"+account+"</accountno>\n");
627 xmlString.append("<objectcode>"+fundCode+"</objectcode>\n");
628 emptyFlag = true;
629 }
630
631 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("h")) {
632 location = subField[i].substring(1, subField[i].length());
633 xmlString.append("<location><![CDATA["+location.trim()+"]]></location>\n");
634 emptyFlag = true;
635 }
636 }
637 xmlString.append("</funddetails>\n");
638 } else if (fieldCode.contains("961")) {
639 String[] subField = fieldLine.split("\\$");
640 String libraryNote = "";
641 for (int i = 0; i < subField.length; i++) {
642 String subFieldCode = String.valueOf(subField[i].charAt(0));
643 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("d")) {
644 libraryNote = subField[1].substring(1, subField[1].length());
645 xmlString.append("<librarynote><![CDATA["+libraryNote.trim()+"]]></librarynote>\n");
646 emptyFlag = true;
647 }
648 }
649 } else if (fieldCode.contains("980")) {
650 String[] subField = fieldLine.split("\\$");
651 String listPrice = "";
652 String quantity = "";
653 xmlString.append("<quantitydetails>\n");
654 for (int i = 0; i < subField.length; i++) {
655 String subFieldCode = String.valueOf(subField[i].charAt(0));
656 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("b")) {
657 listPrice = subField[i].substring(1, subField[i].length());
658 xmlString.append("<listprice><![CDATA["+listPrice.trim()+"]]></listprice>\n");
659 emptyFlag = true;
660 }
661 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("q")) {
662 quantity = subField[i].substring(1, subField[i].length());
663 xmlString.append("<quantity><![CDATA["+quantity.trim()+"]]></quantity>\n");
664 emptyFlag = true;
665 }
666 }
667 xmlString.append("</quantitydetails>\n");
668
669 } else if (fieldCode.contains("982")) {
670 String[] subField = fieldLine.split("\\$");
671 String ybp = "";
672 String binding = "";
673 String initials = "";
674 xmlString.append("<transactiondata1>\n");
675 for (int i = 0; i < subField.length; i++) {
676 String subFieldCode = String.valueOf(subField[i].charAt(0));
677 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
678 ybp = subField[i].substring(1, subField[i].length());
679 xmlString.append("<YBP><![CDATA["+ybp.trim()+"]]></YBP>\n");
680 emptyFlag = true;
681 }
682 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("b")) {
683 xmlString.append("<subAccountNumber></subAccountNumber>\n");
684 emptyFlag = true;
685 }
686 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("d")) {
687 binding = subField[i].substring(1, subField[i].length());
688 xmlString.append("<binding><![CDATA["+binding.trim()+"]]></binding>\n");
689 emptyFlag = true;
690 }
691 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("f")) {
692 initials = subField[i].substring(1, subField[i].length());
693 xmlString.append("<initials><![CDATA["+initials.trim()+"]]></initials>\n");
694 xmlString.append("<deliverytoname><![CDATA["+deliverToName.get(initials.trim())+"]]></deliverytoname>\n");
695 emptyFlag = true;
696 }
697 }
698 xmlString.append("</transactiondata1>\n");
699
700 } else if (fieldCode.contains("984")) {
701
702 String[] subField = fieldLine.split("\\$");
703 String orderDate = "";
704 String vendorCode = "";
705
706 xmlString.append("<vendor>\n");
707 for (int i = 0; i < subField.length; i++) {
708 String subFieldCode = String.valueOf(subField[i].charAt(0));
709
710 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
711 orderDate = subField[i].substring(1, subField[i].length());
712 xmlString.append("<dateOrdered><![CDATA["+orderDate.trim()+"]]></dateOrdered>\n");
713 emptyFlag = true;
714 }
715
716 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("c")) {
717 vendorCode = subField[i].substring(1, subField[i].length());
718 xmlString.append("<vendorcode>12106-0</vendorcode>\n");
719 emptyFlag = true;
720 }
721 }
722 xmlString.append("</vendor>\n");
723 } else if (fieldCode.contains("987")) {
724 String[] subField = fieldLine.split("\\$");
725 String ybpuid = "";
726 for (int i = 0; i < subField.length; i++) {
727 String subFieldCode = String.valueOf(subField[i].charAt(0));
728 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
729 ybpuid = subField[1].substring(1, subField[1].length());
730 xmlString.append("<ybpuid><![CDATA["+ybpuid.trim()+"]]></ybpuid>\n");
731 emptyFlag = true;
732 }
733 }
734 } else if (fieldCode.contains("993")) {
735 String[] subField = fieldLine.split("\\$");
736 String volumeNumber = "";
737 for (int i = 0; i < subField.length; i++) {
738 String subFieldCode = String.valueOf(subField[i].charAt(0));
739 if (subFieldCode != null && subFieldCode != "" && subFieldCode.equalsIgnoreCase("a")) {
740 volumeNumber = subField[1].substring(1, subField[1].length());
741 xmlString.append("<volumenumber><![CDATA["+volumeNumber.trim()+"]]></volumenumber>\n");
742 emptyFlag = true;
743 }
744 }
745 }
746
747 }
748 }
749 try{
750 if(emptyFlag){
751 parseDefaultValues();
752 xmlString = getDefaultValues(xmlString);
753 }
754 }catch(Exception e){
755 e.printStackTrace();
756 }
757 if(emptyFlag){
758 xmlString.append("</requisition>\n");
759 emptyFlag = false;
760 }
761 xmlString.append("</requisitions>");
762 return xmlString.toString();
763 }
764
765
766 private StringBuilder getDefaultValues(StringBuilder xmlString){
767 xmlString.append("<deliverycampuscode>"+bibInfoBean.getDeliveryCampusCode()+"</deliverycampuscode>\n");
768
769 xmlString.append("<deliverybuildingcode>"+bibInfoBean.getDeliveryBuildingCode()+"</deliverybuildingcode>\n");
770 xmlString.append("<deliverybuildingline1address>"+bibInfoBean.getDeliveryBuildingLine1Address()+"</deliverybuildingline1address>\n");
771 xmlString.append("<deliverybuildingroomnumber>"+bibInfoBean.getDeliveryBuildingRoomNumber()+"</deliverybuildingroomnumber>\n");
772 xmlString.append("<deliverycityname>"+bibInfoBean.getDeliveryCityName()+"</deliverycityname>\n");
773 xmlString.append("<deliverystatecode>"+bibInfoBean.getDeliveryStateCode()+"</deliverystatecode>\n");
774 xmlString.append("<deliverypostalcode>"+bibInfoBean.getDeliveryPostalCode()+"</deliverypostalcode>\n");
775 xmlString.append("<deliverycountrycode>"+bibInfoBean.getDeliveryCountryCode()+"</deliverycountrycode>\n");
776 xmlString.append("<purchaseordertransmissionmethodcode>"+bibInfoBean.getPurchaseOrderTransmissionMethodCode()+"</purchaseordertransmissionmethodcode>\n");
777 xmlString.append("<purchaseordercostsourcecode>"+bibInfoBean.getPurchaseOrderCostSourceCode()+"</purchaseordercostsourcecode>\n");
778 xmlString.append("<requestorpersonname>"+bibInfoBean.getRequestorPersonName()+"</requestorpersonname>\n");
779 xmlString.append("<requestorpersonphonenumber>"+bibInfoBean.getRequestorPersonPhoneNumber()+"</requestorpersonphonenumber>\n");
780 xmlString.append("<requestorpersonemailaddress>"+bibInfoBean.getRequestorPersonEmailAddress()+"</requestorpersonemailaddress>\n");
781 xmlString.append("<requisitiondescription>"+bibInfoBean.getRequisitionDescription()+"</requisitiondescription>\n");
782 xmlString.append("<fundingsource>"+bibInfoBean.getFundingSource()+"</fundingsource>\n");
783 xmlString.append("<financialyear>"+bibInfoBean.getFinancialYear()+"</financialyear>\n");
784 xmlString.append("<uom>"+bibInfoBean.getUom()+"</uom>\n");
785 xmlString.append("<chart>"+bibInfoBean.getChart()+"</chart>\n");
786
787 xmlString.append("<percent>"+bibInfoBean.getPercent()+"</percent>\n");
788 xmlString.append("<chartofaccountscode>"+bibInfoBean.getChartOfAccountsCode()+"</chartofaccountscode>\n");
789 xmlString.append("<organizationcode>"+bibInfoBean.getOrganizationCode()+"</organizationcode>\n");
790 xmlString.append("<documentfundingsourcecode>"+bibInfoBean.getDocumentFundingSourceCode()+"</documentfundingsourcecode>\n");
791 xmlString.append("<usetaxindicator>"+bibInfoBean.isUseTaxIndicator()+"</usetaxindicator>\n");
792 xmlString.append("<deliverybuildingotherindicator>"+bibInfoBean.isDeliveryBuildingOtherIndicator()+"</deliverybuildingotherindicator>\n");
793 xmlString.append("<organizationautomaticpurchaseorderlimit>"+bibInfoBean.getOrganizationAutomaticPurchaseOrderLimit()+"</organizationautomaticpurchaseorderlimit>\n");
794 xmlString.append("<purchaseorderautomaticindicator>"+bibInfoBean.isPurchaseOrderAutomaticIndicator()+"</purchaseorderautomaticindicator>\n");
795 xmlString.append("<receivingdocumentrequiredindicator>"+bibInfoBean.isReceivingDocumentRequiredIndicator()+"</receivingdocumentrequiredindicator>\n");
796 xmlString.append("<paymentrequestpositiveapprovalindicator>"+bibInfoBean.isPaymentRequestPositiveApprovalIndicator()+"</paymentrequestpositiveapprovalindicator>\n");
797 xmlString.append("<itemtypecode>"+bibInfoBean.getItemTypeCode()+"</itemtypecode>\n");
798 xmlString.append("<billingname>"+bibInfoBean.getBillingName()+"</billingname>\n");
799 xmlString.append("<billingline1address>"+bibInfoBean.getBillingLine1Address()+"</billingline1address>\n");
800 xmlString.append("<billingcityname>"+bibInfoBean.getBillingCityName()+"</billingcityname>\n");
801 xmlString.append("<billingstatecode>"+bibInfoBean.getBillingStateCode()+"</billingstatecode>\n");
802 xmlString.append("<billingpostalcode>"+bibInfoBean.getBillingPostalCode()+"</billingpostalcode>\n");
803 xmlString.append("<billingcountrycode>"+bibInfoBean.getBillingCountryCode()+"</billingcountrycode>\n");
804 xmlString.append("<billingphonenumber>"+bibInfoBean.getBillingPhoneNumber()+"</billingphonenumber>\n");
805 xmlString.append("<acquisitionunitvendoraccount>"+bibInfoBean.getVendorCustomerNumber()+"</acquisitionunitvendoraccount>\n");
806 return xmlString;
807 }
808
809
810 public String getFailureRawData(String rawData,List<List> bibinfoFailure) throws Exception{
811 StringBuilder failureBuilder = new StringBuilder();
812 for(int failure=0;failure<bibinfoFailure.size();failure++){
813 BibInfoBean bibBean = (BibInfoBean)bibinfoFailure.get(failure);
814 String leader = bibBean.getLeader();
815 String ybpUid=bibBean.getYbpuid();
816 StringTokenizer field = new StringTokenizer(rawData, "=");
817 int fromIndex = 0;
818 int toIndex =0;
819 String rawdata = "";
820 while (field.hasMoreTokens()) {
821
822 String fieldLine = field.nextToken();
823 if(!fieldLine.equalsIgnoreCase("\n")){
824 String fieldCode = fieldLine.substring(0, 4);
825 if (fieldCode.contains("LDR")) {
826 if(fieldLine.contains(leader)){
827 fromIndex = rawData.indexOf(fieldLine);
828 }
829 }
830 if (fieldCode.contains("987")) {
831 if(fieldLine.contains(ybpUid)){
832 toIndex = rawData.indexOf(fieldLine);
833 rawdata = rawData.substring(fromIndex,toIndex);
834 failureBuilder.append(rawdata+fieldLine+"\nFailure Information :::"+bibBean.getFailure()+"\n\n");
835 }
836 }
837
838 }
839 }
840 }
841
842 return failureBuilder.toString();
843 }
844
845
846 }