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.utility.HttpUtil;
19 import org.kuali.ole.docstore.util.PropertyUtil;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import javax.servlet.RequestDispatcher;
24 import javax.servlet.ServletException;
25 import javax.servlet.http.HttpServlet;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import java.io.IOException;
29
30
31 public class BulkOptimizeServlet extends HttpServlet {
32 private static final Logger LOG = LoggerFactory.getLogger(BulkOptimizeServlet.class);
33 private static final String RESULTS_JSP = "/bulkOptimizeResult.jsp";
34
35 @Override
36 protected void doPost(HttpServletRequest request,
37 HttpServletResponse response) throws ServletException, IOException {
38 optimizeAllRecords(request, response);
39 LOG.info("Optimization of both Auth and bib is done");
40
41 }
42
43
44
45
46 public void optimizeAllRecords(HttpServletRequest request,
47 HttpServletResponse response) {
48 RequestDispatcher rd = getServletContext().getRequestDispatcher(
49 RESULTS_JSP);
50 request.setAttribute("result",
51 "Optimization started. Please check logs for further details");
52 LOG.info("Ready for optimizing Auth and Bib Records");
53 try {
54 optimizeAuthRecords();
55 optimizeBibRecords();
56 rd.forward(request, response);
57 } catch (Exception e) {
58 LOG.error(
59 "Problem optimizing records! Please refer application logs for details",
60 e);
61 }
62 }
63
64
65
66
67 public void optimizeBibRecords() throws Exception {
68 String docSearchURL = PropertyUtil.getPropertyUtil().getProperty(
69 "docSearchURL");
70 String indexCategory = "bib";
71 StringBuffer optimizeBibURL = new StringBuffer("");
72 optimizeBibURL.append(docSearchURL);
73 optimizeBibURL.append(indexCategory);
74 optimizeBibURL.append("/update/");
75 if (LOG.isDebugEnabled()) {
76 LOG.debug("optimizeBibURL " + optimizeBibURL);
77 }
78 String parametersForOptimizeBibUrl = "optimize=true";
79 if (LOG.isDebugEnabled()) {
80 LOG.debug("updateUrl for bib-->"
81 + parametersForOptimizeBibUrl);
82 }
83 HttpUtil.postData(optimizeBibURL.toString(),
84 parametersForOptimizeBibUrl);
85 LOG.info("Optimization of bib records is done");
86 }
87
88
89
90
91 public void optimizeAuthRecords() throws Exception {
92 String docSearchURL = PropertyUtil.getPropertyUtil().getProperty(
93 "docSearchURL");
94 String indexCategory = "auth";
95 StringBuffer optimizeAuthURL = new StringBuffer("");
96 optimizeAuthURL.append(docSearchURL);
97 optimizeAuthURL.append(indexCategory);
98 optimizeAuthURL.append("/update/");
99 if (LOG.isDebugEnabled()) {
100 LOG.debug("optimizeAuthURL " + optimizeAuthURL);
101 }
102 String parametersForOptimizeAuthUrl = "optimize=true";
103 if (LOG.isDebugEnabled()) {
104 LOG.debug("parametersForOptimizeAuthUrl-->"
105 + parametersForOptimizeAuthUrl);
106 }
107 HttpUtil.postData(optimizeAuthURL.toString(),
108 parametersForOptimizeAuthUrl);
109 LOG.info("Optimization of auth reocrds is done");
110 }
111
112 }