Skip to content

Commit

Permalink
accomodate NodeRemoved in ATOM/JMS messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Dec 9, 2013
1 parent 03fd28f commit a618ce9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
14 changes: 7 additions & 7 deletions fcrepo-jms/src/main/java/org/fcrepo/jms/legacy/LegacyMethod.java
Expand Up @@ -63,17 +63,16 @@ public class LegacyMethod {

private static final String MODIFY_OBJ_METHOD = "modifyObject";

private static final String PURGE_OBJ_METHOD = "purgeObject";
// pending JCR 2.1, there is no way to detect Obj/DS node types
private static final String PURGE_METHOD = "purge";

private static final String ADD_DS_METHOD = "addDatastream";

private static final String MODIFY_DS_METHOD = "modifyDatastream";

private static final String PURGE_DS_METHOD = "purgeDatastream";

private static final String[] METHODS = new String[] {INGEST_METHOD,
MODIFY_OBJ_METHOD, PURGE_OBJ_METHOD, ADD_DS_METHOD,
MODIFY_DS_METHOD, PURGE_DS_METHOD};
MODIFY_OBJ_METHOD, PURGE_METHOD, ADD_DS_METHOD,
MODIFY_DS_METHOD, };

private static final List<String> METHOD_NAMES = Arrays.asList(METHODS);

Expand Down Expand Up @@ -110,9 +109,10 @@ public LegacyMethod(final Event jcrEvent)
FedoraJcrTypes.FEDORA_DATASTREAM.equals(wrappedType);
final boolean isObjectNode =
FedoraJcrTypes.FEDORA_OBJECT.equals(wrappedType);
final boolean isPurge = jcrEvent.getType() == Event.NODE_REMOVED;

String resource = getResource(jcrEvent);
if (isDatastreamNode || isObjectNode) {
if (isDatastreamNode || isObjectNode || isPurge) {
setMethodName(mapMethodName(jcrEvent.getType(), isObjectNode));
final String returnValue = getReturnValue(jcrEvent);
setContent(getEntryContent(getMethodName(), returnValue));
Expand Down Expand Up @@ -380,7 +380,7 @@ protected static String mapMethodName(final int eventType,
case NODE_ADDED:
return isObjectNode ? INGEST_METHOD : ADD_DS_METHOD;
case NODE_REMOVED:
return isObjectNode ? PURGE_OBJ_METHOD : PURGE_DS_METHOD;
return PURGE_METHOD;
default :
return isObjectNode ? MODIFY_OBJ_METHOD : MODIFY_DS_METHOD;
}
Expand Down
@@ -1,5 +1,7 @@
ingest.datatype = xsd:string
ingest.parameter = objectPID
purge.datatype = xsd:string
purge.parameter = purgedDate
purgeObject.datatype = xsd:string
purgeObject.parameter = purgedDate
modifyObject.datatype = xsd:string
Expand Down
Expand Up @@ -131,8 +131,9 @@ public void testAtomStream() throws RepositoryException,
public void testAtomStreamNodePath() throws RepositoryException,
InterruptedException {
final int minEntriesSize = 2;
final Session session = repository.login();
session.getRootNode().addNode("test1/sigma").addMixin(FEDORA_OBJECT);
Session session = repository.login();
final String testPath = "/test1/sigma";
session.getRootNode().addNode(testPath.substring(1)).addMixin(FEDORA_OBJECT);
session.save();

waitForEntry(minEntriesSize);
Expand All @@ -143,6 +144,37 @@ public void testAtomStreamNodePath() throws RepositoryException,
}

String path = null;
String title = null;
assertEquals("Entries size not 2", entries.size(), 2);
for (final Entry entry : entries) {
final List<Category> categories = copyOf(entry.getCategories("xsd:string"));
String p = null;
for (final Category cat : categories) {
if (cat.getLabel().equals("path")) {
logger.debug("Found Category with term: " + cat.getTerm());
p = cat.getTerm();
}
}
if (testPath.equals(p)) {
path = p;
title = entry.getTitle();
}
}
assertEquals("Got wrong path!", testPath, path);
assertEquals("Got wrong title/method!", "ingest", title);
entries.clear();
path = null;
title = null;
session = repository.login();
session.removeItem(testPath);
session.save();
waitForEntry(2);
session.logout();
if (entries.isEmpty()) {
fail("Waited a second, got no messages");
}

// wait for both the parent update and the removal message
assertEquals("Entries size not 2", entries.size(), 2);
for (final Entry entry : entries) {
final List<Category> categories = copyOf(entry.getCategories("xsd:string"));
Expand All @@ -153,11 +185,13 @@ public void testAtomStreamNodePath() throws RepositoryException,
p = cat.getTerm();
}
}
if (p.equals("/test1/sigma")) {
if (p.equals(testPath)) {
path = p;
title = entry.getTitle();
}
}
assertEquals("Got wrong path!", "/test1/sigma", path);
assertEquals("Got wrong path!", testPath, path);
assertEquals("Got wrong title/method!", "purge", title);
}

@Test
Expand Down

0 comments on commit a618ce9

Please sign in to comment.