Search in sources :

Example 1 with JackrabbitObservationManager

use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit by apache.

the class JackrabbitObservationManagerTest method testDisjunctPaths.

public void testDisjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
    JackrabbitObservationManager oManager = (JackrabbitObservationManager) obsMgr;
    EventResult listener = new EventResult(log);
    JackrabbitEventFilter filter = new JackrabbitEventFilter().setAdditionalPaths('/' + testPath + "/a", '/' + testPath + "/x").setEventTypes(NODE_ADDED);
    oManager.addEventListener(listener, filter);
    try {
        Node b = testRootNode.addNode("a").addNode("b");
        b.addNode("c");
        Node y = testRootNode.addNode("x").addNode("y");
        y.addNode("z");
        testRootNode.getSession().save();
        Event[] added = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
        checkNodeAdded(added, new String[] { "a/b", "x/y" }, null);
    } finally {
        oManager.removeEventListener(listener);
    }
}
Also used : JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter)

Example 2 with JackrabbitObservationManager

use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit-oak by apache.

the class ObservationTest method filterDisjunctPaths.

@Test
public void filterDisjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
    assumeTrue(observationManager instanceof JackrabbitObservationManager);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    FilterBuilder builder = new FilterBuilder();
    builder.condition(builder.any(builder.path(TEST_PATH + "/a/b"), builder.path(TEST_PATH + "/x/y")));
    oManager.addEventListener(listener, builder.build());
    Node testNode = getNode(TEST_PATH);
    Node b = testNode.addNode("a").addNode("b");
    b.addNode("c");
    Node y = testNode.addNode("x").addNode("y");
    y.addNode("z");
    listener.expect(b.getPath(), NODE_ADDED);
    listener.expect(y.getPath(), NODE_ADDED);
    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());
}
Also used : JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) FilterBuilder(org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 3 with JackrabbitObservationManager

use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit-oak by apache.

the class ObservationTest method disjunctPaths.

@Test
public void disjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
    assumeTrue(observationManager instanceof JackrabbitObservationManager);
    JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter().setAdditionalPaths(TEST_PATH + "/a", TEST_PATH + "/x").setEventTypes(NODE_ADDED);
    oManager.addEventListener(listener, filter);
    Node testNode = getNode(TEST_PATH);
    Node b = testNode.addNode("a").addNode("b");
    b.addNode("c");
    Node y = testNode.addNode("x").addNode("y");
    y.addNode("z");
    listener.expect(b.getPath(), NODE_ADDED);
    listener.expect(y.getPath(), NODE_ADDED);
    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());
}
Also used : JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 4 with JackrabbitObservationManager

use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project jackrabbit-oak by apache.

the class ObservationTest method pathExclude.

@Test
public void pathExclude() throws ExecutionException, InterruptedException, RepositoryException {
    assumeTrue(observationManager instanceof JackrabbitObservationManager);
    JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter().setAbsPath(TEST_PATH).setIsDeep(true).setExcludedPaths(TEST_PATH + "/c", TEST_PATH + "/d", "/x/y").setEventTypes(ALL_EVENTS);
    oManager.addEventListener(listener, filter);
    Node n = getNode(TEST_PATH);
    listener.expectAdd(listener.expectAdd(listener.expectAdd(n.addNode("a")).addNode("a1")).setProperty("p", "q"));
    listener.expectAdd(listener.expectAdd(n.addNode("b")).setProperty("p", "q"));
    n.addNode("c").addNode("c1").setProperty("p", "q");
    n.addNode("d").setProperty("p", "q");
    getAdminSession().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());
}
Also used : JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 5 with JackrabbitObservationManager

use of org.apache.jackrabbit.api.observation.JackrabbitObservationManager in project sling by apache.

the class JcrListenerBaseConfig method register.

/**
     * Register a JCR event listener
     * @param listener The listener
     * @param config The configuration
     * @throws RepositoryException If registration fails.
     */
public void register(final EventListener listener, final ObserverConfiguration config) throws RepositoryException {
    final ObservationManager mgr = this.session.getWorkspace().getObservationManager();
    if (mgr instanceof JackrabbitObservationManager) {
        final OakEventFilter filter = FilterFactory.wrap(new JackrabbitEventFilter());
        // paths
        final Set<String> paths = config.getPaths().toStringSet();
        int globCount = 0, pathCount = 0;
        for (final String p : paths) {
            if (p.startsWith(Path.GLOB_PREFIX)) {
                globCount++;
            } else {
                pathCount++;
            }
        }
        final String[] pathArray = pathCount > 0 ? new String[pathCount] : null;
        final String[] globArray = globCount > 0 ? new String[globCount] : null;
        pathCount = 0;
        globCount = 0;
        // create arrays and remove global prefix
        for (final String p : paths) {
            if (p.startsWith(Path.GLOB_PREFIX)) {
                globArray[globCount] = p.substring(Path.GLOB_PREFIX.length());
                globCount++;
            } else {
                pathArray[pathCount] = p;
                pathCount++;
            }
        }
        if (globArray != null) {
            filter.withIncludeGlobPaths(globArray);
        }
        if (pathArray != null) {
            filter.setAdditionalPaths(pathArray);
        }
        filter.setIsDeep(true);
        // exclude paths
        final Set<String> excludePaths = config.getExcludedPaths().toStringSet();
        if (!excludePaths.isEmpty()) {
            filter.setExcludedPaths(excludePaths.toArray(new String[excludePaths.size()]));
        }
        // external
        filter.setNoExternal(!config.includeExternal());
        // types
        filter.setEventTypes(this.getTypes(config));
        // nt:file handling
        filter.withNodeTypeAggregate(new String[] { "nt:file" }, new String[] { "", "jcr:content" });
        // anchestor removes
        filter.withIncludeAncestorsRemove();
        ((JackrabbitObservationManager) mgr).addEventListener(listener, filter);
    } else {
        throw new RepositoryException("Observation manager is not a JackrabbitObservationManager");
    }
}
Also used : JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) ObservationManager(javax.jcr.observation.ObservationManager) JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) RepositoryException(javax.jcr.RepositoryException) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) OakEventFilter(org.apache.jackrabbit.oak.jcr.observation.filter.OakEventFilter)

Aggregations

JackrabbitObservationManager (org.apache.jackrabbit.api.observation.JackrabbitObservationManager)8 Node (javax.jcr.Node)7 Event (javax.jcr.observation.Event)7 JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)7 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)6 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)6 Test (org.junit.Test)6 RepositoryException (javax.jcr.RepositoryException)1 NodeDefinition (javax.jcr.nodetype.NodeDefinition)1 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)1 ObservationManager (javax.jcr.observation.ObservationManager)1 OakEventFilter (org.apache.jackrabbit.oak.jcr.observation.filter.OakEventFilter)1 FilterBuilder (org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder)1 EventResult (org.apache.jackrabbit.test.api.observation.EventResult)1