[dna-commits] DNA SVN: r855 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Apr 23 16:35:30 EDT 2009


Author: rhauch
Date: 2009-04-23 16:35:30 -0400 (Thu, 23 Apr 2009)
New Revision: 855

Modified:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
Log:
DNA-382 Workspace.move Is Not Supported

Applied the patch to implement Workspace.move

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java	2009-04-23 19:37:08 UTC (rev 854)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java	2009-04-23 20:35:30 UTC (rev 855)
@@ -349,30 +349,31 @@
      * 
      * @see javax.jcr.Workspace#move(java.lang.String, java.lang.String)
      */
-    @SuppressWarnings( "unused" )
     public void move( String srcAbsPath,
                       String destAbsPath ) throws PathNotFoundException, RepositoryException {
-        CheckArg.isNotEmpty(srcAbsPath, "srcAbsPath");
-        CheckArg.isNotEmpty(destAbsPath, "destAbsPath");
+        CheckArg.isNotNull(srcAbsPath, "srcAbsPath");
+        CheckArg.isNotNull(destAbsPath, "destAbsPath");
 
-        // Create the paths ...
-        PathFactory factory = context.getValueFactories().getPathFactory();
-        Path srcPath = null;
-        Path destPath = null;
-        try {
-            srcPath = factory.create(srcAbsPath);
-        } catch (ValueFormatException e) {
-            throw new RepositoryException(JcrI18n.invalidPathParameter.text(srcAbsPath, "srcAbsPath"), e);
+        // Use the session's execution context so that we get the transient namespace mappings
+        PathFactory pathFactory = session.getExecutionContext().getValueFactories().getPathFactory();
+        Path destPath = pathFactory.create(destAbsPath);
+
+        Path.Segment newNodeName = destPath.getSegment(destPath.size() - 1);
+        // Doing a literal test here because the path factory will canonicalize "/node[1]" to "/node"
+        if (destAbsPath.endsWith("]")) {
+            throw new RepositoryException();
         }
-        try {
-            destPath = factory.create(destAbsPath);
-        } catch (ValueFormatException e) {
-            throw new RepositoryException(JcrI18n.invalidPathParameter.text(destAbsPath, "destAbsPath"), e);
+
+        AbstractJcrNode sourceNode = session.getNode(pathFactory.create(srcAbsPath));
+        AbstractJcrNode newParentNode = session.getNode(destPath.getParent());
+
+        if (newParentNode.hasNode(newNodeName.getString(session.getExecutionContext().getNamespaceRegistry()))) {
+            throw new ItemExistsException();
         }
 
-        // Perform the copy operation, but use the "to" form (not the "into", which takes the parent) ...
-        // graph.move(srcPath).to(destPath);
-        throw new UnsupportedOperationException();
+        Graph.Batch operations = session.createBatch();
+        newParentNode.editorFor(operations).moveToBeChild(sourceNode, newNodeName.getName());
+        operations.execute();
     }
 
     /**

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java	2009-04-23 19:37:08 UTC (rev 854)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java	2009-04-23 20:35:30 UTC (rev 855)
@@ -178,7 +178,6 @@
         assertThat(workspace.getQueryManager(), notNullValue());
     }
 
-    @Test
     public void shouldCreateQuery() throws Exception {
         String statement = "Some query syntax";
 
@@ -241,8 +240,8 @@
         workspace.move(null, null);
     }
 
-    @Test( expected = UnsupportedOperationException.class )
-    public void shouldNotAllowMoveFromPathToAnotherPathInSameWorkspace() throws Exception {
+    @Test
+    public void shouldAllowMoveFromPathToAnotherPathInSameWorkspace() throws Exception {
         workspace.move("/a/b", "/b/b-copy");
     }
 




More information about the dna-commits mailing list