Skip to content

Commit

Permalink
Altered PUT to /rest/objects/[pid] for: https://www.pivotaltracker.co…
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 21, 2013
1 parent 3c8073d commit 8abf937
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 47 deletions.
Expand Up @@ -116,11 +116,10 @@ public Response addDatastreams(@PathParam("pid")
final String dsid =
a.getContentDisposition().getParameter("name");
final String dsPath = "/objects/" + pid + "/" + dsid;
if (session.hasPermission(dsPath, "add_node")) {
new DatastreamService().createDatastreamNode(session,
dsPath, a.getDataHandler().getContentType(), a
.getDataHandler().getInputStream());
}
new DatastreamService().createDatastreamNode(session, dsPath, a
.getDataHandler().getContentType(), a.getDataHandler()
.getInputStream());

}
session.save();

Expand Down Expand Up @@ -175,7 +174,6 @@ public Response addDatastream(@PathParam("pid")
addDatastreamNode(pid, dspath, contentType,
requestBodyStream, session)).build();
} else {

session.getNode(dspath).remove();
session.save();
return created(
Expand Down
Expand Up @@ -8,8 +8,6 @@
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.ok;
import static javax.ws.rs.core.Response.status;
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static org.fcrepo.api.legacy.FedoraDatastreams.getContentSize;
import static org.fcrepo.jaxb.responses.ObjectProfile.ObjectStates.A;
import static org.fcrepo.utils.FedoraJcrTypes.DC_TITLE;
Expand Down Expand Up @@ -90,22 +88,12 @@ public Response ingestAndMint() throws RepositoryException {
@Path("/{pid}")
@Consumes({TEXT_XML, APPLICATION_JSON})
public Response modify(@PathParam("pid")
final String pid, final ObjectProfile objProfile)
throws RepositoryException {

final String pid) throws RepositoryException {
final String objPath = "/objects/" + pid;
final Session session = repo.login();
try {
if (!session.nodeExists(objPath)) {
session.logout();
return status(CONFLICT).entity("No such object").build();
}
final Node obj = session.getNode(objPath);
obj.setProperty(DC_TITLE, objProfile.objLabel);
if (objProfile.objModels != null)
for (String model : objProfile.objModels) {
obj.addMixin(model);
}
// TODO do something with awful mess of fcrepo3 query params
session.save();
} finally {
session.logout();
Expand Down
Expand Up @@ -2,16 +2,13 @@
package org.fcrepo.api.legacy;

import static java.util.regex.Pattern.compile;
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

Expand Down Expand Up @@ -60,28 +57,4 @@ public void testDeleteObject() throws Exception {
"objects/FedoraObjectsTest3")));
}

@Test
public void testModifyObject() throws Exception {
final String label = "Muy especial!";
assertEquals(201, getStatus(postObjMethod("FedoraObjectsTest4")));

HttpPut modifyMethod =
new HttpPut(serverAddress + "objects/FedoraObjectsTest4");
modifyMethod
.setEntity(new StringEntity(
"<objectProfile xmlns=\"http://www.fedora.info/definitions/1/0/access/\">" +
"<objLabel>" +
label +
"</objLabel>" +
"</objectProfile>"));
modifyMethod.setHeader("Content-type", TEXT_XML);
assertEquals(201, getStatus(modifyMethod));
final HttpGet getMethod =
new HttpGet(serverAddress + "objects/FedoraObjectsTest4");
final HttpResponse response = client.execute(getMethod);
final String content = EntityUtils.toString(response.getEntity());
logger.debug("Retrieved object profile:\n" + content);
assertTrue("Object wasn't updated!", compile(label).matcher(content)
.find());
}
}

0 comments on commit 8abf937

Please sign in to comment.