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.docstore.process;
17  
18  import org.apache.camel.CamelContext;
19  import org.apache.camel.builder.RouteBuilder;
20  import org.apache.camel.support.TokenXMLPairExpressionIterator;
21  import org.kuali.ole.docstore.model.enums.DocCategory;
22  import org.kuali.ole.docstore.model.enums.DocFormat;
23  import org.kuali.ole.docstore.model.enums.DocType;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  /**
28   * Class BulkIngestDocStoreRequestBuilder.
29   *
30   * @author Rajesh Chowdary K
31   * @version 0.8
32   * @created Aug 1, 2012
33   */
34  public class BulkIngestDocStoreRequestBuilder
35          extends RouteBuilder {
36  
37      private static Logger log    = LoggerFactory.getLogger(BulkIngestDocStoreRequestBuilder.class);
38      private        String folder = null;
39      private        String user   = null;
40      private        String action = null;
41      private String category;
42      private String type;
43      private String format;
44      private String target;
45  
46      /**
47       * Constructor.
48       *
49       * @param folder
50       * @param user
51       * @param action
52       * @param context
53       */
54      public BulkIngestDocStoreRequestBuilder(String folder, String user, String action, CamelContext context,
55                                              String category, String type, String format, String target) {
56          super(context);
57          this.folder = folder;
58          this.user = user;
59          this.action = action;
60          this.category = category;
61          this.type = type;
62          this.format = format;
63          this.target = target;
64      }
65  
66      /*
67       * (non-Javadoc)
68       * 
69       * @see org.apache.camel.builder.RouteBuilder#configure()
70       */
71      @Override
72      public void configure() throws Exception {
73          log.debug("Loading Bulk Ingest DocStore Request Builder Process @" + folder);
74          if (DocCategory.WORK.isEqualTo(category) && DocType.BIB.isEqualTo(type) && DocFormat.MARC.isEqualTo(format)) {
75              from("file:" + folder + "?noop=false&move=.done")
76                      .split(new TokenXMLPairExpressionIterator("<record>", "</record>", "<collection>"))
77                      .process(new BulkIngestDocumentReqProcessor(user, action, category, type, format, target));
78          }
79          else if (DocCategory.WORK.isEqualTo(category) && DocType.BIB.isEqualTo(type) && DocFormat.DUBLIN_CORE
80                  .isEqualTo(format)) {
81              from("file:" + folder + "?noop=false&move=.done")
82                      .split(new TokenXMLPairExpressionIterator("<dublin_core>", "</dublin_core>", "<>"))
83                      .process(new BulkIngestDocumentReqProcessor(user, action, category, type, format, target));
84          }
85          else if (DocCategory.WORK.isEqualTo(category) && DocType.BIB.isEqualTo(type) && DocFormat.DUBLIN_UNQUALIFIED
86                  .isEqualTo(format)) {
87              from("file:" + folder + "?noop=false&move=.done")
88                      .split(new TokenXMLPairExpressionIterator("<record>", "</record>", "<ListRecords>"))
89                      .process(new BulkIngestDocumentReqProcessor(user, action, category, type, format, target));
90          }
91          else {
92              log.error("Un Supported Document Category/Type/Format : " + category + "/" + type + "/" + format);
93              throw new Exception("Un Supported Document Category/Type/Format : " + category + "/" + type + "/" + format);
94          }
95          log.info("Loaded Bulk Ingest DocStore Request Builder Process @" + folder);
96      }
97  
98  }