jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1128368 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
Date Fri, 27 May 2011 15:42:29 GMT
Author: mduerig
Date: Fri May 27 15:42:28 2011
New Revision: 1128368

URL: http://svn.apache.org/viewvc?rev=1128368&view=rev
Log:
spi2microkernel prototype (WIP)

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1128368&r1=1128367&r2=1128368&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Fri May 27 15:42:28 2011
@@ -47,6 +47,7 @@ import org.json.simple.parser.ParseExcep
 
 import javax.jcr.Credentials;
 import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
@@ -121,12 +122,12 @@ public class RepositoryServiceImpl exten
 
     public String[] getWorkspaceNames(SessionInfo sessionInfo) throws RepositoryException
{
         String rev = getRevision(sessionInfo);
-        String json = microKernel.getNodes("/", 0, rev);
 
         // Names of first level nodes correspond to workspace names
         final List<String> workspaces = new ArrayList<String>();
 
         try {
+            String json = microKernel.getNodes("/", 0, rev);
             new JSONParser().parse(json, new JsonHandlerBase(){
                 public String currentKey;
 
@@ -145,6 +146,9 @@ public class RepositoryServiceImpl exten
                 }
             });
         }
+        catch (MicroKernelException e) {
+            throw new RepositoryException(e.getMessage(), e );
+        }
         catch (ParseException e) {
             throw new RepositoryException(e.getMessage(), e );
         }
@@ -172,8 +176,13 @@ public class RepositoryServiceImpl exten
             String mkPath = Paths.translateQPath(wspName, path);
             String rev = getRevision(sessionInfo);
 
-            String json = microKernel.getNodes(mkPath, 1, rev);
-            return Json.buildItemInfos(path, json);
+            if (microKernel.nodeExists(mkPath, rev)) {
+                String json = microKernel.getNodes(mkPath, 1, rev);
+                return Json.buildItemInfos(path, json);
+            }
+            else {
+                throw new PathNotFoundException(path.toString());
+            }
         }
         catch (MicroKernelException e) {
             // todo throw correct exceptions
@@ -188,8 +197,13 @@ public class RepositoryServiceImpl exten
             String mkPath = Paths.translateQPath(wspName, path);
             String rev = getRevision(sessionInfo);
 
-            String json = microKernel.getNodes(mkPath, 1, rev);
-            return Json.buildNodeInfo(path, json);
+            if (microKernel.nodeExists(mkPath, rev)) {
+                String json = microKernel.getNodes(mkPath, 1, rev);
+                return Json.buildNodeInfo(path, json);
+            }
+            else {
+                throw new PathNotFoundException(path.toString());
+            }
         }
         catch (MicroKernelException e) {
             // todo throw correct exceptions
@@ -204,8 +218,13 @@ public class RepositoryServiceImpl exten
             String mkPath = Paths.translateQPath(wspName, path.getAncestor(1));
             String rev = getRevision(sessionInfo);
 
-            String json = microKernel.getNodes(mkPath, 0, rev);
-            return Json.buildPropertyInfo(path, json);
+            if (microKernel.nodeExists(mkPath, rev)) {
+                String json = microKernel.getNodes(mkPath, 0, rev);
+                return Json.buildPropertyInfo(path, json);
+            }
+            else {
+                throw new PathNotFoundException(path.toString());
+            }
         }
         catch (MicroKernelException e) {
             // todo throw correct exceptions
@@ -281,17 +300,22 @@ public class RepositoryServiceImpl exten
     }
 
     private void createWorkspace(String revisionId, String name, boolean ignoreExisting)
throws RepositoryException {
-        String wspName = Paths.getWorkspaceName(name);
-        if (microKernel.nodeExists('/' + wspName, revisionId)) {
-            if (ignoreExisting) {
-                return;
-            }
-            else {
-                throw new RepositoryException("Workspace already exists: " + name);
+        try {
+            String wspName = Paths.getWorkspaceName(name);
+            if (microKernel.nodeExists('/' + wspName, revisionId)) {
+                if (ignoreExisting) {
+                    return;
+                }
+                else {
+                    throw new RepositoryException("Workspace already exists: " + name);
+                }
             }
-        }
 
-        microKernel.commit("/", '+' + wspName + " : {}" , revisionId);
+            microKernel.commit("/", '+' + wspName + " : {}" , revisionId);
+        }
+        catch (MicroKernelException e) {
+            throw new RepositoryException(e.getMessage(), e);
+        }
     }
 
     private static void copyWorkspace(String revisionId, String name, String srcWorkspaceName)
throws RepositoryException {
@@ -299,8 +323,17 @@ public class RepositoryServiceImpl exten
     }
 
     private void deleteWorkspace(String revisionId, String name)  throws RepositoryException
{
-        String wspName = Paths.getWorkspaceName(name);
-        microKernel.commit("/", '-' + wspName + " : ", revisionId);
+        try {
+            String wspName = Paths.getWorkspaceName(name);
+            if (!microKernel.nodeExists('/' + wspName, revisionId)) {
+                throw new NoSuchWorkspaceException("No such workspace: " + name);       
        
+            }
+
+            microKernel.commit("/", '-' + wspName + " : ", revisionId);
+        }
+        catch (MicroKernelException e) {
+            throw new RepositoryException(e.getMessage(), e);
+        }
     }
 
 }

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java?rev=1128368&r1=1128367&r2=1128368&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
Fri May 27 15:42:28 2011
@@ -20,7 +20,6 @@ package org.apache.jackrabbit.spi2microk
 
 import org.apache.jackrabbit.mk.MicroKernelImpl;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import javax.imageio.spi.ServiceRegistry;
@@ -130,7 +129,6 @@ public class Tests {
         assertEquals("/foo", node.getPath());
     }
 
-    @Ignore  // todo RepositoryServiceImpl throws wrong exception 
     @Test(expected = PathNotFoundException.class)
     public void getNonexNode() throws RepositoryException {
         getNode("/qoo");



Mime
View raw message