Skip to content

Commit

Permalink
Not yet compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed May 2, 2013
1 parent fb6c8ea commit 27fe449
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 86 deletions.
69 changes: 27 additions & 42 deletions fcrepo-http-api/pom.xml
@@ -1,51 +1,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo</artifactId>
<version>4.0-SNAPSHOT</version>
</parent>

<artifactId>fcrepo-http-api</artifactId>
<packaging>bundle</packaging>

<description>Fedora 4.x HTTP API</description>

<name>fcrepo 4.x HTTP API</name>

<properties>
<resteasy.version>2.3.5.Final</resteasy.version>
</properties>

<dependencies>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-commons</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Apache Velocity -->
<!-- Apache Velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-kernel</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
</dependency>
<dependency>
<groupId>com.yammer.metrics</groupId>
Expand All @@ -58,14 +50,13 @@
<version>${metrics.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
</dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<!-- test gear -->
<dependency>
<groupId>org.fcrepo</groupId>
Expand All @@ -74,7 +65,7 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-commons</artifactId>
<version>${project.version}</version>
Expand Down Expand Up @@ -102,17 +93,17 @@
<artifactId>mail</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -121,11 +112,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>

<!-- This dependency is for compile-time: it keeps this module independent
of any given choice of JAX-RS implementation. It must be _after_ the test
gear. Otherwise it will get loaded during test phase, but because this is
Expand All @@ -147,17 +137,15 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey.version}</version>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -183,14 +171,11 @@
</executions>
</plugin>
</plugins>

</build>

<repositories>
<repository>
<id>htmleasy</id>
<url>http://htmleasy-maven.googlecode.com/svn/trunk/</url>
</repository>
</repositories>

</project>
</project>
63 changes: 34 additions & 29 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraDatastreams.java
Expand Up @@ -42,6 +42,7 @@
import org.fcrepo.jaxb.responses.management.DatastreamProfile;
import org.fcrepo.services.DatastreamService;
import org.fcrepo.services.LowLevelStorageService;
import org.fcrepo.session.SessionProvider.InjectedSession;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -77,19 +78,21 @@ public class FedoraDatastreams extends AbstractResource {
@Timed
@Produces({TEXT_XML, APPLICATION_JSON})
public ObjectDatastreams getDatastreams(@PathParam("path")
final List<PathSegment> pathList) throws RepositoryException, IOException {

final Session session = getAuthenticatedSession();
final String path = toPath(pathList);
logger.info("getting datastreams of {}", path);
final ObjectDatastreams objectDatastreams = new ObjectDatastreams();

objectDatastreams.datastreams =
copyOf(transform(datastreamService
.getDatastreamsForPath(session, path), ds2dsElement));
final List<PathSegment> pathList, @InjectedSession
final Session session) throws RepositoryException, IOException {
try {
final String path = toPath(pathList);
logger.info("getting datastreams of {}", path);
final ObjectDatastreams objectDatastreams = new ObjectDatastreams();

return objectDatastreams;
objectDatastreams.datastreams =
copyOf(transform(datastreamService.getDatastreamsForPath(
session, path), ds2dsElement));

return objectDatastreams;
} finally {
session.logout();
}
}

@POST
Expand All @@ -112,7 +115,7 @@ public Response modifyDatastreams(@PathParam("path")
part.getContentDisposition().getParameters()
.get("name");
logger.debug("Adding datastream: " + dsid);
final String dsPath = path + "/" + dsid;
final String dsPath = path + "/" + dsid;
final Object obj = part.getEntity();
InputStream src = null;
if (obj instanceof BodyPartEntity) {
Expand All @@ -132,19 +135,18 @@ public Response modifyDatastreams(@PathParam("path")
session.logout();
}
}

@DELETE
@Timed
public Response deleteDatastreams(
@PathParam("path") final List<PathSegment> pathList,
@QueryParam("dsid") final List<String> dsidList
) throws RepositoryException {
public Response deleteDatastreams(@PathParam("path")
final List<PathSegment> pathList, @QueryParam("dsid")
final List<String> dsidList) throws RepositoryException {
final Session session = getAuthenticatedSession();
try {
String path = toPath(pathList);
final String path = toPath(pathList);
for (final String dsid : dsidList) {
logger.debug("purging datastream {}", path + "/" + dsid);
datastreamService.purgeDatastream(session, path + "/" + dsid);
logger.debug("purging datastream {}", path + "/" + dsid);
datastreamService.purgeDatastream(session, path + "/" + dsid);
}
session.save();
return noContent().build();
Expand All @@ -158,13 +160,14 @@ public Response deleteDatastreams(
@Produces("multipart/mixed")
@Timed
public Response getDatastreamsContents(@PathParam("path")
List<PathSegment> pathList, @QueryParam("dsid")
final List<PathSegment> pathList, @QueryParam("dsid")
final List<String> dsids) throws RepositoryException, IOException {

final Session session = getAuthenticatedSession();
String path = toPath(pathList);
final Session session = getAuthenticatedSession();
final String path = toPath(pathList);
if (dsids.isEmpty()) {
final NodeIterator ni = objectService.getObject(session, path).getNode().getNodes();
final NodeIterator ni =
objectService.getObject(session, path).getNode().getNodes();
while (ni.hasNext()) {
dsids.add(ni.nextNode().getName());
}
Expand All @@ -178,7 +181,8 @@ public Response getDatastreamsContents(@PathParam("path")

try {
final Datastream ds =
datastreamService.getDatastream(session, path + "/" + dsid);
datastreamService.getDatastream(session, path + "/" +
dsid);
multipart.bodyPart(ds.getContent(), MediaType.valueOf(ds
.getMimeType()));
} catch (final PathNotFoundException e) {
Expand All @@ -205,12 +209,13 @@ public Response getDatastreamsContents(@PathParam("path")
@Timed
@Produces({TEXT_XML, APPLICATION_JSON})
public DatastreamHistory getDatastreamHistory(@PathParam("path")
List<PathSegment> pathList, @PathParam("dsid")
final List<PathSegment> pathList, @PathParam("dsid")
final String dsId) throws RepositoryException, IOException {
final Session session = getAuthenticatedSession();
String path = toPath(pathList);
final Session session = getAuthenticatedSession();
final String path = toPath(pathList);
// TODO implement this after deciding on a versioning model
final Datastream ds = datastreamService.getDatastream(session, path + "/" + dsId);
final Datastream ds =
datastreamService.getDatastream(session, path + "/" + dsId);
final DatastreamHistory dsHistory =
new DatastreamHistory(singletonList(getDSProfile(ds)));
dsHistory.dsID = dsId;
Expand Down
Expand Up @@ -102,9 +102,13 @@ public void testGetDatastreams() throws RepositoryException, IOException {
final String path = "/objects/" + pid;
final String dsid = "testDS";
final DatastreamIterator mockIter =
org.fcrepo.TestHelpers.mockDatastreamIterator(pid, dsid, "asdf");
when(mockDatastreams.getDatastreamsForPath(mockSession, path)).thenReturn(mockIter);
final ObjectDatastreams actual = testObj.getDatastreams(createPathList("objects",pid));
org.fcrepo.TestHelpers
.mockDatastreamIterator(pid, dsid, "asdf");
when(mockDatastreams.getDatastreamsForPath(mockSession, path))
.thenReturn(mockIter);
final ObjectDatastreams actual =
testObj.getDatastreams(createPathList("objects", pid),
mockSession);
verify(mockDatastreams).getDatastreamsForPath(mockSession, path);
verify(mockSession, never()).save();
assertEquals(1, actual.datastreams.size());
Expand All @@ -122,8 +126,8 @@ public void testModifyDatastreams() throws RepositoryException,
atts.put(dsId2, "sdfg");
final MultiPart multipart = TestHelpers.getStringsAsMultipart(atts);
final Response actual =
testObj.modifyDatastreams(createPathList(pid), Arrays.asList(new String[] {
dsId1, dsId2}), multipart);
testObj.modifyDatastreams(createPathList(pid), Arrays
.asList(new String[] {dsId1, dsId2}), multipart);
assertEquals(Status.CREATED.getStatusCode(), actual.getStatus());
verify(mockDatastreams).createDatastreamNode(any(Session.class),
eq("/" + pid + "/" + dsId1), anyString(),
Expand All @@ -140,10 +144,13 @@ public void testDeleteDatastreams() throws RepositoryException, IOException {
final String path = "/" + pid;
final List<String> dsidList =
Arrays.asList(new String[] {"ds1", "ds2"});
final Response actual = testObj.deleteDatastreams(createPathList(pid), dsidList);
final Response actual =
testObj.deleteDatastreams(createPathList(pid), dsidList);
assertEquals(Status.NO_CONTENT.getStatusCode(), actual.getStatus());
verify(mockDatastreams).purgeDatastream(mockSession, path + "/" + "ds1");
verify(mockDatastreams).purgeDatastream(mockSession, path + "/" + "ds2");
verify(mockDatastreams)
.purgeDatastream(mockSession, path + "/" + "ds1");
verify(mockDatastreams)
.purgeDatastream(mockSession, path + "/" + "ds2");
verify(mockSession).save();
}

Expand All @@ -152,10 +159,12 @@ public void testGetDatastreamsContents() throws RepositoryException,
IOException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
final String path = "/" + pid + "/" + dsId;
final String path = "/" + pid + "/" + dsId;
final String dsContent = "asdf";
final Datastream mockDs = org.fcrepo.TestHelpers.mockDatastream(pid, dsId, dsContent);
when(mockDatastreams.getDatastream(mockSession, path)).thenReturn(mockDs);
final Datastream mockDs =
org.fcrepo.TestHelpers.mockDatastream(pid, dsId, dsContent);
when(mockDatastreams.getDatastream(mockSession, path)).thenReturn(
mockDs);

final Response resp =
testObj.getDatastreamsContents(createPathList(pid), Arrays
Expand All @@ -175,15 +184,16 @@ public void testGetDatastreamHistory() throws RepositoryException,
IOException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
final String path = "/" + pid + "/" + dsId;
final Datastream mockDs = org.fcrepo.TestHelpers.mockDatastream(pid, dsId, null);
when(mockDatastreams.getDatastream(mockSession, path)).thenReturn(mockDs);
final String path = "/" + pid + "/" + dsId;
final Datastream mockDs =
org.fcrepo.TestHelpers.mockDatastream(pid, dsId, null);
when(mockDatastreams.getDatastream(mockSession, path)).thenReturn(
mockDs);
final DatastreamHistory actual =
testObj.getDatastreamHistory(createPathList(pid), dsId);
assertNotNull(actual);
verify(mockDatastreams).getDatastream(mockSession, path);
verify(mockSession, never()).save();
}


}

0 comments on commit 27fe449

Please sign in to comment.