/** Test if the removeExisting-flag removes an existing node in case of uuid conflict. */ public void testWorkspaceRestoreWithRemoveExistingJcr2() throws NotExecutableException, RepositoryException { // create version for parentNode of childNode superuser .getWorkspace() .clone( workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false); Version parentV = versionableNode .getSession() .getWorkspace() .getVersionManager() .checkin(versionableNode.getPath()); // move child node in order to produce the uuid conflict String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName(); wSuperuser.move(wVersionableChildNode.getPath(), newChildPath); wSuperuser.save(); // restore the parent with removeExisting == true >> moved child node // must be removed. wSuperuser.getWorkspace().getVersionManager().restore(new Version[] {parentV}, true); if (wSuperuser.itemExists(newChildPath)) { fail( "Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict."); } }
/** * Tests if restoring the <code>Version</code> of an existing node throws an <code> * ItemExistsException</code> if removeExisting is set to FALSE. */ public void testWorkspaceRestoreWithUUIDConflictJcr2() throws RepositoryException, NotExecutableException { try { // Verify that nodes used for the test are indeed versionable NodeDefinition nd = wVersionableNode.getDefinition(); if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { throw new NotExecutableException("Nodes must be versionable in order to run this test."); } VersionManager versionManager = wVersionableNode.getSession().getWorkspace().getVersionManager(); String path = wVersionableNode.getPath(); Version v = versionManager.checkin(path); versionManager.checkout(path); wSuperuser.move( wVersionableChildNode.getPath(), wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName()); wSuperuser.save(); wSuperuser.getWorkspace().getVersionManager().restore(new Version[] {v}, false); fail( "Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); } catch (ItemExistsException e) { // success } }
/** {@inheritDoc} */ public void undeleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException { Node fileToUndeleteNode = session.getNodeByIdentifier(fileId.toString()); String trashFileIdNodePath = fileToUndeleteNode.getParent().getPath(); String origParentFolderPath = getOriginalParentFolderPath(session, pentahoJcrConstants, fileToUndeleteNode, false); String absDestPath = origParentFolderPath + RepositoryFile.SEPARATOR + fileToUndeleteNode.getName(); if (session.itemExists(absDestPath)) { RepositoryFile file = JcrRepositoryFileUtils.nodeToFile( session, pentahoJcrConstants, pathConversionHelper, lockHelper, (Node) session.getItem(absDestPath)); throw new RepositoryFileDaoFileExistsException(file); } session.move(fileToUndeleteNode.getPath(), absDestPath); session.getItem(trashFileIdNodePath).remove(); }
public Location move(Node original, Node newParent, Name newName, Node beforeSibling) throws RepositoryException { // Determine whether the node needs to move ... if (newParent == null && beforeSibling != null) { newParent = beforeSibling.getParent(); } if (newName != null || (newParent != null && !original.getParent().equals(newParent))) { // This is not just a reorder, so we definitely have to move first ... String destAbsPath = newParent != null ? newParent.getPath() : original.getParent().getPath(); assert !destAbsPath.endsWith("/"); String newNameStr = newName != null ? stringFor(newName) : original.getName(); destAbsPath += '/' + newNameStr; session.move(original.getPath(), destAbsPath); } if (beforeSibling != null) { // Even if moved, the 'orginal' node should still point to the node we just moved ... String siblingName = nameFor(beforeSibling); String originalName = nameFor(original); original.getParent().orderBefore(originalName, siblingName); } return locationFor(original); }
public void testConcurrentSessionMove() throws RepositoryException { testRootPath = testRootNode.getPath(); Node aa = testRootNode.addNode("a").addNode("aa"); Node b = testRootNode.addNode("b"); testRootNode.getSession().save(); String aaId = aa.getIdentifier(); String bId = b.getIdentifier(); Session session1 = getHelper().getReadWriteSession(); Session session2 = getHelper().getReadWriteSession(); // results in /b/a/aa session1.move(testRootPath + "/a", testRootPath + "/b/a"); assertEquals(testRootPath + "/b/a/aa", session1.getNodeByIdentifier(aaId).getPath()); // results in a/aa/b session2.move(testRootPath + "/b", testRootPath + "/a/aa/b"); assertEquals(testRootPath + "/a/aa/b", session2.getNodeByIdentifier(bId).getPath()); session1.save(); // path should not have changed after save. assertEquals(testRootPath + "/a/aa/b", session2.getNodeByIdentifier(bId).getPath()); try { session2.save(); fail("Save should have failed. Possible cyclic persistent path created."); } catch (InvalidItemStateException e) { // expect is a ex caused by a StaleItemStateException with "has been modified externally" if (!(e.getCause() instanceof StaleItemStateException)) { throw e; } } }
@Override public void move(String srcDir, String destDir) throws SystemException { Session session = null; try { session = JCRFactoryUtil.createSession(); session.move(srcDir, destDir); session.save(); } catch (RepositoryException re) { throw new SystemException(re); } finally { JCRFactoryUtil.closeSession(session); } }
/** {@inheritDoc} */ public void deleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId) throws RepositoryException { Node fileToDeleteNode = session.getNodeByIdentifier(fileId.toString()); // move file to .trash subfolder named with the UUID of the file to delete Node trashFileIdNode = getOrCreateTrashFileIdNode(session, pentahoJcrConstants, fileId); trashFileIdNode.setProperty(pentahoJcrConstants.getPHO_DELETEDDATE(), Calendar.getInstance()); trashFileIdNode.setProperty( pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH(), pathConversionHelper.absToRel(fileToDeleteNode.getParent().getPath())); // origName only stored in order to do a jcr:like query later on the node name; fn:name() can // only do equals trashFileIdNode.setProperty(pentahoJcrConstants.getPHO_ORIGNAME(), fileToDeleteNode.getName()); session.move( fileToDeleteNode.getPath(), trashFileIdNode.getPath() + RepositoryFile.SEPARATOR + fileToDeleteNode.getName()); }