Skip to content

Commit

Permalink
fixed get ds/obj version
Browse files Browse the repository at this point in the history
  • Loading branch information
fasseg committed Apr 29, 2013
1 parent b5f4fe3 commit 3840e34
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraVersions.java
@@ -1,7 +1,9 @@
package org.fcrepo.api;

import static org.fcrepo.jaxb.responses.management.DatastreamProfile.DatastreamStates.A;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
Expand All @@ -15,6 +17,7 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
Expand All @@ -25,6 +28,7 @@
import org.fcrepo.AbstractResource;
import org.fcrepo.Datastream;
import org.fcrepo.FedoraObject;
import org.fcrepo.jaxb.responses.management.DatastreamProfile;
import org.fcrepo.services.DatastreamService;
import org.fcrepo.services.LowLevelStorageService;
import org.fcrepo.services.ObjectService;
Expand Down Expand Up @@ -61,17 +65,37 @@ public List<Version> getVersionProfile(@PathParam("path") final List<PathSegment
@Path("/{id}")
@GET
@Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML})
public Response getVersion(@PathParam("path") final List<PathSegment> segments, @PathParam("id") final String id) throws RepositoryException{
public Response getVersion(@PathParam("path") final List<PathSegment> segments, @PathParam("id") final String id) throws RepositoryException,IOException{
final String path = toPath(segments);
if (path.contains("/fcr:datastreams/")){
Datastream ds = datastreamService.getDatastream(path);
return Response.ok(ds).build();
return Response.ok(getDSProfile(ds)).build();
}
FedoraObject obj = objectService.getObject(path);
return Response.ok(obj).build();
return Response.ok(objectService.getObjectNames(path, null).toString()).build();
}


/* duplicate of FedoraDatatstreams.getDSProfile */
private DatastreamProfile getDSProfile(final Datastream ds)
throws RepositoryException, IOException {
logger.trace("Executing getDSProfile() with node: " + ds.getDsId());
final DatastreamProfile dsProfile = new DatastreamProfile();
dsProfile.dsID = ds.getDsId();
dsProfile.pid = ds.getObject().getName();
logger.trace("Retrieved datastream " + ds.getDsId() + "'s parent: " +
dsProfile.pid);
dsProfile.dsLabel = ds.getLabel();
logger.trace("Retrieved datastream " + ds.getDsId() + "'s label: " +
ds.getLabel());
dsProfile.dsOwnerId = ds.getOwnerId();
dsProfile.dsChecksumType = ds.getContentDigestType();
dsProfile.dsChecksum = ds.getContentDigest();
dsProfile.dsState = A;
dsProfile.dsMIME = ds.getMimeType();
dsProfile.dsSize = ds.getSize();
dsProfile.dsCreateDate = ds.getCreatedDate().toString();
return dsProfile;
}


/* this is just a inner static to mock the yet non existant versioning model */
/* TODO: use a real versioning mechanism */
Expand Down

0 comments on commit 3840e34

Please sign in to comment.