Refine search
private Set<String> getSelfPlusSubTypes(final String primaryNodeType) throws RepositoryException { Set<String> subTypes = new LinkedHashSet<>(); NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator allTypes = ntMgr.getAllNodeTypes(); while (allTypes.hasNext()) { NodeType nt = allTypes.nextNodeType(); if (nt.isNodeType(primaryNodeType)) { subTypes.add(nt.getName()); } } return subTypes; }
private List<ExtensibleType> getTypesList(final String typeName) { final Session session = getSession(); try { final List<ExtensibleType> list = new ArrayList<>(); final NodeTypeManager typeMgr = session.getWorkspace().getNodeTypeManager(); final NodeTypeIterator typeItr = typeMgr.getPrimaryNodeTypes(); final NodeType extensibleType = typeMgr.getNodeType(typeName); while (typeItr.hasNext()) { final NodeType nodeType = (NodeType) typeItr.next(); if (nodeType.isNodeType(extensibleType.getName()) && !nodeType.equals(extensibleType)) { String nodeTypePath = ExtensionsConstants.TYPES + "/" + nodeType.getName(); if (session.getRootNode().hasNode(nodeTypePath)) { final Node typeNode = session.getRootNode().getNode(nodeTypePath); list.add(new JcrExtensibleType(typeNode, nodeType)); } } } return list; } catch (RepositoryException e) { throw new MetadataRepositoryException("Failed to lookup all extensible types", e); } }
@Override public List<String> getAvailableNodeTypes() throws SerializedException { List<String> availableNodeTypeList; try { availableNodeTypeList = new ArrayList<String>(); NodeTypeIterator nodeTypeIterator = getJcrSession().getWorkspace().getNodeTypeManager().getAllNodeTypes(); for (int j = 0; j < nodeTypeIterator.getSize(); j++) { NodeType nodeType = nodeTypeIterator.nextNodeType(); availableNodeTypeList.add(nodeType.getName()); } } catch (Exception e) { log.error("Failed fetching available node types. ", e); throw new SerializedException(e.getMessage()); } return availableNodeTypeList; }
private static String getPrimaryTypeName(Session session, Node node) throws RepositoryException { NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = manager.getPrimaryNodeTypes(); while (nts.hasNext()) { String name = nts.nextNodeType().getName(); if (!name.equals(node.getPrimaryNodeType().getName())) { return name; } } return null; } }
/** * Return the set of node type names for the specified node types. */ private Set<String> asSetOfNames(NodeTypeIterator it) { Set<String> result = new HashSet<String>(); while (it.hasNext()) { result.add(it.nextNodeType().getName()); } return result; } }
Session session = testRootNode.getSession(); Session otherSession = null; Node node = testRootNode.addNode(nodeName1, testNodeType); superuser.save(); NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = manager.getPrimaryNodeTypes(); while (nts.hasNext()) { NodeType nt = nts.nextNodeType(); String ntName = nt.getName(); if (!nt.isAbstract() && !ntFrozenNode.equals(ntName)) { try { node.setPrimaryType(ntName); assertEquals("The value of the jcr:primaryType property must change upon setPrimaryType.", ntName, node.getProperty(jcrPrimaryType).getString()); superuser.save(); assertEquals("Node.getPrimaryNodeType must reflect the changes made.", ntName, node.getPrimaryNodeType().getName()); assertEquals("The value of the jcr:primaryType property must change upon setPrimaryType.", ntName, node.getProperty(jcrPrimaryType).getString());
public void ensureTypeDescriptors() { try { Session session = JcrMetadataAccess.getActiveSession(); Node typesNode = session.getRootNode().getNode(ExtensionsConstants.TYPES); NodeTypeManager typeMgr = (NodeTypeManager) session.getWorkspace().getNodeTypeManager(); NodeTypeIterator typeItr = typeMgr.getPrimaryNodeTypes(); NodeType extensionsType = typeMgr.getNodeType(ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE); while (typeItr.hasNext()) { NodeType type = (NodeType) typeItr.next(); if (type.isNodeType(ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE) && !type.equals(extensionsType) && !typesNode.hasNode(type.getName())) { Node descrNode = typesNode.addNode(type.getName(), ExtensionsConstants.TYPE_DESCRIPTOR_TYPE); descrNode.setProperty("jcr:title", simpleName(type.getName())); Node typeNode = (Node) nodeItr.next(); if (!typeMgr.hasNodeType(typeNode.getName())) { typeNode.remove();
String nodeTypeNotSatisfied = null; NodeTypeManager manager = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator types = manager.getAllNodeTypes(); while (types.hasNext()) { NodeType type = types.nextNodeType(); String name = type.getName(); if (constraints.contains(name) || ntFrozenNode.equals(name)) { continue; if (type.getChildNodeDefinitions() != null && type.getChildNodeDefinitions().length > 0) { continue; try { String nodeType = propDef.getDeclaringNodeType().getName(); node = testRootNode.addNode(nodeName2, nodeType); nodeSatisfied = testRootNode.addNode(nodeName3, nodeTypeSatisfied); ensureMixinType(nodeSatisfied, mixReferenceable); nodeNotSatisfied = testRootNode.addNode(nodeName4, nodeTypeNotSatisfied); ensureMixinType(nodeNotSatisfied, mixReferenceable); testRootNode.getSession().save();
/** * Tests if addNode() throws a ConstraintViolationException in case * of an mixin node type. */ public void testMixinNodeType() throws RepositoryException, NotExecutableException { NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = ntMgr.getMixinNodeTypes(); if (nts.hasNext()) { try { testRootNode.addNode(nodeName1, nts.nextNodeType().getName()); superuser.save(); fail("Expected ConstraintViolationException."); } catch (ConstraintViolationException e) { // correct. } } else { throw new NotExecutableException("no mixins."); } }
public void testDescendantNodesDoNotMatchSelector() throws RepositoryException, NotExecutableException { testRootNode.addNode(nodeName1, testNodeType); superuser.save(); NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator it = ntMgr.getPrimaryNodeTypes(); NodeType testNt = ntMgr.getNodeType(testNodeType); while (it.hasNext()) { NodeType nt = it.nextNodeType(); if (!testNt.isNodeType(nt.getName())) { // perform test QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"), qf.descendantNode("s", testRoot), null, null); checkQOM(qom, new Node[]{}); return; } } throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes"); }
NodeTypeIterator types = null; try { ntmgr = workspace.getNodeTypeManager(); types = ntmgr.getMixinNodeTypes(); } catch (RepositoryException e) { fail("Cannot access NodeType iterator: " + e); while (types.hasNext()) { NodeType t = (NodeType) types.next(); String name = t.getName(); name = "Node_" + name.replaceAll(":", "_"); try { n = nt.addNode(name); n.addMixin(t.getName()); session.save(); } catch (RepositoryException e) { sc.log("Cannot create node with mixin node type: " + e); pt.setProperty(sc.booleanTestProperty, true); pt.setProperty(sc.nameTestProperty, session.getValueFactory().createValue(sc.jcrPrimaryType, PropertyType.NAME)); pt.setProperty(sc.pathTestProperty, session.getValueFactory().createValue("paths/dont/have/to/point/anywhere", PropertyType.PATH));
/** * Tests if <code>Node.setPrimaryType(String)</code> throws a * <code>ConstraintViolationException</code> if the * name of a mixin type is passed */ public void testSetAbstractAsPrimaryType() throws RepositoryException { Session session = testRootNode.getSession(); NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = manager.getPrimaryNodeTypes(); while (nts.hasNext()) { NodeType nt = nts.nextNodeType(); if (nt.isAbstract()) { try { Node node = testRootNode.addNode(nodeName1, testNodeType); node.setPrimaryType(nt.getName()); fail("Node.setPrimaryType(String) must throw ConstraintViolationException if the specified node type name refers to an abstract node type."); } catch (ConstraintViolationException e) { // success } finally { // reset the changes. session.refresh(false); } } } }
/** * Tests if <code>Node.setPrimaryType(String)</code> throws a * <code>ConstraintViolationException</code> if the * name of a mixin type is passed */ public void testSetMixinAsPrimaryType() throws RepositoryException { Session session = testRootNode.getSession(); NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = manager.getMixinNodeTypes(); while (nts.hasNext()) { try { Node node = testRootNode.addNode(nodeName1, testNodeType); node.setPrimaryType(nts.nextNodeType().getName()); fail("Node.setPrimaryType(String) must throw ConstraintViolationException if the specified node type name refers to a mixin."); } catch (ConstraintViolationException e) { // success } finally { // reset the changes. session.refresh(false); } } }
/** * Tests if addNode() throws a ConstraintViolationException in case * of an abstract node type. */ public void testAbstractNodeType() throws RepositoryException { NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator nts = ntMgr.getPrimaryNodeTypes(); while (nts.hasNext()) { NodeType nt = nts.nextNodeType(); if (nt.isAbstract()) { try { testRootNode.addNode(nodeName1, nt.getName()); superuser.save(); fail("Expected ConstraintViolationException."); } catch (ConstraintViolationException e) { // correct. } finally { superuser.refresh(false); } } } }
/** * @return a string that is not the name of a mixin type */ public static String getNonExistingMixinName(Session session) throws RepositoryException { NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator mixins = manager.getMixinNodeTypes(); StringBuffer s = new StringBuffer("X"); while (mixins.hasNext()) { s.append(mixins.nextNodeType().getName()); } return s.toString().replaceAll(":", ""); }
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager(); NodeType base = ntMgr.getNodeType(resolvedName); if (base.isMixin()) { 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 {
/** * @return the name of a mixin node type that can be added by the requested * <code>node</code> */ public static String getAddableMixinName(Session session, Node node) throws RepositoryException { NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator mixins = manager.getMixinNodeTypes(); // Skip mix:shareable since not supported by removeMixin String mixShareable = session.getNamespacePrefix(AbstractJCRTest.NS_MIX_URI) + ":shareable"; while (mixins.hasNext()) { String name = mixins.nextNodeType().getName(); if (node.canAddMixin(name) && !node.isNodeType(name) && !mixShareable.equals(name)) { return name; } } return null; }
NodeTypeIterator it = superuser.getWorkspace().getNodeTypeManager().getPrimaryNodeTypes(); while (it.hasNext() && referenceableNt == null) { NodeType nt = it.nextNodeType(); String ntName = nt.getName(); if (nt.isNodeType(mixReferenceable) && !nt.isAbstract() && superuser.importXML(testRootNode.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator iter = ntMgr.getAllNodeTypes(); while (iter.hasNext()) { NodeType nt = iter.nextNodeType(); set.remove(npResolver.getQName(nt.getName())); if (nodeTypes.size() > 0) { try { ntMgr.registerNodeTypes(nodeTypes.toArray(new NodeTypeDefinition[nodeTypes.size()]), true); } catch (UnsupportedOperationException e) { log.error("Unable to install node types."); String name = npResolver.getJCRName(t.getName()); track(tracker, "A", name); nts.add(session.getWorkspace().getNodeTypeManager().getNodeType(name));
private void fetch() { while (nextNode == null) { while (nodeIter == null || !nodeIter.hasNext()) { if (!typeIter.hasNext()) { return; } NodeType nodeType = typeIter.nextNodeType(); if (nodeType.getName().startsWith(namespace + ":")) { try { Query query = session.getWorkspace().getQueryManager().createQuery("SELECT * FROM " + nodeType.getName(), Query.SQL); QueryResult result = query.execute(); log.debug("upgrade querying for namespace " + namespace + ": " + query.getStatement()); nodeIter = result.getNodes(); } catch (RepositoryException ex) { log.debug(ex.getClass().getName() + ": " + ex.getMessage(), ex); } } } Node candidate = nodeIter.nextNode(); try { if (isMatch(candidate)) { nextNode = candidate; return; } } catch (RepositoryException ex) { log.debug(ex.getClass().getName() + ": " + ex.getMessage(), ex); } } }