Skip to content

Commit

Permalink
Using filter() and correctly handling other containers that start wit…
Browse files Browse the repository at this point in the history
…h /audit
  • Loading branch information
escowles committed Apr 27, 2015
1 parent a8f9d91 commit 1266e95
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions audit-triplestore-web/README.md
Expand Up @@ -32,6 +32,12 @@ All configurable properties are stored in the `WEB-INF/classes/application.prope

In addition, many of these can be set from the external environment.

The name of the container where internal audit events are created (if using
[fcrepo-audit](http://github.com/fcrepo4-labs/fcrepo-audit)). Events about
resources in this container are ignored.

fcrepo.audit.container=/audit

In the event of failure, the maximum number of times a redelivery will be attempted.

fcrepo.audit.redeliveries (default=10)
Expand Down
6 changes: 6 additions & 0 deletions audit-triplestore/README.md
Expand Up @@ -35,6 +35,12 @@ The application can be configured by creating the following configuration
file `$KARAF_HOME/etc/org.fcrepo.camel.audit.cfg`. The following values
are available for configuration:

The name of the container where internal audit events are created (if using
[fcrepo-audit](http://github.com/fcrepo4-labs/fcrepo-audit)). Events about
resources in this container are ignored.

audit.container=/audit

In the event of failure, the maximum number of times a redelivery will be attempted.

error.maxRedeliveries=10
Expand Down
Expand Up @@ -15,7 +15,9 @@
*/
package org.fcrepo.camel.audit.triplestore;

import static org.fcrepo.camel.JmsHeaders.IDENTIFIER;
import static org.apache.camel.builder.PredicateBuilder.not;
import static org.apache.camel.builder.PredicateBuilder.or;

import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
Expand All @@ -24,6 +26,7 @@
* A content router for handling JMS events.
*
* @author Aaron Coburn
* @author escowles
*/
public class EventRouter extends RouteBuilder {

Expand All @@ -44,8 +47,8 @@ public void configure() throws Exception {
*/
from("activemq:{{jms.fcrepoEndpoint}}")
.routeId("AuditFcrepoRouter")
.choice()
.when(not(header("org.fcrepo.jms.identifier").startsWith(simple("{{audit.container}}"))))
.filter(not(or(header(IDENTIFIER).startsWith(simple("{{audit.container}}/")),
header(IDENTIFIER).isEqualTo(simple("{{audit.container}}")))))
.to("direct:event");

from("direct:event")
Expand Down
Expand Up @@ -51,7 +51,9 @@ public class RouteTest extends CamelBlueprintTestSupport {
private static final String baseURL = "http://localhost/rest";
private static final String nodeID = "/foo";
private static final String fileID = "/file1";
private static final String auditID = "/audit/1234";
private static final String auditContainer = "/audit";
private static final String auditNode = auditContainer + "/1234";
private static final String similarNode = auditContainer + "ions/1234";
private static final long timestamp = 1428360320168L;
private static final String eventDate = "2015-04-06T22:45:20Z";
private static final String userID = "bypassAdmin";
Expand Down Expand Up @@ -80,15 +82,18 @@ public void configure() throws Exception {
}
});

resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedMessageCount(2);
resultEndpoint.expectedHeaderReceived(Exchange.CONTENT_TYPE, "application/x-www-form-urlencoded");
resultEndpoint.expectedHeaderReceived(Exchange.HTTP_METHOD, "POST");
resultEndpoint.expectedHeaderReceived(AuditHeaders.EVENT_BASE_URI, "http://example.com/event");

final String eventTypes = REPOSITORY + "NODE_REMOVED";
final String eventProps = REPOSITORY + "hasContent";
template.sendBodyAndHeaders("", createEvent(fileID, eventTypes, eventProps));
template.sendBodyAndHeaders("", createEvent(auditID, eventTypes, eventProps));
template.sendBodyAndHeaders("", createEvent(similarNode, eventTypes, eventProps));
template.sendBodyAndHeaders("", createEvent(auditNode, REPOSITORY + "NODE_ADDED", REPOSITORY + "lastModified"));
template.sendBodyAndHeaders("", createEvent(auditContainer, REPOSITORY + "PROPERTY_CHANGED",
REPOSITORY + "lastModified"));

assertMockEndpointsSatisfied();
final String body = (String)resultEndpoint.assertExchangeReceived(0).getIn().getBody();
Expand Down

0 comments on commit 1266e95

Please sign in to comment.