Search in sources :

Example 1 with NoSuchNodeTypeException

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

the class TypeEditorProvider method isTrivialChange.

private boolean isTrivialChange(ReadOnlyNodeTypeManager ntBefore, ReadOnlyNodeTypeManager ntAfter, String nodeType) {
    NodeType nb, na;
    try {
        nb = ntBefore.getNodeType(nodeType);
    } catch (NoSuchNodeTypeException ex) {
        LOG.info(nodeType + " not present in 'before' state");
        return true;
    } catch (RepositoryException ex) {
        LOG.info("getting node type", ex);
        return false;
    }
    try {
        na = ntAfter.getNodeType(nodeType);
    } catch (NoSuchNodeTypeException ex) {
        LOG.info(nodeType + " was removed");
        return false;
    } catch (RepositoryException ex) {
        LOG.info("getting node type", ex);
        return false;
    }
    NodeTypeDefDiff diff = NodeTypeDefDiff.create(nb, na);
    if (!diff.isModified()) {
        LOG.info("Node type " + nodeType + " was not changed");
        return true;
    } else if (diff.isTrivial()) {
        LOG.info("Node type change for " + nodeType + " appears to be trivial");
        return true;
    } else {
        LOG.info("Node type change for " + nodeType + " requires repository scan: " + diff);
        return false;
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 2 with NoSuchNodeTypeException

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

the class ReadWriteNodeTypeManager method unregisterNodeType.

@Override
public void unregisterNodeType(String name) throws RepositoryException {
    Root root = getWriteRoot();
    Tree type = root.getTree(NODE_TYPES_PATH).getChild(getOakName(name));
    if (!type.exists()) {
        throw new NoSuchNodeTypeException("Node type " + name + " can not be unregistered.");
    }
    try {
        type.remove();
        root.commit();
        refresh();
    } catch (CommitFailedException e) {
        String message = "Failed to unregister node type " + name;
        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 3 with NoSuchNodeTypeException

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

the class NodeDelegate method removeMixin.

public void removeMixin(String typeName) throws RepositoryException {
    Tree tree = getTree();
    Set<String> mixins = newLinkedHashSet(getNames(tree, JCR_MIXINTYPES));
    if (!mixins.remove(typeName)) {
        throw new NoSuchNodeTypeException("Mixin " + typeName + " not contained in " + getPath());
    }
    updateMixins(mixins, Collections.singleton(typeName));
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 4 with NoSuchNodeTypeException

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

the class MixinTest method testRemoveInheritedMixin.

public void testRemoveInheritedMixin() throws Exception {
    Node node = testRootNode.addNode("testRemoveInheritedMixin", NT_UNSTRUCTURED);
    node.addMixin(JcrConstants.MIX_VERSIONABLE);
    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)

Example 5 with NoSuchNodeTypeException

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

the class GQL method collectNodeTypes.

/**
 * Resolves and collects all node types that match <code>ntName</code>.
 *
 * @param ntName the name of a node type (optionally without prefix).
 * @throws RepositoryException if an error occurs while reading from the
 *                             node type manager.
 */
private void collectNodeTypes(String ntName) throws RepositoryException {
    NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
    String[] resolvedNames = resolveNodeTypeName(ntName);
    // now resolve node type hierarchy
    for (String resolvedName : resolvedNames) {
        try {
            NodeType base = ntMgr.getNodeType(resolvedName);
            if (base.isMixin()) {
                // search for nodes where jcr:mixinTypes is set to this mixin
                addTypeConstraint(new MixinComparision(resolvedName));
            } else {
                // search for nodes where jcr:primaryType is set to this type
                addTypeConstraint(new PrimaryTypeComparision(resolvedName));
            }
            // now search for all node types that are derived from base
            NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
            while (allTypes.hasNext()) {
                NodeType nt = allTypes.nextNodeType();
                NodeType[] superTypes = nt.getSupertypes();
                if (Arrays.asList(superTypes).contains(base)) {
                    if (nt.isMixin()) {
                        addTypeConstraint(new MixinComparision(nt.getName()));
                    } else {
                        addTypeConstraint(new PrimaryTypeComparision(nt.getName()));
                    }
                }
            }
        } catch (NoSuchNodeTypeException e) {
            // add anyway -> will not match anything
            addTypeConstraint(new PrimaryTypeComparision(resolvedName));
        }
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) 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