Refine search
/** * If successful, the changes are persisted immediately, there is no need to * call save. */ public void testCloneNodes() throws RepositoryException { // clone referenceable node below non-referenceable node String dstAbsPath = node2W2.getPath() + "/" + node1.getName(); workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true); // there should not be any pending changes after clone assertFalse(superuserW2.hasPendingChanges()); }
/** * A NoSuchWorkspaceException is thrown if srcWorkspace does not exist. */ public void testCloneNodesInvalidWorkspace() throws RepositoryException { // clone a node to a non-existing workspace String dstAbsPath = node2W2.getPath() + "/" + node1.getName(); try { workspaceW2.clone(getNonExistingWorkspaceName(superuser), node1.getPath(), dstAbsPath, true); fail("Invalid Source Workspace should throw NoSuchWorkspaceException."); } catch (NoSuchWorkspaceException e) { // successful } }
private static String clone(Session session, String[] cloneArgs, DavResourceLocator reqLocator) throws RepositoryException { Workspace wsp = session.getWorkspace(); String destPath = null; for (String cloneArg : cloneArgs) { String[] args = cloneArg.split(","); if (args.length == 4) { wsp.clone(args[0], args[1], args[2], Boolean.valueOf(args[3])); destPath = args[2]; } else { throw new RepositoryException(":clone parameter must have a value consisting of the 4 args needed for a Workspace.clone() call."); } } return buildLocationHref(session, destPath, reqLocator); }
/** * initialize a three-step-hierarchy on default and second workspace */ protected void initNodes() throws RepositoryException { // create a versionable parent node // nodeName1 Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType); topVNode.setProperty(propertyName1, topVNode.getName()); // create a non'versionable sub node // nodeName1/nodeName2 Node subNvNode = topVNode.addNode(nodeName2, testNodeType); subNvNode.setProperty(propertyName1, subNvNode.getName()); // create a non'versionable sub node below nonversionable node // nodeName1/nodeName2/nodeName3 Node subSubNvNode = subNvNode.addNode(nodeName3, testNodeType); subSubNvNode.setProperty(propertyName1, subSubNvNode.getName()); // save default workspace testRootNode.getSession().save(); log.println("test nodes created successfully on " + workspace.getName()); // clone the newly created node from src workspace into second workspace workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true); log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName() + " at " + topVNode.getPath()); testRootNodeW2 = (Node) superuserW2.getItem(testRoot); }
superuser.save(); String wsp = superuser.getWorkspace().getName(); String workspace2 = getAlternativeWorkspaceName(); if (workspace2 == null) { s2.getWorkspace().clone(wsp, "/" + nodeName, "/" + nodeName, true);
/** * Test if the removeExisting-flag removes an existing node in case of uuid conflict. */ @SuppressWarnings("deprecation") public void testWorkspaceRestoreWithRemoveExisting() throws NotExecutableException, RepositoryException { // create version for parentNode of childNode superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false); Version parentV = versionableNode.checkin(); // 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().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."); } }
/** * initialize a two-step-hierarchy on default and second workspace */ protected void initNodes() throws RepositoryException { // create a versionable parent node // nodeName1 Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType); topVNode.setProperty(propertyName1, topVNode.getName()); // create a versionable sub node // nodeName1/nodeName2 Node subNvNode = topVNode.addNode(nodeName2, versionableNodeType); subNvNode.setProperty(propertyName1, subNvNode.getName()); // save default workspace testRootNode.getSession().save(); log.println("test nodes created successfully on " + workspace.getName()); // clone the newly created node from src workspace into second workspace workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true); log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName() + " at " + topVNode.getPath()); testRootNodeW2 = (Node) superuserW2.getItem(testRoot); }
/** * The destAbsPath provided must not have an index on its final element. If * it does, then a RepositoryException is thrown. Strictly speaking, the * destAbsPath parameter is actually an absolute path to the parent node of * the new location, appended with the new name desired for the copied node. * It does not specify a position within the child node ordering. */ public void testCloneNodesAbsolutePath() { try { // copy referenceable node to an absolute path containing index String dstAbsPath = node2W2.getPath() + "/" + node1.getName() + "[2]"; workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true); fail("Cloning a node to an absolute path containing index should not be possible."); } catch (RepositoryException e) { // successful } }
@Test @FixFor( "MODE-1975" ) public void shouldNotAllowCloneWithinTheSameWs() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); try { jcrSession().getWorkspace().clone(jcrSession().getWorkspace().getName(), "/testRoot", "/testRoot1", false); fail("Should not be able to clone in the same ws if external nodes are involved"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
/** * 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."); } }
public Object run() throws RepositoryException { SessionInfoImpl srcInfo = getSessionInfoImpl(obtain(sessionInfo, srcWorkspaceName)); try { String srcPath = pathForId(srcNodeId, srcInfo); String destPath = getDestinationPath(destParentNodeId, destName, sInfo); Workspace wsp = sInfo.getSession().getWorkspace(); wsp.clone(srcWorkspaceName, srcPath, destPath, removeExisting); } finally { dispose(srcInfo); } return null; } }, sInfo);
/** * initialize a two-step-hierarchy on default and second workspace */ protected void initNodes() throws RepositoryException { // create a versionable parent node // nodeName1 Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType); topVNode.setProperty(propertyName1, topVNode.getName()); // create a versionable sub node // nodeName1/nodeName2 Node subNvNode = topVNode.addNode(nodeName2, versionableNodeType); subNvNode.setProperty(propertyName1, subNvNode.getName()); // save default workspace testRootNode.getSession().save(); log.println("test nodes created successfully on " + workspace.getName()); // clone the newly created node from src workspace into second workspace workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true); log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName() + " at " + topVNode.getPath()); testRootNodeW2 = (Node) superuserW2.getItem(testRoot); } }
/** * If removeExisting is false then a UUID collision causes this method to * throw a ItemExistsException and no changes are made. */ public void testCloneNodesRemoveExistingFalse() throws RepositoryException, NotExecutableException { // add mixin referenceable to node1 addMixinReferenceableToNode(node1); // clone a node from default workspace to have the same uuid on second workspace workspaceW2.clone(workspace.getName(), node1.getPath(), testRootNodeW2.getPath() + "/" + nodeName3, false); // clone node1 from default workspace to second workspace try { workspaceW2.clone(workspace.getName(), node1.getPath(), testRootNodeW2.getPath() + "/" + nodeName4, false); fail("If removeExisting is false then a UUID collision should throw a ItemExistsException"); } catch (ItemExistsException e) { // successful } }
@Test @FixFor( "MODE-1975" ) public void shouldNotAllowMoveWithinTheSameWsViaClone() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); try { // clone with removeExisting = true in the same ws is a move jcrSession().getWorkspace().clone(jcrSession().getWorkspace().getName(), "/testRoot", "/testRoot1", true); fail("Should not be able to clone in the same ws if external nodes are involved"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
public Object run() throws RepositoryException { SessionInfoImpl srcInfo = getSessionInfoImpl(obtain(sessionInfo, srcWorkspaceName)); try { String srcPath = pathForId(srcNodeId, srcInfo); String destPath = getDestinationPath(destParentNodeId, destName, sInfo); Workspace wsp = sInfo.getSession().getWorkspace(); wsp.clone(srcWorkspaceName, srcPath, destPath, removeExisting); } finally { dispose(srcInfo); } return null; } }, sInfo);
/** * Clone a mix:shareable node to the same workspace (6.13.20). Verify * that cloning without mix:shareable fails. */ public void testClone() throws Exception { // setup parent nodes and first child Node a1 = testRootNode.addNode("a1"); Node a2 = testRootNode.addNode("a2"); Node b1 = a1.addNode("b1"); testRootNode.getSession().save(); Workspace workspace = b1.getSession().getWorkspace(); try { // clone (1st attempt, without mix:shareable, should fail) workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false); fail("Cloning a node into the same workspace should fail."); } catch (RepositoryException e) { // expected } // add mixin ensureMixinType(b1, mixShareable); b1.save(); // clone (2nd attempt, with mix:shareable) workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false); }
/** * If ordering is supported by the node type of the parent node of the new * location, then the newly moved node is appended to the end of the child * node list. */ public void testCloneNodesOrderingSupportedByParent() throws RepositoryException { // test assumes that repositry supports Orderable Child Node Support (optional) String[] orderList = {nodeName1, nodeName2, nodeName3}; // copy node three times below a node and check the order for (int i = 0; i < orderList.length; i++) { workspaceW2.clone(workspace.getName(), node1.getPath(), node2.getPath() + "/" + orderList[i], true); } // check regarding orderList with the counter if nodes are added at the end int cnt = 0; NodeIterator iter = node2.getNodes(); while (iter.hasNext()) { Node n = iter.nextNode(); assertTrue(n.getName().equals(orderList[cnt])); cnt++; } }
assertThat(session.getWorkspace().getName(), is("otherWorkspace")); superuser.getWorkspace().clone("otherWorkspace", "/cloneSource", "/cloneTarget/cloneSource", false); superuser.getWorkspace().clone("otherWorkspace", "/cloneSource", "/" + nodeName3 + "/cloneSource", true); superuser.refresh(false); superuser.getWorkspace().clone("otherWorkspace", "/cloneSource", "/" + nodeName3 + "/cloneSource", true); fail("Should not be able to use clone to remove the mandatory child node at /nodeWithMandatoryChild/modetest:mandatoryChild"); } catch (ConstraintViolationException cve) {
protected void cloneWorkspace( String sourceWorkspace, String targetWorkspace, boolean removeExisting ) throws Exception { Session session = repository.login(targetWorkspace); try { session.getWorkspace().clone(sourceWorkspace, "/", "/", removeExisting); } finally { session.logout(); } }
private void clone(Node node, Node parent) throws RepositoryException { if (node.getDefinition().isAutoCreated()) { Node destination = parent.getNode(node.getName()); this.removeProperties(destination); this.updateProperties(node, destination); } else { final String parentPath = parent.getPath(); final String srcWorkspaceLogicalName = node.getSession().getWorkspace().getName(); final String srcWorkspacePhysicalName = repositoryManager.getWorkspaceMapping(srcWorkspaceLogicalName).getPhysicalWorkspaceName(); final Workspace targetWorkspace = parent.getSession().getWorkspace(); final String srcPath = node.getPath(); final String targetPath = parentPath + (parentPath != null && parentPath.endsWith("/") ? "" : "/") + node.getName(); log.debug("workspace level clone from {}:{} to {}:{}", srcWorkspaceLogicalName, srcPath, targetWorkspace.getName(), parentPath); targetWorkspace.clone(srcWorkspacePhysicalName, srcPath, targetPath, true); } }