Skip to content

Commit

Permalink
use uriinfo to build paths
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jun 4, 2013
1 parent 7fcadb5 commit af2f5a4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
Expand Up @@ -80,7 +80,7 @@ public Response create(
session.save();
session.logout();
}
return created(uriInfo.getBaseUriBuilder().path("/rest" + path).build()).build();
return created(uriInfo.getBaseUriBuilder().path(FedoraContent.class).build(path.substring(1))).build();
}


Expand Down Expand Up @@ -133,7 +133,7 @@ public Response modifyContent(
session.save();

if (isNew) {
return created(uriInfo.getBaseUriBuilder().path("/rest" + path).build()).build();
return created(uriInfo.getBaseUriBuilder().path(FedoraContent.class).build(path.substring(1))).build();
} else {
return noContent().build();
}
Expand Down
Expand Up @@ -102,7 +102,7 @@ public Response modifyDatastreams(@PathParam("path")
}

session.save();
return created(uriInfo.getRequestUri()).build();
return created(uriInfo.getAbsolutePathBuilder().path(FedoraNodes.class).build(path.substring(1))).build();
} finally {
session.logout();
}
Expand Down
Expand Up @@ -49,8 +49,7 @@ public Response importObject(@PathParam("path")
try {
serializers.get(format).deserialize(session, path, stream);
session.save();
// TODO return proper URI for new resource
return created(uriInfo.getAbsolutePath()).build();
return created(uriInfo.getAbsolutePathBuilder().path(FedoraNodes.class).build(path.substring(1))).build();
} finally {
session.logout();
}
Expand Down
4 changes: 2 additions & 2 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraNodes.java
Expand Up @@ -148,7 +148,7 @@ public Response modifyObject(@PathParam("path")
session.save();

if (isNew) {
return created(uriInfo.getBaseUriBuilder().path("/rest" + path).build()).build();
return created(uriInfo.getBaseUriBuilder().path(FedoraNodes.class).build(path.substring(1))).build();
} else {
return noContent().build();
}
Expand Down Expand Up @@ -250,7 +250,7 @@ public Response createObject(@PathParam("path")

session.save();
logger.debug("Finished creating {} with path: {}", mixin, path);
return created(uriInfo.getRequestUri()).entity(path).build();
return created(uriInfo.getRequestUri()).entity(path.substring(1)).build();

} finally {
session.logout();
Expand Down
Expand Up @@ -23,6 +23,7 @@

import org.apache.http.HttpStatus;
import org.fcrepo.AbstractResource;
import org.fcrepo.FedoraResource;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.utils.FedoraJcrTypes;
import org.slf4j.Logger;
Expand Down Expand Up @@ -61,11 +62,11 @@ public Response ingestAndMint(@PathParam("path") final List<PathSegment> pathLis
return Response.status(HttpStatus.SC_CONFLICT).entity(path + " is an existing resource").build();
}

createObjectOrDatastreamFromRequestContent(FedoraNodes.class, session, path, mixin, uriInfo, requestBodyStream, requestContentType, checksumType, checksum);
final FedoraResource resource = createObjectOrDatastreamFromRequestContent(FedoraNodes.class, session, path, mixin, uriInfo, requestBodyStream, requestContentType, checksumType, checksum);

session.save();
logger.debug("Finished creating {} with path: {}", mixin, path);
return created(uriInfo.getRequestUri()).entity(path).build();
return created(uriInfo.getAbsolutePathBuilder().path(FedoraNodes.class).build(resource.getPath().substring(1))).entity(path).build();

} finally {
session.logout();
Expand Down
Expand Up @@ -15,6 +15,7 @@
import javax.jcr.Session;
import javax.ws.rs.core.Response;

import org.fcrepo.FedoraObject;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.identifiers.UUIDPidMinter;
import org.fcrepo.services.NodeService;
Expand Down Expand Up @@ -42,6 +43,8 @@ public void setUp() throws RepositoryException {
mockSession = TestHelpers.mockSession(testObj);
testObj.setNodeService(mockNodeService);
testObj.setObjectService(mockObjects);

testObj.setUriInfo(TestHelpers.getUriInfoImpl());
}

@After
Expand All @@ -56,6 +59,9 @@ public void testIngestAndMint() throws RepositoryException, IOException,
testObj.setPidMinter(mockMint);
when(mockMint.mintPid()).thenReturn("uuid-123");

final FedoraObject mockObject = mock(FedoraObject.class);
when(mockObject.getPath()).thenReturn("/objects/uuid-123");
when(mockObjects.createObject(mockSession, "/objects/uuid-123")).thenReturn(mockObject);
final Response actual =
testObj.ingestAndMint(createPathList("objects"),
FedoraJcrTypes.FEDORA_OBJECT, null, null, null, null, TestHelpers.getUriInfoImpl());
Expand Down
Expand Up @@ -32,7 +32,7 @@ public void testAddDatastream() throws Exception {
assertEquals(
"Got wrong URI in Location header for datastream creation!",
serverAddress + OBJECT_PATH.replace("/", "") +
"/FedoraDatastreamsTest2/zxc", location);
"/FedoraDatastreamsTest2/zxc/fcr:content", location);
}

@Test
Expand All @@ -45,7 +45,7 @@ public void testAddDeepDatastream() throws Exception {
assertEquals(
"Got wrong URI in Location header for datastream creation!",
serverAddress + OBJECT_PATH.replace("/", "") +
"/FedoraDatastreamsTest2/does/not/exist/yet/zxc", location);
"/FedoraDatastreamsTest2/does/not/exist/yet/zxc/fcr:content", location);
}


Expand All @@ -61,7 +61,7 @@ public void testPutDatastream() throws Exception {
assertEquals(
"Got wrong URI in Location header for datastream creation!",
serverAddress + OBJECT_PATH.replace("/", "") +
"/FedoraDatastreamsTestPut/zxc", location);
"/FedoraDatastreamsTestPut/zxc/fcr:content", location);
}

@Test
Expand Down

0 comments on commit af2f5a4

Please sign in to comment.