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