Skip to content

Commit

Permalink
Merge pull request #6 from mikedurbin/56429862
Browse files Browse the repository at this point in the history
Makes fedora 3 datastream content available.
  • Loading branch information
Andrew Woods committed Sep 27, 2013
2 parents e745ad7 + e7bc64e commit 3b5bc0c
Show file tree
Hide file tree
Showing 19 changed files with 503 additions and 159 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -3,11 +3,13 @@ target/
.settings/
.project
.metadata
.idea
ActiveMQ/
FedoraRepository/
indexes/
ObjectStore/
*/.cache
.cache
.DS_Store
*~
*~
*.iml
42 changes: 38 additions & 4 deletions fcrepo-fedora3-federation-connector/pom.xml
Expand Up @@ -43,6 +43,10 @@
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>jena</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand All @@ -63,12 +67,12 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-kernel</artifactId>
Expand All @@ -79,24 +83,54 @@
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-commons</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-commons</artifactId>
<artifactId>fcrepo-auth-oauth</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-jcr</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-serialization</artifactId>
<version>${project.version}</version>
</dependency>


<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-auth-common</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.glassfish.grizzly</groupId>
Expand Down
Expand Up @@ -54,5 +54,4 @@ public FedoraDatastreamRecord getDatastream(String pid,
* with the given dsid.
*/
public boolean doesDatastreamExist(String pid, String dsid);

}
Expand Up @@ -16,14 +16,6 @@

package org.fcrepo.connector.fedora3;


import java.io.IOException;
import java.util.Collection;
import java.util.Collections;

import javax.jcr.NamespaceRegistry;
import javax.jcr.RepositoryException;

import org.fcrepo.connector.fedora3.rest.RESTFedora3DataImpl;
import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.kernel.utils.ContentDigest;
Expand All @@ -34,10 +26,19 @@
import org.modeshape.jcr.federation.spi.PageKey;
import org.modeshape.jcr.federation.spi.Pageable;
import org.modeshape.jcr.federation.spi.ReadOnlyConnector;
import org.modeshape.jcr.value.BinaryKey;
import org.modeshape.jcr.value.BinaryValue;
import org.modeshape.jcr.value.binary.ExternalBinaryValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.NamespaceRegistry;
import javax.jcr.RepositoryException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;

/**
* A ReadOnly connector to a fedora 3 repository.
*
Expand Down Expand Up @@ -115,6 +116,7 @@ public Document getDocumentById(String idStr) {
LOGGER.trace("getDocumentById {}", idStr);
ID id = new ID(idStr);
DocumentWriter writer = newDocument(idStr);
writer.setNotQueryable();
if (id.isRootID()) {
// return a root object
writer.setPrimaryType(JcrConstants.NT_FOLDER);
Expand Down Expand Up @@ -167,13 +169,13 @@ public Document getDocumentById(String idStr) {
writer.setParent(id.getParentId());
writer.addMixinType(FEDORA_BINARY);
try {
BinaryValue binary = ds.getContent();
BinaryValue binary = new Fedora3DatastreamBinaryValue(ds);
writer.addProperty(JcrConstants.JCR_DATA, binary);
LOGGER.trace("{} size: {}", ds.getId(), binary.getSize());
LOGGER.trace("{} hash: {}", ds.getId(), binary.getHexHash());
writer.addProperty(CONTENT_DIGEST, ContentDigest.
asURI("SHA-1", binary.getHexHash()).toString());
asURI("SHA-1", binary.getHexHash()));
writer.addProperty(CONTENT_SIZE, binary.getSize());
writer.addProperty(JcrConstants.JCR_DATA, binary);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Expand Down Expand Up @@ -251,4 +253,53 @@ public Document getChildren(PageKey pageKey) {
throw new UnsupportedOperationException();
}
}

/**
* Gets an ExternalBinaryValue that exposes access to content nodes in
* the federation.
*/
public ExternalBinaryValue getBinaryValue(String idStr) {
ID id = new ID(idStr);
FedoraDatastreamRecord ds = f3.getDatastream(id.getPid(),
id.getDSID());
try {
return new Fedora3DatastreamBinaryValue(ds);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public class Fedora3DatastreamBinaryValue extends ExternalBinaryValue {

private static final long serialVersionUID = 1L;

private FedoraDatastreamRecord ds;

Fedora3DatastreamBinaryValue(FedoraDatastreamRecord ds) throws Exception {
super(new BinaryKey(ds.getSha1()),
Fedora3FederationConnector.this.getSourceName(),
ID.contentID(ds.getPid(), ds.getId()).getId(),
ds.getContentLength(), null, null);
this.ds = ds;
}

/**
* Gets the InputStream for the content.
*/
public InputStream getStream() throws RepositoryException {
try {
return ds.getStream();
} catch (Exception e) {
throw new RepositoryException(e);
}
}

/**
* Overrides the superclass to return the MIME type declared on the
* fedora 3 datastream whose content is exposed by this BinaryValue.
*/
public String getMimeType() {
return ds.getMimeType();
}
}
}
Expand Up @@ -16,10 +16,9 @@

package org.fcrepo.connector.fedora3;

import java.io.InputStream;
import java.util.Date;

import org.modeshape.jcr.value.BinaryValue;

/**
* An interface to expose enough information about a Fedora 3 datastream to
* import it into fedora 4.
Expand All @@ -28,6 +27,11 @@
*/
public interface FedoraDatastreamRecord {

/**
* Gets the pid of the object whose datastream is represented.
*/
public String getPid();

/**
* Gets the DSID.
*/
Expand All @@ -49,9 +53,19 @@ public interface FedoraDatastreamRecord {
public Date getCreatedDate();

/**
* Gets a JCR BinaryValue representing the content of the datastream.
* Gets a new InputStream to access the content of the datastream.
*/
public InputStream getStream() throws Exception;

/**
* Gets the length in bytes of the content of the datastream.
*/
public long getContentLength();

/**
* Gets (or computes) a SHA-1 hash of the content of the datastream.
*/
public BinaryValue getContent() throws Exception;
public byte[] getSha1() throws Exception;

// TODO: expose other properties
}
Expand Up @@ -16,6 +16,7 @@

package org.fcrepo.connector.fedora3;

import org.fcrepo.jcr.FedoraJcrTypes;
import org.modeshape.common.text.Jsr283Encoder;
import org.modeshape.jcr.api.JcrConstants;

Expand Down Expand Up @@ -44,7 +45,7 @@
*
* @author Michael Durbin
*/
public class ID {
public class ID implements FedoraJcrTypes {

private String id;

Expand Down Expand Up @@ -75,6 +76,18 @@ public String getId() {
return id;
}

/**
* Gets the URL path (relative to the federation root) that would address
* the node with this id.
*/
public String getURLPath() {
if (isContentID()) {
return getId().replace(JcrConstants.JCR_CONTENT, FCR_CONTENT);
} else {
return getId();
}
}

/**
* Gets the id for the parent within the federation of the node with
* this id.
Expand Down
Expand Up @@ -76,6 +76,7 @@ public FedoraObjectRecord getObjectByPid(String pid) {
DefaultFedoraObjectRecordImpl r
= new DefaultFedoraObjectRecordImpl();
r.pid = pid;
LOGGER.debug("Getting object profile for " + pid + ".");
ObjectProfile op = FedoraClient.getObjectProfile(pid)
.execute(fc).getObjectProfile();
r.createdDate = op.getObjCreateDate()
Expand Down

0 comments on commit 3b5bc0c

Please sign in to comment.