Search in sources :

Example 1 with RetentionManager

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

the class HoldTest method testAddHoldOnCheckedInNode.

public void testAddHoldOnCheckedInNode() throws NotExecutableException, RepositoryException {
    Node child = getVersionableChildNode();
    child.checkout();
    child.checkin();
    // 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 checked-in node must throw VersionException.");
    } catch (VersionException e) {
    // success
    } finally {
        otherS.logout();
        // clear holds (in case of test failure)
        child.checkout();
        Hold[] holds = retentionMgr.getHolds(child.getPath());
        for (int i = 0; i < holds.length; i++) {
            retentionMgr.removeHold(child.getPath(), holds[i]);
        }
        superuser.save();
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) Node(javax.jcr.Node) Hold(javax.jcr.retention.Hold) VersionException(javax.jcr.version.VersionException)

Example 2 with RetentionManager

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

the class RetentionPolicyTest method testSetRetentionPolicyOnLockedNode.

public void testSetRetentionPolicyOnLockedNode() throws NotExecutableException, RepositoryException {
    String childPath = getLockedChildNode().getPath();
    // get another session.
    Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.setRetentionPolicy(childPath, getApplicableRetentionPolicy());
        otherS.save();
        fail("Setting a retention policy on a locked node must throw LockException.");
    } catch (LockException e) {
    // success
    } finally {
        otherS.logout();
        if (retentionMgr.getRetentionPolicy(childPath) != null) {
            retentionMgr.removeRetentionPolicy(childPath);
        }
        superuser.save();
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) LockException(javax.jcr.lock.LockException) Session(javax.jcr.Session)

Example 3 with RetentionManager

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

the class RetentionPolicyTest method testRemoveRetentionPolicyOnCheckedInNode.

public void testRemoveRetentionPolicyOnCheckedInNode() throws NotExecutableException, RepositoryException {
    Node child = getVersionableChildNode();
    child.checkout();
    retentionMgr.setRetentionPolicy(child.getPath(), getApplicableRetentionPolicy());
    superuser.save();
    child.checkin();
    Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.removeRetentionPolicy(child.getPath());
        otherS.save();
        fail("Removing a retention policy on a checked-in node must throw VersionException.");
    } catch (VersionException e) {
    // success
    } finally {
        otherS.logout();
        // clear policy added before
        child.checkout();
        try {
            retentionMgr.removeRetentionPolicy(child.getPath());
            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) Session(javax.jcr.Session) VersionException(javax.jcr.version.VersionException)

Example 4 with RetentionManager

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

the class AbstractJCRTest method cleanUpTestRoot.

/**
     * Reverts any pending changes made by <code>s</code> and deletes any nodes
     * under {@link #testRoot}. If there is no node at {@link #testRoot} then
     * the necessary nodes are created.
     *
     * @param s the session to clean up.
     * @return the {@link javax.jcr.Node} that represents the test root.
     * @throws RepositoryException if an error occurs.
     */
protected Node cleanUpTestRoot(Session s) throws RepositoryException {
    // do a 'rollback'
    s.refresh(false);
    Node root = s.getRootNode();
    Node testRootNode;
    if (root.hasNode(testPath)) {
        RetentionManager rm;
        try {
            rm = s.getRetentionManager();
        } catch (UnsupportedRepositoryOperationException e) {
            rm = null;
        }
        // clean test root
        testRootNode = root.getNode(testPath);
        NodeIterator children = testRootNode.getNodes();
        while (children.hasNext()) {
            Node child = children.nextNode();
            // Remove retention policy if needed
            String childPath = child.getPath();
            if (rm != null && rm.getRetentionPolicy(childPath) != null) {
                rm.removeRetentionPolicy(childPath);
                s.save();
            }
            NodeDefinition nodeDef = child.getDefinition();
            if (!nodeDef.isMandatory() && !nodeDef.isProtected()) {
                // try to remove child
                try {
                    child.remove();
                } catch (ConstraintViolationException e) {
                    log.println("unable to remove node: " + child.getPath());
                }
            }
        }
    } else {
        // create nodes to testPath
        StringTokenizer names = new StringTokenizer(testPath, "/");
        Node currentNode = root;
        while (names.hasMoreTokens()) {
            String name = names.nextToken();
            if (currentNode.hasNode(name)) {
                currentNode = currentNode.getNode(name);
            } else {
                currentNode = currentNode.addNode(name, testNodeTypeTestRoot);
            }
        }
        testRootNode = currentNode;
    }
    s.save();
    return testRootNode;
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) NodeIterator(javax.jcr.NodeIterator) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) StringTokenizer(java.util.StringTokenizer) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 5 with RetentionManager

use of javax.jcr.retention.RetentionManager 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)

Aggregations

RetentionManager (javax.jcr.retention.RetentionManager)11 Node (javax.jcr.Node)7 RepositoryException (javax.jcr.RepositoryException)5 Session (javax.jcr.Session)5 LockException (javax.jcr.lock.LockException)4 Hold (javax.jcr.retention.Hold)4 VersionException (javax.jcr.version.VersionException)4 AccessDeniedException (javax.jcr.AccessDeniedException)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 NodeIterator (javax.jcr.NodeIterator)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 NodeDefinition (javax.jcr.nodetype.NodeDefinition)1