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.audit.triplestore;
019
020import static org.fcrepo.camel.JmsHeaders.IDENTIFIER;
021import static org.apache.camel.builder.PredicateBuilder.not;
022import static org.apache.camel.builder.PredicateBuilder.or;
023
024import org.apache.camel.LoggingLevel;
025import org.apache.camel.builder.RouteBuilder;
026
027/**
028 * A content router for handling JMS events.
029 *
030 * @author Aaron Coburn
031 * @author escowles
032 */
033public class EventRouter extends RouteBuilder {
034
035    /**
036     * Configure the message route workflow.
037     */
038    public void configure() throws Exception {
039
040        /**
041         * A generic error handler (specific to this RouteBuilder)
042         */
043        onException(Exception.class)
044            .maximumRedeliveries("{{error.maxRedeliveries}}")
045            .log("Event Routing Error: ${routeId}");
046
047        /**
048         * Process a message.
049         */
050        from("{{input.stream}}")
051            .routeId("AuditFcrepoRouter")
052            .filter(not(or(header(IDENTIFIER).startsWith(simple("{{audit.container}}/")),
053                           header(IDENTIFIER).isEqualTo(simple("{{audit.container}}")))))
054                .to("direct:event");
055
056        from("direct:event")
057            .routeId("AuditEventRouter")
058            .setHeader(AuditHeaders.EVENT_BASE_URI, simple("{{event.baseUri}}"))
059            .process(new AuditSparqlProcessor())
060            .log(LoggingLevel.INFO, "org.fcrepo.camel.audit",
061                    "Audit Event: ${headers[org.fcrepo.jms.identifier]} :: ${headers[CamelAuditEventUri]}")
062            .to("{{triplestore.baseUrl}}?useSystemProperties=true");
063    }
064}