Search in sources :

Example 66 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class WorkspaceImporter method resolveUUIDConflict.

/**
     * @param parent parent node state
     * @param conflicting conflicting node state
     * @param nodeInfo the node info
     * @return the resolved node state
     * @throws RepositoryException if an error occurs
     */
protected NodeState resolveUUIDConflict(NodeState parent, NodeState conflicting, NodeInfo nodeInfo) throws RepositoryException {
    NodeState node;
    if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW) {
        // create new with new uuid:
        // check if new node can be added (check access rights &
        // node type constraints only, assume locking & versioning status
        // and retention/hold has already been checked on ancestor)
        itemOps.checkAddNode(parent, nodeInfo.getName(), nodeInfo.getNodeTypeName(), BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_CONSTRAINTS);
        node = itemOps.createNodeState(parent, nodeInfo.getName(), nodeInfo.getNodeTypeName(), nodeInfo.getMixinNames(), null);
        // remember uuid mapping
        EffectiveNodeType ent = itemOps.getEffectiveNodeType(node);
        if (ent.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
            refTracker.mappedId(nodeInfo.getId(), node.getNodeId());
        }
    } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW) {
        // new node and share with existing
        if (conflicting.isShareable()) {
            itemOps.clone(conflicting, parent, nodeInfo.getName());
            return null;
        }
        String msg = "a node with uuid " + nodeInfo.getId() + " already exists!";
        log.debug(msg);
        throw new ItemExistsException(msg);
    } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING) {
        // make sure conflicting node is not importTarget or an ancestor thereof
        Path p0 = hierMgr.getPath(importTarget.getNodeId());
        Path p1 = hierMgr.getPath(conflicting.getNodeId());
        try {
            if (p1.equals(p0) || p1.isAncestorOf(p0)) {
                String msg = "cannot remove ancestor node";
                log.debug(msg);
                throw new ConstraintViolationException(msg);
            }
        } catch (MalformedPathException mpe) {
            // should never get here...
            String msg = "internal error: failed to determine degree of relationship";
            log.error(msg, mpe);
            throw new RepositoryException(msg, mpe);
        }
        // remove conflicting:
        // check if conflicting can be removed
        // (access rights, node type constraints, locking & versioning status)
        itemOps.checkRemoveNode(conflicting, BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_LOCK | BatchedItemOperations.CHECK_CHECKED_OUT | BatchedItemOperations.CHECK_CONSTRAINTS | BatchedItemOperations.CHECK_HOLD | BatchedItemOperations.CHECK_RETENTION);
        // do remove conflicting (recursive)
        itemOps.removeNodeState(conflicting);
        // create new with given uuid:
        // check if new node can be added (check access rights &
        // node type constraints only, assume locking & versioning status
        // and retention/hold has already been checked on ancestor)
        itemOps.checkAddNode(parent, nodeInfo.getName(), nodeInfo.getNodeTypeName(), BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_CONSTRAINTS);
        // do create new node
        node = itemOps.createNodeState(parent, nodeInfo.getName(), nodeInfo.getNodeTypeName(), nodeInfo.getMixinNames(), nodeInfo.getId());
    } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING) {
        NodeId parentId = conflicting.getParentId();
        if (parentId == null) {
            String msg = "root node cannot be replaced";
            log.debug(msg);
            throw new RepositoryException(msg);
        }
        // 'replace' current parent with parent of conflicting
        try {
            parent = itemOps.getNodeState(parentId);
        } catch (ItemNotFoundException infe) {
            // should never get here...
            String msg = "internal error: failed to retrieve parent state";
            log.error(msg, infe);
            throw new RepositoryException(msg, infe);
        }
        // remove conflicting:
        // check if conflicting can be removed
        // (access rights, node type constraints, locking & versioning status)
        itemOps.checkRemoveNode(conflicting, BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_LOCK | BatchedItemOperations.CHECK_CHECKED_OUT | BatchedItemOperations.CHECK_CONSTRAINTS | BatchedItemOperations.CHECK_HOLD | BatchedItemOperations.CHECK_RETENTION);
        // 'replace' is actually a 'remove existing/add new' operation;
        // this unfortunately changes the order of the parent's
        // child node entries (JCR-1055);
        // => backup list of child node entries beforehand in order
        // to restore it afterwards
        ChildNodeEntry cneConflicting = parent.getChildNodeEntry(nodeInfo.getId());
        List<ChildNodeEntry> cneList = new ArrayList<ChildNodeEntry>(parent.getChildNodeEntries());
        // do remove conflicting (recursive)
        itemOps.removeNodeState(conflicting);
        // create new with given uuid at same location as conflicting:
        // check if new node can be added at other location
        // (access rights, node type constraints, locking & versioning
        // status and retention/hold)
        itemOps.checkAddNode(parent, nodeInfo.getName(), nodeInfo.getNodeTypeName(), BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_LOCK | BatchedItemOperations.CHECK_CHECKED_OUT | BatchedItemOperations.CHECK_CONSTRAINTS | BatchedItemOperations.CHECK_HOLD | BatchedItemOperations.CHECK_RETENTION);
        // do create new node
        node = itemOps.createNodeState(parent, nodeInfo.getName(), nodeInfo.getNodeTypeName(), nodeInfo.getMixinNames(), nodeInfo.getId());
        // restore list of child node entries (JCR-1055)
        if (cneConflicting.getName().equals(nodeInfo.getName())) {
            // restore original child node list
            parent.setChildNodeEntries(cneList);
        } else {
            // replace child node entry with different name
            // but preserving original position
            parent.removeAllChildNodeEntries();
            for (ChildNodeEntry cne : cneList) {
                if (cne.getId().equals(nodeInfo.getId())) {
                    // replace entry with different name
                    parent.addChildNodeEntry(nodeInfo.getName(), nodeInfo.getId());
                } else {
                    parent.addChildNodeEntry(cne.getName(), cne.getId());
                }
            }
        }
    } else {
        String msg = "unknown uuidBehavior: " + uuidBehavior;
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    return node;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) RepositoryException(javax.jcr.RepositoryException) EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) ItemExistsException(javax.jcr.ItemExistsException) NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) ArrayList(java.util.ArrayList) List(java.util.List) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 67 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class AccessControlImporter method checkIdMixins.

private static void checkIdMixins(NodeInfo nInfo) throws ConstraintViolationException {
    // neither explicit id NOR mixin types may be present.
    Name[] mixins = nInfo.getMixinNames();
    NodeId id = nInfo.getId();
    if (id != null || mixins != null) {
        throw new ConstraintViolationException("The node represented by NodeInfo " + nInfo + " may neither be referenceable nor have mixin types.");
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Name(org.apache.jackrabbit.spi.Name)

Example 68 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class DocViewImportHandler method startElement.

//-------------------------------------------------------< ContentHandler >
/**
     * {@inheritDoc}
     * <p>
     * See also {@link org.apache.jackrabbit.commons.xml.Exporter#exportProperties(Node)}
     * regarding special handling of multi-valued properties on export.
     */
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    // process buffered character data
    processCharacters();
    try {
        Name nodeName = NameFactoryImpl.getInstance().create(namespaceURI, localName);
        // process node name
        nodeName = processName(nodeName);
        // properties
        NodeId id = null;
        Name nodeTypeName = null;
        Name[] mixinTypes = null;
        List<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
        for (int i = 0; i < atts.getLength(); i++) {
            if (atts.getURI(i).equals(Name.NS_XMLNS_URI)) {
                // see http://issues.apache.org/jira/browse/JCR-620#action_12448164
                continue;
            }
            Name propName = NameFactoryImpl.getInstance().create(atts.getURI(i), atts.getLocalName(i));
            // process property name
            propName = processName(propName);
            // value(s)
            String attrValue = atts.getValue(i);
            TextValue[] propValues;
            // always assume single-valued property for the time being
            // until a way of properly serializing/detecting multi-valued
            // properties on re-import is found (see JCR-325);
            // see also DocViewSAXEventGenerator#leavingProperties(Node, int)
            // todo proper multi-value serialization support
            propValues = new TextValue[1];
            propValues[0] = new StringValue(attrValue, resolver, valueFactory);
            if (propName.equals(NameConstants.JCR_PRIMARYTYPE)) {
                // jcr:primaryType
                if (attrValue.length() > 0) {
                    try {
                        nodeTypeName = resolver.getQName(attrValue);
                    } catch (NameException ne) {
                        throw new SAXException("illegal jcr:primaryType value: " + attrValue, ne);
                    }
                }
            } else if (propName.equals(NameConstants.JCR_MIXINTYPES)) {
                // jcr:mixinTypes
                mixinTypes = parseNames(attrValue);
            } else if (propName.equals(NameConstants.JCR_UUID)) {
                // jcr:uuid
                if (attrValue.length() > 0) {
                    id = NodeId.valueOf(attrValue);
                }
            } else {
                props.add(new PropInfo(propName, PropertyType.UNDEFINED, propValues));
            }
        }
        NodeInfo node = new NodeInfo(nodeName, nodeTypeName, mixinTypes, id);
        // all information has been collected, now delegate to importer
        importer.startNode(node, props);
        // push current node data onto stack
        stack.push(node);
    } catch (RepositoryException re) {
        throw new SAXException(re);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) SAXException(org.xml.sax.SAXException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 69 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class AccessManagerTest method testIsGrantedOnNewNode.

public void testIsGrantedOnNewNode() throws RepositoryException, NotExecutableException {
    Session s = getHelper().getReadWriteSession();
    try {
        AccessManager acMgr = getAccessManager(s);
        Node newNode = ((Node) s.getItem(testRoot)).addNode(nodeName2, testNodeType);
        NodeId id = (NodeId) getItemId(newNode);
        assertTrue(acMgr.isGranted(id, AccessManager.READ));
        assertTrue(acMgr.isGranted(id, AccessManager.WRITE));
        assertTrue(acMgr.isGranted(id, AccessManager.WRITE | AccessManager.REMOVE));
    } finally {
        s.logout();
    }
}
Also used : Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.core.id.NodeId) Session(javax.jcr.Session)

Example 70 with NodeId

use of org.apache.jackrabbit.core.id.NodeId in project jackrabbit by apache.

the class AccessManagerTest method testCheckPermissionWithInvalidPermission.

public void testCheckPermissionWithInvalidPermission() throws RepositoryException, NotExecutableException {
    AccessManager acMgr = getAccessManager(superuser);
    NodeId id = (NodeId) getItemId(superuser.getItem(testRootNode.getPath()));
    // NOTE: backwards compatibility.
    // for deprecated method: invalid perm-flags will be ignored
    acMgr.checkPermission(id, AccessManager.READ | AccessManager.WRITE | AccessManager.REMOVE + 1);
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId)

Aggregations

NodeId (org.apache.jackrabbit.core.id.NodeId)203 RepositoryException (javax.jcr.RepositoryException)68 NodeState (org.apache.jackrabbit.core.state.NodeState)52 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)48 Name (org.apache.jackrabbit.spi.Name)37 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)31 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)23 Path (org.apache.jackrabbit.spi.Path)23 ItemNotFoundException (javax.jcr.ItemNotFoundException)22 NodeImpl (org.apache.jackrabbit.core.NodeImpl)20 InternalValue (org.apache.jackrabbit.core.value.InternalValue)20 ArrayList (java.util.ArrayList)19 PropertyId (org.apache.jackrabbit.core.id.PropertyId)16 HashSet (java.util.HashSet)15 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)14 PropertyState (org.apache.jackrabbit.core.state.PropertyState)14 Session (javax.jcr.Session)13 HashMap (java.util.HashMap)12 ItemExistsException (javax.jcr.ItemExistsException)12