View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Created by IntelliJ IDEA.
37   * User: peris
38   * Date: 5/18/11
39   * Time: 10:35 AM
40   * To change this template use File | Settings | File Templates.
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      private BulkIngestStatistics bulkLoadStatistics = BulkIngestStatistics.getInstance();
53  
54      @Override
55      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
56          doPost(req, resp);
57      }
58  
59      @Override
60      protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
61          try {
62              /*if ("Start".equals(req.getParameter("action"))) {
63                  if ("DocStore Request".equals(req.getParameter("bulkIngestDataFormat"))) {
64                      if (bulkLoadHandler != null) {
65                          DocStoreCamelContext.getInstance().resume();
66                          outputMessage(resp, "Ingestion has started. Please check logs for further details");
67                      }
68                      else {
69                          bIService.startBulkIngestForDocStoreRequestFormat(req.getParameter("bulkIngestFolder1"));
70                          bulkLoadHandler = bIService.getLoadHandler();
71                          bulkIngestNIndexRouteBuilder = bulkLoadHandler.getBulkRoute();
72                          bulkIngestNIndexProcessor = bulkIngestNIndexRouteBuilder.getBulkIngestNIndexProcessor();
73                          bulkLoadStatistics = bulkIngestNIndexProcessor.getBulkLoadStatistics();
74                          DocStoreCamelContext.getInstance().resume();
75                      }
76                  }
77                  else if ("Standard Doc Format".equals(req.getParameter("bulkIngestDataFormat"))) {
78                      String folder = req.getParameter("bulkIngestFolder");
79                      if (folder != null && folder.trim().length() != 0) {
80                          bIService.startBulkIngestForStandardXMLFormat(req.getParameter("bulkIngestFolder"),
81                                                                        req.getParameter("bulkIngestDocCategory"),
82                                                                        req.getParameter("bulkIngestDocType"),
83                                                                        req.getParameter("bulkIngestDocFormat"),req.getParameter("bulkIngestFolder1"));
84                      }
85                      else {
86                          outputMessage(resp, "'Folder' field should not be empty.");
87                          return;
88                      }
89                  }
90                  outputMessage(resp, "Ingestion has started. Please check logs for further details");
91              }
92              else if ("statistics".equals(req.getParameter("action"))) {
93                  outputMessage(resp, bulkLoadStatistics.getJsonString());
94              }
95              else if ("Stop".equals(req.getParameter("action"))) {
96                  outputMessage(resp, "Ingestion process has been stopped.");
97                  DocStoreCamelContext.getInstance().suspend();
98              }
99              else if ("Clear Status".equals(req.getParameter("action"))) {
100                 bulkLoadStatistics.clearBulkIngestStatistics();
101             }*/
102             BulkProcessRequest bulkProcessRequest = new BulkProcessRequest();
103             bulkProcessRequest.setUser(req.getParameter("user"));
104             bulkProcessRequest.setOperation(BulkProcessRequest.BulkProcessOperation.INGEST);
105             bulkProcessRequest.setDataFolder(req.getParameter("bulkIngestFolder"));
106             bulkProcessRequest.setDocCategory(req.getParameter("bulkIngestDocCategory"));
107             bulkProcessRequest.setDocType(req.getParameter("bulkIngestDocType"));
108             bulkProcessRequest.setDocFormat(req.getParameter("bulkIngestDocFormat"));
109             bulkProcessRequest.setBulkIngestFolder(req.getParameter("bulkIngestFolder1"));
110             if ("Start".equals(req.getParameter("action"))) {
111                 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.START);
112                 outputMessage(resp, "Ingestion has started. Please check logs for further details");
113                 if ("DocStore Request".equals(req.getParameter("bulkIngestDataFormat"))) {
114                     bulkProcessRequest.setDataFormat(BulkProcessRequest.BulkIngestDataFormat.DOCSTORE);
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             } else if ("statistics".equals(req.getParameter("action"))) {
120                 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.STATUS);
121                 outputMessage(resp, bulkLoadStatistics.getJsonString());
122             } else if ("Stop".equals(req.getParameter("action"))) {
123                 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.STOP);
124                 outputMessage(resp, "Ingestion process has been stopped.");
125             } else if ("Clear Status".equals(req.getParameter("action"))) {
126                 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.CLEAR);
127             }
128             BeanLocator.getDocumentServiceImpl().bulkProcess(bulkProcessRequest);
129         } catch (Exception e) {
130             LOG.error("Bulk Ingest STARTUP Failed: ", e);
131             outputMessage(resp, "Problem in loading Bulk Ingest!\ncause:\n" + e.getMessage()
132                     + "\nPlease refer to Application log for further details!");
133         }
134     }
135 
136 
137     private void outputMessage(HttpServletResponse resp, String s) throws IOException {
138         PrintWriter out = resp.getWriter();
139         out.println(s);
140         out.flush();
141         out.close();
142     }
143 }