Search in sources :

Example 66 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.

the class RestoreTest method testRestoreWithUUIDConflictJcr2_4.

/**
     * Tests if restoring the <code>Version</code> of an existing node throws an
     * <code>ItemExistsException</code> if removeExisting is set to FALSE.
     */
public void testRestoreWithUUIDConflictJcr2_4() throws RepositoryException, NotExecutableException {
    try {
        Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
        // Verify that nodes used for the test have proper opv behaviour
        NodeDefinition nd = naa.getDefinition();
        if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
            throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
        }
        Version v = versionManager.checkin(versionableNode.getPath());
        versionManager.checkout(versionableNode.getPath());
        superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
        superuser.save();
        versionManager.restore(new Version[] { v }, false);
        fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
    } catch (ItemExistsException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Version(javax.jcr.version.Version) ItemExistsException(javax.jcr.ItemExistsException) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 67 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.

the class RestoreTest method testRestoreWithUUIDConflict.

/**
     * Tests if restoring the <code>Version</code> of an existing node throws an
     * <code>ItemExistsException</code> if removeExisting is set to FALSE.
     */
@SuppressWarnings("deprecation")
public void testRestoreWithUUIDConflict() throws RepositoryException, NotExecutableException {
    try {
        Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
        // Verify that nodes used for the test have proper opv behaviour
        NodeDefinition nd = naa.getDefinition();
        if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
            throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
        }
        Version v = versionableNode.checkin();
        versionableNode.checkout();
        superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
        superuser.save();
        versionableNode.restore(v, false);
        fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
    } catch (ItemExistsException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Version(javax.jcr.version.Version) ItemExistsException(javax.jcr.ItemExistsException) Node(javax.jcr.Node) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 68 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.

the class NodeTypeManagerImpl method getNodeDefinition.

/**
     * Retrieve the <code>NodeDefinition</code> for the given
     * <code>QNodeDefinition</code>.
     *
     * @param def
     * @return
     */
@Override
public NodeDefinition getNodeDefinition(QNodeDefinition def) {
    synchronized (ndCache) {
        NodeDefinition ndi = ndCache.get(def);
        if (ndi == null) {
            ndi = new NodeDefinitionImpl(def, this, getNamePathResolver());
            ndCache.put(def, ndi);
        }
        return ndi;
    }
}
Also used : NodeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Example 69 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project jackrabbit by apache.

the class NodeTypeUtil method locateChildNodeDef.

/**
     * Locate a non-protected child node def declared by a non-abstract node type
     * parsing all node types
     *
     * @param session                  the session to access the node types
     * @param regardDefaultPrimaryType if true, the default primary type of the
     *                                 returned <code>NodeDef</code> is
     *                                 according to param <code>defaultPrimaryType</code>.
     *                                 If false, the returned <code>NodeDef</code>
     *                                 might have a default primary type or
     *                                 not.
     * @param defaultPrimaryType       if <code>regardDefaultPrimaryType</code>
     *                                 is true: if true, the returned
     *                                 <code>NodeDef</code> has a default
     *                                 primary type, else not
     * @param residual                 if true, the returned <code>NodeDef</code>
     *                                 is of the residual name "*", else not
     * @return
     * @throws RepositoryException
     */
public static NodeDefinition locateChildNodeDef(Session session, boolean regardDefaultPrimaryType, boolean defaultPrimaryType, boolean residual) throws RepositoryException {
    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    NodeTypeIterator types = manager.getAllNodeTypes();
    boolean skip = false;
    while (types.hasNext()) {
        NodeType type = types.nextNodeType();
        // node types with more than one residual child node definition
        // will cause trouble in test cases. the implementation
        // might pick another definition than the definition returned by
        // this method, when a child node is set.
        NodeDefinition[] childDefs = type.getChildNodeDefinitions();
        int residuals = 0;
        for (int i = 0; i < childDefs.length; i++) {
            if (childDefs[i].getName().equals("*")) {
                residuals++;
            }
        }
        if (residuals > 1) {
            // more than one residual, not suitable for tests
            continue;
        }
        NodeDefinition[] nodeDefs = type.getDeclaredChildNodeDefinitions();
        for (int i = 0; i < nodeDefs.length; i++) {
            NodeDefinition nodeDef = nodeDefs[i];
            if (nodeDef.getDeclaringNodeType().isAbstract()) {
                continue;
            }
            if (nodeDef.isProtected()) {
                continue;
            }
            if (nodeDef.getRequiredPrimaryTypes().length > 1) {
                // of primary node types is not specified
                continue;
            }
            if (regardDefaultPrimaryType) {
                if (defaultPrimaryType && nodeDef.getDefaultPrimaryType() == null) {
                    continue;
                }
                if (!defaultPrimaryType && nodeDef.getDefaultPrimaryType() != null) {
                    continue;
                }
            }
            if (residual && !nodeDef.getName().equals("*")) {
                continue;
            }
            if (!residual) {
                // if another child node def is a residual definition
                // skip the current node type
                NodeDefinition[] nodeDefsAll = type.getChildNodeDefinitions();
                for (int j = 0; j < nodeDefsAll.length; j++) {
                    if (nodeDefsAll[j].getName().equals("*")) {
                        skip = true;
                        break;
                    }
                }
                if (skip) {
                    // break the loop of the current child not defs
                    skip = false;
                    break;
                }
            }
            return nodeDef;
        }
    }
    return null;
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator)

Example 70 with NodeDefinition

use of javax.jcr.nodetype.NodeDefinition in project sling by apache.

the class MockNodeTypeGenerator method getSimpleChildNodeDef.

public NodeDefinition getSimpleChildNodeDef(String name) {
    NodeDefinition childNodeDef1 = mock(NodeDefinition.class);
    NodeType[] reqPrimaryTypes = { getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME1), getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME2) };
    when(childNodeDef1.getRequiredPrimaryTypes()).thenReturn(reqPrimaryTypes);
    when(childNodeDef1.getName()).thenReturn(name);
    when(childNodeDef1.getOnParentVersion()).thenReturn(OnParentVersionAction.COPY);
    return childNodeDef1;
}
Also used : NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition)

Aggregations

NodeDefinition (javax.jcr.nodetype.NodeDefinition)77 NodeType (javax.jcr.nodetype.NodeType)44 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)29 Node (javax.jcr.Node)17 ItemExistsException (javax.jcr.ItemExistsException)14 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)13 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)13 Version (javax.jcr.version.Version)12 Test (org.junit.Test)11 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 RepositoryException (javax.jcr.RepositoryException)7 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 Name (org.apache.jackrabbit.spi.Name)5 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)5 NodeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl)5 ArrayList (java.util.ArrayList)4 NodeState (org.apache.jackrabbit.core.state.NodeState)4 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)4 Session (javax.jcr.Session)3