001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.camel.fixity; 019 020import static org.slf4j.LoggerFactory.getLogger; 021 022import org.apache.camel.LoggingLevel; 023import org.apache.camel.builder.RouteBuilder; 024import org.apache.camel.builder.xml.Namespaces; 025import org.apache.jena.vocabulary.RDF; 026import org.slf4j.Logger; 027 028/** 029 * A content router for checking fixity of Binary resources. 030 * 031 * @author Aaron Coburn 032 * @since 2015-06-18 033 */ 034public class FixityRouter extends RouteBuilder { 035 036 private static final Logger LOGGER = getLogger(FixityRouter.class); 037 038 private static final String REPOSITORY = "http://fedora.info/definitions/v4/repository#"; 039 040 /** 041 * Configure the message route workflow. 042 */ 043 public void configure() throws Exception { 044 045 final Namespaces ns = new Namespaces("rdf", RDF.uri); 046 ns.add("premis", "http://www.loc.gov/premis/rdf/v1#"); 047 048 /** 049 * A generic error handler (specific to this RouteBuilder) 050 */ 051 onException(Exception.class) 052 .maximumRedeliveries("{{error.maxRedeliveries}}") 053 .log("Index Routing Error: ${routeId}"); 054 055 /** 056 * Handle fixity events 057 */ 058 from("{{fixity.stream}}") 059 .routeId("FcrepoFixity") 060 .to("fcrepo:{{fcrepo.baseUrl}}?preferInclude=ServerManged&accept=application/rdf+xml") 061 .filter().xpath( 062 "/rdf:RDF/rdf:Description/rdf:type" + 063 "[@rdf:resource='" + REPOSITORY + "Binary']", ns) 064 .log(LoggingLevel.INFO, LOGGER, 065 "Checking Fixity for ${headers[CamelFcrepoUri]}") 066 .delay(simple("{{fixity.delay}}")) 067 .to("fcrepo:{{fcrepo.baseUrl}}?fixity=true&accept=application/rdf+xml") 068 .choice() 069 .when().xpath( 070 "/rdf:RDF/rdf:Description/premis:hasEventOutcome" + 071 "[text()='SUCCESS']", ns) 072 .to("{{fixity.success}}") 073 .otherwise() 074 .log(LoggingLevel.WARN, LOGGER, 075 "Fixity error on ${headers[CamelFcrepoUri]}") 076 .to("{{fixity.failure}}"); 077 } 078}