Search in sources :

Example 6 with RetentionRegistry

use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.

the class BatchedItemOperations method checkRemoveNode.

/**
     * Checks if removing the given target node from the specifed parent
     * is allowed in the current context.
     *
     * @param targetState
     * @param parentId
     * @param options     bit-wise OR'ed flags specifying the checks that should be
     *                    performed; any combination of the following constants:
     *                    <ul>
     *                    <li><code>{@link #CHECK_ACCESS}</code>: make sure
     *                    current session is granted read access on parent
     *                    and remove privilege on target node</li>
     *                    <li><code>{@link #CHECK_LOCK}</code>: make sure
     *                    there's no foreign lock on parent node</li>
     *                    <li><code>{@link #CHECK_CHECKED_OUT}</code>: make sure
     *                    parent node is checked-out</li>
     *                    <li><code>{@link #CHECK_CONSTRAINTS}</code>:
     *                    make sure no node type constraints would be violated</li>
     *                    <li><code>{@link #CHECK_REFERENCES}</code>:
     *                    make sure no references exist on target node</li>
     *                    <li><code>{@link #CHECK_HOLD}</code>: check for effective holds preventing the add operation</li>
     *                    <li><code>{@link #CHECK_RETENTION}</code>: check for effective retention policy preventing the add operation</li>
     *                    </ul>
     * @throws ConstraintViolationException
     * @throws AccessDeniedException
     * @throws VersionException
     * @throws LockException
     * @throws ItemNotFoundException
     * @throws ReferentialIntegrityException
     * @throws RepositoryException
     */
public void checkRemoveNode(NodeState targetState, NodeId parentId, int options) throws ConstraintViolationException, AccessDeniedException, VersionException, LockException, ItemNotFoundException, ReferentialIntegrityException, RepositoryException {
    if (targetState.getParentId() == null) {
        // root or orphaned node
        throw new ConstraintViolationException("cannot remove root node");
    }
    Path targetPath = hierMgr.getPath(targetState.getNodeId());
    NodeState parentState = getNodeState(parentId);
    Path parentPath = hierMgr.getPath(parentId);
    if ((options & CHECK_LOCK) == CHECK_LOCK) {
        // make sure there's no foreign lock on parent node
        verifyUnlocked(parentPath);
    }
    if ((options & CHECK_CHECKED_OUT) == CHECK_CHECKED_OUT) {
        // make sure parent node is checked-out
        verifyCheckedOut(parentPath);
    }
    if ((options & CHECK_ACCESS) == CHECK_ACCESS) {
        try {
            AccessManager accessMgr = context.getAccessManager();
            // make sure current session is granted read access on parent node
            if (!accessMgr.isGranted(targetPath, Permission.READ)) {
                throw new PathNotFoundException(safeGetJCRPath(targetPath));
            }
            // make sure current session is allowed to remove target node
            if (!accessMgr.isGranted(targetPath, Permission.REMOVE_NODE)) {
                throw new AccessDeniedException(safeGetJCRPath(targetPath) + ": not allowed to remove node");
            }
        } catch (ItemNotFoundException infe) {
            String msg = "internal error: failed to check access rights for " + safeGetJCRPath(targetPath);
            log.debug(msg);
            throw new RepositoryException(msg, infe);
        }
    }
    if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
        QItemDefinition parentDef = context.getItemManager().getDefinition(parentState).unwrap();
        if (parentDef.isProtected()) {
            throw new ConstraintViolationException(safeGetJCRPath(parentId) + ": cannot remove child node of protected parent node");
        }
        QItemDefinition targetDef = context.getItemManager().getDefinition(targetState).unwrap();
        if (targetDef.isMandatory()) {
            throw new ConstraintViolationException(safeGetJCRPath(targetPath) + ": cannot remove mandatory node");
        }
        if (targetDef.isProtected()) {
            throw new ConstraintViolationException(safeGetJCRPath(targetPath) + ": cannot remove protected node");
        }
    }
    if ((options & CHECK_REFERENCES) == CHECK_REFERENCES) {
        EffectiveNodeType ent = getEffectiveNodeType(targetState);
        if (ent.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
            NodeId targetId = targetState.getNodeId();
            if (stateMgr.hasNodeReferences(targetId)) {
                try {
                    NodeReferences refs = stateMgr.getNodeReferences(targetId);
                    if (refs.hasReferences()) {
                        throw new ReferentialIntegrityException(safeGetJCRPath(targetPath) + ": cannot remove node with references");
                    }
                } catch (ItemStateException ise) {
                    String msg = "internal error: failed to check references on " + safeGetJCRPath(targetPath);
                    log.error(msg, ise);
                    throw new RepositoryException(msg, ise);
                }
            }
        }
    }
    RetentionRegistry retentionReg = context.getSessionImpl().getRetentionRegistry();
    if ((options & CHECK_HOLD) == CHECK_HOLD) {
        if (retentionReg.hasEffectiveHold(targetPath, true)) {
            throw new RepositoryException("Unable to perform removal. Node is affected by a hold.");
        }
    }
    if ((options & CHECK_RETENTION) == CHECK_RETENTION) {
        if (retentionReg.hasEffectiveRetention(targetPath, true)) {
            throw new RepositoryException("Unable to perform removal. Node is affected by a retention.");
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) AccessManager(org.apache.jackrabbit.core.security.AccessManager) AccessDeniedException(javax.jcr.AccessDeniedException) NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) RetentionRegistry(org.apache.jackrabbit.core.retention.RetentionRegistry) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 7 with RetentionRegistry

use of org.apache.jackrabbit.core.retention.RetentionRegistry 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 8 with RetentionRegistry

use of org.apache.jackrabbit.core.retention.RetentionRegistry in project jackrabbit by apache.

the class RetentionRegistryImplTest method testRemoveRetentionPolicy.

public void testRemoveRetentionPolicy() throws RepositoryException {
    SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
    RetentionRegistry re = s.getRetentionRegistry();
    try {
        retentionMgr.removeRetentionPolicy(childNPath);
        // retention must still be in effect.
        assertTrue(re.hasEffectiveRetention(s.getQPath(childNPath), false));
        superuser.save();
        assertFalse(re.hasEffectiveRetention(s.getQPath(childNPath), false));
    } finally {
        s.logout();
    }
}
Also used : RetentionRegistry(org.apache.jackrabbit.core.retention.RetentionRegistry)

Example 9 with RetentionRegistry

use of org.apache.jackrabbit.core.retention.RetentionRegistry 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)

Aggregations

RetentionRegistry (org.apache.jackrabbit.core.retention.RetentionRegistry)9 RepositoryException (javax.jcr.RepositoryException)3 Hold (javax.jcr.retention.Hold)3 AccessManager (org.apache.jackrabbit.core.security.AccessManager)3 NodeState (org.apache.jackrabbit.core.state.NodeState)3 AccessDeniedException (javax.jcr.AccessDeniedException)2 ItemNotFoundException (javax.jcr.ItemNotFoundException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)2 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)2 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)2 Path (org.apache.jackrabbit.spi.Path)2 QItemDefinition (org.apache.jackrabbit.spi.QItemDefinition)2 ItemExistsException (javax.jcr.ItemExistsException)1 ReferentialIntegrityException (javax.jcr.ReferentialIntegrityException)1 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)1 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)1 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)1