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 */ 016package org.kuali.ole.docstore.process; 017 018import org.apache.camel.CamelContext; 019import org.apache.camel.builder.RouteBuilder; 020import org.apache.camel.support.TokenXMLPairExpressionIterator; 021import org.kuali.ole.docstore.model.enums.DocCategory; 022import org.kuali.ole.docstore.model.enums.DocFormat; 023import org.kuali.ole.docstore.model.enums.DocType; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027/** 028 * Class BulkIngestDocStoreRequestBuilder. 029 * 030 * @author Rajesh Chowdary K 031 * @version 0.8 032 * @created Aug 1, 2012 033 */ 034public class BulkIngestDocStoreRequestBuilder 035 extends RouteBuilder { 036 037 private static Logger log = LoggerFactory.getLogger(BulkIngestDocStoreRequestBuilder.class); 038 private String folder = null; 039 private String user = null; 040 private String action = null; 041 private String category; 042 private String type; 043 private String format; 044 private String target; 045 046 /** 047 * Constructor. 048 * 049 * @param folder 050 * @param user 051 * @param action 052 * @param context 053 */ 054 public BulkIngestDocStoreRequestBuilder(String folder, String user, String action, CamelContext context, 055 String category, String type, String format, String target) { 056 super(context); 057 this.folder = folder; 058 this.user = user; 059 this.action = action; 060 this.category = category; 061 this.type = type; 062 this.format = format; 063 this.target = target; 064 } 065 066 /* 067 * (non-Javadoc) 068 * 069 * @see org.apache.camel.builder.RouteBuilder#configure() 070 */ 071 @Override 072 public void configure() throws Exception { 073 log.debug("Loading Bulk Ingest DocStore Request Builder Process @" + folder); 074 if (DocCategory.WORK.isEqualTo(category) && DocType.BIB.isEqualTo(type) && DocFormat.MARC.isEqualTo(format)) { 075 from("file:" + folder + "?noop=false&move=.done") 076 .split(new TokenXMLPairExpressionIterator("<record>", "</record>", "<collection>")) 077 .process(new BulkIngestDocumentReqProcessor(user, action, category, type, format, target)); 078 } else if (DocCategory.WORK.isEqualTo(category) && DocType.BIB.isEqualTo(type) && DocFormat.DUBLIN_CORE 079 .isEqualTo(format)) { 080 from("file:" + folder + "?noop=false&move=.done") 081 .split(new TokenXMLPairExpressionIterator("<dublin_core>", "</dublin_core>", "<>")) 082 .process(new BulkIngestDocumentReqProcessor(user, action, category, type, format, target)); 083 } else if (DocCategory.WORK.isEqualTo(category) && DocType.BIB.isEqualTo(type) && DocFormat.DUBLIN_UNQUALIFIED 084 .isEqualTo(format)) { 085 from("file:" + folder + "?noop=false&move=.done") 086 .split(new TokenXMLPairExpressionIterator("<record>", "</record>", "<ListRecords>")) 087 .process(new BulkIngestDocumentReqProcessor(user, action, category, type, format, target)); 088 } else { 089 log.error("Un Supported Document Category/Type/Format : " + category + "/" + type + "/" + format); 090 throw new Exception("Un Supported Document Category/Type/Format : " + category + "/" + type + "/" + format); 091 } 092 log.info("Loaded Bulk Ingest DocStore Request Builder Process @" + folder); 093 } 094 095}