Search in sources :

Example 6 with NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.

the class JcrVersionManager method removeActivity.

/**
     * @see javax.jcr.version.VersionManager#removeActivity(Node)
     */
public void removeActivity(Node activityNode) throws UnsupportedRepositoryOperationException, RepositoryException {
    session.checkIsAlive();
    NodeImpl activity = getValidActivity(activityNode, "remove");
    NodeState nState = (NodeState) activity.getItemState();
    ItemId removeId = nState.getId();
    vMgr.removeActivity(nState);
    // setting on this session, that points to the removed activity.
    if (activityId != null && activityId.equals(removeId)) {
        activityId = null;
    }
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ItemId(org.apache.jackrabbit.spi.ItemId)

Example 7 with NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.

the class ItemManagerImpl method getItem.

/**
     * @see ItemManager#getItem(HierarchyEntry)
     */
public Item getItem(HierarchyEntry hierarchyEntry) throws ItemNotFoundException, RepositoryException {
    session.checkIsAlive();
    ItemState state = hierarchyEntry.getItemState();
    if (!state.isValid()) {
        throw new ItemNotFoundException(LogUtil.safeGetJCRPath(state, session.getPathResolver()));
    }
    // first try to access item from cache
    Item item = itemCache.getItem(state);
    // not yet in cache, need to create instance
    if (item == null) {
        // create instance of item
        if (hierarchyEntry.denotesNode()) {
            item = createNodeInstance((NodeState) state);
        } else {
            item = createPropertyInstance((PropertyState) state);
        }
    }
    return item;
}
Also used : Item(javax.jcr.Item) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ItemState(org.apache.jackrabbit.jcr2spi.state.ItemState) ItemNotFoundException(javax.jcr.ItemNotFoundException) PropertyState(org.apache.jackrabbit.jcr2spi.state.PropertyState)

Example 8 with NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.

the class SessionImporter method resolveUUIDConflict.

//----------------------------------------------------< Private methods >---
/**
     * @param parent
     * @param conflicting
     * @param nodeInfo
     * @return
     * @throws RepositoryException
     */
NodeState resolveUUIDConflict(NodeState parent, NodeEntry conflicting, NodeInfo nodeInfo) throws ItemExistsException, RepositoryException {
    NodeState nodeState;
    switch(uuidBehavior) {
        case ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW:
            String originalUUID = nodeInfo.getUUID();
            String newUUID = UUID.randomUUID().toString();
            // reset id on nodeInfo to force creation with new uuid:
            nodeInfo.setUUID(newUUID);
            nodeState = importNode(nodeInfo, parent);
            if (nodeState != null) {
                // remember uuid mapping
                refTracker.mappedUUIDs(originalUUID, newUUID);
            }
            break;
        case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
            String msg = "a node with uuid " + nodeInfo.getUUID() + " already exists!";
            log.debug(msg);
            throw new ItemExistsException(msg);
        case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
            // make sure conflicting node is not importTarget or an ancestor thereof
            Path p0 = importTarget.getPath();
            Path p1 = conflicting.getPath();
            if (p1.equals(p0) || p1.isAncestorOf(p0)) {
                msg = "cannot remove ancestor node";
                log.debug(msg);
                throw new ConstraintViolationException(msg);
            }
            // do remove conflicting (recursive) including validation check
            try {
                Operation op = Remove.create(conflicting.getNodeState());
                stateMgr.execute(op);
            } catch (ItemNotFoundException e) {
            // conflicting does not exist any more. no need for a removal
            }
            // create new with given uuid:
            nodeState = importNode(nodeInfo, parent);
            break;
        case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING:
            if (conflicting.getNodeState().isRoot()) {
                msg = "Root node cannot be replaced";
                log.debug(msg);
                throw new RepositoryException(msg);
            }
            // 'replace' current parent with parent of conflicting
            parent = conflicting.getParent().getNodeState();
            // do remove conflicting (recursive), including validation checks
            Operation op = Remove.create(conflicting.getNodeState());
            stateMgr.execute(op);
            // create new with given uuid at same location as conflicting
            nodeState = importNode(nodeInfo, parent);
            break;
        default:
            msg = "Unknown uuidBehavior: " + uuidBehavior;
            log.debug(msg);
            throw new RepositoryException(msg);
    }
    return nodeState;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ItemExistsException(javax.jcr.ItemExistsException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 9 with NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.

the class AccessControlManagerImpl method removePolicy.

public void removePolicy(String absPath, AccessControlPolicy policy) throws RepositoryException {
    checkValidNodePath(absPath);
    checkValidPolicy(policy);
    NodeState aclNode = getAclNode(absPath);
    if (aclNode != null) {
        removeNode(aclNode);
    } else {
        throw new AccessControlException("No policy exist at " + absPath);
    }
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) AccessControlException(javax.jcr.security.AccessControlException)

Example 10 with NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.

the class AccessControlManagerImpl method getApplicable.

//--------------------------------------------------< private >---
private AccessControlPolicy[] getApplicable(String absPath) throws RepositoryException {
    NodeState controlledState;
    if (absPath == null) {
        controlledState = getRootNodeState();
    } else {
        controlledState = getNodeState(absPath);
    }
    AccessControlPolicy acl = null;
    NodeState aclNode = getAclNode(controlledState, absPath);
    if (aclNode == null) {
        acl = new AccessControlListImpl(absPath, npResolver, qvf);
    }
    return (acl == null) ? new AccessControlPolicy[0] : new AccessControlPolicy[] { acl };
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState)

Aggregations

NodeState (org.apache.jackrabbit.jcr2spi.state.NodeState)31 Name (org.apache.jackrabbit.spi.Name)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 RepositoryException (javax.jcr.RepositoryException)5 PropertyState (org.apache.jackrabbit.jcr2spi.state.PropertyState)5 Path (org.apache.jackrabbit.spi.Path)5 NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)4 ItemExistsException (javax.jcr.ItemExistsException)3 Operation (org.apache.jackrabbit.jcr2spi.operation.Operation)3 NodeId (org.apache.jackrabbit.spi.NodeId)3 Item (javax.jcr.Item)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 AccessControlException (javax.jcr.security.AccessControlException)2 Privilege (javax.jcr.security.Privilege)2 Version (javax.jcr.version.Version)2 VersionException (javax.jcr.version.VersionException)2 AddNode (org.apache.jackrabbit.jcr2spi.operation.AddNode)2 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)2 QValue (org.apache.jackrabbit.spi.QValue)2 ArrayList (java.util.ArrayList)1