View Javadoc
1   package org.kuali.ole.web;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
5   import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
6   import org.kuali.ole.docstore.common.document.content.enums.DocType;
7   import org.kuali.ole.docstore.engine.service.index.solr.BibConstants;
8   import org.kuali.ole.docstore.metrics.reindex.ReIndexingStatus;
9   import org.kuali.ole.docstore.process.RebuildIndexesHandler;
10  import org.kuali.ole.logger.DocStoreLogger;
11  
12  import javax.servlet.ServletException;
13  import javax.servlet.http.HttpServlet;
14  import javax.servlet.http.HttpServletRequest;
15  import javax.servlet.http.HttpServletResponse;
16  import java.io.IOException;
17  import java.io.PrintWriter;
18  
19  /**
20   * Created by IntelliJ IDEA.
21   * User: pvsubrah
22   * Date: 11/12/11
23   * Time: 3:41 PM
24   * To change this template use File | Settings | File Templates.
25   */
26  public class RebuildIndexServlet extends HttpServlet {
27  
28      private static final long serialVersionUID = 1L;
29      DocStoreLogger docStoreLogger = new DocStoreLogger(getClass().getName());
30  
31      @Override
32      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
33          doPost(req, resp);
34      }
35  
36      @Override
37      protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
38          try {
39  
40              String docCategory = DocCategory.WORK.getCode();
41              String docType = DocType.BIB.getCode();
42              String docFormat = DocFormat.MARC.getCode();
43              String action = req.getParameter("action");
44              String batchSizeReq = req.getParameter("batchSize");
45              String startIndexReq = req.getParameter("startIndex");
46              String endIndexReq = req.getParameter("endIndex");
47              String updateDate=null;
48              if(req.getParameter("updateDate")!=null){
49                  updateDate=req.getParameter("updateDate").trim();
50              }
51              int batchSize = 0;
52              int startIndex = 0;
53              int endIndex = 0;
54              if(StringUtils.isNotEmpty(batchSizeReq)) {
55                  batchSize = Integer.parseInt(batchSizeReq);
56              }
57              if(StringUtils.isNotEmpty(startIndexReq)) {
58                  startIndex = Integer.parseInt(startIndexReq);
59              }
60              if(StringUtils.isNotEmpty(endIndexReq)) {
61                  endIndex = Integer.parseInt(endIndexReq);
62              }
63              if(startIndex > endIndex) {
64                  String result = "Please provide valid input " +  startIndex + " > " + endIndex;
65                  outputMessage(resp, result);
66              }
67              RebuildIndexesHandler rebuildIndexesHandler = RebuildIndexesHandler.getInstance();
68  
69              if (action.equalsIgnoreCase("start")) {
70                  String result = rebuildIndexesHandler.startProcess(docCategory, docType, docFormat, batchSize, startIndex, endIndex,updateDate);
71                  outputMessage(resp, result);
72              } else if (action.equalsIgnoreCase("stop")) {
73                  String result = rebuildIndexesHandler.stopProcess();
74                  outputMessage(resp, result);
75              } else if (action.equalsIgnoreCase("status")) {
76  //                ReIndexingStatus reIndexingStatus = ReIndexingStatus.getInstance();
77  //                String result = reIndexingStatus.getJsonString();
78                  String result = rebuildIndexesHandler.showStatus();
79                  outputMessage(resp, result);
80              } else if (action.equalsIgnoreCase("bibStatus")) {
81                  String result = rebuildIndexesHandler.showBibStatus();
82                  outputMessage(resp, result);
83              } else if (action.equalsIgnoreCase("Clear Status")) {
84                  ReIndexingStatus reIndexingStatus = ReIndexingStatus.getInstance();
85                  reIndexingStatus.reset();
86              } else if (action.equalsIgnoreCase("store")) {
87                  String result = rebuildIndexesHandler.storeBibInfo(batchSize);
88                  outputMessage(resp, result);
89              } else {
90                  String result = "Invalid action :" + action;
91                  outputMessage(resp, result);
92              }
93          } catch (Exception e) {
94              docStoreLogger.log("Error during rebuilding of the indexes from documentstore", e);
95          }
96      }
97  
98      private void outputMessage(HttpServletResponse resp, String s) throws IOException {
99          PrintWriter out = resp.getWriter();
100         out.println(s);
101         out.flush();
102         out.close();
103     }
104 }