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  
53      @Override
54      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
55          doPost(req, resp);
56      }
57  
58      @Override
59      protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
60          try {
61              /*if ("Start".equals(req.getParameter("action"))) {
62                  if ("DocStore Request".equals(req.getParameter("bulkIngestDataFormat"))) {
63                      if (bulkLoadHandler != null) {
64                          DocStoreCamelContext.getInstance().resume();
65                          outputMessage(resp, "Ingestion has started. Please check logs for further details");
66                      }
67                      else {
68                          bIService.startBulkIngestForDocStoreRequestFormat(req.getParameter("bulkIngestFolder1"));
69                          bulkLoadHandler = bIService.getLoadHandler();
70                          bulkIngestNIndexRouteBuilder = bulkLoadHandler.getBulkRoute();
71                          bulkIngestNIndexProcessor = bulkIngestNIndexRouteBuilder.getBulkIngestNIndexProcessor();
72                          bulkLoadStatistics = bulkIngestNIndexProcessor.getBulkLoadStatistics();
73                          DocStoreCamelContext.getInstance().resume();
74                      }
75                  }
76                  else if ("Standard Doc Format".equals(req.getParameter("bulkIngestDataFormat"))) {
77                      String folder = req.getParameter("bulkIngestFolder");
78                      if (folder != null && folder.trim().length() != 0) {
79                          bIService.startBulkIngestForStandardXMLFormat(req.getParameter("bulkIngestFolder"),
80                                                                        req.getParameter("bulkIngestDocCategory"),
81                                                                        req.getParameter("bulkIngestDocType"),
82                                                                        req.getParameter("bulkIngestDocFormat"),req.getParameter("bulkIngestFolder1"));
83                      }
84                      else {
85                          outputMessage(resp, "'Folder' field should not be empty.");
86                          return;
87                      }
88                  }
89                  outputMessage(resp, "Ingestion has started. Please check logs for further details");
90              }
91              else if ("statistics".equals(req.getParameter("action"))) {
92                  outputMessage(resp, bulkLoadStatistics.getJsonString());
93              }
94              else if ("Stop".equals(req.getParameter("action"))) {
95                  outputMessage(resp, "Ingestion process has been stopped.");
96                  DocStoreCamelContext.getInstance().suspend();
97              }
98              else if ("Clear Status".equals(req.getParameter("action"))) {
99                  bulkLoadStatistics.clearBulkIngestStatistics();
100             }*/
101             BulkProcessRequest bulkProcessRequest = new BulkProcessRequest();
102             bulkProcessRequest.setUser(req.getParameter("user"));
103             bulkProcessRequest.setOperation(BulkProcessRequest.BulkProcessOperation.INGEST);
104             bulkProcessRequest.setDataFolder(req.getParameter("bulkIngestFolder"));
105             bulkProcessRequest.setDocCategory(req.getParameter("bulkIngestDocCategory"));
106             bulkProcessRequest.setDocType(req.getParameter("bulkIngestDocType"));
107             bulkProcessRequest.setDocFormat(req.getParameter("bulkIngestDocFormat"));
108             bulkProcessRequest.setBulkIngestFolder(req.getParameter("bulkIngestFolder1"));
109             if ("Start".equals(req.getParameter("action"))) {
110                 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.START);
111                 outputMessage(resp, "Ingestion has started. Please check logs for further details");
112                 if ("DocStore Request".equals(req.getParameter("bulkIngestDataFormat"))) {
113                     bulkProcessRequest.setDataFormat(BulkProcessRequest.BulkIngestDataFormat.DOCSTORE);
114                 }
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             }
120             else if ("statistics".equals(req.getParameter("action"))) {
121                 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.STATUS);
122                 outputMessage(resp, bulkLoadStatistics.getJsonString());
123             }
124             else if ("Stop".equals(req.getParameter("action"))) {
125                 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.STOP);
126                 outputMessage(resp, "Ingestion process has been stopped.");
127             }
128             else if ("Clear Status".equals(req.getParameter("action"))) {
129                 bulkProcessRequest.setAction(BulkProcessRequest.BulkProcessAction.CLEAR);
130             }
131             BeanLocator.getDocumentServiceImpl().bulkProcess(bulkProcessRequest);
132         }
133         catch (Exception e) {
134             LOG.error("Bulk Ingest STARTUP Failed: ", e);
135             outputMessage(resp, "Problem in loading Bulk Ingest!\ncause:\n" + e.getMessage()
136                                 + "\nPlease refer to Application log for further details!");
137         }
138     }
139 
140 
141     private void outputMessage(HttpServletResponse resp, String s) throws IOException {
142         PrintWriter out = resp.getWriter();
143         out.println(s);
144         out.flush();
145         out.close();
146     }
147 }