Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved DatastreamHistory response
  • Loading branch information
ajs6f committed Feb 5, 2013
1 parent 3af4d67 commit b6f6fff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/main/java/org/fcrepo/modeshape/FedoraDatastreams.java
@@ -1,6 +1,7 @@
package org.fcrepo.modeshape;

import static com.google.common.collect.ImmutableSet.builder;
import static java.util.Collections.singletonList;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static org.fcrepo.modeshape.jaxb.responses.DatastreamProfile.DatastreamStates.A;
Expand All @@ -11,7 +12,6 @@
import java.io.InputStream;
import java.net.URI;
import java.util.Calendar;
import java.util.Collections;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
Expand Down Expand Up @@ -264,13 +264,7 @@ public Response getDatastream(@PathParam("pid") final String pid,

if (obj.hasNode(dsid)) {
final Node ds = obj.getNode(dsid);
DatastreamProfile dsProfile = new DatastreamProfile();
dsProfile.dsID = dsid;
dsProfile.pid = pid;
dsProfile.dsLabel = dsid;
dsProfile.dsState = A;
dsProfile.dsMIME = getDSMimeType(ds);
dsProfile.dsCreateDate = ds.getProperty("jcr:created").getString();
DatastreamProfile dsProfile = getDSProfile(ds);
session.logout();
return Response.ok(dsProfile).build();
} else {
Expand Down Expand Up @@ -338,11 +332,12 @@ public Response getDatastreamHistory(@PathParam("pid") final String pid,

if (session.nodeExists(dsPath)) {
final Node ds = session.getNode(dsPath);
final DatastreamHistory dsHistory = new DatastreamHistory(
singletonList(getDSProfile(ds)));
dsHistory.dsID = dsid;
dsHistory.pid = pid;
session.logout();
return Response
.ok()
.entity(new DatastreamHistory(Collections
.singletonList(new DatastreamProfile()))).build();
return Response.ok().entity(dsHistory).build();
} else {
session.logout();
return four04;
Expand Down Expand Up @@ -391,6 +386,18 @@ public Response deleteDatastream(@PathParam("pid") String pid,
return deleteResource("/" + pid + "/" + dsid);
}

private DatastreamProfile getDSProfile(Node ds) throws RepositoryException,
IOException {
DatastreamProfile dsProfile = new DatastreamProfile();
dsProfile.dsID = ds.getName();
dsProfile.pid = ds.getParent().getName();
dsProfile.dsLabel = ds.getName();
dsProfile.dsState = A;
dsProfile.dsMIME = getDSMimeType(ds);
dsProfile.dsCreateDate = ds.getProperty("jcr:created").getString();
return dsProfile;
}

private String getDSMimeType(Node ds) throws ValueFormatException,
PathNotFoundException, RepositoryException, IOException {
Binary b = (Binary) ds.getNode(JCR_CONTENT).getProperty(JCR_DATA)
Expand Down
Expand Up @@ -2,12 +2,19 @@

import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "datastreamHistory", namespace = "http://www.fedora.info/definitions/1/0/management/")
public class DatastreamHistory {

@XmlAttribute
public String pid;

@XmlAttribute
public String dsID;

@XmlElement
List<DatastreamProfile> datastreamProfiles;

Expand Down

0 comments on commit b6f6fff

Please sign in to comment.