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 private BulkIngestProcessHandlerService bIService = (BulkIngestProcessHandlerService) BeanLocator
47 .getBean("bulkIngestProcessHandlerService");
48 private BulkLoadHandler bulkLoadHandler = null;
49 private BulkIngestNIndexRouteBuilder bulkIngestNIndexRouteBuilder = null;
50 private BulkIngestNIndexProcessor bulkIngestNIndexProcessor = null;
51 private BulkIngestStatistics bulkLoadStatistics = null;
52
53 @Override
54 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
55 doPost(req, resp);
56 }
57
58 @Override
59 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
60 try {
61
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 BulkProcessRequest bulkProcessRequest = new BulkProcessRequest();
102 bulkProcessRequest.setUser(req.getParameter("user"));
103 bulkProcessRequest.setOperation(BulkProcessRequest.BulkProcessOperation.INGEST);
104 bulkProcessRequest.setDataFolder(req.getParameter("bulkIngestFolder"));
105 bulkProcessRequest.setDocCategory(req.getParameter("bulkIngestDocCategory"));
106 bulkProcessRequest.setDocType(req.getParameter("bulkIngestDocType"));
107 bulkProcessRequest.setDocFormat(req.getParameter("bulkIngestDocFormat"));
108 bulkProcessRequest.setBulkIngestFolder(req.getParameter("bulkIngestFolder1"));
109 if ("Start".equals(req.getParameter("action"))) {
110 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.START);
111 outputMessage(resp, "Ingestion has started. Please check logs for further details");
112 if ("DocStore Request".equals(req.getParameter("bulkIngestDataFormat"))) {
113 bulkProcessRequest.setDataFormat(BulkProcessRequest.BulkIngestDataFormat.DOCSTORE);
114 }
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 }
120 else if ("statistics".equals(req.getParameter("action"))) {
121 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.STATUS);
122 outputMessage(resp, bulkLoadStatistics.getJsonString());
123 }
124 else if ("Stop".equals(req.getParameter("action"))) {
125 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.STOP);
126 outputMessage(resp, "Ingestion process has been stopped.");
127 }
128 else if ("Clear Status".equals(req.getParameter("action"))) {
129 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.CLEAR);
130 }
131 BeanLocator.getDocumentServiceImpl().bulkProcess(bulkProcessRequest);
132 }
133 catch (Exception e) {
134 LOG.error("Bulk Ingest STARTUP Failed: ", e);
135 outputMessage(resp, "Problem in loading Bulk Ingest!\ncause:\n" + e.getMessage()
136 + "\nPlease refer to Application log for further details!");
137 }
138 }
139
140
141 private void outputMessage(HttpServletResponse resp, String s) throws IOException {
142 PrintWriter out = resp.getWriter();
143 out.println(s);
144 out.flush();
145 out.close();
146 }
147 }