Skip to content
Permalink
Browse files

factored out the BagItWatchService, as we didn't need to subclass Wat…

…chService

added events to the connector for when a bag node is added/removed, triggered on manifest file
added integration test code that includes testing for add and remove of projected node events
separated some of the manifest file pattern matching code into a util class
  • Loading branch information...
gregjan committed Jun 10, 2013
1 parent eb565ab commit 07060913aa3be04824f8c15fc8577ccfd71b070b
@@ -9,9 +9,6 @@
<artifactId>fcrepo-bagit-modeshape-federation-connector</artifactId>
<name>fcrepo-bagit-modeshape-federation-connector</name>
<description>Connects ModeShape to a filesystem directory containing BagIt directories.</description>
<properties>
<modeshape.version>3.3-SNAPSHOT</modeshape.version>
</properties>
<dependencies>
<dependency>
<groupId>org.modeshape</groupId>
@@ -44,6 +41,10 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
@@ -57,4 +58,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
@@ -11,6 +11,8 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
@@ -29,9 +31,10 @@
import org.modeshape.jcr.api.JcrConstants;
import org.modeshape.jcr.api.nodetype.NodeTypeManager;
import org.modeshape.jcr.cache.DocumentStoreException;
import org.modeshape.jcr.federation.spi.ConnectorChangeSet;
import org.modeshape.jcr.federation.spi.DocumentChanges;
import org.modeshape.jcr.federation.spi.DocumentReader;
import org.modeshape.jcr.federation.spi.DocumentWriter;
import org.modeshape.jcr.federation.spi.change.ConnectorChangedSet;
import org.modeshape.jcr.value.BinaryValue;
import org.modeshape.jcr.value.PropertyFactory;
import org.modeshape.jcr.value.ValueFactories;
@@ -83,6 +86,8 @@
// so this is a dummy file for that situation
private File m_directory = TempFile.createTempFile("stub", "stub");

private Path rootPath;

/**
* A string that is created in the {@link #initialize(NamespaceRegistry, NodeTypeManager)} method that represents the absolute
* path to the {@link #m_directory}. This path is removed from an absolute path of a file to obtain the ID of the node.
@@ -135,6 +140,8 @@ public void initialize(final NamespaceRegistry registry,
directoryAbsolutePathLength =
directoryAbsolutePath.length() - File.separator.length(); // does NOT include the separator

rootPath = Paths.get(directoryAbsolutePath);

setExtraPropertiesStore(new BagItExtraPropertiesStore(this));
getLogger().trace("Initialized.");
final BlockingQueue<Runnable> workQueue =
@@ -155,11 +162,11 @@ public void shutdown() {
@Override
public Document getDocumentById(final String id) {
getLogger().trace("Entering getDocumentById()...");
getLogger().debug("Received request for document: " + id);
getLogger().trace("Received request for document: " + id);
final File file = fileFor(id);
getLogger().debug(
"Received request for document: " + id + ", resolved to " +
file);
//getLogger().debug(
//"Received request for document: " + id + ", resolved to " +
// file);
if (file == null || isExcluded(file) || !file.exists()) {
return null;
}
@@ -168,7 +175,7 @@ public Document getDocumentById(final String id) {
final DocumentWriter writer = newDocument(id);
File parentFile = file.getParentFile();
if (isRoot) {
getLogger().debug(
getLogger().trace(
"Determined document: " + id +
" to be the projection root.");
writer.setPrimaryType(NT_FOLDER);
@@ -189,7 +196,7 @@ public Document getDocumentById(final String id) {
}
}
} else if (isResource) {
getLogger().debug(
getLogger().trace(
"Determined document: " + id + " to be a binary resource.");
final BinaryValue binaryValue = binaryFor(file);
writer.setPrimaryType(NT_RESOURCE);
@@ -215,8 +222,8 @@ public Document getDocumentById(final String id) {
writer.setNotQueryable();
parentFile = file;
} else if (file.isFile()) {
getLogger().debug(
"Determined document: " + id + " to be a datastream.");
getLogger().trace(
"Determined document: " + id + " to be a datastream.");
writer.setPrimaryType(JcrConstants.NT_FILE);
writer.addProperty(JCR_CREATED, factories().getDateFactory()
.create(file.lastModified()));
@@ -230,12 +237,12 @@ public Document getDocumentById(final String id) {
isRoot ? JCR_CONTENT_SUFFIX : id + JCR_CONTENT_SUFFIX;
writer.addChild(childId, JCR_CONTENT);
} else {
getLogger().debug(
getLogger().trace(
"Determined document: " + id + " to be a Fedora object.");
final File dataDir =
new File(new File(file.getAbsolutePath()), "data");
getLogger()
.debug("searching data dir " + dataDir.getAbsolutePath());
.trace("searching data dir " + dataDir.getAbsolutePath());
writer.setPrimaryType(NT_FOLDER);
writer.addMixinType(BAGIT_ARCHIVE_TYPE);
writer.addProperty(JCR_CREATED, factories().getDateFactory()
@@ -307,7 +314,7 @@ protected File fileFor(String id) {
id = id.substring(0, id.length() - JCR_CONTENT_SUFFIX_LENGTH);
}
if ("".equals(id)) {
getLogger().debug(
getLogger().trace(
"#fileFor returning root directory for \"" + id + "\"");
return this.m_directory; // root node
}
@@ -327,7 +334,7 @@ protected File fileFor(String id) {
final File result =
new File(this.m_directory, id.replace(JCR_PATH_DELIMITER_CHAR,
File.separatorChar));
getLogger().debug(result.getAbsolutePath());
getLogger().trace(result.getAbsolutePath());
//return super.fileFor(id);
return result;
}
@@ -381,7 +388,7 @@ protected String idFor(final File file) {
id = JCR_PATH_DELIMITER;
}
assert id.startsWith(JCR_PATH_DELIMITER);
System.out.println("idFor = " + id);
//System.out.println("idFor = " + id);
return id;
}

@@ -407,8 +414,32 @@ protected BagInfo getBagInfo(final String id) {
return result;
}

@Override
protected ConnectorChangedSet newConnectorChangedSet() {
return super.newConnectorChangedSet();
/**
* Sends a change set with a new node event for the bag.
* @param p the path to the bag folder
*/
protected void fireNewBagEvent(Path path) {
ConnectorChangeSet changes = newConnectorChangedSet();
String key = idFor(path.toFile());
Document doc = getDocumentById(key);
DocumentReader reader = readDocument(doc);
getLogger().debug("firing new bag node event with\n\tkey {0}\n\tpathToNode {1}",
key, key);
changes.nodeCreated(key,
"/",
key, reader.getProperties());
changes.publish(null);
}

/**
* @param path the path of the bag folder
*/
public void fireRemoveBagEvent(Path path) {
ConnectorChangeSet changes = newConnectorChangedSet();
String key = idFor(path.toFile());
getLogger().debug("firing remove bag node event with\n\tkey {0}\n\tpathToNode {1}",
key, key);
changes.nodeRemoved(key, "/", key);
changes.publish(null);
}
}
@@ -78,10 +78,10 @@ public void updateProperties(final String id,

final BagInfo bagInfo = connector.getBagInfo(id);
if (bagInfo == null) {
logger.debug("No bag-info.txt for " + id);
if(!"/".equals(id)) logger.trace("No bag-info.txt for " + id);
return EMPTY;
}
logger.debug("Operating on bagInfoFile(" + id + "):" +
logger.trace("Operating on bagInfoFile(" + id + "):" +
bagInfo.getFilepath());
try {
return bagInfo.getProperties();

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 0706091

Please sign in to comment.
You can’t perform that action at this time.