Search in sources :

Example 36 with NoSuchNodeTypeException

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

the class NodeTypeRegistryImpl method getEffectiveNodeType.

/**
 * @param ntNames
 * @param entCache
 * @param ntdCache
 * @return
 * @throws ConstraintViolationException
 * @throws NoSuchNodeTypeException
 */
private EffectiveNodeType getEffectiveNodeType(Name[] ntNames, EffectiveNodeTypeCache entCache, Map<Name, QNodeTypeDefinition> ntdCache) throws ConstraintViolationException, NoSuchNodeTypeException {
    EffectiveNodeTypeCache.Key key = entCache.getKey(ntNames);
    // 1. check if aggregate has already been built
    if (entCache.contains(key)) {
        return entCache.get(key);
    }
    // 2. make sure we've got the definitions of the specified node types
    for (Name ntName : ntNames) {
        if (!ntdCache.containsKey(ntName)) {
            throw new NoSuchNodeTypeException(ntName.toString());
        }
    }
    // 3. build aggregate
    EffectiveNodeTypeCache.Key requested = key;
    EffectiveNodeTypeImpl result = null;
    synchronized (entCache) {
        // build list of 'best' existing sub-aggregates
        while (key.getNames().length > 0) {
            // find the (sub) key that matches the current key the best
            EffectiveNodeTypeCache.Key subKey = entCache.findBest(key);
            if (subKey != null) {
                EffectiveNodeTypeImpl ent = (EffectiveNodeTypeImpl) entCache.get(subKey);
                if (result == null) {
                    result = ent;
                } else {
                    result = result.merge(ent);
                    // store intermediate result
                    entCache.put(result);
                }
                // subtract the result from the temporary key
                key = key.subtract(subKey);
            } else {
                /**
                 * no matching sub-aggregates found:
                 * build aggregate of remaining node types through iteration
                 */
                for (Name remainder : key.getNames()) {
                    QNodeTypeDefinition ntd = ntdCache.get(remainder);
                    EffectiveNodeType ent = getEffectiveNodeType(ntd, ntdCache);
                    // store new effective node type
                    entCache.put(ent);
                    if (result == null) {
                        result = (EffectiveNodeTypeImpl) ent;
                    } else {
                        result = result.merge((EffectiveNodeTypeImpl) ent);
                        // store intermediate result (sub-aggregate)
                        entCache.put(result);
                    }
                }
                break;
            }
        }
    }
    // the redundant nodetypes
    if (!entCache.contains(requested)) {
        entCache.put(requested, result);
    }
    // we're done
    return result;
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 37 with NoSuchNodeTypeException

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

the class NodeTypeManagerImplTest method testUnregisterNodeTypes.

public void testUnregisterNodeTypes() throws RepositoryException {
    NodeTypeTemplate test = ntMgr.createNodeTypeTemplate();
    test.setName("testNodeType2");
    ntMgr.registerNodeType(test, true);
    NodeType nt = ntMgr.getNodeType("testNodeType2");
    assertNotNull(nt);
    assertEquals("testNodeType2", nt.getName());
    boolean supported = false;
    try {
        ntMgr.unregisterNodeType(test.getName());
        supported = true;
    } catch (UnsupportedRepositoryOperationException e) {
    // ok
    } catch (RepositoryException e) {
        // TODO improve
        if (e.getMessage().contains("not yet implemented")) {
        // ok (original message in jr-core)
        } else {
            throw e;
        }
    }
    if (supported) {
        try {
            ntMgr.getNodeType("testNodeType2");
            fail("should not be available any more");
        } catch (NoSuchNodeTypeException e) {
        // success
        }
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 38 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_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 39 with NoSuchNodeTypeException

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

the class JcrExtensibleTypeProvider method getType.

@Override
public ExtensibleType getType(final ID id) {
    final JcrExtensibleType.TypeId typeId = (JcrExtensibleType.TypeId) id;
    final Session session = getSession();
    try {
        final Node typeNode = session.getNodeByIdentifier(typeId.getIdValue());
        final NodeType nodeType = session.getWorkspace().getNodeTypeManager().getNodeType(typeNode.getName());
        return new JcrExtensibleType(typeNode, nodeType);
    } catch (ItemNotFoundException e) {
        return null;
    } catch (NoSuchNodeTypeException | PathNotFoundException e) {
        return null;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failure retriving exstenible type with ID: " + id, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 40 with NoSuchNodeTypeException

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

the class JcrExtensibleTypeProvider method getType.

@Override
public ExtensibleType getType(final String name) {
    final Session session = getSession();
    final String typeName = ensureTypeName(name);
    try {
        final NodeType nodeType = session.getWorkspace().getNodeTypeManager().getNodeType(typeName);
        final Node typeNode = session.getRootNode().getNode(ExtensionsConstants.TYPES + "/" + typeName);
        return new JcrExtensibleType(typeNode, nodeType);
    } catch (NoSuchNodeTypeException | PathNotFoundException e) {
        return null;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to lookup extensible type: " + name, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) NodeType(javax.jcr.nodetype.NodeType) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session) 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