use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.
the class ObservationManagerImpl method addEventListener.
@Override
public void addEventListener(EventListener listener, int eventTypes, String absPath, boolean isDeep, String[] uuids, String[] nodeTypeName, boolean noLocal) throws RepositoryException {
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setEventTypes(eventTypes);
if (absPath != null) {
filter.setAbsPath(absPath);
}
filter.setIsDeep(isDeep);
if (uuids != null) {
filter.setIdentifiers(uuids);
}
if (nodeTypeName != null) {
filter.setNodeTypes(nodeTypeName);
}
filter.setNoLocal(noLocal);
filter.setNoExternal(listener instanceof ExcludeExternal);
addEventListener(listener, filter);
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.
the class ObservationTest method testAggregate1.
@Test
public void testAggregate1() throws Exception {
assumeTrue(observationManager instanceof ObservationManagerImpl);
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setAbsPath("/parent");
filter.setIsDeep(true);
filter.setEventTypes(ALL_EVENTS);
filter = FilterFactory.wrap(filter).withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "", "jcr:content", "jcr:content/**" });
oManager.addEventListener(listener, filter);
Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
// OAK-5096: in OR mode the following event also gets sent:
listener.expect(parent.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
Node child = parent.addNode("child", "nt:unstructured");
// OAK-5096: in OR mode the following event also gets sent:
listener.expectAdd(child);
Node file = child.addNode("file", "oak:Unstructured");
listener.expectAdd(file);
Node jcrContent = file.addNode("jcr:content", "nt:unstructured");
listener.expect(jcrContent.getPath(), "/parent/child/file", NODE_ADDED);
listener.expect(jcrContent.getPath() + "/jcr:primaryType", "/parent/child/file", PROPERTY_ADDED);
Property jcrDataProperty = jcrContent.setProperty("jcr:data", "foo");
listener.expect(jcrDataProperty.getPath(), "/parent/child/file", PROPERTY_ADDED);
parent.getSession().save();
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
assertTrue("Missing events: " + missing, missing.isEmpty());
file = getAdminSession().getRootNode().getNode("parent").getNode("child").getNode("file");
jcrContent = file.getNode("jcr:content");
Property newProperty = jcrContent.setProperty("newProperty", "foo");
listener.expect(newProperty.getPath(), "/parent/child/file", PROPERTY_ADDED);
Property lastModifiedBy = jcrContent.setProperty("jcr:lastModifiedBy", "bar");
listener.expect(lastModifiedBy.getPath(), "/parent/child/file", PROPERTY_ADDED);
jcrContent.getSession().save();
Thread.sleep(2000);
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
assertTrue("Missing events: " + missing, missing.isEmpty());
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.
the class ObservationTest method doTestFileWithGlobs.
private void doTestFileWithGlobs(String globPath, String... expectedSubTrees) throws RepositoryException, ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, AccessDeniedException, ReferentialIntegrityException, InvalidItemStateException, InterruptedException, ExecutionException {
assumeTrue(observationManager instanceof ObservationManagerImpl);
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
filter = FilterFactory.wrap(filter).withIncludeGlobPaths(globPath);
oManager.addEventListener(listener, filter);
ChangeProcessor cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
FilterProvider filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
assertArrayEquals(expectedSubTrees, Iterables.toArray(filterProvider.getSubTrees(), String.class));
Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
Node bar = parent.addNode("bar", "nt:unstructured");
Node zetDotJsp = bar.addNode("zet.jsp", "nt:unstructured");
listener.expect(zetDotJsp.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
parent.getSession().save();
Thread.sleep(1000);
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
assertTrue("Missing events: " + missing, missing.isEmpty());
Session session = getAdminSession();
session.getRootNode().getNode("parent").remove();
session.save();
oManager.removeEventListener(listener);
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.
the class ObservationTest method doIncludeAncestorsRemove_Unrelated.
private void doIncludeAncestorsRemove_Unrelated(String[] absPaths, String[] createAndRemoveNodes, String[] expectedRemoveNodeEvents, String[] expectedRemovePropertyEvents) throws Exception {
assumeTrue(observationManager instanceof ObservationManagerImpl);
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
OakEventFilter filterWithAncestorsRemove = FilterFactory.wrap(new JackrabbitEventFilter());
filterWithAncestorsRemove.setEventTypes(NODE_REMOVED | PROPERTY_REMOVED);
assertTrue(absPaths.length >= 1);
String[] additionalPaths = new String[absPaths.length];
System.arraycopy(absPaths, 0, additionalPaths, 0, absPaths.length);
if (!absPaths[0].contains("*")) {
filterWithAncestorsRemove.setAbsPath(absPaths[0]);
if (absPaths.length > 1) {
additionalPaths = new String[absPaths.length - 1];
System.arraycopy(absPaths, 1, additionalPaths, 0, absPaths.length - 1);
}
}
filterWithAncestorsRemove.withIncludeGlobPaths(additionalPaths);
filterWithAncestorsRemove.setIsDeep(true);
filterWithAncestorsRemove = filterWithAncestorsRemove.withIncludeAncestorsRemove();
ExpectationListener listenerWithAncestorsRemove = new ExpectationListener();
oManager.addEventListener(listenerWithAncestorsRemove, filterWithAncestorsRemove);
OakEventFilter filterWithoutAncestorsRemove = FilterFactory.wrap(new JackrabbitEventFilter());
filterWithoutAncestorsRemove.setEventTypes(NODE_REMOVED);
if (!absPaths[0].contains("*")) {
filterWithoutAncestorsRemove.setAbsPath(absPaths[0]);
}
filterWithoutAncestorsRemove.withIncludeGlobPaths(additionalPaths);
filterWithoutAncestorsRemove.setIsDeep(true);
ExpectationListener listenerWithoutAncestorsRemove = new ExpectationListener();
oManager.addEventListener(listenerWithoutAncestorsRemove, filterWithoutAncestorsRemove);
Session session = getAdminSession();
for (String path : createAndRemoveNodes) {
Iterator<String> it = PathUtils.elements(path).iterator();
Node node = session.getRootNode();
while (it.hasNext()) {
String elem = it.next();
if (!node.hasNode(elem)) {
node = node.addNode(elem);
} else {
node = node.getNode(elem);
}
}
}
session.save();
for (String nodePath : expectedRemoveNodeEvents) {
listenerWithAncestorsRemove.expect(nodePath, NODE_REMOVED);
}
for (String propertyPath : expectedRemovePropertyEvents) {
listenerWithAncestorsRemove.expect(propertyPath, PROPERTY_REMOVED);
}
for (String path : createAndRemoveNodes) {
Iterator<String> it = PathUtils.elements(path).iterator();
Node node = session.getRootNode();
while (it.hasNext()) {
String elem = it.next();
node = node.getNode(elem);
}
node.remove();
session.save();
}
Thread.sleep(1000);
List<Expectation> missing = listenerWithoutAncestorsRemove.getMissing(TIME_OUT, TimeUnit.SECONDS);
List<Event> unexpected = listenerWithoutAncestorsRemove.getUnexpected();
assertTrue("Unexpected events (listenerWithoutAncestorsRemove): " + unexpected, unexpected.isEmpty());
assertTrue("Missing events (listenerWithoutAncestorsRemove): " + missing, missing.isEmpty());
missing = listenerWithAncestorsRemove.getMissing(TIME_OUT, TimeUnit.SECONDS);
unexpected = listenerWithAncestorsRemove.getUnexpected();
assertTrue("Unexpected events (listenerWithAncestorsRemove): " + unexpected, unexpected.isEmpty());
assertTrue("Missing events (listenerWithAncestorsRemove): " + missing, missing.isEmpty());
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.
the class ObservationTest method includeRemovedSubtree_BeforeValue.
@Test
public void includeRemovedSubtree_BeforeValue() throws RepositoryException, ExecutionException, InterruptedException {
assumeTrue(observationManager instanceof ObservationManagerImpl);
Node testNode = getNode(TEST_PATH);
Node a = testNode.addNode("a");
a.setProperty("propA", "24");
a.addNode("c").setProperty("propB", "42");
testNode.getSession().save();
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
filter.setAbsPath("/");
filter.setIsDeep(true);
filter = FilterFactory.wrap(filter).withIncludeSubtreeOnRemove();
oManager.addEventListener(listener, filter);
Node c = testNode.getNode("a").getNode("c");
listener.expectRemove(c);
listener.expectBeforeValue(c.getProperty("propB").getPath(), PROPERTY_REMOVED, "42");
a = testNode.getNode("a");
listener.expectBeforeValue(a.getProperty("propA").getPath(), PROPERTY_REMOVED, "24");
listener.expectRemove(a).remove();
testNode.getSession().save();
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
Aggregations