Search in sources :

Example 21 with NoSuchNodeTypeException

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

the class AbstractVersionTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    super.checkSupportedOption(Repository.OPTION_SIMPLE_VERSIONING_SUPPORTED);
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    // assert that this repository support versioning
    try {
        NodeType versionableNt = ntMgr.getNodeType(mixSimpleVersionable);
        if (versionableNt == null) {
            fail("Repository does not support Versioning: mixin nodetype 'mix:simpleVersionable' is missing.");
        }
    } catch (NoSuchNodeTypeException e) {
        fail("Repository does not support Versioning: mixin nodetype 'mix:simpleVersionable' 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 'simpleVersionableNodeType' 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 22 with NoSuchNodeTypeException

use of javax.jcr.nodetype.NoSuchNodeTypeException in project kylo by Teradata.

the class JcrExtensibleTypeProvider method deleteType.

@Override
public boolean deleteType(final ID id) {
    final Session session = getSession();
    final JcrExtensibleType.TypeId typeId = (JcrExtensibleType.TypeId) id;
    try {
        final Node typeNode = session.getNodeByIdentifier(typeId.getIdValue());
        final String typeName = typeNode.getName();
        session.getWorkspace().getNodeTypeManager().unregisterNodeType(typeName);
        session.getRootNode().getNode(ExtensionsConstants.TYPES + "/" + typeName).remove();
        return JcrExtensibleEntityProvider.cleanupDeletedType(session, typeName);
    } catch (ItemNotFoundException | NoSuchNodeTypeException | NullPointerException e) {
        // KYLO-8: Ignore NPE caused by unregistering a node type
        return true;
    } catch (UnsupportedRepositoryOperationException e) {
        return false;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to retrieve extensible type: " + id, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 23 with NoSuchNodeTypeException

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

the class ReadWriteNodeTypeManager method unregisterNodeTypes.

@Override
public void unregisterNodeTypes(String[] names) throws RepositoryException {
    Root root = getWriteRoot();
    Tree types = root.getTree(NODE_TYPES_PATH);
    if (!types.exists()) {
        throw new NoSuchNodeTypeException("Node types can not be unregistered.");
    }
    try {
        for (String name : names) {
            Tree type = types.getChild(getOakName(name));
            if (!type.exists()) {
                throw new NoSuchNodeTypeException("Node type " + name + " can not be unregistered.");
            }
            type.remove();
        }
        root.commit();
        refresh();
    } catch (CommitFailedException e) {
        String message = "Failed to unregister node types.";
        throw e.asRepositoryException(message);
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 24 with NoSuchNodeTypeException

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

the class MixinTest method testRemoveInheritedMixin2.

public void testRemoveInheritedMixin2() throws Exception {
    try {
        Authorizable user = ((JackrabbitSession) superuser).getUserManager().getAuthorizable("admin");
        if (user == null) {
            throw new NotExecutableException();
        }
        Node node = superuser.getNode(user.getPath());
        assertTrue(node.isNodeType(JcrConstants.MIX_REFERENCEABLE));
        node.removeMixin(JcrConstants.MIX_REFERENCEABLE);
    } catch (NoSuchNodeTypeException e) {
    // success
    } finally {
        superuser.refresh(false);
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 25 with NoSuchNodeTypeException

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

the class MixinTest method testRemoveMixinWithoutMixinProperty.

public void testRemoveMixinWithoutMixinProperty() throws Exception {
    Node node = testRootNode.addNode("testRemoveMixinWithoutMixinProperty", NT_UNSTRUCTURED);
    superuser.save();
    try {
        node.removeMixin(JcrConstants.MIX_REFERENCEABLE);
        fail();
    } catch (NoSuchNodeTypeException e) {
    // success
    } finally {
        node.remove();
        superuser.save();
    }
}
Also used : Node(javax.jcr.Node) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Aggregations

NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)47 Name (org.apache.jackrabbit.spi.Name)16 NodeType (javax.jcr.nodetype.NodeType)15 RepositoryException (javax.jcr.RepositoryException)11 Node (javax.jcr.Node)10 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)9 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 Session (javax.jcr.Session)7 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)7 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)7 HashSet (java.util.HashSet)5 Tree (org.apache.jackrabbit.oak.api.Tree)4 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)4 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)4 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)3 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)3 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)3 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 Stack (java.util.Stack)2