Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add fedora:object to federated filesystem directories
- Replace loop/flag logic with Guava one-liners

Resolves: https://www.pivotaltracker.com/story/show/70990124
  • Loading branch information
escowles authored and Andrew Woods committed Sep 10, 2014
1 parent 55c4a61 commit 1737afc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
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 @@ -18,9 +18,12 @@
import static java.lang.System.clearProperty;
import static java.lang.System.getProperty;
import static java.lang.System.setProperty;
import static java.util.Arrays.asList;
import static com.google.common.collect.Lists.transform;
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 All @@ -41,7 +44,6 @@

import javax.inject.Inject;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
Expand All @@ -50,7 +52,9 @@
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.impl.utils.FedoraTypesUtils;
import org.fcrepo.kernel.services.DatastreamService;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.services.ObjectService;
Expand Down Expand Up @@ -87,6 +91,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,19 +180,32 @@ 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_DATASTREAM)) {
found = true;
}
}
final boolean found = transform(asList(mixins),FedoraTypesUtils.nodetype2name).contains(FEDORA_OBJECT);
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);

final boolean found = transform(asList(mixins),FedoraTypesUtils.nodetype2name).contains(FEDORA_DATASTREAM);
assertTrue("Mixin not found: " + FEDORA_DATASTREAM, found);

session.save();
Expand All @@ -199,19 +222,12 @@ public void testGetFederatedContent() throws RepositoryException {
final NodeType[] mixins = node.getMixinNodeTypes();
assertEquals(2, mixins.length);

boolean found = false;
for (final NodeType nodeType : mixins) {
if (nodeType.getName().equals(FEDORA_BINARY)) {
found = true;
}
}
final boolean found = transform(asList(mixins),FedoraTypesUtils.nodetype2name).contains(FEDORA_BINARY);
assertTrue("Mixin not found: " + FEDORA_BINARY, found);

final Property size = node.getProperty(CONTENT_SIZE);

final File file = fileForNode(node);
assertTrue(file.getAbsolutePath(), file.exists());
assertEquals(file.length(), size.getLong());
assertEquals(file.length(), node.getProperty(CONTENT_SIZE).getLong());

session.save();
session.logout();
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 1737afc

Please sign in to comment.