View Javadoc
1   /*
2    * Copyright 2012 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.docstore.service;
17  
18  import org.apache.camel.CamelContext;
19  import org.kuali.ole.docstore.process.BulkIngestDocStoreRequestBuilder;
20  import org.kuali.ole.docstore.process.BulkLoadHandler;
21  import org.kuali.ole.docstore.process.DocStoreCamelContext;
22  import org.kuali.ole.docstore.process.ProcessParameters;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  import java.util.HashSet;
27  import java.util.Set;
28  
29  /**
30   * Class BulkIngest Process Handler Service.
31   *
32   * @author Rajesh Chowdary K
33   * @version 0.8
34   * @created Aug 8, 2012
35   */
36  public class BulkIngestProcessHandlerService {
37  
38      private Logger logger = LoggerFactory.getLogger(BulkIngestProcessHandlerService.class);
39      private static Set<String> processMonitor = new HashSet<String>();
40      private BulkLoadHandler loadHandler = BulkLoadHandler.getInstance();
41  
42      /**
43       * Method to start Bulk Ingest Process for DocStore Request Format.
44       *
45       * @throws Exception
46       */
47      public void startBulkIngestForDocStoreRequestFormat(String folder) throws Exception {
48          loadHandler.loadBulk(folder, ProcessParameters.BULK_DEFAULT_USER, ProcessParameters.BULK_DEFUALT_ACTION);
49      }
50  
51      /**
52       * Method to start Bulk Ingest Process For Standard XML Format.
53       *
54       * @param folder
55       * @param category
56       * @param type
57       * @param format
58       * @throws Exception
59       */
60      public void startBulkIngestForStandardXMLFormat(String folder, String category, String type, String format,
61                                                      String bulkIngestUploadDir) throws Exception {
62          String cmd = category + "/" + type + "/" + format + "@" + folder;
63          try {
64              logger.info("Bulk Ingest Process for " + cmd + " \t\t: STARTING...");
65              if (processMonitor.contains(cmd)) {
66                  throw new Exception("Process Already Running : " + cmd);
67              }
68              CamelContext camelContext = DocStoreCamelContext.getInstance().getCamelContext();
69              BulkIngestDocStoreRequestBuilder builder = new BulkIngestDocStoreRequestBuilder(folder,
70                      ProcessParameters.BULK_DEFAULT_USER,
71                      ProcessParameters.BULK_DEFUALT_ACTION,
72                      camelContext, category,
73                      type, format,
74                      bulkIngestUploadDir);
75              camelContext.addRoutes(builder);
76              camelContext.start();
77              processMonitor.add(cmd);
78              logger.info("Bulk Ingest Process for " + cmd + " \t\t: STARTED");
79          } catch (Exception e) {
80              logger.error("Unable to Start Bulk Ingest Process for " + cmd + ".\n Cuase: " + e.getMessage(), e);
81              throw new Exception("Unable to Start Bulk Ingest Process for " + cmd + ".\n Cuase: " + e.getMessage(), e);
82          }
83  
84      }
85  
86      public BulkLoadHandler getLoadHandler() {
87          return loadHandler;
88      }
89  
90      public void setLoadHandler(BulkLoadHandler loadHandler) {
91          this.loadHandler = loadHandler;
92      }
93  }