1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.web;
17
18 import org.kuali.ole.docstore.process.BulkIngestNIndexProcessor;
19 import org.kuali.ole.docstore.process.BulkIngestNIndexRouteBuilder;
20 import org.kuali.ole.docstore.process.BulkLoadHandler;
21 import org.kuali.ole.docstore.process.batch.BulkProcessRequest;
22 import org.kuali.ole.docstore.service.BeanLocator;
23 import org.kuali.ole.docstore.service.BulkIngestProcessHandlerService;
24 import org.kuali.ole.docstore.utility.BulkIngestStatistics;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 import javax.servlet.ServletException;
29 import javax.servlet.http.HttpServlet;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.io.IOException;
33 import java.io.PrintWriter;
34
35
36
37
38
39
40
41
42 public class BulkIngestServlet extends HttpServlet {
43
44 private static final long serialVersionUID = 1L;
45 private static final Logger LOG = LoggerFactory.getLogger(BulkIngestServlet.class);
46
47
48
49
50
51
52 private BulkIngestStatistics bulkLoadStatistics = BulkIngestStatistics.getInstance();
53
54 @Override
55 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
56 doPost(req, resp);
57 }
58
59 @Override
60 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
61 try {
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 BulkProcessRequest bulkProcessRequest = new BulkProcessRequest();
103 bulkProcessRequest.setUser(req.getParameter("user"));
104 bulkProcessRequest.setOperation(BulkProcessRequest.BulkProcessOperation.INGEST);
105 bulkProcessRequest.setDataFolder(req.getParameter("bulkIngestFolder"));
106 bulkProcessRequest.setDocCategory(req.getParameter("bulkIngestDocCategory"));
107 bulkProcessRequest.setDocType(req.getParameter("bulkIngestDocType"));
108 bulkProcessRequest.setDocFormat(req.getParameter("bulkIngestDocFormat"));
109 bulkProcessRequest.setBulkIngestFolder(req.getParameter("bulkIngestFolder1"));
110 if ("Start".equals(req.getParameter("action"))) {
111 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.START);
112 outputMessage(resp, "Ingestion has started. Please check logs for further details");
113 if ("DocStore Request".equals(req.getParameter("bulkIngestDataFormat"))) {
114 bulkProcessRequest.setDataFormat(BulkProcessRequest.BulkIngestDataFormat.DOCSTORE);
115 } else if ("Standard Doc Format".equals(req.getParameter("bulkIngestDataFormat"))) {
116 bulkProcessRequest.setDataFormat(BulkProcessRequest.BulkIngestDataFormat.STANDARD);
117 }
118 outputMessage(resp, "Ingestion has started. Please check logs for further details");
119 } else if ("statistics".equals(req.getParameter("action"))) {
120 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.STATUS);
121 outputMessage(resp, bulkLoadStatistics.getJsonString());
122 } else if ("Stop".equals(req.getParameter("action"))) {
123 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.STOP);
124 outputMessage(resp, "Ingestion process has been stopped.");
125 } else if ("Clear Status".equals(req.getParameter("action"))) {
126 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.CLEAR);
127 }
128 BeanLocator.getDocumentServiceImpl().bulkProcess(bulkProcessRequest);
129 } catch (Exception e) {
130 LOG.error("Bulk Ingest STARTUP Failed: ", e);
131 outputMessage(resp, "Problem in loading Bulk Ingest!\ncause:\n" + e.getMessage()
132 + "\nPlease refer to Application log for further details!");
133 }
134 }
135
136
137 private void outputMessage(HttpServletResponse resp, String s) throws IOException {
138 PrintWriter out = resp.getWriter();
139 out.println(s);
140 out.flush();
141 out.close();
142 }
143 }