Skip to content

Commit

Permalink
globbing a node path to support hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Apr 23, 2013
1 parent 75e327d commit 95dcaa5
Show file tree
Hide file tree
Showing 26 changed files with 504 additions and 183 deletions.
Expand Up @@ -15,6 +15,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;

import org.fcrepo.AbstractResource;
Expand All @@ -24,7 +25,7 @@
import org.springframework.stereotype.Component;

@Component
@Path("/oai/objects/{pid}/oai_dc")
@Path("/oai/{path: .*(?!(oai_dc))}/oai_dc")
public class DublinCoreGenerator extends AbstractResource {

@Resource
Expand All @@ -35,10 +36,11 @@ public class DublinCoreGenerator extends AbstractResource {

@GET
@Produces(TEXT_XML)
public Response getObjectAsDublinCore(@PathParam("pid")
final String pid) throws RepositoryException {

final Node obj = objectService.getObjectNode(pid);
public Response getObjectAsDublinCore(@PathParam("path")
final List<PathSegment> pathList) throws RepositoryException {

final String path = toPath(pathList);
final Node obj = objectService.getObjectNode(path);

for (final DCGenerator indexer : dcgenerators) {
final InputStream inputStream = indexer.getStream(obj);
Expand Down
@@ -1,8 +1,7 @@
package org.fcrepo.generator;

import static org.mockito.Mockito.*;
import static org.mockito.Matchers.any;

import static org.fcrepo.test.util.PathSegmentImpl.createPathList;
import static org.junit.Assert.fail;

import java.io.InputStream;
Expand Down Expand Up @@ -37,15 +36,15 @@ public void testGetObjectAsDublinCore() throws RepositoryException {
testObj.dcgenerators = Arrays.asList(new DCGenerator[]{mockGenerator});
InputStream mockIS = mock(InputStream.class);
when(mockGenerator.getStream(any(Node.class))).thenReturn(mockIS);
testObj.getObjectAsDublinCore("foo");
testObj.getObjectAsDublinCore(createPathList("objects","foo"));

}

@Test
public void testNoGenerators() {
testObj.dcgenerators = Arrays.asList(new DCGenerator[0]);
try {
testObj.getObjectAsDublinCore("foo");
testObj.getObjectAsDublinCore(createPathList("objects","foo"));
fail("Should have failed without a generator configured!");
} catch (PathNotFoundException ex) {
// this is what we expect
Expand Down
Expand Up @@ -60,13 +60,13 @@ protected static HttpPost postDSMethod(final String pid, final String ds,
final String content) throws UnsupportedEncodingException {
final HttpPost post =
new HttpPost(serverAddress + "objects/" + pid +
"/datastreams/" + ds);
"/fcr:datastreams/" + ds);
post.setEntity(new StringEntity(content));
return post;
}

protected static HttpPut putDSMethod(final String pid, final String ds) {
return new HttpPut(serverAddress + "objects/" + pid + "/datastreams/" +
return new HttpPut(serverAddress + "objects/" + pid + "/fcr:datastreams/" +
ds);
}

Expand Down
Expand Up @@ -24,6 +24,7 @@ public void testJcrPropertiesBasedOaiDc() throws Exception {
new HttpGet(serverOAIAddress + "objects/DublinCoreTest1/oai_dc");
getWorstCaseOaiMethod.setHeader("Accept", TEXT_XML);
final HttpResponse response = client.execute(getWorstCaseOaiMethod);

assertEquals(200, response.getStatusLine().getStatusCode());

final String content = EntityUtils.toString(response.getEntity());
Expand Down
Expand Up @@ -16,6 +16,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.PathSegment;

import org.apache.any23.extractor.ExtractionContext;
import org.apache.any23.writer.TripleHandler;
Expand All @@ -31,11 +32,10 @@
import org.openrdf.sail.memory.model.MemValueFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Path("/rest/objects/{pid}/datastreams/{dsid}/rdf")
@Path("/rest/{path: .*(?!(fcr\\:))}/fcr:datastreams/{dsid}/fcr:rdf")
@Produces({TEXT_XML, "text/turtle", TEXT_PLAIN})
public class DatastreamRdfGenerator extends AbstractResource {

Expand All @@ -49,15 +49,16 @@ public class DatastreamRdfGenerator extends AbstractResource {
@GET
@Path("/")
@Produces({TEXT_XML, "text/turtle", TEXT_PLAIN})
public String getRdfXml(@PathParam("pid")
final String pid, @PathParam("dsid")
public String getRdfXml(@PathParam("path")
final List<PathSegment> pathList, @PathParam("dsid")
final String dsId, @HeaderParam("Accept")
@DefaultValue(TEXT_XML)
final String mimeType) throws IOException, RepositoryException,
TripleHandlerException {

final Datastream ds = datastreamService.getDatastream(pid, dsId);
final URI docURI = valFactory.createURI("info:" + pid + "/" + dsId);
final String path = toPath(pathList);
final Datastream ds = datastreamService.getDatastream(path, dsId);
final URI docURI = valFactory.createURI("info:" + path + "/" + dsId);
logger.debug("Using ValueFactory: " + valFactory.toString());
final ExtractionContext context =
new ExtractionContext("Fedora Serialization Context", docURI);
Expand Down
Expand Up @@ -17,6 +17,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.PathSegment;

import org.apache.any23.extractor.ExtractionContext;
import org.apache.any23.writer.TripleHandler;
Expand All @@ -33,7 +34,7 @@
import org.springframework.stereotype.Component;

@Component
@Path("/rest/objects/{pid}/rdf")
@Path("/rest/{path: .*(?!(fcr\\:))}/fcr:rdf")
@Produces({TEXT_XML, "text/turtle", TEXT_PLAIN})
public class ObjectRdfGenerator extends AbstractResource {

Expand All @@ -46,14 +47,15 @@ public class ObjectRdfGenerator extends AbstractResource {
@GET
@Path("/")
@Produces({TEXT_XML, "text/turtle", TEXT_PLAIN})
public String getRdfXml(@PathParam("pid")
final String pid, @HeaderParam("Accept")
public String getRdfXml(@PathParam("path")
final List<PathSegment> pathList, @HeaderParam("Accept")
@DefaultValue(TEXT_XML)
final String mimeType) throws IOException, RepositoryException,
TripleHandlerException {

final FedoraObject obj = objectService.getObject(pid);
final URI docURI = valFactory.createURI("info:" + pid);
final String path = toPath(pathList);
final FedoraObject obj = objectService.getObject(path);
final URI docURI = valFactory.createURI("info:" + path);
logger.debug("Using ValueFactory: " + valFactory.toString());
final ExtractionContext context =
new ExtractionContext("Fedora Serialization Context", docURI);
Expand Down
Expand Up @@ -57,13 +57,13 @@ protected static HttpPost postDSMethod(final String pid, final String ds,
final String content) throws UnsupportedEncodingException {
final HttpPost post =
new HttpPost(serverAddress + "objects/" + pid +
"/datastreams/" + ds);
"/fcr:datastreams/" + ds);
post.setEntity(new StringEntity(content));
return post;
}

protected static HttpPut putDSMethod(final String pid, final String ds) {
return new HttpPut(serverAddress + "objects/" + pid + "/datastreams/" +
return new HttpPut(serverAddress + "objects/" + pid + "/fcr:datastreams/" +
ds);
}

Expand Down
Expand Up @@ -6,6 +6,7 @@
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.fcrepo.test.util.PathSegmentImpl.createPathList;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
Expand All @@ -24,7 +25,7 @@ public void testXMLObjectTriples() throws Exception {
client.execute(postObjMethod("RdfTest1"));

final HttpGet getRdfMethod =
new HttpGet(serverAddress + "objects/RdfTest1/rdf");
new HttpGet(serverAddress + "objects/RdfTest1/fcr:rdf");
getRdfMethod.setHeader("Accept", TEXT_XML);
final HttpResponse response = client.execute(getRdfMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
Expand All @@ -44,7 +45,7 @@ public void testNTriplesObjectTriples() throws Exception {
client.execute(postObjMethod("RdfTest2"));

final HttpGet getRdfMethod =
new HttpGet(serverAddress + "objects/RdfTest2/rdf");
new HttpGet(serverAddress + "objects/RdfTest2/fcr:rdf");
final HttpResponse response = client.execute(getRdfMethod);
assertEquals(200, response.getStatusLine().getStatusCode());

Expand All @@ -61,7 +62,7 @@ public void testTurtleObjectTriples() throws Exception {
client.execute(postObjMethod("RdfTest3"));

final HttpGet getRdfMethod =
new HttpGet(serverAddress + "objects/RdfTest3/rdf");
new HttpGet(serverAddress + "objects/RdfTest3/fcr:rdf");
getRdfMethod.setHeader("Accept", "text/turtle");

final HttpResponse response = client.execute(getRdfMethod);
Expand All @@ -83,7 +84,7 @@ public void testXMLDSTriples() throws Exception {
client.execute(postDSMethod("RdfTest4", "testDS", "foobar"));
final HttpGet getRdfMethod =
new HttpGet(serverAddress +
"objects/RdfTest4/datastreams/testDS/rdf");
"objects/RdfTest4/fcr:datastreams/testDS/fcr:rdf");
getRdfMethod.setHeader("Accept", TEXT_XML);
final HttpResponse response = client.execute(getRdfMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
Expand Down
78 changes: 78 additions & 0 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraChildren.java
@@ -0,0 +1,78 @@

package org.fcrepo.api;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.ok;
import static org.fcrepo.jaxb.responses.access.ObjectProfile.ObjectStates.A;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;

import org.fcrepo.AbstractResource;
import org.fcrepo.FedoraObject;
import org.fcrepo.jaxb.responses.access.ObjectProfile;
import org.fcrepo.services.ObjectService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.collect.ImmutableList;

@Component
@Path("/rest/{path: .*(?!(fcr\\:))}/fcr:children")
public class FedoraChildren extends AbstractResource {

private static final Logger logger = getLogger(FedoraChildren.class);

@Autowired
private ObjectService objectService;

/**
*
* Provides a serialized list of JCR names for all objects in the repo.
*
* @return 200
* @throws RepositoryException
*/
@GET
@Path("")
public Response getObjects(@PathParam("path")
final List<PathSegment> pathList) throws RepositoryException {

logger.trace("children of {}", toPath(pathList));
return ok(objectService.getObjectNames(toPath(pathList.subList(0, pathList.size()-1))).toString()).build();

}

public ObjectService getObjectService() {
return objectService;
}


public void setObjectService(ObjectService objectService) {
this.objectService = objectService;
}

}

0 comments on commit 95dcaa5

Please sign in to comment.