Skip to content

Commit

Permalink
Adding fedora:object to federated filesystem directories
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Sep 10, 2014
1 parent 9735004 commit 9799154
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
Expand Up @@ -19,13 +19,15 @@
import static org.fcrepo.jcr.FedoraJcrTypes.CONTENT_SIZE;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_BINARY;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_DATASTREAM;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_OBJECT;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_RESOURCE;
import static org.fcrepo.jcr.FedoraJcrTypes.JCR_CREATED;
import static org.fcrepo.jcr.FedoraJcrTypes.JCR_LASTMODIFIED;
import static org.fcrepo.kernel.utils.ContentDigest.asURI;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import static org.modeshape.jcr.api.JcrConstants.JCR_PRIMARY_TYPE;
import static org.modeshape.jcr.api.JcrConstants.NT_FILE;
import static org.modeshape.jcr.api.JcrConstants.NT_FOLDER;
import static org.modeshape.jcr.api.JcrConstants.NT_RESOURCE;

import java.io.File;
Expand Down Expand Up @@ -139,6 +141,10 @@ public Document getDocumentById(final String id) {
// Is Fedora Content?
} else if (primaryType.equals(NT_RESOURCE)) {
decorateContentNode(docReader, docWriter, fileFor(id));

// Is Fedora Object?
} else if (primaryType.equals(NT_FOLDER)) {
decorateObjectNode(docReader, docWriter);
}

// Persist new properties (if allowed)
Expand Down Expand Up @@ -205,6 +211,13 @@ private String computeAndCacheSha1(final File file) {



private static void decorateObjectNode(final DocumentReader docReader, final DocumentWriter docWriter) {
if (!docReader.getMixinTypeNames().contains(FEDORA_OBJECT)) {
LOGGER.trace("Adding mixin: {}, to {}", FEDORA_OBJECT, docReader.getDocumentId());
docWriter.addMixinType(FEDORA_OBJECT);
}
}

private static void decorateDatastreamNode(final DocumentReader docReader, final DocumentWriter docWriter) {
if (!docReader.getMixinTypeNames().contains(FEDORA_DATASTREAM)) {
LOGGER.trace("Adding mixin: {}, to {}", FEDORA_DATASTREAM, docReader.getDocumentId());
Expand Down
Expand Up @@ -21,6 +21,7 @@
import static org.fcrepo.jcr.FedoraJcrTypes.CONTENT_SIZE;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_BINARY;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_DATASTREAM;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_OBJECT;
import static org.fcrepo.kernel.utils.ContentDigest.asURI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -50,6 +51,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraObject;
import org.fcrepo.kernel.services.DatastreamService;
import org.fcrepo.kernel.services.NodeService;
Expand Down Expand Up @@ -87,6 +89,12 @@ public abstract class AbstractFedoraFileSystemConnectorIT {
@Inject
protected DatastreamService datastreamService;

/**
* Gets the path (relative to the filesystem federation) of a directory
* that's expected to be present.
*/
protected abstract String testDirPath();

/**
* Gets the path (relative to the filesystem federation) of a file
* that's expected to be present.
Expand Down Expand Up @@ -170,13 +178,36 @@ protected static void cleanUpJsonFilesFiles(final File directory) {
public void testGetFederatedObject() throws RepositoryException {
final Session session = repo.login();

final FedoraObject object = objectService.getObject(session, testFilePath());
final FedoraObject object = objectService.getObject(session, testDirPath());
assertNotNull(object);

final Node node = object.getNode();
final NodeType[] mixins = node.getMixinNodeTypes();
assertEquals(2, mixins.length);

boolean found = false;
for (final NodeType nodeType : mixins) {
if (nodeType.getName().equals(FEDORA_OBJECT)) {
found = true;
}
}
assertTrue("Mixin not found: " + FEDORA_OBJECT, found);

session.save();
session.logout();
}

@Test
public void testGetFederatedDatastream() throws RepositoryException {
final Session session = repo.login();

final Datastream datastream = datastreamService.getDatastream(session, testFilePath());
assertNotNull(datastream);

final Node node = datastream.getNode();
final NodeType[] mixins = node.getMixinNodeTypes();
assertEquals(2, mixins.length);

boolean found = false;
for (final NodeType nodeType : mixins) {
if (nodeType.getName().equals(FEDORA_DATASTREAM)) {
Expand Down
Expand Up @@ -58,6 +58,11 @@ protected String testFilePath() {
return "/" + federationName() + "/repository.json";
}

@Override
protected String testDirPath() {
return "/" + federationName();
}

@Override
protected String getFederationRoot() {
return getReadWriteFederationRoot();
Expand Down
Expand Up @@ -43,6 +43,10 @@ protected String getFederationRoot() {
return getReadOnlyFederationRoot();
}

protected String testDirPath() {
return "/" + federationName();
}

protected String testFilePath() {
return "/" + federationName() + "/repo.xml";
}
Expand Down

0 comments on commit 9799154

Please sign in to comment.