001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.ole.web;
017
018 import org.kuali.ole.utility.HttpUtil;
019 import org.kuali.ole.docstore.util.PropertyUtil;
020 import org.slf4j.Logger;
021 import org.slf4j.LoggerFactory;
022
023 import javax.servlet.RequestDispatcher;
024 import javax.servlet.ServletException;
025 import javax.servlet.http.HttpServlet;
026 import javax.servlet.http.HttpServletRequest;
027 import javax.servlet.http.HttpServletResponse;
028 import java.io.IOException;
029
030
031 public class BulkOptimizeServlet extends HttpServlet {
032 private static final Logger LOG = LoggerFactory.getLogger(BulkOptimizeServlet.class);
033 private static final String RESULTS_JSP = "/bulkOptimizeResult.jsp";
034
035 @Override
036 protected void doPost(HttpServletRequest request,
037 HttpServletResponse response) throws ServletException, IOException {
038 optimizeAllRecords(request, response);
039 LOG.info("Optimization of both Auth and bib is done");
040
041 }
042
043 /**
044 * @throws Exception
045 */
046 public void optimizeAllRecords(HttpServletRequest request,
047 HttpServletResponse response) {
048 RequestDispatcher rd = getServletContext().getRequestDispatcher(
049 RESULTS_JSP);
050 request.setAttribute("result",
051 "Optimization started. Please check logs for further details");
052 LOG.info("Ready for optimizing Auth and Bib Records");
053 try {
054 optimizeAuthRecords();
055 optimizeBibRecords();
056 rd.forward(request, response);
057 } catch (Exception e) {
058 LOG.error(
059 "Problem optimizing records! Please refer application logs for details",
060 e);
061 }
062 }
063
064 /**
065 * @throws Exception
066 */
067 public void optimizeBibRecords() throws Exception {
068 String docSearchURL = PropertyUtil.getPropertyUtil().getProperty(
069 "docSearchURL");
070 String indexCategory = "bib";
071 StringBuffer optimizeBibURL = new StringBuffer("");
072 optimizeBibURL.append(docSearchURL);
073 optimizeBibURL.append(indexCategory);
074 optimizeBibURL.append("/update/");
075 if (LOG.isDebugEnabled()) {
076 LOG.debug("optimizeBibURL " + optimizeBibURL);
077 }
078 String parametersForOptimizeBibUrl = "optimize=true";
079 if (LOG.isDebugEnabled()) {
080 LOG.debug("updateUrl for bib-->"
081 + parametersForOptimizeBibUrl);
082 }
083 HttpUtil.postData(optimizeBibURL.toString(),
084 parametersForOptimizeBibUrl);
085 LOG.info("Optimization of bib records is done");
086 }
087
088 /**
089 * @throws Exception
090 */
091 public void optimizeAuthRecords() throws Exception {
092 String docSearchURL = PropertyUtil.getPropertyUtil().getProperty(
093 "docSearchURL");
094 String indexCategory = "auth";
095 StringBuffer optimizeAuthURL = new StringBuffer("");
096 optimizeAuthURL.append(docSearchURL);
097 optimizeAuthURL.append(indexCategory);
098 optimizeAuthURL.append("/update/");
099 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 }