1 package org.kuali.ole.web;
2
3 import org.kuali.ole.docstore.metrics.reindex.ReIndexingStatus;
4 import org.kuali.ole.docstore.process.RebuildIndexesHandler;
5 import org.kuali.ole.logger.DocStoreLogger;
6
7 import javax.servlet.ServletException;
8 import javax.servlet.http.HttpServlet;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 import java.io.IOException;
12 import java.io.PrintWriter;
13
14
15
16
17
18
19
20
21 public class RebuildIndexServlet extends HttpServlet {
22
23 private static final long serialVersionUID = 1L;
24 DocStoreLogger docStoreLogger = new DocStoreLogger(getClass().getName());
25
26 @Override
27 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
28 doPost(req, resp);
29 }
30
31 @Override
32 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
33 try {
34
35 String docCategory = req.getParameter("docCategory");
36 String docType = req.getParameter("docType");
37 String docFormat = req.getParameter("docFormat");
38 String action = req.getParameter("action");
39 RebuildIndexesHandler rebuildIndexesHandler = RebuildIndexesHandler.getInstance();
40
41 if (action.equalsIgnoreCase("start")) {
42 String result = rebuildIndexesHandler.startProcess(docCategory, docType, docFormat);
43 outputMessage(resp, result);
44 }
45 else if (action.equalsIgnoreCase("stop")) {
46 String result = rebuildIndexesHandler.stopProcess();
47 outputMessage(resp, result);
48 }
49 else if (action.equalsIgnoreCase("status")) {
50 ReIndexingStatus reIndexingStatus = ReIndexingStatus.getInstance();
51 String result = reIndexingStatus.getJsonString();
52 outputMessage(resp, result);
53 }
54 else if (action.equalsIgnoreCase("Clear Status")) {
55 ReIndexingStatus reIndexingStatus = ReIndexingStatus.getInstance();
56 reIndexingStatus.reset();
57 }
58 else {
59 String result = "Invalid action :" + action ;
60 outputMessage(resp, result);
61 }
62 } catch (Exception e) {
63 docStoreLogger.log("Error during rebuilding of the indexes from documentstore", e);
64 }
65 }
66
67 private void outputMessage(HttpServletResponse resp, String s) throws IOException {
68 PrintWriter out = resp.getWriter();
69 out.println(s);
70 out.flush();
71 out.close();
72 }
73 }