Skip to content

Commit

Permalink
Added more helper methods on FedoraObject and Datastream
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 21, 2013
1 parent 21a5699 commit 448d54f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
22 changes: 16 additions & 6 deletions fcrepo-kernel/src/main/java/org/fcrepo/Datastream.java
Expand Up @@ -11,7 +11,6 @@
import java.io.InputStream;

import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
Expand All @@ -37,19 +36,30 @@ public Node getNode() {
return node;
}

public InputStream getContent() throws ValueFormatException,
PathNotFoundException, RepositoryException {
public InputStream getContent() throws RepositoryException {
return node.getNode(JCR_CONTENT).getProperty(JCR_DATA).getBinary()
.getStream();
}

public String getMimeType() throws ValueFormatException,
PathNotFoundException, RepositoryException {
public long getContentSize() throws RepositoryException {
return node.getNode(JCR_CONTENT).getProperty(JCR_DATA).getBinary()
.getSize();
}

public String getDsId() throws RepositoryException {
return node.getName();
}

public FedoraObject getObject() throws RepositoryException {
return new FedoraObject(node.getParent());
}

public String getMimeType() throws RepositoryException {
return node.hasProperty("fedora:contentType") ? node.getProperty(
"fedora:contentType").getString() : "application/octet-stream";
}

public String getLabel() throws PathNotFoundException, RepositoryException {
public String getLabel() throws RepositoryException {
if (node.hasProperty(DC_TITLE)) {

Property labels = node.getProperty(DC_TITLE);
Expand Down
7 changes: 6 additions & 1 deletion fcrepo-kernel/src/main/java/org/fcrepo/FedoraObject.java
Expand Up @@ -24,7 +24,8 @@ public FedoraObject(Node n) {
}

public FedoraObject(Session session, String path)
throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
throws NoSuchNodeTypeException, VersionException,
ConstraintViolationException, LockException, RepositoryException {
this.node = findOrCreateNode(session, path, NT_FOLDER);
node.addMixin("fedora:object");
node.addMixin("fedora:owned");
Expand All @@ -34,6 +35,10 @@ public FedoraObject(Session session, String path)
node.getName()});
}

public String getName() throws RepositoryException {
return node.getName();
}

public Node getNode() {
return node;
}
Expand Down
Expand Up @@ -11,7 +11,6 @@
import static org.fcrepo.api.legacy.FedoraObjects.getObjectSize;
import static org.fcrepo.jaxb.responses.DatastreamProfile.DatastreamStates.A;
import static org.fcrepo.services.DatastreamService.createDatastreamNode;
import static org.fcrepo.services.DatastreamService.getDatastreamNode;
import static org.fcrepo.services.ObjectService.getObjectNode;
import static org.fcrepo.services.PathService.getDatastreamJcrNodePath;
import static org.fcrepo.services.PathService.getObjectJcrNodePath;
Expand Down Expand Up @@ -197,7 +196,7 @@ public Response modifyDatastream(@PathParam("pid")
final Session session = repo.login();
contentType =
contentType != null ? contentType
: MediaType.APPLICATION_OCTET_STREAM_TYPE;
: APPLICATION_OCTET_STREAM_TYPE;
String dspath = getDatastreamJcrNodePath(pid, dsid);

return created(
Expand Down Expand Up @@ -256,9 +255,9 @@ public DatastreamProfile getDatastream(@PathParam("pid")
final String pid, @PathParam("dsid")
final String dsId) throws RepositoryException, IOException {
logger.trace("Executing getDatastream() with dsId: " + dsId);
Node dsNode = getDatastreamNode(pid, dsId);
logger.debug("Retrieved dsNode: " + dsNode.getName());
return getDSProfile(dsNode);
Datastream ds = DatastreamService.getDatastream(pid, dsId);
logger.debug("Retrieved dsNode: " + ds.getNode().getName());
return getDSProfile(ds);

}

Expand Down Expand Up @@ -287,7 +286,7 @@ public Response getDatastreamContent(@PathParam("pid")
*
* @param pid
* persistent identifier of the digital object
* @param dsid
* @param dsId
* datastream identifier
* @return 200
* @throws RepositoryException
Expand All @@ -301,12 +300,12 @@ public Response getDatastreamContent(@PathParam("pid")
public
DatastreamHistory getDatastreamHistory(@PathParam("pid")
final String pid, @PathParam("dsid")
final String dsid) throws RepositoryException, IOException {
final String dsId) throws RepositoryException, IOException {

final Datastream ds = DatastreamService.getDatastream(pid, dsid);
final Datastream ds = DatastreamService.getDatastream(pid, dsId);
final DatastreamHistory dsHistory =
new DatastreamHistory(singletonList(getDSProfile(ds.getNode())));
dsHistory.dsID = dsid;
new DatastreamHistory(singletonList(getDSProfile(ds)));
dsHistory.dsID = dsId;
dsHistory.pid = pid;
return dsHistory;
}
Expand Down Expand Up @@ -351,31 +350,30 @@ public DatastreamHistory getDatastreamHistoryOld(@PathParam("pid")
public Response deleteDatastream(@PathParam("pid")
String pid, @PathParam("dsid")
String dsid) throws RepositoryException {
final String dsPath = getDatastreamJcrNodePath(pid , dsid);
final String dsPath = getDatastreamJcrNodePath(pid, dsid);
final Session session = repo.login();
final Node ds = session.getNode(dsPath);
updateRepositorySize(0L - getDatastreamSize(ds), session);
return deleteResource(ds);
}

private DatastreamProfile getDSProfile(Node ds) throws RepositoryException,
IOException {
logger.trace("Executing getDSProfile() with node: " + ds.getName());
private DatastreamProfile getDSProfile(Datastream ds)
throws RepositoryException, IOException {
logger.trace("Executing getDSProfile() with node: " + ds.getDsId());
final DatastreamProfile dsProfile = new DatastreamProfile();
dsProfile.dsID = ds.getName();
dsProfile.pid = ds.getParent().getName();
logger.trace("Retrieved datastream " + ds.getName() + "'s parent: " +
dsProfile.dsID = ds.getDsId();
dsProfile.pid = ds.getObject().getName();
logger.trace("Retrieved datastream " + ds.getDsId() + "'s parent: " +
dsProfile.pid);
dsProfile.dsLabel = new Datastream(ds).getLabel();
logger.trace("Retrieved datastream " + ds.getName() + "'s label: " +
new Datastream(ds).getLabel());
dsProfile.dsLabel = ds.getLabel();
logger.trace("Retrieved datastream " + ds.getDsId() + "'s label: " +
ds.getLabel());
dsProfile.dsState = A;
dsProfile.dsMIME = new Datastream(ds).getMimeType();
dsProfile.dsMIME = ds.getMimeType();
dsProfile.dsSize =
getNodePropertySize(ds) +
ds.getNode(JCR_CONTENT).getProperty(JCR_DATA)
.getBinary().getSize();
dsProfile.dsCreateDate = ds.getProperty("jcr:created").getString();
getNodePropertySize(ds.getNode()) + ds.getContentSize();
dsProfile.dsCreateDate =
ds.getNode().getProperty("jcr:created").getString();
return dsProfile;
}

Expand Down

0 comments on commit 448d54f

Please sign in to comment.