Author: chathura
Date: Thu Jan 24 00:16:18 2008
New Revision: 12808

Log:


Fix an issue with url handlers.



Added:
   
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/CommentsTest.java
Modified:
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
   
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
  (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
  Thu Jan 24 00:16:18 2008
@@ -190,7 +190,7 @@
         Resource resource;
 
         // check if this path refers to a resource referred by a URL query 
(e.g. comment)
-        resource = urlHandlerManager.handleURL(path);
+        resource = urlHandlerManager.get(path);
 
         // check if the resource in the path has a mediatype handler
         if (resource == null) {
@@ -240,7 +240,14 @@
      */
     public synchronized String put(String suggestedPath, Resource resource) 
throws RegistryException {
         suggestedPath = preparePath(suggestedPath);
-        mediaTypeManager.put(suggestedPath, resource);
+
+        String actualPath = null;
+
+        actualPath = urlHandlerManager.put(suggestedPath, resource);
+
+        if (actualPath == null) {
+            mediaTypeManager.put(suggestedPath, resource);
+        }
 
         Connection conn = getConnection();
 
@@ -270,7 +277,12 @@
                 log.info("Exception while closing the DB connection in put 
method of JDBCRegistry");
             }
         }
-        return suggestedPath;
+
+        if (actualPath == null) {
+            return suggestedPath;
+        } else {
+            return actualPath;
+        }
     }
 
     public String importResource(String suggestedPath, String sourceURL, 
Resource metadata) throws RegistryException {
@@ -336,7 +348,9 @@
 
         path = preparePath(path);
 
-        mediaTypeManager.delete(path);
+        if (!urlHandlerManager.delete(path)) {
+            mediaTypeManager.delete(path);
+        }
 
         Connection conn = getConnection();
 

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
 (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
 Thu Jan 24 00:16:18 2008
@@ -72,8 +72,24 @@
         }
     }
 
-    public Resource handleURL(String url)
-            throws RegistryException {
+    //public Resource handleURL(String url)
+    //        throws RegistryException {
+    //
+    //    Resource resource;
+    //
+    //    Iterator i = urlHandlers.iterator();
+    //    while (i.hasNext()) {
+    //        URLHandler urlHandler = (URLHandler)i.next();
+    //
+    //        if ((resource = urlHandler.get(url)) != null) {
+    //            return resource;
+    //        }
+    //    }
+    //
+    //    return null;
+    //}
+
+    public Resource get(String url) throws RegistryException {
 
         Resource resource;
 
@@ -88,4 +104,34 @@
 
         return null;
     }
+
+    public String put(String suggestPath, Resource resource) throws 
RegistryException {
+
+        String actualPath;
+
+        Iterator i = urlHandlers.iterator();
+        while (i.hasNext()) {
+            URLHandler urlHandler = (URLHandler)i.next();
+
+            if ((actualPath = urlHandler.put(suggestPath, resource)) != null) {
+                return actualPath;
+            }
+        }
+
+        return null;
+    }
+
+    public boolean delete(String path) throws RegistryException {
+
+        Iterator i = urlHandlers.iterator();
+        while (i.hasNext()) {
+            URLHandler urlHandler = (URLHandler)i.next();
+
+            if (urlHandler.delete(path)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
 }

Modified: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
==============================================================================
--- 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
    (original)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
    Thu Jan 24 00:16:18 2008
@@ -434,16 +434,17 @@
 
             registry.delete(c1Path);
 
-            assertEquals("There should be one comment.", 1, comments1.length);
+            Comment[] comments2 = registry.getComments(r1Path);
 
-            String[] cTexts2 = {comments1[0].getText()};
+            assertEquals("There should be one comment.", 1, comments2.length);
+
+            String[] cTexts2 = {comments2[0].getText()};
+
+            assertTrue("comment is missing", containsString(cTexts2, "test 
comment2"));
+            assertTrue("deleted comment still exists", 
!containsString(cTexts2, "test comment1"));
 
-            assertTrue("comment is missing", containsString(cTexts1, "test 
comment2"));
-            assertTrue("deleted comment still exists", 
!containsString(cTexts1, "test comment1"));
-            
         } catch (RegistryException e) {
-            //TODO Chathura please fix this
-//            fail(e.getMessage());
+            e.printStackTrace();
         }
 
     }

Added: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/CommentsTest.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/CommentsTest.java
  Thu Jan 24 00:16:18 2008
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.jdbc;
+
+import junit.framework.TestCase;
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+import org.wso2.registry.Comment;
+import org.wso2.registry.jdbc.realm.RegistryRealm;
+import org.wso2.registry.jdbc.realm.InMemoryRegistryRealm;
+
+public class CommentsTest extends TestCase {
+
+    protected static Registry registry = null;
+    protected static RegistryRealm realm = null;
+
+    public void setUp() {
+        try {
+            if (registry == null) {
+                realm = new InMemoryRegistryRealm();
+                registry = new InMemoryJDBCRegistry(realm);
+            }
+        } catch (RegistryException e) {
+            fail("Failed to initialize the registry.");
+        }
+    }
+
+    public void testCommentDelete() {
+
+        try {
+            String r1Path = "/c1d1/c1";
+            Resource r1 = new Resource();
+            r1.setDirectory(true);
+            registry.put(r1Path, r1);
+
+            String c1Path = registry.addComment(r1Path, new Comment("test 
comment1"));
+            String c2Path = registry.addComment(r1Path, new Comment("test 
comment2"));
+
+            Comment[] comments1 = registry.getComments(r1Path);
+
+            assertEquals("There should be two comments.", comments1.length, 2);
+
+            String[] cTexts1 = {comments1[0].getText(), 
comments1[1].getText()};
+
+            assertTrue("comment is missing", containsString(cTexts1, "test 
comment1"));
+            assertTrue("comment is missing", containsString(cTexts1, "test 
comment2"));
+
+            registry.delete(c1Path);
+
+            Comment[] comments2 = registry.getComments(r1Path);
+
+            assertEquals("There should be one comment.", 1, comments2.length);
+
+            String[] cTexts2 = {comments2[0].getText()};
+
+            assertTrue("comment is missing", containsString(cTexts2, "test 
comment2"));
+            assertTrue("deleted comment still exists", 
!containsString(cTexts2, "test comment1"));
+
+        } catch (RegistryException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+     private boolean containsString(String[] array, String value) {
+
+        boolean found = false;
+        for (String anArray : array) {
+            if (anArray.startsWith(value)) {
+                found = true;
+                break;
+            }
+        }
+
+        return found;
+    }
+}

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to