Skip to content

Commit

Permalink
Fixing fcr:content/jcr:content mixup, tagging content events with fed…
Browse files Browse the repository at this point in the history
…ora:hasContent property
  • Loading branch information
escowles committed Apr 9, 2015
1 parent 3de050c commit cb4d302
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Expand Up @@ -16,6 +16,7 @@
package org.fcrepo.kernel.impl.observer.eventmappings;

import static com.google.common.collect.Multimaps.index;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;
import static java.util.Arrays.asList;
import static javax.jcr.observation.Event.PROPERTY_ADDED;
Expand Down Expand Up @@ -60,7 +61,7 @@ public class AllNodeEventsOneEvent implements InternalExternalEventMapper {
public String apply(final Event ev) {
try {
// build id from nodepath+user to collapse multiple nodes from adding/removing content nodes
final String id = FedoraEvent.getPath(ev).replaceAll("/fcr:content","") + "-" + ev.getUserID();
final String id = FedoraEvent.getPath(ev).replaceAll("/" + JCR_CONTENT,"") + "-" + ev.getUserID();
LOGGER.debug("Sorting an event by identifier: {}", id);
return id;
} catch (final RepositoryException e) {
Expand Down Expand Up @@ -123,6 +124,9 @@ public void remove() {

private void addProperty( final FedoraEvent fedoraEvent, final Event ev ) {
try {
if (ev.getPath().indexOf(JCR_CONTENT) != -1) {
fedoraEvent.addProperty("fedora:hasContent");
}
if (PROPERTY_EVENT_TYPES.contains(ev.getType())) {
final String eventPath = ev.getPath();
fedoraEvent.addProperty(eventPath.substring(eventPath.lastIndexOf('/') + 1));
Expand Down
Expand Up @@ -27,6 +27,7 @@
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;

import javax.jcr.RepositoryException;
import javax.jcr.observation.Event;
Expand Down Expand Up @@ -65,7 +66,7 @@ public class AllNodeEventsOneEventTest {

private static final String TEST_IDENTIFIER5 = randomUUID().toString();

private static final String TEST_PATH5 = "/test/node3/fcr:content";
private static final String TEST_PATH5 = "/test/node3/" + JCR_CONTENT;

private final AllNodeEventsOneEvent testMapping = new AllNodeEventsOneEvent();

Expand All @@ -90,6 +91,9 @@ public class AllNodeEventsOneEventTest {
@Mock
private Iterator<Event> mockIterator2;

@Mock
private Iterator<Event> mockIterator3;

@Before
public void setUp() throws RepositoryException {
initMocks(this);
Expand All @@ -113,6 +117,9 @@ public void setUp() throws RepositoryException {
when(mockEvent5.getType()).thenReturn(NODE_ADDED);
when(mockIterator2.next()).thenReturn(mockEvent4, mockEvent5);
when(mockIterator2.hasNext()).thenReturn(true, true, false);

when(mockIterator3.next()).thenReturn(mockEvent4, mockEvent5);
when(mockIterator3.hasNext()).thenReturn(true, true, false);
}

@Test
Expand All @@ -126,6 +133,13 @@ public void testCollapseContentEvents() {
assertEquals("Didn't collapse content node and fcr:content events!", 1, size(testMapping.apply(mockIterator2)));
}

@Test
public void testFileEventProperties() {
FedoraEvent e = testMapping.apply(mockIterator3).next();
assertTrue("Didn't add fedora:hasContent property to fcr:content events!: " + e.getProperties(),
e.getProperties().contains("fedora:hasContent"));
}

@Test(expected = UnsupportedOperationException.class)
public void testBadOPeration() {
testMapping.apply(mockIterator).remove();
Expand Down

0 comments on commit cb4d302

Please sign in to comment.