/** * Used for building exception messages where we want to avoid handling another exception inside a throws clause. */ public static String getNodeIdentifierIfPossible(Node content) { try { return content.getIdentifier(); } catch (RepositoryException e) { return "<not available>"; } }
@Override public int compare(Node node1, Node node2) { try { final String identifier1 = node1.getIdentifier(); final String identifier2 = node2.getIdentifier(); return identifier1.compareTo(identifier2); } catch (RepositoryException e) { throw new RuntimeException("Error getting identifier from jcr node.", e); } }
String getSavePath(Node node) throws RepositoryException { String uuid = node.getIdentifier(); return String.format("%s/%s/%s", StringUtils.substring(uuid, 0, 2), StringUtils.substring(uuid, 9, 11), StringUtils.substring(uuid, 14, 16)); } }
public LazyNodeWrapper(Node node) throws RepositoryException { this.workspace = node.getSession().getWorkspace().getName(); this.nodeIdentifier = node.getIdentifier(); this.node = node; }
@Override public MgnlGroup doExec(Session session) throws RepositoryException { String parentPath = StringUtils.defaultString(path, "/"); Node groupNode = session.getNode(parentPath).addNode(name, NodeTypes.Group.NAME); session.save(); return new MgnlGroup(groupNode.getIdentifier(), groupNode.getName(), Collections.EMPTY_LIST, Collections.EMPTY_LIST); }
@Override public void setWrappedNode(Node node) { try { this.workspace = node.getSession().getWorkspace().getName(); this.nodeIdentifier = node.getIdentifier(); this.node = node; } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } }
public String getUUID() { if (StringUtils.isEmpty(this.uuid) && this.getJCRNode() != null) { try { this.uuid = this.getJCRNode().getIdentifier(); } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } } return this.uuid; }
private String getSavePath(Node node) throws RepositoryException { String uuid = node.getIdentifier(); return String.format("%s/%s/%s", StringUtils.substring(uuid, 0, 2), StringUtils.substring(uuid, 9, 11), StringUtils.substring(uuid, 14, 16)); } }
private void prepareGroupData() throws Exception { String peopleGroup = "people"; String employeesGroup = "employees"; String developersGroup = "developers"; // Create a group (developers) which has an assigned group (employees) which again has an assigned group (people) final Node developersNode = session.getRootNode().addNode(developersGroup, NodeTypes.Group.NAME); final Node employeesNode = session.getRootNode().addNode(employeesGroup, NodeTypes.Group.NAME); final Node peopleNode = session.getRootNode().addNode(peopleGroup, NodeTypes.Group.NAME); developersNode.addNode(RepositoryBackedSecurityManager.GROUPS_NODE_NAME, NodeTypes.ContentNode.NAME).setProperty("0", employeesNode.getIdentifier()); employeesNode.addNode(RepositoryBackedSecurityManager.GROUPS_NODE_NAME, NodeTypes.ContentNode.NAME).setProperty("0", peopleNode.getIdentifier()); session.save(); }
public Object doInJcr( final Session session ) throws RepositoryException, IOException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session ); Node node = session.getNodeByIdentifier( id.toString() ); if ( !node.getParent().isSame( session.getRootNode() ) ) { return toAcl( session, pentahoJcrConstants, node.getParent().getIdentifier() ); } else { return null; } } } );
@Override public Boolean answer(InvocationOnMock invocation) throws Throwable { Node foo = parentNode.addNode("foo", Page.NAME); Node bar = parentNode.addNode("bar", Page.NAME); expectedItemIds.add(new JcrNodeItemId(foo.getIdentifier(), WEBSITE)); expectedItemIds.add(new JcrNodeItemId(bar.getIdentifier(), WEBSITE)); return true; } }).when(commandsManager).executeCommand(eq(mockCommand), anyMapOf(String.class, Object.class));
public Link(Node node) { try { setJCRNode(node); setWorkspace(node.getSession().getWorkspace().getName()); if (node.isNodeType(JcrConstants.MIX_REFERENCEABLE)) { setUUID(node.getIdentifier()); } } catch (RepositoryException e) { throw new RuntimeRepositoryException(e); } }
@Override protected void setUp() throws Exception { super.setUp(); Node node = testRootNode.addNode(nodeName1); node.addMixin(mixReferenceable); Node sibling = testRootNode.addNode(nodeName2); uuid = node.getIdentifier(); path = node.getPath(); siblingPath = sibling.getPath(); }
private void createUserAndAddToGroup(String userName, String groupName, String basePath) throws Exception { // "manually" create a user and assign it to a group => /admin/<userName>/groups/0=<group-uuid> Session groupsSession = MgnlContext.getJCRSession(RepositoryConstants.USER_GROUPS); String groupUuid = groupsSession.getNode("/" + groupName).getIdentifier(); // Session usersSession = MgnlContext.getJCRSession(RepositoryConstants.USERS); Node parentNode = NodeUtil.createPath(session.getRootNode(), basePath, NodeTypes.Folder.NAME); Node newUserNode = parentNode.addNode(userName, NodeTypes.User.NAME); Node groupsNode = newUserNode.addNode("groups", NodeTypes.ContentNode.NAME); groupsNode.setProperty("0", groupUuid); usersSession.save(); }
@Test public void testGetNodeByIdentifierBadId() throws RepositoryException { // GIVEN Node addedNode = MgnlContext.getJCRSession(WEBSITE).getRootNode().addNode("1"); // WHEN Node returnedNode = SessionUtil.getNodeByIdentifier(WEBSITE, addedNode.getIdentifier() + 1); // THEN assertEquals(null, returnedNode); }
@Test public void versionNodesAreRenamed() throws Exception { // WHEN task.execute(installContext); // THEN assertThat(testNode.getPath(), is("/" + getSavePath(testNode) + "/" + testNode.getIdentifier())); }
@Test public void testGetNodeByIdentifier() throws RepositoryException { // GIVEN Node addedNode = MgnlContext.getJCRSession(WEBSITE).getRootNode().addNode("1"); // WHEN Node returnedNode = SessionUtil.getNodeByIdentifier(WEBSITE, addedNode.getIdentifier()); // THEN assertEquals(addedNode, returnedNode); }
public void testRemoveUUID() throws Exception { superuser.save(); superuser.importXML(siblingPath, getImportStream(), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING); superuser.save(); // original node must have been removed assertFalse(testRootNode.hasNode(nodeName1)); Node sibling = superuser.getNode(siblingPath); assertTrue(sibling.hasNode(nodeName1)); Node imported = sibling.getNode(nodeName1); assertTrue(imported.isNodeType(mixReferenceable)); assertEquals(uuid, imported.getIdentifier()); }
@Test public void testCreateSessionFromString() throws IOException, RepositoryException { String workspace = "workspace"; String content = "/parent1/sub1.prop1=one"; MockSession session = SessionTestUtil.createSession(workspace, content); assertEquals("one", session.getNode("/parent1/sub1").getProperty("prop1").getString()); content = "/parent1/sub1.@uuid=1\n" + "/parent2/sub2.@uuid=2"; session = SessionTestUtil.createSession("testWorkspace", content); assertEquals("1", session.getNode("/parent1/sub1").getIdentifier()); assertEquals("2", session.getNode("/parent2/sub2").getIdentifier()); }
@Test public void copyToVersionWithNewStructure() throws Exception { // GIVEN Node testNode = websiteSession.getRootNode().addNode("test", NodeTypes.Page.NAME); // WHEN copyUtil.copyToVersion(testNode, new RuleBasedNodePredicate(new Rule())); // THEN Node versionNode = versionSession.getNodeByIdentifier(testNode.getIdentifier()); assertThat(versionNode.getParent().getPath(), matchesRegex("/\\w{2}/\\w{2}/\\w{2}")); assertThat(versionSession.getRootNode(), hasNode(CopyUtil.getSavePath(versionNode) + "/" + testNode.getIdentifier())); }