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);
}
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
}
}
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
}
}
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);
}
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());
}
Aggregations