/** * @throws RepositoryException */ public void testFrozenChildNodeNodeType() throws RepositoryException { versionableNode.addNode("child"); versionableNode.getSession().save(); VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); String path = versionableNode.getPath(); Version v = versionManager.checkin(path); Node n = v.getFrozenNode().getNode("child"); String puuid = n.getProperty(jcrPrimaryType).getValue().getString(); String nuuid = n.getPrimaryNodeType().getName(); assertEquals("jcr:primaryType needs to be equal to the getPrimaryNodeType() return value.", nuuid, puuid); }
private static boolean hasMixin(Node node, String type) throws RepositoryException { if (!node.hasProperty("jcr:mixinTypes")) { return false; } NodeTypeManager ntMgr = node.getSession().getWorkspace().getNodeTypeManager(); for (Value value : node.getProperty("jcr:mixinTypes").getValues()) { NodeType nt = ntMgr.getNodeType(value.getString()); if (nt.isNodeType(type)) { return true; } } return false; }
private boolean canSetProperty(NodeType nodeType, String propertyName, int propertyType, boolean isMultiple) { PropertyDefinition propDefs[] = nodeType.getPropertyDefinitions(); for (int i = 0; i < propDefs.length; i++) { if (propDefs[i].getName().equals(propertyName) || propDefs[i].getName().equals("*")) { if ((propDefs[i].getRequiredType() == propertyType || propDefs[i].getRequiredType() == PropertyType.UNDEFINED) && propDefs[i].isMultiple() == isMultiple) { return true; } } } return false; }
private String getPrimaryItemName(final Node document) throws RepositoryException { NodeType primaryType = document.getPrimaryNodeType(); String primaryItemName = primaryType.getPrimaryItemName(); while (primaryItemName == null && !NT_BASE.equals(primaryType.getName())) { for (NodeType nt : primaryType.getSupertypes()) { if (nt.getPrimaryItemName() != null) { primaryItemName = nt.getPrimaryItemName(); break; } if (nt.isNodeType(NT_BASE)) { primaryType = nt; } } } return primaryItemName; }
/** * Checks whether the node already has the specified mixin node type */ protected boolean needsMixin(Node node, String mixin) throws RepositoryException { return ! node.getSession().getWorkspace().getNodeTypeManager().getNodeType(node.getPrimaryNodeType().getName()).isNodeType(mixin); }
/** * @throws RepositoryException */ public void testFrozenNodeNodeType() throws RepositoryException { VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); String path = versionableNode.getPath(); Version v = versionManager.checkin(path); Node n = v.getFrozenNode(); String puuid = n.getProperty(jcrPrimaryType).getValue().getString(); String nuuid = n.getPrimaryNodeType().getName(); assertEquals("jcr:primaryType needs to be equal to the getPrimaryNodeType() return value.", nuuid, puuid); }
public void testFrozenNode() throws RepositoryException { Node n = testRootNode.addNode(nodeName1, testNodeType); n.addMixin(mixVersionable); Node child = n.addNode(nodeName2, ntUnstructured); superuser.save(); VersionManager vMgr = superuser.getWorkspace().getVersionManager(); vMgr.checkpoint(n.getPath()); Version v = vMgr.getBaseVersion(n.getPath()); Node frozenChild = v.getFrozenNode().getNode(child.getName()); assertEquals(ntFrozenNode, frozenChild.getPrimaryNodeType().getName()); }
/** * 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."); } }
@Test @FixFor( "MODE-1976" ) public void shouldBeAbleToCopyFromRepositoryToExternalSource() throws Exception { jcrSession().getRootNode().addNode("files").addNode("dir", "nt:folder"); jcrSession().save(); jcrSession().getWorkspace().copy("/files/dir", "/testRoot/store/dir"); Node dir = session.getNode("/testRoot/store/dir"); assertNotNull(dir); assertEquals("nt:folder", dir.getPrimaryNodeType().getName()); }
protected void assertFile( Node node, File file ) throws Exception { assertThat(node.getName(), is(file.getName())); assertThat(node.getIndex(), is(1)); assertThat(node.getPrimaryNodeType().getName(), is("nt:file")); assertThat(node.getProperty("jcr:created").getLong(), is(createdTimeFor(file))); Node content = node.getNode("jcr:content"); assertThat(content.getName(), is("jcr:content")); assertThat(content.getIndex(), is(1)); assertThat(content.getPrimaryNodeType().getName(), is("nt:resource")); assertThat(content.getProperty("jcr:lastModified").getLong(), is(file.lastModified())); }
/** * Checks if the node is of the supplied node type or if the node type is a mixin checks if the node has the mixin. * Also, if the node is frozen checks the node's type prior to being frozen. */ public static boolean isNodeType(Node node, String nodeTypeName) throws RepositoryException { node = NodeUtil.deepUnwrap(node, JCRPropertiesFilteringNodeWrapper.class); final String actualType = node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString(); // if the node is frozen, and we're not looking specifically for frozen nodes, then we compare with the original // node type if (JcrConstants.NT_FROZENNODE.equals(actualType) && !(JcrConstants.NT_FROZENNODE.equals(nodeTypeName))) { final Property p = node.getProperty(JcrConstants.JCR_FROZENPRIMARYTYPE); final String s = p.getString(); NodeTypeManager ntManager = node.getSession().getWorkspace().getNodeTypeManager(); NodeType primaryNodeType = ntManager.getNodeType(s); return primaryNodeType.isNodeType(nodeTypeName); } return node.isNodeType(nodeTypeName); }
/** * Sets up the test cases */ protected void setUp() throws Exception { isReadOnly = true; super.setUp(); session = getHelper().getReadOnlySession(); testRootNode = session.getRootNode().getNode(testPath); nodeTypeName = session.getRootNode().getPrimaryNodeType().getName(); qm = session.getWorkspace().getQueryManager(); }
public Boolean isFileNodeType(final ResourceResolver resolver, final String nodeType) { final Session session = resolver.adaptTo(Session.class); if ( session != null ) { try { final NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager(); final NodeType nt = ntMgr.getNodeType(nodeType); return nt.isNodeType(JcrConstants.NT_FILE); } catch (RepositoryException e) { // assuming type not valid. return null; } } return false; }
public void testChildInSubTree() throws Exception { Node frozenN1 = frozen.getNode(nodeName1); Node frozenN2 = frozenN1.getNode(nodeName2); assertEquals(NT_VERSIONEDCHILD, frozenN2.getPrimaryNodeType().getName()); Property childVh = frozenN2.getProperty(JCR_CHILD_VERSION_HISTORY); assertEquals(versionManager.getVersionHistory(testRoot + '/' + nodeName1 + '/' + nodeName2).getUUID(), childVh.getString()); Node frozenN3 = frozenN1.getNode(nodeName3); assertEquals(NT_FROZENNODE, frozenN3.getPrimaryNodeType().getName()); } }
public void testChildNodesDoNotMatchSelector() 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.sameNode("s", testRoot + "/" + nodeName1), null, null); checkQOM(qom, new Node[]{}); return; } } throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes"); }
/** * Test if an inherited mixin could be added. * * @throws RepositoryException * @since JCR 2.0 */ public void testAddInheritedMixin() throws RepositoryException { Session session = testRootNode.getSession(); Node node = testRootNode.addNode(nodeName1, testNodeType); session.save(); NodeType nt = node.getPrimaryNodeType(); NodeType[] superTypes = nt.getSupertypes(); for (int i = 0; i < superTypes.length; i++) { if (superTypes[i].isMixin()) { String mixinName = superTypes[i].getName(); // adding again must be possible (though it has no effect) assertTrue(node.canAddMixin(mixinName)); } } }
private Node getActualNode(Session session, Node node) throws RepositoryException { NodeType type = node.getPrimaryNodeType(); if (type.getName().equals("nt:versionedChild")) { String uuid = node.getProperty("jcr:childVersionHistory").getValue().getString(); Node actualNode = session.getNodeByIdentifier(uuid); String name = actualNode.getName(); actualNode = session.getNodeByIdentifier(name); return actualNode; } return node; }
public static String getNotAssignedMixinName(Session session, Node node) throws RepositoryException { NodeTypeManager manager = session.getWorkspace().getNodeTypeManager(); NodeTypeIterator mixins = manager.getMixinNodeTypes(); Set<String> existingMixins = new HashSet<String>(); for (NodeType nt : node.getMixinNodeTypes()) { existingMixins.add(nt.getName()); } while (mixins.hasNext()) { String ntName = mixins.nextNodeType().getName(); if (!existingMixins.contains(ntName)) { return ntName; } } return null; }
private Item getPrimaryItem(Node node) throws Exception { NodeType primaryType = node.getPrimaryNodeType(); String primaryItemName = primaryType.getPrimaryItemName(); while (primaryItemName == null && !"nt:base".equals(primaryType.getName())) { for (NodeType nt : primaryType.getSupertypes()) { if (nt.getPrimaryItemName() != null) { primaryItemName = nt.getPrimaryItemName(); break; } if (nt.isNodeType("nt:base")) { primaryType = nt; } } } if (primaryItemName == null) { throw new ItemNotFoundException("No primary item definition found in type hierarchy"); } return node.getSession().getItem(node.getPath() + "/" + primaryItemName); }