Commit 0d8a5a9c authored by acoburn's avatar acoburn
Browse files

update interface for pcdm service

parent 3ea021a4
...@@ -6,6 +6,10 @@ an RDF graph of the complete object (following `pcdm:hasMember`, ...@@ -6,6 +6,10 @@ an RDF graph of the complete object (following `pcdm:hasMember`,
`pcdm:hasRelatedObject` and `pcdm:hasFile` links). The complete `pcdm:hasRelatedObject` and `pcdm:hasFile` links). The complete
graph is returned in the requested serialization, using an `Accept` header. graph is returned in the requested serialization, using an `Accept` header.
For example:
curl http://localhost:9107/pcdm?context=http://localhost:8080/fcrepo/rest/a/b/c
Building Building
-------- --------
......
...@@ -22,7 +22,7 @@ jar { ...@@ -22,7 +22,7 @@ jar {
vendor project.vendor vendor project.vendor
license project.license license project.license
instruction 'Import-Package', "org.apache.camel,edu.amherst.acdc.services.pcdm,${defaultOsgiImports}" instruction 'Import-Package', "org.apache.camel,org.fcrepo.camel,edu.amherst.acdc.services.pcdm,${defaultOsgiImports}"
instruction 'Export-Package', "edu.amherst.acdc.exts.pcdm;version=${projectOsgiVersion}" instruction 'Export-Package', "edu.amherst.acdc.exts.pcdm;version=${projectOsgiVersion}"
} }
} }
......
...@@ -8,6 +8,8 @@ pcdm.concurrency=10 ...@@ -8,6 +8,8 @@ pcdm.concurrency=10
# Repository Base URL (it MUST start with http:// or https://) # Repository Base URL (it MUST start with http:// or https://)
fcrepo.baseUrl=http://localhost:8080/fcrepo/rest fcrepo.baseUrl=http://localhost:8080/fcrepo/rest
fcrepo.authUsername=
fcrepo.authPassword=
# API-X configuration # API-X configuration
extension.load=true extension.load=true
......
...@@ -18,10 +18,9 @@ package edu.amherst.acdc.exts.pcdm; ...@@ -18,10 +18,9 @@ package edu.amherst.acdc.exts.pcdm;
import static java.util.Optional.ofNullable; import static java.util.Optional.ofNullable;
import static org.apache.camel.Exchange.CONTENT_TYPE; import static org.apache.camel.Exchange.CONTENT_TYPE;
import static org.apache.camel.Exchange.HTTP_METHOD; import static org.apache.camel.Exchange.HTTP_METHOD;
import static org.apache.camel.Exchange.HTTP_PATH;
import static org.apache.camel.Exchange.HTTP_RESPONSE_CODE; import static org.apache.camel.Exchange.HTTP_RESPONSE_CODE;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_IDENTIFIER;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_BASE_URL; import static org.fcrepo.camel.FcrepoHeaders.FCREPO_BASE_URL;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_URI;
import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_ACCEPT; import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_ACCEPT;
import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_SUBJECT; import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_SUBJECT;
...@@ -39,6 +38,7 @@ import org.apache.jena.riot.RDFLanguages; ...@@ -39,6 +38,7 @@ import org.apache.jena.riot.RDFLanguages;
public class PcdmRouter extends RouteBuilder { public class PcdmRouter extends RouteBuilder {
private final static String DEFAULT_CONTENT_TYPE = "text/turtle"; private final static String DEFAULT_CONTENT_TYPE = "text/turtle";
private final static String HTTP_QUERY_CONTEXT = "context";
/** /**
* Configure the message route workflow. * Configure the message route workflow.
...@@ -46,25 +46,26 @@ public class PcdmRouter extends RouteBuilder { ...@@ -46,25 +46,26 @@ public class PcdmRouter extends RouteBuilder {
public void configure() throws Exception { public void configure() throws Exception {
from("jetty:http://{{rest.host}}:{{rest.port}}{{rest.prefix}}?" + from("jetty:http://{{rest.host}}:{{rest.port}}{{rest.prefix}}?" +
"matchOnUriPrefix=true&sendServerVersion=false&httpMethodRestrict=GET,OPTIONS") "sendServerVersion=false&httpMethodRestrict=GET,OPTIONS")
.routeId("PcdmRouter") .routeId("PcdmRouter")
.removeHeader("User-Agent") .removeHeader("User-Agent")
.process(e -> e.getIn().setHeader(FCREPO_URI,
e.getIn().getHeader(HTTP_QUERY_CONTEXT,
e.getIn().getHeader("Apix-Ldp-Resource"))))
.setHeader(FCREPO_BASE_URL).simple("{{fcrepo.baseUrl}}")
.choice() .choice()
.when(header(HTTP_METHOD).isEqualTo("GET"))
.to("direct:get")
.when(header(HTTP_METHOD).isEqualTo("OPTIONS")) .when(header(HTTP_METHOD).isEqualTo("OPTIONS"))
.setHeader(CONTENT_TYPE).constant("text/turtle") .setHeader(CONTENT_TYPE).constant("text/turtle")
.setHeader("Allow").constant("GET,OPTIONS") .setHeader("Allow").constant("GET,OPTIONS")
.to("language:simple:resource:classpath:options.ttl"); .to("language:simple:resource:classpath:options.ttl")
.when(header(HTTP_QUERY_CONTEXT).startsWith(header(FCREPO_BASE_URL)))
.to("direct:get");
from("direct:get") from("direct:get")
.routeId("PcdmGet") .routeId("PcdmGet")
.setHeader(PCDM_ACCEPT, header("Accept")) .setHeader(PCDM_ACCEPT, header("Accept"))
.process(e -> e.getIn().setBody(
e.getIn().getHeader("Apix-Ldp-Resource-Path",
e.getIn().getHeader(HTTP_PATH))))
.log("Building PCDM Object ${body}") .log("Building PCDM Object ${body}")
.setHeader(FCREPO_BASE_URL).simple("{{fcrepo.baseUrl}}") .setBody().header(FCREPO_URI)
.to("seda:recurse") .to("seda:recurse")
.removeHeader("breadcrumbId") .removeHeader("breadcrumbId")
.process(exchange -> { .process(exchange -> {
...@@ -77,12 +78,12 @@ public class PcdmRouter extends RouteBuilder { ...@@ -77,12 +78,12 @@ public class PcdmRouter extends RouteBuilder {
from("seda:recurse?concurrentConsumers={{pcdm.concurrency}}") from("seda:recurse?concurrentConsumers={{pcdm.concurrency}}")
.routeId("PcdmBuildRecursive") .routeId("PcdmBuildRecursive")
.setHeader(FCREPO_IDENTIFIER, body()) .setHeader(FCREPO_URI, body())
.to("direct:getResource") .to("direct:getResource")
.filter(header(HTTP_RESPONSE_CODE).isEqualTo(200)) .filter(header(HTTP_RESPONSE_CODE).isEqualTo(200))
.log("Getting related resources for ${headers[CamelFcrepoIdentifier]}") .log("Getting related resources for ${headers[CamelFcrepoUri]}")
.to("direct:parse") .to("direct:parse")
.setHeader(PCDM_SUBJECT).simple("${headers.CamelFcrepoBaseUrl}${headers.CamelFcrepoIdentifier}") .setHeader(PCDM_SUBJECT).header(FCREPO_URI)
.to("direct:members") .to("direct:members")
.to("direct:files") .to("direct:files")
.to("direct:relatedObjects") .to("direct:relatedObjects")
...@@ -94,7 +95,6 @@ public class PcdmRouter extends RouteBuilder { ...@@ -94,7 +95,6 @@ public class PcdmRouter extends RouteBuilder {
.routeId("PcdmResource") .routeId("PcdmResource")
.removeHeader("breadcrumbId") .removeHeader("breadcrumbId")
.removeHeader("Accept") .removeHeader("Accept")
.setHeader(FCREPO_BASE_URL).simple("{{fcrepo.baseUrl}}")
.to("fcrepo:{{fcrepo.baseUrl}}?throwExceptionOnFailure=false"); .to("fcrepo:{{fcrepo.baseUrl}}?throwExceptionOnFailure=false");
} }
} }
...@@ -16,11 +16,9 @@ ...@@ -16,11 +16,9 @@
package edu.amherst.acdc.exts.pcdm; package edu.amherst.acdc.exts.pcdm;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toSet;
import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_FILES; import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_FILES;
import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_MEMBERS; import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_MEMBERS;
import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_RELATED_OBJECTS; import static edu.amherst.acdc.exts.pcdm.PcdmHeaders.PCDM_RELATED_OBJECTS;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_BASE_URL;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
import java.util.List; import java.util.List;
...@@ -56,8 +54,6 @@ class RelatedProcessor implements Processor { ...@@ -56,8 +54,6 @@ class RelatedProcessor implements Processor {
ids.addAll(files); ids.addAll(files);
ids.addAll(relatedObjects); ids.addAll(relatedObjects);
exchange.getIn().setBody(ids.stream() exchange.getIn().setBody(ids);
.map(id -> id.replace(exchange.getIn().getHeader(FCREPO_BASE_URL, "", String.class), ""))
.collect(toSet()));
} }
} }
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
<cm:property name="rest.host" value="localhost"/> <cm:property name="rest.host" value="localhost"/>
<cm:property name="pcdm.concurrency" value="10"/> <cm:property name="pcdm.concurrency" value="10"/>
<cm:property name="fcrepo.baseUrl" value="http://localhost:8080/fcrepo/rest"/> <cm:property name="fcrepo.baseUrl" value="http://localhost:8080/fcrepo/rest"/>
<cm:property name="fcrepo.authUsername" value=""/>
<cm:property name="fcrepo.authPassword" value=""/>
<cm:property name="extension.load" value="true" /> <cm:property name="extension.load" value="true" />
<cm:property name="extension.load.uri" value="http://apix/services//apix:load" /> <cm:property name="extension.load.uri" value="http://apix/services//apix:load" />
<cm:property name="extension.load.maximumRedeliveries" value="60" /> <cm:property name="extension.load.maximumRedeliveries" value="60" />
...@@ -23,6 +25,12 @@ ...@@ -23,6 +25,12 @@
<reference id="pcdmService" interface="edu.amherst.acdc.services.pcdm.PcdmService" filter="(osgi.jndi.service.name=acrepo/Pcdm)" /> <reference id="pcdmService" interface="edu.amherst.acdc.services.pcdm.PcdmService" filter="(osgi.jndi.service.name=acrepo/Pcdm)" />
<bean id="fcrepo" class="org.fcrepo.camel.FcrepoComponent">
<property name="authUsername" value="${fcrepo.authUsername}"/>
<property name="authPassword" value="${fcrepo.authPassword}"/>
<property name="baseUrl" value="${fcrepo.baseUrl}"/>
</bean>
<camelContext id="AcrepoExtPcdm" xmlns="http://camel.apache.org/schema/blueprint"> <camelContext id="AcrepoExtPcdm" xmlns="http://camel.apache.org/schema/blueprint">
<package>edu.amherst.acdc.exts.pcdm</package> <package>edu.amherst.acdc.exts.pcdm</package>
...@@ -60,7 +68,7 @@ ...@@ -60,7 +68,7 @@
<method ref="pcdmService" method="serialize(${header[CamelPcdmModel]}, ${header[CamelPcdmAccept]})"/> <method ref="pcdmService" method="serialize(${header[CamelPcdmModel]}, ${header[CamelPcdmAccept]})"/>
</setBody> </setBody>
</route> </route>
<!-- Self-register the loader service as an extension --> <!-- Self-register the loader service as an extension -->
<route id="load-extension"> <route id="load-extension">
<from uri="timer:register?repeatCount=1" /> <from uri="timer:register?repeatCount=1" />
......
@prefix owl:<http://www.w3.org/2002/07/owl#> . @prefix owl:<http://www.w3.org/2002/07/owl#> .
@prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#> . @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#> .
@prefix fedora:<http://fedora.info/definitions/v4/repository#> . @prefix registry:<http://acdc.amherst.edu/ns/extensions#> .
@prefix registry:<http://acdc.amherst.edu/extensions#> .
@prefix pcdm:<http://pcdm.org/models#> . @prefix pcdm:<http://pcdm.org/models#> .
@prefix apix:<http://fedora.info/definitions/v4/api-extension#> . @prefix apix:<http://fedora.info/definitions/v4/api-extension#> .
......
...@@ -139,7 +139,7 @@ public class AcrepoPcdmIT extends AbstractOSGiIT { ...@@ -139,7 +139,7 @@ public class AcrepoPcdmIT extends AbstractOSGiIT {
final String page3 = post(members); final String page3 = post(members);
final String page4 = post(members); final String page4 = post(members);
final String response = get(baseSvcUrl + pcdmObj.replace(baseUrl, "")); final String response = get(baseSvcUrl + "?context=" + pcdmObj);
final InputStream input = new ByteArrayInputStream(response.getBytes(UTF_8)); final InputStream input = new ByteArrayInputStream(response.getBytes(UTF_8));
final Model model = createDefaultModel(); final Model model = createDefaultModel();
...@@ -173,7 +173,7 @@ public class AcrepoPcdmIT extends AbstractOSGiIT { ...@@ -173,7 +173,7 @@ public class AcrepoPcdmIT extends AbstractOSGiIT {
final String page3 = post(members); final String page3 = post(members);
final String page4 = post(members); final String page4 = post(members);
final String response = get(baseSvcUrl + pcdmObj.replace(baseUrl, ""), "application/ld+json"); final String response = get(baseSvcUrl + "?context=" + pcdmObj, "application/ld+json");
final InputStream input = new ByteArrayInputStream(response.getBytes(UTF_8)); final InputStream input = new ByteArrayInputStream(response.getBytes(UTF_8));
final Model model = createDefaultModel(); final Model model = createDefaultModel();
......
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