Search in sources :

Example 66 with NodeTypeManager

use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.

the class CopyNodeTypesUpgradeTest method customNodeTypesAreRegistered.

@Test
public void customNodeTypesAreRegistered() throws RepositoryException {
    final JackrabbitSession adminSession = createAdminSession();
    final NodeTypeManager nodeTypeManager = adminSession.getWorkspace().getNodeTypeManager();
    final NodeType testFolderNodeType = nodeTypeManager.getNodeType("test:Folder");
    final NodeDefinition[] cnd = testFolderNodeType.getChildNodeDefinitions();
    final PropertyDefinition[] pd = testFolderNodeType.getPropertyDefinitions();
    assertEquals("More than one child node definition", 1, cnd.length);
    assertEquals("Incorrect default primary type", "test:Folder", cnd[0].getDefaultPrimaryTypeName());
    assertEquals("More than two property definitions", 4, pd.length);
    adminSession.logout();
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) NodeDefinition(javax.jcr.nodetype.NodeDefinition) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Test(org.junit.Test)

Example 67 with NodeTypeManager

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

the class AbstractVersionTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    super.checkSupportedOption(Repository.OPTION_VERSIONING_SUPPORTED);
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    // assert that this repository support versioning
    try {
        NodeType versionableNt = ntMgr.getNodeType(mixVersionable);
        if (versionableNt == null) {
            fail("Repository does not support Versioning: mixin nodetype 'mix:versionable' is missing.");
        }
    } catch (NoSuchNodeTypeException e) {
        fail("Repository does not support Versioning: mixin nodetype 'mix:versionable' is missing.");
    }
    // retrieve versionable nodetype
    String versionableNodeTypeName = getProperty("versionableNodeType");
    try {
        versionableNodeType = ntMgr.getNodeType(versionableNodeTypeName);
        if (versionableNodeType == null) {
            fail("Property 'versionableNodeType' does not define a valid nodetype: '" + versionableNodeTypeName + "'");
        }
    } catch (NoSuchNodeTypeException e) {
        fail("Property 'versionableNodeType' does not define an existing nodetype: '" + versionableNodeTypeName + "'");
    }
    // make sure 'non-versionable' nodetype is properly defined
    try {
        nonVersionableNodeType = ntMgr.getNodeType(testNodeType);
        if (nonVersionableNodeType == null || nonVersionableNodeType.isNodeType(mixVersionable)) {
            fail("Property 'testNodeType' does define a versionable nodetype: '" + testNodeType + "'");
        }
    } catch (NoSuchNodeTypeException e) {
        fail("Property 'testNodeType' does not define an existing nodetype: '" + testNodeType + "'");
    }
    // build persistent versionable and non-versionable nodes
    try {
        versionableNode = createVersionableNode(testRootNode, nodeName1, versionableNodeType);
    } catch (RepositoryException e) {
        fail("Failed to create versionable test node." + e.getMessage());
    }
    try {
        nonVersionableNode = testRootNode.addNode(nodeName3, nonVersionableNodeType.getName());
        testRootNode.getSession().save();
    } catch (RepositoryException e) {
        fail("Failed to create non-versionable test node." + e.getMessage());
    }
    propertyValue = getProperty("propertyValue");
    if (propertyValue == null) {
        fail("Property 'propertyValue' is not defined.");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 68 with NodeTypeManager

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

the class AbstractMergeTest method setUp.

/**
     * Initialising used variables coming from the properties file.<br> Setup
     * some nodes on the 2 workspaces.<br>
     */
protected void setUp() throws Exception {
    super.setUp();
    super.checkSupportedOption(Repository.OPTION_VERSIONING_SUPPORTED);
    NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
    // versionable node type
    versionableNodeType = getProperty(PROP_VERSIONABLE_NODE_TYPE);
    if (versionableNodeType == null) {
        fail("Property '" + PROP_VERSIONABLE_NODE_TYPE + "' is not defined.");
    }
    NodeType vNt = ntm.getNodeType(versionableNodeType);
    if (!vNt.isNodeType(mixVersionable)) {
        fail("Property '" + PROP_VERSIONABLE_NODE_TYPE + "' does not define a versionable nodetype.");
    }
    // non versionable node type
    // test node type defines always a non versionable node type
    nonVersionableNodeType = testNodeType;
    if (nonVersionableNodeType == null) {
        fail("Property '" + testNodeType + "' is not defined.");
    }
    NodeType nvNt = ntm.getNodeType(nonVersionableNodeType);
    if (nvNt.isNodeType(mixVersionable)) {
        fail("Property '" + testNodeType + "' does define a versionable nodetype.");
    }
    // initialise a new session on second workspace as superuser
    superuserW2 = getHelper().getSuperuserSession(workspaceName);
    workspace = superuser.getWorkspace();
    workspaceW2 = superuserW2.getWorkspace();
    // get/create test root node on second workspace
    testRootNodeW2 = cleanUpTestRoot(superuserW2);
    // initialize test nodes
    initNodes();
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType)

Example 69 with NodeTypeManager

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

the class RepositoryServiceImpl method getQNodeTypeDefinitions.

/**
     * {@inheritDoc}
     */
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames) throws RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
    List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
    for (Name nodetypeName : nodetypeNames) {
        try {
            String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
            NodeType nt = ntMgr.getNodeType(ntName);
            defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
            // in addition pack all supertypes into the return value
            NodeType[] supertypes = nt.getSupertypes();
            for (NodeType supertype : supertypes) {
                defs.add(new QNodeTypeDefinitionImpl(supertype, sInfo.getNamePathResolver(), getQValueFactory()));
            }
        } catch (NameException e) {
            throw new RepositoryException(e);
        }
    }
    return defs.iterator();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

Example 70 with NodeTypeManager

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

the class RepositoryServiceImpl method unregisterNodeTypes.

/**
     * {@inheritDoc}
     */
public void unregisterNodeTypes(SessionInfo sessionInfo, Name[] nodeTypeNames) throws UnsupportedRepositoryOperationException, NoSuchNodeTypeException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
    String[] names = new String[nodeTypeNames.length];
    for (int i = 0; i < nodeTypeNames.length; i++) {
        names[i] = sInfo.getNamePathResolver().getJCRName(nodeTypeNames[i]);
    }
    ntMgr.unregisterNodeTypes(names);
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager)

Aggregations

NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)93 NodeType (javax.jcr.nodetype.NodeType)41 Node (javax.jcr.Node)32 Session (javax.jcr.Session)30 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)29 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)27 Test (org.junit.Test)24 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)14 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)14 RepositoryException (javax.jcr.RepositoryException)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 ArrayList (java.util.ArrayList)8 Workspace (javax.jcr.Workspace)8 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)8 NodeDefinition (javax.jcr.nodetype.NodeDefinition)8 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)8 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)7 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)7 InputStream (java.io.InputStream)6