1 package org.kuali.ole.ingest;
2
3 import org.kuali.ole.DataCarrierService;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.OleOrderRecordHandler;
6 import org.kuali.ole.OleOrderRecords;
7 import org.kuali.ole.batch.bo.OLEBatchProcessJobDetailsBo;
8 import org.kuali.ole.batch.bo.OrderImportHelperBo;
9 import org.kuali.ole.converter.MarcXMLConverter;
10 import org.kuali.ole.converter.OLEEDIConverter;
11 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
12 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
13 import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
14 import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
15 import org.kuali.ole.pojo.OleBibRecord;
16 import org.kuali.ole.pojo.OleOrderRecord;
17 import org.kuali.ole.select.businessobject.OleRequisitionItem;
18 import org.kuali.ole.select.service.OleExposedWebService;
19 import org.kuali.ole.select.service.impl.OleExposedWebServiceImpl;
20 import org.kuali.ole.sys.context.SpringContext;
21 import org.kuali.rice.core.api.config.property.ConfigContext;
22 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
23 import org.xml.sax.SAXException;
24
25 import java.io.IOException;
26 import java.util.*;
27
28
29
30
31
32 public class IngestProcessor extends AbstractIngestProcessor {
33
34 private DocstoreClientLocator docstoreClientLocator;
35
36 public DocstoreClientLocator getDocstoreClientLocator() {
37
38 if (docstoreClientLocator == null) {
39 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
40
41 }
42 return docstoreClientLocator;
43 }
44
45
46
47
48
49
50
51
52 @Override
53 public String preProcessMarc(String marcFileContent, OLEBatchProcessJobDetailsBo job) {
54 OrderImportHelperBo orderImportHelperBo = job.getOrderImportHelperBo();
55 String marcXMLContent = null;
56 MarcXMLConverter marcXMLConverter = new MarcXMLConverter();
57 try {
58 marcXMLContent = marcXMLConverter.convert(marcFileContent);
59 }
60 catch(Exception ex){
61 ex.getMessage();
62 List<String> reasonForFailure = new ArrayList<>();
63 reasonForFailure.add("Unable to parse the marc file. Allowed format is UTF-8");
64 reasonForFailure.add("======================================================");
65 reasonForFailure.add(ex.getMessage());
66
67 orderImportHelperBo.setFailureReason(reasonForFailure);
68 }
69
70
71 String modifiedXMLContent =
72 marcXMLContent.
73 replace("collection xmlns=\"http://www.loc.gov/MARC21/slim\" xmlns=\"http://www.loc.gov/MARC21/slim",
74 "collection xmlns=\"http://www.loc.gov/MARC21/slim");
75 return modifiedXMLContent;
76 }
77
78
79
80
81
82
83
84 @Override
85 public String preProcessEDI(String ediFileContent) {
86 String ediXMLContent = null;
87 OLEEDIConverter oleEDIConverter = new OLEEDIConverter();
88 try {
89 ediXMLContent = oleEDIConverter.convertToXML(ediFileContent);
90 } catch (IOException e) {
91 System.out.println(e.getMessage());
92 } catch (SAXException e) {
93 System.out.println(e.getMessage());
94 }
95 return ediXMLContent;
96 }
97
98
99
100
101
102 @Override
103 public void postProcess(OLEBatchProcessJobDetailsBo job) {
104 OleOrderRecords oleOrderRecords = new OleOrderRecords();
105 try {
106 List<OleOrderRecord> oleOrderRecordList = getOleOrderRecordList();
107 oleOrderRecords.setRecords(oleOrderRecordList);
108 OleOrderRecordHandler oleEditorResponseHandler = new OleOrderRecordHandler();
109 String oleOrderRecordXml = oleEditorResponseHandler.toXML(oleOrderRecords);
110 OleExposedWebServiceImpl oleExposedWebService = (OleExposedWebServiceImpl) SpringContext.getBean(OleExposedWebService.class);
111 oleExposedWebService.createReqAndPO(oleOrderRecordXml, job);
112 } catch (Exception e) {
113 e.printStackTrace();
114 }
115 }
116
117
118
119
120
121
122
123 private String buildRequestForRollback(OleOrderRecords oleOrderRecords) {
124 String xml = null;
125 for (Iterator<OleOrderRecord> iterator = oleOrderRecords.getRecords().iterator(); iterator.hasNext(); ) {
126 OleOrderRecord oleOrderRecord = iterator.next();
127 OleBibRecord oleBibRecord = oleOrderRecord.getOleBibRecord();
128 String bibUUID = oleBibRecord.getBibUUID();
129
130 RequestHandler requestHandler = new RequestHandler();
131 Request request = new Request();
132 request.setOperation("deleteWithLinkedDocs");
133 RequestDocument requestDocument = new RequestDocument();
134 requestDocument.setId(bibUUID);
135 request.setRequestDocuments(Arrays.asList(requestDocument));
136 xml = requestHandler.toXML(request);
137 }
138 return xml;
139 }
140
141
142
143
144
145
146 public String getURL() {
147 String url = ConfigContext.getCurrentContextConfig().getProperty("oleExposedWebService.url");
148 return url;
149 }
150
151 }