Commit ad52095c authored by acoburn's avatar acoburn
Browse files

Merge branch 'template_customization'

parents 32602d55 b9aac260
......@@ -106,6 +106,7 @@
<feature version="${camel.version}">camel-blueprint</feature>
<feature version="${camel.version}">camel-mustache</feature>
<feature version="${camel.version}">camel-jetty9</feature>
<feature version="${camel.version}">camel-jackson</feature>
<feature version="${camel.version}">camel-http4</feature>
<feature version="${fcrepo-camel.version}">fcrepo-camel</feature>
<feature version="${project.version}">acrepo-jsonld-cache</feature>
......
Amherst College XML-based metadata transformation service
=========================================================
Amherst College Template Rendering Service
==========================================
This service implements a translation service from Fedora RDF-based metadata
to either a DC/XML or MODS/XML serialization. This translation relies on
pluggable XSLT 2.0 documents.
This service renders fedora resources using a Mustache template.
The service becomes available over HTTP on the configured port. For example,
in order to retrieve a MODS version of the resource `a/b/c`:
curl localhost:9070/mods/a/b/c
And the DC version:
curl localhost:9070/dc/a/b/c
curl localhost:9070/template/a/b/c
Building
--------
......@@ -21,10 +15,6 @@ To build this project use
mvn install
To run the project you can execute the following Maven goal
mvn camel:run
Deploying in OSGi
-----------------
......@@ -33,7 +23,7 @@ This project can be deployed in an OSGi container. For example using
command from its shell:
feature:repo-add mvn:edu.amherst.acdc/repository-services/LATEST/xml/features
feature:install acrepo-xml-metadata
feature:install acrepo-template-mustache
Or by copying the compiled bundle into `$KARAF_HOME/deploy`.
......@@ -41,32 +31,40 @@ Configuration
-------------
The application can be configured by creating the following configuration
file `$KARAF_HOME/etc/edu.amherst.acdc.xml.metadata.cfg`. The following values
file `$KARAF_HOME/etc/edu.amherst.acdc.template.mustache.cfg`. The following values
are available for configuration:
In the event of failure, the maximum number of times a redelivery will be attempted.
error.maxRedeliveries=10
The location of the XSLT document for MODS. This can be a file path (using the `file:` prefix)
or an external URL (e.g. using a `http:` scheme). Without a prefix, the XSL file will
be loaded from the classpath.
The port on which the service is available
mods.xslt=edu/amherst/acdc/xml/metadata/rdf2mods.xsl
rest.port=13433
The location of the XSLT document for DC. This can be a file path (using the `file:` prefix)
or an external URL (e.g. using a `http:` scheme). Without a prefix, the XSL file will
be loaded from the classpath.
The fedora baseUrl value
dc.xslt=edu/amherst/acdc/xml/metadata/rdf2dc.xsl
fcrepo.baseUrl=localhost:8080/fcrepo/rest
The port on which the service is available
The location of the mustache template
rest.port=9070
mustache.template=edu/amherst/acdc/template/mustache/template.mustache
The fedora baseUrl value
The content-type of the rendered template
fcrepo.baseUrl=localhost:8080/fcrepo/rest
mustache.contentType=text/html
The json+ld context file
jsonld.context=https://acdc.amherst.edu/jsonld/context.json
The riak caching datastore host
riak.host=localhost:8098
The riak caching datastore bucket name
riak.bucket=fcrepo
By editing this file, any currently running routes will be immediately redeployed
with the new values.
......
......@@ -35,6 +35,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-http4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mustache</artifactId>
......
......@@ -7,6 +7,15 @@ rest.port=13433
# The fedora baseUrl
fcrepo.baseUrl=localhost:8080/fcrepo/rest
# The resulting content-type
mustache.contentType=text/html
# The mustache template
mustache.contentType=edu/amherst/acdc/template/mustache/template.mustache
# The json+ld context file
jsonld.context=https://acdc.amherst.edu/jsonld/context.json
# The host and prefix of the riak cluster
riak.host=localhost:8098
riak.bucket=fcrepo
......@@ -13,11 +13,15 @@
*/
package edu.amherst.acdc.template.mustache;
import static org.apache.camel.Exchange.CONTENT_TYPE;
import static org.apache.camel.Exchange.HTTP_RESPONSE_CODE;
import static org.apache.camel.Exchange.HTTP_URL;
import static org.apache.camel.Exchange.HTTP_URI;
import static org.apache.camel.Exchange.HTTP_URL;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_IDENTIFIER;
import java.util.Map;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.apache.camel.builder.RouteBuilder;
import edu.amherst.acdc.jsonld.cache.RiakKeyBuilder;
......@@ -67,8 +71,9 @@ public class EventRouter extends RouteBuilder {
from("direct:template")
.routeId("TemplateRoute")
.setHeader(CONTENT_TYPE).simple("{{mustache.contentType}}")
.unmarshal().json(JsonLibrary.Jackson, Map.class)
.to("mustache:{{mustache.template}}");
}
}
......@@ -13,6 +13,7 @@
<cm:property name="error.maxRedeliveries" value="10"/>
<cm:property name="rest.port" value="13433"/>
<cm:property name="mustache.template" value="edu/amherst/acdc/template/mustache/template.mustache"/>
<cm:property name="mustache.contentType" value="text/html"/>
<cm:property name="jsonld.context" value="https://acdc.amherst.edu/jsonld/context.json"/>
<cm:property name="fcrepo.baseUrl" value="localhost:8080/fcrepo/rest"/>
<cm:property name="riak.host" value="localhost:8098"/>
......
Hello Fedora {{body}}
<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns#">
<head>
<title>{{body.title}}</title>
</head>
<body>
<h1>Fedora Template Service: {{body.title}}</h1>
<p>{{body.description}}</p>
</body>
</html>
package edu.amherst.acdc.template.mustache;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.junit.Test;
......@@ -9,17 +14,47 @@ import org.junit.Test;
*/
public class RouteTest extends CamelBlueprintTestSupport {
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Produce(uri = "direct:template")
protected ProducerTemplate template;
@Override
protected String getBlueprintDescriptor() {
return "/OSGI-INF/blueprint/blueprint.xml";
}
@Override
public boolean isUseAdviceWith() {
return true;
}
@Override
public boolean isUseRouteBuilder() {
return false;
}
@Test
public void testRoute() throws Exception {
getMockEndpoint("mock:result").expectedMinimumMessageCount(0);
context.getRouteDefinition("TemplateRoute").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveAddLast().to("mock:result");
}
});
context.start();
resultEndpoint.expectedMinimumMessageCount(1);
resultEndpoint.expectedHeaderReceived("Content-Type", "text/html");
resultEndpoint.allMessages().body().contains("Fedora Template Service: Foo");
resultEndpoint.allMessages().body().contains("<p>sample description</p>");
template.sendBody("{\"title\" : \"Foo\", \"description\" : \"sample description\"}");
// assert expectations
assertMockEndpointsSatisfied();
}
}
......@@ -67,6 +67,11 @@
<artifactId>camel-blueprint</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mustache</artifactId>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment