Skip to content

Commit

Permalink
Moved JAXB resources to fcrepo-http-commons
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 12, 2013
1 parent 7d401ff commit a0bb36e
Show file tree
Hide file tree
Showing 19 changed files with 138 additions and 107 deletions.
24 changes: 17 additions & 7 deletions fcrepo-dc/pom.xml
Expand Up @@ -25,27 +25,28 @@
<version>${project.version}</version>
</dependency>

<!-- test gear -->
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-legacy-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand All @@ -55,6 +56,15 @@
<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
just an API, the tests will not be able to execute. -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
24 changes: 15 additions & 9 deletions fcrepo-http-commons/pom.xml
Expand Up @@ -18,22 +18,28 @@
</dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>

<!-- test gear -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>

<!-- test gear -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>

</dependencies>
Expand Down
11 changes: 0 additions & 11 deletions fcrepo-kernel/pom.xml
Expand Up @@ -35,17 +35,6 @@
<groupId>org.modeshape</groupId>
<artifactId>modeshape-jcr-api</artifactId>
</dependency>
<dependency>
<groupId>org.modeshape</groupId>
<artifactId>modeshape-web-jcr-rest</artifactId>
<version>${modeshape.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.jbossts</groupId>
Expand Down
@@ -1,5 +1,9 @@

package org.fcrepo.services;

import static org.fcrepo.utils.FedoraJcrTypes.DC_IDENTIFER;
import static org.fcrepo.utils.FedoraJcrTypes.FEDORA_DATASTREAM;
import static org.fcrepo.utils.FedoraJcrTypes.FEDORA_OWNED;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import static org.modeshape.jcr.api.JcrConstants.NT_FILE;
Expand All @@ -15,13 +19,11 @@
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.core.MediaType;

import org.modeshape.jcr.api.JcrTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class DatastreamService {

private static final Logger logger = LoggerFactory
Expand All @@ -32,49 +34,50 @@ public class DatastreamService {

private JcrTools jcrTools = new JcrTools();

public Node createDatastreamNode(final Session session, final String dsPath, final MediaType contentType, final InputStream requestBodyStream) throws RepositoryException, IOException {
public Node createDatastreamNode(final Session session,
final String dsPath, final String contentType,
final InputStream requestBodyStream) throws RepositoryException,
IOException {

final Node ds = jcrTools.findOrCreateNode(session, dsPath, NT_FILE);
ds.addMixin("fedora:datastream");
ds.addMixin(FEDORA_DATASTREAM);

final Node contentNode = jcrTools.findOrCreateChild(ds, JCR_CONTENT,
NT_RESOURCE);
final Node contentNode =
jcrTools.findOrCreateChild(ds, JCR_CONTENT, NT_RESOURCE);
logger.debug("Created content node at path: " + contentNode.getPath());
/*
* This next line of code deserves explanation. If we chose for the
* simpler line:
*
* Property dataProperty = contentNode.setProperty(JCR_DATA,
* requestBodyStream);
*
* then the JCR would not block on the stream's completion, and we would
* return to the requestor before the mutation to the repo had actually
* completed. So instead we use createBinary(requestBodyStream), because
* its contract specifies:
*
* "The passed InputStream is closed before this method returns either
* normally or because of an exception."
*
* which lets us block and not return until the job is done! The simpler
* code may still be useful to us for an asychronous method that we
* develop later.
*/
Property dataProperty = contentNode.setProperty(JCR_DATA, session
.getValueFactory().createBinary(requestBodyStream));
/*
* This next line of code deserves explanation. If we chose for the
* simpler line:
* Property dataProperty = contentNode.setProperty(JCR_DATA,
* requestBodyStream);
* then the JCR would not block on the stream's completion, and we would
* return to the requestor before the mutation to the repo had actually
* completed. So instead we use createBinary(requestBodyStream), because
* its contract specifies:
* "The passed InputStream is closed before this method returns either
* normally or because of an exception."
* which lets us block and not return until the job is done! The simpler
* code may still be useful to us for an asychronous method that we
* develop later.
*/
Property dataProperty =
contentNode.setProperty(JCR_DATA, session.getValueFactory()
.createBinary(requestBodyStream));
logger.debug("Created data property at path: " + dataProperty.getPath());

ds.setProperty("fedora:contentType", contentType.toString());
ds.setProperty("fedora:contentType", contentType);

ds.addMixin("fedora:owned");
ds.addMixin(FEDORA_OWNED);
ds.setProperty("fedora:ownerId", session.getUserID());

if(!ds.hasProperty("fedora:created")) {
if (!ds.hasProperty("fedora:created")) {
ds.setProperty("fedora:created", Calendar.getInstance());
}
ds.setProperty("jcr:lastModified", Calendar.getInstance());

// TODO: I guess we should also have the PID + DSID..
ds.setProperty("dc:identifier", new String[] { ds.getIdentifier(), ds.getParent().getName() + "/" + ds.getName() });
ds.setProperty(DC_IDENTIFER, new String[] {ds.getIdentifier(),
ds.getParent().getName() + "/" + ds.getName()});

return ds;
}
Expand Down
@@ -1,5 +1,7 @@

package org.fcrepo.services;

import static org.modeshape.jcr.api.JcrConstants.NT_FOLDER;

import java.util.Calendar;

Expand All @@ -23,16 +25,17 @@ public class ObjectService {

private JcrTools jcrTools = new JcrTools();

public Node createObjectNode(Session session, String path) throws RepositoryException {
final Node obj = jcrTools.findOrCreateNode(session, path, "nt:folder");
public Node createObjectNode(Session session, String path)
throws RepositoryException {
final Node obj = jcrTools.findOrCreateNode(session, path, NT_FOLDER);
obj.addMixin("fedora:object");
obj.addMixin("fedora:owned");
obj.setProperty("fedora:ownerId", session.getUserID());
obj.setProperty("jcr:lastModified", Calendar.getInstance());
obj.setProperty("dc:identifier", new String[]{obj.getIdentifier(), obj.getName()});
obj.setProperty("dc:identifier", new String[] {obj.getIdentifier(),
obj.getName()});

return obj;
}


}
13 changes: 13 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/utils/FedoraJcrTypes.java
@@ -0,0 +1,13 @@

package org.fcrepo.utils;

public class FedoraJcrTypes {

public static final String FEDORA_DATASTREAM = "fedora:datastream";

public static final String FEDORA_OBJECT = "fedora:object";

public static final String FEDORA_OWNED = "fedora:owned";

public static final String DC_IDENTIFER = "dc:identifier";
}
73 changes: 37 additions & 36 deletions fcrepo-legacy-api/pom.xml
Expand Up @@ -16,25 +16,45 @@
<name>fcrepo 3.x compatible REST API</name>

<dependencies>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.0</version>
</dependency>

<dependency>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>enunciate-cxf-rt</artifactId>
<version>${enunciate.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- test gear -->
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-kernel</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -50,44 +70,25 @@
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>enunciate-cxf-rt</artifactId>
<version>${enunciate.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-kernel</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</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
just an API, the tests will not be able to execute. -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>test</scope>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
</dependencies>

Expand Down
Expand Up @@ -4,6 +4,7 @@
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.APPLICATION_OCTET_STREAM_TYPE;
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.notAcceptable;
Expand Down Expand Up @@ -116,7 +117,7 @@ public Response addDatastream(@PathParam("pid")

contentType =
contentType != null ? contentType
: MediaType.APPLICATION_OCTET_STREAM_TYPE;
: APPLICATION_OCTET_STREAM_TYPE;
String dspath = "/objects/" + pid + "/" + dsid;

if (!session.nodeExists("/objects/" + pid)) {
Expand Down Expand Up @@ -198,7 +199,7 @@ private URI addDatastreamNode(final String pid, final String dsPath,
boolean created = session.nodeExists(dsPath);

new DatastreamService().createDatastreamNode(session, dsPath,
contentType, requestBodyStream);
contentType.toString(), requestBodyStream);

session.save();
if (created) {
Expand Down

0 comments on commit a0bb36e

Please sign in to comment.