Skip to content

Commit

Permalink
Merge pull request #371 from fcrepo4/restore-conflict
Browse files Browse the repository at this point in the history
Restoring item with same UUID as existing node returns 409 Conflict
  • Loading branch information
Andrew Woods committed May 21, 2014
2 parents 8d6ca58 + 249482d commit 1b1758c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
Expand Up @@ -16,6 +16,8 @@
package org.fcrepo.http.api;

import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static javax.ws.rs.core.Response.status;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
Expand All @@ -24,6 +26,7 @@
import java.net.URISyntaxException;
import java.util.List;

import javax.jcr.ItemExistsException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.DefaultValue;
Expand Down Expand Up @@ -94,6 +97,8 @@ public Response importObject(@PathParam("path") final List<PathSegment> pathList
.deserialize(session, path, stream);
session.save();
return created(new URI(subjects.getSubject(path).getURI())).build();
} catch ( ItemExistsException ex ) {
return status(CONFLICT).entity("Item already exists").build();
} finally {
session.logout();
}
Expand Down
Expand Up @@ -31,7 +31,7 @@ public class FedoraExportIT extends AbstractResourceIT {

@Test
public void shouldRoundTripOneObject() throws IOException {
final String objName = "JcrXmlSerializerIT1";
final String objName = getRandomUniquePid();

// set up the object
client.execute(postObjMethod(objName));
Expand All @@ -40,7 +40,7 @@ public void shouldRoundTripOneObject() throws IOException {
// export it
logger.debug("Attempting to export: " + objName);
final HttpGet getObjMethod =
new HttpGet(serverAddress + "JcrXmlSerializerIT1" + "/fcr:export");
new HttpGet(serverAddress + objName + "/fcr:export");
HttpResponse response = client.execute(getObjMethod);
assertEquals("application/xml", response.getEntity().getContentType()
.getValue());
Expand All @@ -50,9 +50,9 @@ public void shouldRoundTripOneObject() throws IOException {
logger.debug("Found exported object: " + content);

// delete it
client.execute(new HttpDelete(serverAddress + "JcrXmlSerializerIT1"));
client.execute(new HttpDelete(serverAddress + objName));
response =
client.execute(new HttpGet(serverAddress + "JcrXmlSerializerIT1"));
client.execute(new HttpGet(serverAddress + objName));
assertEquals(404, response.getStatusLine().getStatusCode());

// try to import it
Expand All @@ -62,7 +62,7 @@ public void shouldRoundTripOneObject() throws IOException {

// check that we made it
response =
client.execute(new HttpGet(serverAddress + "JcrXmlSerializerIT1"));
client.execute(new HttpGet(serverAddress + objName));
assertEquals(200, response.getStatusLine().getStatusCode());

}
Expand All @@ -72,7 +72,7 @@ public void shouldRoundTripOneObject() throws IOException {
void
shouldMoveObjectToTheRootLevelUsingTheRepositoryWideApi()
throws IOException {
final String objName = "JcrXmlSerializerIT2";
final String objName = getRandomUniquePid();

// set up the object
client.execute(postObjMethod(objName));
Expand All @@ -81,17 +81,17 @@ public void shouldRoundTripOneObject() throws IOException {
// export it
logger.debug("Attempting to export: " + objName);
final HttpGet getObjMethod =
new HttpGet(serverAddress + "JcrXmlSerializerIT2" + "/fcr:export");
new HttpGet(serverAddress + objName + "/fcr:export");
HttpResponse response = client.execute(getObjMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
logger.debug("Successfully exported: " + objName);
final String content = EntityUtils.toString(response.getEntity());
logger.debug("Found exported object: " + content);

// delete it
client.execute(new HttpDelete(serverAddress + "JcrXmlSerializerIT2"));
client.execute(new HttpDelete(serverAddress + objName));
response =
client.execute(new HttpGet(serverAddress + "JcrXmlSerializerIT2"));
client.execute(new HttpGet(serverAddress + objName));
assertEquals(404, response.getStatusLine().getStatusCode());

// try to import it
Expand All @@ -101,14 +101,36 @@ public void shouldRoundTripOneObject() throws IOException {

// check that we made it
response =
client.execute(new HttpGet(serverAddress + "JcrXmlSerializerIT2"));
client.execute(new HttpGet(serverAddress + objName));
assertEquals(200, response.getStatusLine().getStatusCode());

}

@Test
public void shouldFailToImportOverExistingNode() throws IOException {
final String objName = getRandomUniquePid();

// set up the object
client.execute(postObjMethod(objName));
client.execute(postDSMethod(objName, "testDS", "stuff"));

// export it
logger.debug("Attempting to export: " + objName);
final HttpGet getObjMethod =
new HttpGet(serverAddress + objName + "/fcr:export");
HttpResponse response = client.execute(getObjMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
final String content = EntityUtils.toString(response.getEntity());

// try to import it
final HttpPost importMethod = new HttpPost(serverAddress + objName + "/fcr:import");
importMethod.setEntity(new StringEntity(content));
assertEquals( 409, getStatus(importMethod));
}

@Test
public void shouldExportUsingTheRepositoryWideApi() throws IOException {
final String objName = "JcrXmlSerializerIT2";
final String objName = getRandomUniquePid();

// set up the object
client.execute(postObjMethod(objName));
Expand All @@ -117,7 +139,7 @@ public void shouldExportUsingTheRepositoryWideApi() throws IOException {
// export it
logger.debug("Attempting to export: " + objName);
final HttpGet getObjMethod =
new HttpGet(serverAddress + "JcrXmlSerializerIT2" + "/fcr:export");
new HttpGet(serverAddress + objName + "/fcr:export");
final HttpResponse response = client.execute(getObjMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
logger.debug("Successfully exported: " + objName);
Expand Down

0 comments on commit 1b1758c

Please sign in to comment.