Search in sources :

Example 16 with Hold

use of javax.jcr.retention.Hold in project jackrabbit by apache.

the class RetentionRegistryImplTest method testAddMultipleHold.

public void testAddMultipleHold() throws RepositoryException, NotExecutableException {
    SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
    RetentionRegistry re = s.getRetentionRegistry();
    try {
        retentionMgr.addHold(childN2.getPath(), getHoldName(), false);
        superuser.save();
        // hold is not deep -> only applies to childN2
        assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
        assertFalse(re.hasEffectiveHold(s.getQPath(childN2.getPath() + "/child"), false));
        retentionMgr.addHold(childN2.getPath(), getHoldName(), true);
        superuser.save();
        // now deep hold must be taken into account
        assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
        assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath() + "/child"), false));
    } finally {
        s.logout();
        Hold[] hdls = retentionMgr.getHolds(childN2.getPath());
        for (int i = 0; i < hdls.length; i++) {
            retentionMgr.removeHold(childN2.getPath(), hdls[i]);
        }
        superuser.save();
    }
}
Also used : RetentionRegistry(org.apache.jackrabbit.core.retention.RetentionRegistry) Hold(javax.jcr.retention.Hold)

Example 17 with Hold

use of javax.jcr.retention.Hold in project jackrabbit by apache.

the class RetentionRegistryImplTest method testAddHold.

public void testAddHold() throws RepositoryException, NotExecutableException {
    SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
    RetentionRegistry re = s.getRetentionRegistry();
    Hold h = null;
    try {
        h = retentionMgr.addHold(childN2.getPath(), getHoldName(), false);
        // hold must not be effective yet
        assertFalse(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
        superuser.save();
        assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
    } finally {
        s.logout();
        if (h != null) {
            retentionMgr.removeHold(childN2.getPath(), h);
            superuser.save();
        }
    }
}
Also used : RetentionRegistry(org.apache.jackrabbit.core.retention.RetentionRegistry) Hold(javax.jcr.retention.Hold)

Example 18 with Hold

use of javax.jcr.retention.Hold in project jackrabbit by apache.

the class HoldTest method testAddHoldOnLockedNode.

public void testAddHoldOnLockedNode() throws NotExecutableException, RepositoryException {
    Node child = getLockedChildNode();
    // remember current holds for clean up.
    List<Hold> holdsBefore = Arrays.asList(retentionMgr.getHolds(child.getPath()));
    // get another session.
    javax.jcr.Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.addHold(child.getPath(), getHoldName(), false);
        otherS.save();
        fail("Adding hold on a locked node must throw LockException.");
    } catch (LockException e) {
    // success
    } finally {
        otherS.logout();
        // clear holds (in case of test failure)
        List<Hold> holds = new ArrayList<Hold>(Arrays.asList(retentionMgr.getHolds(child.getPath())));
        if (holds.removeAll(holdsBefore)) {
            for (Iterator<Hold> it = holds.iterator(); it.hasNext(); ) {
                retentionMgr.removeHold(child.getPath(), (Hold) it.next());
            }
        }
        superuser.save();
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Hold(javax.jcr.retention.Hold)

Example 19 with Hold

use of javax.jcr.retention.Hold in project jackrabbit by apache.

the class HoldTest method testRemoveHold.

public void testRemoveHold() throws RepositoryException, NotExecutableException {
    Hold hold = retentionMgr.addHold(testNodePath, getHoldName(), false);
    Hold[] holds = retentionMgr.getHolds(testNodePath);
    retentionMgr.removeHold(testNodePath, hold);
    Hold[] holds2 = retentionMgr.getHolds(testNodePath);
    assertEquals("RetentionManager.removeHold should removed the hold added before.", holds.length - 1, holds2.length);
    assertFalse("RetentionManager.removeHold should removed the hold added before.", containsHold(holds2, hold));
}
Also used : Hold(javax.jcr.retention.Hold)

Example 20 with Hold

use of javax.jcr.retention.Hold in project jackrabbit by apache.

the class HoldTest method testRemoveHoldOnCheckedInNode.

public void testRemoveHoldOnCheckedInNode() throws NotExecutableException, RepositoryException {
    Node vn = getVersionableChildNode();
    vn.checkout();
    Node n = vn.addNode(nodeName2);
    Hold h = retentionMgr.addHold(n.getPath(), getHoldName(), false);
    superuser.save();
    // checkin on the parent node make the hold-containing node checked-in.
    vn.checkin();
    javax.jcr.Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        Hold[] holds = rmgr.getHolds(n.getPath());
        if (holds.length > 0) {
            rmgr.removeHold(n.getPath(), holds[0]);
            otherS.save();
            fail("Removing a hold on a checked-in node must throw VersionException.");
        }
    } catch (VersionException e) {
    // success
    } finally {
        otherS.logout();
        // clear hold added before
        vn.checkout();
        try {
            retentionMgr.removeHold(n.getPath(), h);
            superuser.save();
        } catch (RepositoryException e) {
        // should not get here if test is correctly executed.
        }
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Hold(javax.jcr.retention.Hold) VersionException(javax.jcr.version.VersionException)

Aggregations

Hold (javax.jcr.retention.Hold)26 RepositoryException (javax.jcr.RepositoryException)9 Node (javax.jcr.Node)4 RetentionManager (javax.jcr.retention.RetentionManager)4 RetentionRegistry (org.apache.jackrabbit.core.retention.RetentionRegistry)3 PathNotFoundException (javax.jcr.PathNotFoundException)2 LockException (javax.jcr.lock.LockException)2 VersionException (javax.jcr.version.VersionException)2 ArrayList (java.util.ArrayList)1 PropertyIterator (javax.jcr.PropertyIterator)1 NodeImpl (org.apache.jackrabbit.core.NodeImpl)1 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)1