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