Permalink
Browse files

Adding fedora:object to federated filesystem directories

  • Loading branch information...
escowles committed Sep 10, 2014
1 parent 9735004 commit 979915495be1c11a99620fe262118cc35635f7d2
@@ -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;
@@ -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)
@@ -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());
@@ -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;
@@ -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;
@@ -87,6 +89,12 @@
@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.
@@ -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)) {
@@ -58,6 +58,11 @@ protected String testFilePath() {
return "/" + federationName() + "/repository.json";
}
@Override
protected String testDirPath() {
return "/" + federationName();
}
@Override
protected String getFederationRoot() {
return getReadWriteFederationRoot();
@@ -43,6 +43,10 @@ protected String getFederationRoot() {
return getReadOnlyFederationRoot();
}
protected String testDirPath() {
return "/" + federationName();
}
protected String testFilePath() {
return "/" + federationName() + "/repo.xml";
}

0 comments on commit 9799154

Please sign in to comment.