Search in sources :

Example 16 with NodeState

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

the class NodeImpl method restore.

/**
     * Common internal restore method for the various Node#restore calls.
     *
     * @param targetNode
     * @param relQPath
     * @param version
     * @param removeExisting
     * @throws PathNotFoundException
     * @throws ItemExistsException
     * @throws VersionException
     * @throws ConstraintViolationException
     * @throws UnsupportedRepositoryOperationException
     * @throws LockException
     * @throws InvalidItemStateException
     * @throws RepositoryException
     */
private void restore(NodeImpl targetNode, Path relQPath, Version version, boolean removeExisting) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
    if (relQPath == null) {
        /* restore target already exists. */
        // target must be versionable
        targetNode.checkIsVersionable();
        VersionHistory vH = targetNode.getVersionHistory();
        // version must be a version of the target node
        if (!vH.isSame(version.getContainingHistory())) {
            throw new VersionException("Version " + version + " does not correspond to the restore target.");
        }
        // version must not be the root version
        if (vH.getRootVersion().isSame(version)) {
            throw new VersionException("Attempt to restore root version.");
        }
        targetNode.checkIsWritable();
        targetNode.checkIsLocked();
    } else {
        /* If no node exists at relPath then a VersionException is thrown if
               the parent node is not checked out. */
        if (!targetNode.isCheckedOut()) {
            throw new VersionException("Parent " + targetNode.safeGetJCRPath() + " for non-existing restore target '" + LogUtil.safeGetJCRPath(relQPath, session.getPathResolver()) + "' must be checked out.");
        }
        targetNode.checkIsLocked();
    // NOTE: check for nodetype constraint violation is left to the 'server'
    }
    NodeState versionState = session.getVersionState(version);
    session.getVersionStateManager().restore(targetNode.getNodeState(), relQPath, versionState, removeExisting);
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) VersionHistory(javax.jcr.version.VersionHistory) VersionException(javax.jcr.version.VersionException)

Example 17 with NodeState

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

the class NodeImpl method resolveMergeConflict.

/**
     * Internal method covering both {@link #doneMerge(Version)} and {@link #cancelMerge(Version)}.
     *
     * @param version
     * @param done
     * @throws VersionException
     * @throws InvalidItemStateException
     * @throws UnsupportedRepositoryOperationException
     * @throws RepositoryException
     */
private void resolveMergeConflict(Version version, boolean done) throws VersionException, InvalidItemStateException, UnsupportedRepositoryOperationException, RepositoryException {
    checkIsVersionable();
    checkHasPendingChanges();
    checkIsLocked();
    // check if checked out
    if (!isCheckedOut()) {
        String msg = "Unable to resolve merge conflict. Node is checked-in: " + safeGetJCRPath();
        log.error(msg);
        throw new VersionException(msg);
    }
    // check if version is in mergeFailed list
    boolean isConflicting = false;
    if (hasProperty(NameConstants.JCR_MERGEFAILED)) {
        Value[] vals = getProperty(NameConstants.JCR_MERGEFAILED).getValues();
        for (int i = 0; i < vals.length && !isConflicting; i++) {
            isConflicting = vals[i].getString().equals(version.getUUID());
        }
    }
    if (!isConflicting) {
        String msg = "Unable to resolve merge conflict. Specified version is not in jcr:mergeFailed property: " + safeGetJCRPath();
        log.error(msg);
        throw new VersionException(msg);
    }
    NodeState versionState = session.getVersionState(version);
    session.getVersionStateManager().resolveMergeConflict(getNodeState(), versionState, done);
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) VersionException(javax.jcr.version.VersionException)

Example 18 with NodeState

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

the class AccessControlManagerImpl method getSupportedPrivileges.

public Privilege[] getSupportedPrivileges(String absPath) throws PathNotFoundException, RepositoryException {
    NodeState state = getNodeState(npResolver.getQPath(absPath));
    Map<String, Privilege> privileges = acProvider.getSupportedPrivileges(sessionInfo, state.getNodeId(), npResolver);
    return privileges.values().toArray(new Privilege[privileges.size()]);
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) Privilege(javax.jcr.security.Privilege)

Example 19 with NodeState

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

the class AccessControlManagerImpl method createAceNode.

private void createAceNode(SetTree operation, NodeState parentState, AccessControlEntry entry) throws RepositoryException {
    AccessControlEntryImpl ace = (AccessControlEntryImpl) entry;
    String uuid = null;
    boolean isAllow = ace.isAllow();
    Name nodeName = getUniqueNodeName(parentState, (isAllow) ? "allow" : "deny");
    Name nodeTypeName = (isAllow) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
    NodeState aceNode = addNode(operation, parentState, nodeName, uuid, nodeTypeName);
    // add rep:principalName property
    String valueStr = ace.getPrincipal().getName();
    QValue value = qvf.create(valueStr, PropertyType.STRING);
    addProperty(operation, aceNode, N_REP_PRINCIPAL_NAME, PropertyType.STRING, new QValue[] { value });
    // add rep:privileges MvProperty
    Privilege[] privs = ace.getPrivileges();
    QValue[] vls = new QValue[privs.length];
    Name privilegeName = null;
    try {
        for (int i = 0; i < privs.length; i++) {
            privilegeName = npResolver.getQName(privs[i].getName());
            vls[i] = qvf.create(privilegeName.toString(), PropertyType.NAME);
        }
    } catch (ValueFormatException e) {
        throw new RepositoryException(e.getMessage());
    }
    addProperty(operation, aceNode, N_REP_PRIVILEGES, PropertyType.NAME, vls);
// TODO: add single and mv restrictions
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) ValueFormatException(javax.jcr.ValueFormatException) RepositoryException(javax.jcr.RepositoryException) Privilege(javax.jcr.security.Privilege) Name(org.apache.jackrabbit.spi.Name)

Example 20 with NodeState

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

the class AccessControlManagerImpl method setPolicy.

public void setPolicy(String absPath, AccessControlPolicy policy) throws RepositoryException {
    checkValidNodePath(absPath);
    checkValidPolicy(policy);
    checkAcccessControlItem(absPath);
    SetTree operation;
    NodeState aclNode = getAclNode(absPath);
    if (aclNode == null) {
        // policy node doesn't exist at absPath -> create one.
        Name name = (absPath == null) ? N_REPO_POLICY : N_POLICY;
        NodeState parent = null;
        Name mixinType = null;
        if (absPath == null) {
            parent = getRootNodeState();
            mixinType = NT_REP_REPO_ACCESS_CONTROLLABLE;
        } else {
            parent = getNodeState(absPath);
            mixinType = NT_REP_ACCESS_CONTROLLABLE;
        }
        setMixin(parent, mixinType);
        operation = SetTree.create(itemStateMgr, parent, name, NT_REP_ACL, null);
        aclNode = operation.getTreeState();
    } else {
        Iterator<NodeEntry> it = getNodeEntry(aclNode).getNodeEntries();
        while (it.hasNext()) {
            it.next().transientRemove();
        }
        operation = SetTree.create(aclNode);
    }
    // create the entry nodes
    for (AccessControlEntry entry : ((AccessControlListImpl) policy).getAccessControlEntries()) {
        createAceNode(operation, aclNode, entry);
    }
    itemStateMgr.execute(operation);
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) SetTree(org.apache.jackrabbit.jcr2spi.operation.SetTree) AccessControlEntry(javax.jcr.security.AccessControlEntry) Name(org.apache.jackrabbit.spi.Name)

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