001/* 002 * Copyright 2016 DuraSpace, Inc. 003 * 004 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 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.fcrepo.camel.fixity; 017 018import static org.slf4j.LoggerFactory.getLogger; 019 020import org.apache.camel.LoggingLevel; 021import org.apache.camel.builder.RouteBuilder; 022import org.apache.camel.builder.xml.Namespaces; 023import org.fcrepo.camel.RdfNamespaces; 024import org.slf4j.Logger; 025 026/** 027 * A content router for checking fixity of Binary resources. 028 * 029 * @author Aaron Coburn 030 * @since 2015-06-18 031 */ 032public class FixityRouter extends RouteBuilder { 033 034 private static final Logger LOGGER = getLogger(FixityRouter.class); 035 036 /** 037 * Configure the message route workflow. 038 */ 039 public void configure() throws Exception { 040 041 final Namespaces ns = new Namespaces("rdf", RdfNamespaces.RDF); 042 ns.add("premis", "http://www.loc.gov/premis/rdf/v1#"); 043 044 /** 045 * A generic error handler (specific to this RouteBuilder) 046 */ 047 onException(Exception.class) 048 .maximumRedeliveries("{{error.maxRedeliveries}}") 049 .log("Index Routing Error: ${routeId}"); 050 051 /** 052 * Handle fixity events 053 */ 054 from("{{fixity.stream}}") 055 .routeId("FcrepoFixity") 056 .to("fcrepo:{{fcrepo.baseUrl}}?preferInclude=ServerManged&accept=application/rdf+xml") 057 .filter().xpath( 058 "/rdf:RDF/rdf:Description/rdf:type" + 059 "[@rdf:resource='" + RdfNamespaces.REPOSITORY + "Binary']", ns) 060 .log(LoggingLevel.INFO, LOGGER, 061 "Checking Fixity for ${headers[CamelFcrepoIdentifier]}") 062 .delay(simple("{{fixity.delay}}")) 063 .to("fcrepo:{{fcrepo.baseUrl}}?fixity=true&accept=application/rdf+xml") 064 .choice() 065 .when().xpath( 066 "/rdf:RDF/rdf:Description/premis:hasEventOutcome" + 067 "[text()='SUCCESS']", ns) 068 .to("{{fixity.success}}") 069 .otherwise() 070 .log(LoggingLevel.WARN, LOGGER, 071 "Fixity error on ${headers[CamelFcrepoIdentifier]}") 072 .to("{{fixity.failure}}"); 073 } 074}