Skip to content

Commit

Permalink
Fixing reposting error handling for indirect datastream creation via …
Browse files Browse the repository at this point in the history
…FedoraNodes
  • Loading branch information
escowles committed Apr 17, 2014
1 parent b60a602 commit 08c7010
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Expand Up @@ -419,7 +419,9 @@ public Response createObject(@PathParam("path")
final HttpIdentifierTranslator idTranslator =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);

final boolean hasContent;
if (nodeService.exists(session, path)) {
hasContent = nodeService.getObject(session,path).hasContent();
String pid;

if (slug != null) {
Expand All @@ -438,6 +440,7 @@ public Response createObject(@PathParam("path")
newObjectPath = path + "/" + pid;
} else {
newObjectPath = path;
hasContent = false;
}

LOGGER.debug("Attempting to ingest with path: {}", newObjectPath);
Expand Down Expand Up @@ -466,6 +469,10 @@ public Response createObject(@PathParam("path")
if (s.equals(contentTypeSPARQLUpdate) || contentTypeToLang(s) != null) {
objectType = FEDORA_OBJECT;
} else {
if ( hasContent ) {
return status(SC_CONFLICT).entity(
path + " is an existing resource!").build();
}
objectType = FEDORA_DATASTREAM;
}
} else {
Expand Down
Expand Up @@ -218,6 +218,9 @@ public void testCreateChildObject() throws Exception {
when(mockNode.getPath()).thenReturn(path);
when(mockSession.getValueFactory()).thenReturn(mockValueFactory);
when(mockValueFactory.createValue("a", PATH)).thenReturn(mockValue);
when(mockNodes.getObject(mockSession,"/" + pid)).thenReturn(mockResource);
when(mockResource.hasContent()).thenReturn(false);

final Response actual =
testObj.createObject(createPathList(pid), FEDORA_OBJECT, null, null,
null, null, getUriInfoImpl(), null);
Expand All @@ -240,6 +243,8 @@ public void testCreateChildObjectWithSlug() throws Exception {
when(mockNode.getPath()).thenReturn(path);
when(mockSession.getValueFactory()).thenReturn(mockValueFactory);
when(mockValueFactory.createValue("a", PATH)).thenReturn(mockValue);
when(mockNodes.getObject(mockSession,"/" + pid)).thenReturn(mockResource);
when(mockResource.hasContent()).thenReturn(false);

final Response actual =
testObj.createObject(createPathList(pid), FEDORA_OBJECT, null, null,
Expand Down Expand Up @@ -565,4 +570,4 @@ public void testMoveObjectWithBadDestination() throws RepositoryException, URISy
// BAD GATEWAY
assertEquals(SC_BAD_GATEWAY, response.getStatus());
}
}
}
Expand Up @@ -285,4 +285,19 @@ public void testPostToExistingDS() throws Exception {
final HttpPost repostDSMethod = postDSMethod(pid, "ds1", "bar");
assertEquals("Reposting should error!", 409, getStatus(repostDSMethod));
}

@Test
public void testPostToExistingDSIndirect() throws Exception {
final String pid = randomUUID().toString();

final HttpPost postDSMethod = new HttpPost(serverAddress + pid);
postDSMethod.setEntity(new StringEntity("foo", "UTF-8"));
postDSMethod.addHeader("Content-Type", "application/foo");
assertEquals(201, getStatus(postDSMethod));

final HttpPost repostDSMethod = new HttpPost(serverAddress + pid);
repostDSMethod.setEntity(new StringEntity("bar", "UTF-8"));
repostDSMethod.addHeader("Content-Type", "application/foo");
assertEquals(409, getStatus(repostDSMethod));
}
}

0 comments on commit 08c7010

Please sign in to comment.