public Object jsFunction_getPrimaryItem() { try { return ScriptRuntime.toObject(this, node.getPrimaryItem()); } catch (RepositoryException re) { return Undefined.instance; } }
/** * @inheritDoc */ public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException { return factory.getItemDecorator(session, node.getPrimaryItem()); }
@Override public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException { return getWrappedNode().getPrimaryItem(); }
@Override public Item getPrimaryItem() throws RepositoryException { return ensureBestWrapper(delegate.getPrimaryItem(), session); }
@Override public Item getPrimaryItem() throws RepositoryException { return getNode().getPrimaryItem(); }
/** * Returns the first descendant of <code>node</code> without a primary item * * @param node * @return first node without primary item */ private Node locateNodeWithoutPrimaryItem(Node node) throws RepositoryException { try { node.getPrimaryItem(); } catch (ItemNotFoundException e) { return node; } NodeIterator nodes = node.getNodes(); while (nodes.hasNext()) { Node returnedNode = this.locateNodeWithoutPrimaryItem(nodes.nextNode()); if (returnedNode != null) { return returnedNode; } } return null; }
/** {@inheritDoc} */ public RemoteItem getPrimaryItem() throws RepositoryException, RemoteException { try { return getRemoteItem(node.getPrimaryItem()); } catch (RepositoryException ex) { throw getRepositoryException(ex); } }
@Override public InputStream getResourceInputStream(final Source source, final String resourcePath) throws IOException { try { final String pathFromBase = makeBaseRelativePath(source, resourcePath); Node resourceNode = baseNode.getNode(pathFromBase); Property primary = (Property) resourceNode.getPrimaryItem(); // JCR API Spec defines conversion of String to binary using UTF-8, which is what we want here return primary.getBinary().getStream(); } catch (RepositoryException e) { throw new RuntimeException("Problem loading stream for resource in baseline", e); } }
public Item getPrimaryItem() throws RepositoryException { Item primaryItem = this.item.getPrimaryItem(); if (primaryItem.isNode()) { return new NodeProxy((Node) primaryItem, this); } else { return new PropertyProxy((Property) primaryItem, this); } }
public JcrItem execute() throws Exception { return JcrItem.Wrapper.wrap(getDelegate().getPrimaryItem(), getJcrSession()); } });
public Item getPrimaryItem() throws RepositoryException { return ItemWrapper.wrap(getDelegate().getPrimaryItem(), getSessionWrapper()); }
/** * Test if getPrimaryItem does throw an ItemNotFoundException if the primary * node type does not define a primary item. Therefor a node without a * primary item is located recursively in the entire repository. A * NotExecutableException is thrown when no such node is found. */ public void testGetPrimaryItemItemNotFoundException() throws NotExecutableException, RepositoryException { Node node = locateNodeWithoutPrimaryItem(testRootNode); if (node == null) { throw new NotExecutableException("Workspace does not contain a node without primary item defined"); } try { node.getPrimaryItem(); fail("getPrimaryItem() must throw a ItemNotFoundException " + "if the primary node type does not define one"); } catch (ItemNotFoundException e) { // success } }
/** * traverses incoming node trying to find primary nt:resource node * * @param node * @return nt:resource node * @throws ItemNotFoundException * if no such node found * @throws RepositoryException */ public static Node getNtResourceRecursively(Node node) throws ItemNotFoundException, RepositoryException { if (node.isNodeType("nt:resource")) return node; Item pi = node.getPrimaryItem(); if (pi.isNode()) { return getNtResourceRecursively((Node)pi); } throw new ItemNotFoundException("No nt:resource node found for " + node.getPath()); } }
/** * Test if getPrimaryItem returns the primary item as defined in the primary * node type. Therefor a node with a primary item is located recursively in * the entire repository. A NotExecutableException is thrown when no such * node is found. */ public void testGetPrimaryItem() throws NotExecutableException, RepositoryException { Node node = locateNodeWithPrimaryItem(testRootNode); if (node == null) { throw new NotExecutableException("Workspace does not contain a node with primary item defined"); } String primaryItemName = node.getPrimaryNodeType().getPrimaryItemName(); Item primaryItem = node.getPrimaryItem(); if (primaryItem.isNode()) { assertTrue("Node returned by getPrimaryItem() is not the same as " + "the one aquired by getNode(String)", node.getNode(primaryItemName).isSame(primaryItem)); } else { assertTrue("Property returned by getPrimaryItem() is not the same as " + "the one aquired by getProperty(String)", node.getProperty(primaryItemName).isSame(primaryItem)); } }
@FixFor( "MODE-1696" ) public void testShouldVerifyNtResourceNodesHavePrimaryItem() throws Exception { Session session1 = getHelper().getSuperuserSession(); // Create node structure Node root1 = getTestRoot(session1); Node resource = root1.addNode("resource", "nt:resource"); Binary binary = session1.getValueFactory().createBinary(getClass().getResourceAsStream("/data/simple.json")); resource.setProperty("jcr:data", binary); session1.save(); // Find the primary item ... resource = root1.getNode("resource"); Item primary = resource.getPrimaryItem(); assertNotNull(primary); assertThat(resource.getProperty("jcr:data"), is(sameInstance(primary))); }
/** * Test if node.getPrimaryItemName() returns the same name as * node.getPrimaryItem().getName() */ public void testGetPrimaryItemName() throws NotExecutableException, RepositoryException { Node node = locateNodeWithPrimaryItem(rootNode); if (node == null) { throw new NotExecutableException("Workspace does not contain a node with primary item defined"); } String name = node.getPrimaryItem().getName(); NodeType type = node.getPrimaryNodeType(); assertEquals("node.getPrimaryNodeType().getPrimaryItemName() " + "must return the same name as " + "node.getPrimaryItem().getName()", name, type.getPrimaryItemName()); }
@Test public void shouldFindMasterBranchAsPrimaryItemUnderTreeNode() throws Exception { Node git = gitRemoteNode(); Node tree = git.getNode("tree"); Item primaryItem = tree.getPrimaryItem(); assertThat(primaryItem, is(notNullValue())); assertThat(primaryItem, is(instanceOf(Node.class))); Node primaryNode = (Node)primaryItem; assertThat(primaryNode.getName(), is("master")); assertThat(primaryNode.getParent(), is(sameInstance(tree))); assertThat(primaryNode, is(sameInstance(tree.getNode("master")))); }
@Test public void shouldFindMasterBranchAsPrimaryItemUnderBranchNode() throws Exception { Node git = gitRemoteNode(); Node branches = git.getNode("branches"); Item primaryItem = branches.getPrimaryItem(); assertThat(primaryItem, is(notNullValue())); assertThat(primaryItem, is(instanceOf(Node.class))); Node primaryNode = (Node)primaryItem; assertThat(primaryNode.getName(), is("master")); assertThat(primaryNode.getParent(), is(sameInstance(branches))); assertThat(primaryNode, is(sameInstance(branches.getNode("master")))); }
public void testShouldVerifyNtFileNodesHavePrimaryItem() throws Exception { Session session1 = getHelper().getSuperuserSession(); // Create node structure Node root1 = getTestRoot(session1); Node folder1 = root1.addNode("folder1", "nt:folder"); String fileName = "simple.json"; String filePath = folder1.getPath() + "/" + fileName; new JcrTools().uploadFile(session1, filePath, getClass().getResourceAsStream("/data/" + fileName)); session1.save(); // Find the primary item ... Node file1 = folder1.getNode(fileName); Node content = file1.getNode("jcr:content"); assertNotNull(file1); Item primary = file1.getPrimaryItem(); assertThat(primary, is(sameInstance((Item)content))); // Change the primary type of the "jcr:content" node to "nt:unstructured" ... content.setPrimaryType("nt:unstructured"); session1.save(); // Find the primary item (again) ... Node content2 = file1.getNode("jcr:content"); assertNotNull(file1); Item primary2 = file1.getPrimaryItem(); assertThat(primary2, is(sameInstance((Item)content2))); }
@Test public void shouldFindTreeBranchAsPrimaryItemUnderGitRoot() throws Exception { Node git = gitRemoteNode(); Node tree = git.getNode("tree"); assertThat(tree, is(notNullValue())); Item primaryItem = git.getPrimaryItem(); assertThat(primaryItem, is(notNullValue())); assertThat(primaryItem, is(instanceOf(Node.class))); Node primaryNode = (Node)primaryItem; assertThat(primaryNode.getName(), is(tree.getName())); assertThat(primaryNode.getParent(), is(sameInstance(git))); assertThat(primaryNode, is(sameInstance(tree))); }