Search in sources :

Example 26 with NoSuchNodeTypeException

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

the class TreeUtil method addMixin.

public static void addMixin(@Nonnull Tree tree, @Nonnull String mixinName, @Nonnull Tree typeRoot, @CheckForNull String userID) throws RepositoryException {
    Tree type = typeRoot.getChild(mixinName);
    if (!type.exists()) {
        throw new NoSuchNodeTypeException("Node type " + mixinName + " does not exist");
    } else if (getBoolean(type, JCR_IS_ABSTRACT)) {
        throw new ConstraintViolationException("Node type " + mixinName + " is abstract");
    } else if (!getBoolean(type, JCR_ISMIXIN)) {
        throw new ConstraintViolationException("Node type " + mixinName + " is a not a mixin type");
    }
    List<String> mixins = Lists.newArrayList();
    String primary = getName(tree, JCR_PRIMARYTYPE);
    if (primary != null && Iterables.contains(getNames(type, NodeTypeConstants.REP_PRIMARY_SUBTYPES), primary)) {
        return;
    }
    Set<String> subMixins = Sets.newHashSet(getNames(type, NodeTypeConstants.REP_MIXIN_SUBTYPES));
    for (String mixin : getNames(tree, NodeTypeConstants.JCR_MIXINTYPES)) {
        if (mixinName.equals(mixin) || subMixins.contains(mixin)) {
            return;
        }
        mixins.add(mixin);
    }
    mixins.add(mixinName);
    tree.setProperty(JcrConstants.JCR_MIXINTYPES, mixins, NAMES);
    autoCreateItems(tree, type, typeRoot, userID);
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 27 with NoSuchNodeTypeException

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

the class NodeRemoveMixinTest method testNotAssigned.

/**
 * Tests if <code>Node.removeMixin(String mixinName)</code> throws a
 * NoSuchNodeTypeException <code>Node</code> does not have assigned the
 * requested mixin
 */
public void testNotAssigned() throws NotExecutableException, RepositoryException {
    Session session = testRootNode.getSession();
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
    if (mixinName == null) {
        throw new NotExecutableException("No testable mixin node type found");
    }
    node.addMixin(mixinName);
    testRootNode.getSession().save();
    String notAssignedMixin = NodeMixinUtil.getNotAssignedMixinName(session, node);
    if (notAssignedMixin == null) {
        throw new NotExecutableException("No testable mixin node type found");
    }
    try {
        node.removeMixin(notAssignedMixin);
        fail("Node.removeMixin(String mixinName) must throw a " + "NoSuchNodeTypeException if Node does not have the " + "specified mixin.");
    } catch (NoSuchNodeTypeException e) {
    // success
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Session(javax.jcr.Session) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 28 with NoSuchNodeTypeException

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

the class NodeAddMixinTest method testAddNonExisting.

/**
 * Tests if <code>Node.addMixin(String mixinName)</code> throws a
 * <code>NoSuchNodeTypeException</code> if <code>mixinName</code> is not the
 * name of an existing mixin node type
 */
public void testAddNonExisting() throws RepositoryException {
    Session session = testRootNode.getSession();
    String nonExistingMixinName = NodeMixinUtil.getNonExistingMixinName(session);
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    try {
        node.addMixin(nonExistingMixinName);
        fail("Node.addMixin(String mixinName) must throw a " + "NoSuchNodeTypeException if mixinName is an unknown mixin type");
    } catch (NoSuchNodeTypeException e) {
    // success
    }
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 29 with NoSuchNodeTypeException

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

the class NodeImpl method removeMixin.

/**
 * @see Node#removeMixin(String)
 */
public void removeMixin(String mixinName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
    checkIsWritable();
    Name ntName = getQName(mixinName);
    List<Name> mixinValue = getMixinTypes();
    // remove name of target mixin
    if (!mixinValue.remove(ntName)) {
        throw new NoSuchNodeTypeException("Cannot remove mixin '" + mixinName + "': Nodetype is not present on this node.");
    }
    // mix:referenceable needs additional assertion: the mixin cannot be
    // removed, if any references are left to this node.
    NodeTypeImpl mixin = session.getNodeTypeManager().getNodeType(ntName);
    if (mixin.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
        EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
        if (!entRemaining.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
            PropertyIterator iter = getReferences();
            if (iter.hasNext()) {
                throw new ConstraintViolationException("Mixin type " + mixinName + " can not be removed: the node is being referenced through at least one property of type REFERENCE");
            }
        }
    }
    /*
         * mix:lockable: the mixin cannot be removed if the node is currently
         * locked even if the editing session is the lock holder.
         */
    if (mixin.isNodeType((NameConstants.MIX_LOCKABLE))) {
        EffectiveNodeType entRemaining = getRemainingENT(mixinValue);
        if (!entRemaining.includesNodeType(NameConstants.MIX_LOCKABLE) && isLocked()) {
            throw new ConstraintViolationException(mixinName + " can not be removed: the node is locked.");
        }
    }
    // delegate to operation
    Name[] mixins = mixinValue.toArray(new Name[mixinValue.size()]);
    Operation op = SetMixin.create(getNodeState(), mixins);
    session.getSessionItemStateManager().execute(op);
}
Also used : EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) NodeTypeImpl(org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeImpl) PropertyIterator(javax.jcr.PropertyIterator) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Operation(org.apache.jackrabbit.jcr2spi.operation.Operation) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 30 with NoSuchNodeTypeException

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

the class GetPersistentQueryPathTest method testGetPersistentQueryPath.

/**
 * Tests if {@link Query#getStoredQueryPath()} returns the correct path
 * where the query had been saved.
 *
 * @throws NotExecutableException if the repository does not support the
 *                                node type nt:query.
 */
public void testGetPersistentQueryPath() throws RepositoryException, NotExecutableException {
    try {
        superuser.getWorkspace().getNodeTypeManager().getNodeType(ntQuery);
    } catch (NoSuchNodeTypeException e) {
        // not supported
        throw new NotExecutableException("repository does not support nt:query");
    }
    String statement = "/" + jcrRoot;
    Query q = superuser.getWorkspace().getQueryManager().createQuery(statement, qsXPATH);
    String path = testRoot + "/" + nodeName1;
    q.storeAsNode(path);
    assertEquals("Query.getPersistentQueryPath() does not return the correct path.", path, q.getStoredQueryPath());
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Query(javax.jcr.query.Query) 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