[Registry-dev] svn commit r16589 - in trunk/registry/modules/core/src: main/java/org/wso2/registry main/java/org/wso2/registry/app main/java/org/wso2/registry/aspects main/java/org/wso2/registry/jdbc/handlers/builtin/utils test/java/org/wso2/registry/app test/java/org/wso2/registry/jdbc

svn at wso2.org svn at wso2.org
Tue May 6 22:24:45 PDT 2008


Author: deepal
Date: Tue May  6 22:24:24 2008
New Revision: 16589

Log:

- added some wsdl extraction 
- collection pagination 


Added:
   trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPBasedPaginationTest.java
   trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PaginationTest.java
Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Collection.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionImpl.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/aspects/DefaultLifecycle.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/SchemaFileProcessor.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/WSDLFileProcessor.java

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Collection.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Collection.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Collection.java	Tue May  6 22:24:24 2008
@@ -18,4 +18,6 @@
 public interface Collection extends Resource {
     String [] getChildren();
     String [] getChildren(int start, int pageLen);
+    int getChildCount();
+    void setChildCount(int count);
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionImpl.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionImpl.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/CollectionImpl.java	Tue May  6 22:24:24 2008
@@ -15,13 +15,21 @@
  */
 package org.wso2.registry;
 
+import org.wso2.registry.utils.AuthorizationUtils;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.List;
 
 public class CollectionImpl extends ResourceImpl implements Collection {
+
+    private int childCount;
     public CollectionImpl() {
     }
 
-    public CollectionImpl(String [] paths) {
+    public CollectionImpl(String[] paths) {
         content = paths;
     }
 
@@ -34,15 +42,66 @@
     }
 
     public String[] getChildren() {
-        return (String[])content;
+        return (String[]) content;
     }
 
     public String[] getChildren(int start, int pageLen) {
+        try {
+            String sql = "SELECT R.RID, R.PATH  FROM RESOURCE R, DEPENDENCY D WHERE D.PARENT_RID=?" +
+                    " AND D.CHILD_RID=R.RID ORDER BY R.PATH";
+            PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);
+            ps.setString(1, getId());
+            List<String> childPathList = new ArrayList();
+            ResultSet results = ps.executeQuery();
+            int current = 0;
+            while (results.next()) {
+                String childID = results.getString("RID");
+                if (AuthorizationUtils.authorize(childID, ActionConstants.GET)) {
+                    if (current >= start && (pageLen == -1 || current < start + pageLen))
+                        childPathList.add(results.getString("PATH"));
+                    System.out.println(results.getString("PARENT_RID"));
+                    current++;
+                }
+            }
+            if (current < start) {
+                throw new RegistryException("Didn't have enough results to start at #" + start);
+            }
+            ps.close();
+            return childPathList.toArray(new String[childPathList.size()]);
+
+
+        } catch (Exception e) {
+            String msg = "Failed to get child paths of resource " +
+                    getPath() + ". " + e.getMessage();
+            //TODO need to log the message
+            return new String[0];
+        }
         // TODO - implement
-        return new String[0];
     }
 
     public List<Resource> getChildResources() {
         return null;
     }
+
+
+    public int getChildCount() {
+        String sql = "SELECT COUNT(*) AS CHILD_COUNT FROM DEPENDENCY WHERE PARENT_RID=?";
+        try {
+            PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);
+            ps.setString(1, getId());
+            ResultSet results = ps.executeQuery();
+            if (results.next()) {
+                childCount = results.getInt("CHILD_COUNT");
+                return childCount;
+            }
+        } catch (SQLException e) {
+            e.printStackTrace();
+        }
+        return 0;
+    }
+
+
+    public void setChildCount(int count) {
+       childCount = count;
+    }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java	Tue May  6 22:24:24 2008
@@ -58,5 +58,6 @@
     static final QName QNAME_ASSOC = new QName(NAMESPACE, "association");
     static final String ASSOC_TYPE = "type";
     static final QName QNAME_LAST_UPDATER = new QName(NAMESPACE, "lastUpdatedUser");
+    static final QName QNAME_CHILD_COUNT = new QName(NAMESPACE, "childCount");
     static final QName QNAME_MEDIATYPE = new QName(NAMESPACE, "mediaType");
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java	Tue May  6 22:24:24 2008
@@ -1003,6 +1003,9 @@
             feed.addSimpleExtension(APPConstants.COMMENTS_QNAME, "true");            
         }
         feed.addSimpleExtension(APPConstants.QNAME_LAST_UPDATER, resource.getLastUpdaterUserName());
+        if (resource instanceof Collection) {
+            feed.addSimpleExtension(APPConstants.QNAME_CHILD_COUNT , ""+((Collection)resource).getChildCount());
+        }
         feed.addLink(resource.getPath(), "path");
         feed.setSubtitle(resource.getDescription());
     }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java	Tue May  6 22:24:24 2008
@@ -186,6 +186,11 @@
             resource.setState(RegistryConstants.DELETED_STATE);
         }
 
+        String childCount = feed.getSimpleExtension(APPConstants.QNAME_CHILD_COUNT);
+        if (childCount != null ) {
+            resource.setChildCount(Integer.parseInt(childCount));
+        }
+
         String isComments = feed.getSimpleExtension(COMMENTS_QNAME);
         if (isComments != null) {
             resource.setContent(getCommentsFromFeed(feed));

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/aspects/DefaultLifecycle.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/aspects/DefaultLifecycle.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/aspects/DefaultLifecycle.java	Tue May  6 22:24:24 2008
@@ -18,17 +18,16 @@
  */
 package org.wso2.registry.aspects;
 
-import org.wso2.registry.*;
-import org.wso2.registry.session.CurrentSession;
+import org.wso2.registry.Aspect;
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
 import org.wso2.registry.config.RegistryContext;
-import org.wso2.registry.jdbc.dao.VersionedResourceDAO;
-import org.wso2.registry.jdbc.dao.ResourceDAO;
-import org.wso2.registry.jdbc.handlers.RequestContext;
 import org.wso2.registry.jdbc.Repository;
-import org.wso2.registry.users.UserRealm;
+import org.wso2.registry.jdbc.handlers.RequestContext;
 
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
 public class DefaultLifecycle extends Aspect {
 

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/SchemaFileProcessor.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/SchemaFileProcessor.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/SchemaFileProcessor.java	Tue May  6 22:24:24 2008
@@ -237,9 +237,12 @@
             } else {
                 xsdPath = registryBasePath + RegistryConstants.PATH_SEPARATOR + fileNameToSave;
             }
+            String targetNamespace = xmlSchema.getTargetNamespace();
+            xsdResource.addProperty("TargetNameSpace" ,targetNamespace);
 
             repository.put(xsdPath, xsdResource);
 
+
             //xmlSchema.write(new FileOutputStream("repository/" + fileNameToSave),
             //                getDefaultOptionMap());
             // add this entry to the proccessed wsdl map

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/WSDLFileProcessor.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/WSDLFileProcessor.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/utils/WSDLFileProcessor.java	Tue May  6 22:24:24 2008
@@ -244,7 +244,20 @@
                 wsdlResource.setMediaType(metadata.getMediaType());
                 wsdlResource.setDescription(metadata.getDescription());
             }
+
+            // getting the paramentes
+            String targetNamespace = wsdlDefinition.getTargetNamespace();
+            String name = wsdlDefinition.getQName().getLocalPart();
+            String document = wsdlDefinition.getDocumentationElement().getTextContent();
+            wsdlResource.addProperty("TargetNamespace" ,targetNamespace);
+            if (name != null) {
+                wsdlResource.addProperty("Name" ,name);
+            }
+            if (document != null) {
+                wsdlResource.addProperty("documentation" ,document);
+            }
             wsdlResource.setContent(wsdlResourceContent);
+
             repository.put(wsdlPath, wsdlResource);
 
         } catch (WSDLException e) {

Added: trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPBasedPaginationTest.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPBasedPaginationTest.java	Tue May  6 22:24:24 2008
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2007, 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.app;
+
+import org.wso2.registry.jdbc.PaginationTest;
+
+import java.net.URL;
+
+public class APPBasedPaginationTest extends PaginationTest {
+     RegistryServer server = new RegistryServer();
+
+    public void setUp() {
+        try {
+            if (registry == null) {
+                server.start();
+                registry = new RemoteRegistry(new URL("http://localhost:8081/wso2registry"),
+                                              "admin", "admin");
+            }
+        } catch (Exception e) {
+            fail("Failed to initialize the registry.");
+        }
+    }
+}

Added: trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PaginationTest.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/PaginationTest.java	Tue May  6 22:24:24 2008
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2007, 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.*;
+import org.wso2.registry.jdbc.realm.RegistryRealm;
+
+public class PaginationTest extends TestCase {
+
+    protected static EmbeddedRegistry embeddedRegistry = null;
+    protected static Registry registry = null;
+    protected static RegistryRealm realm = null;
+
+    public void setUp() throws RegistryException {
+        if (registry == null) {
+            embeddedRegistry = new InMemoryEmbeddedRegistry();
+            registry = embeddedRegistry.getUserRegistry(
+                    RegistryConstants.ADMIN_USER, RegistryConstants.ADMIN_PASSWORD);
+        }
+    }
+
+    public void testCollectionPagination() throws RegistryException {
+        Collection c1 = registry.newCollection();
+        registry.put("/test/c1", c1);
+        for (int j = 0; j < 50; j++) {
+            Collection ci = registry.newCollection();
+            registry.put("/test/c1/c_" + j, ci);
+        }
+        Resource collection = registry.get("/test/c1");
+        String childNodes [] = (String[])collection.getContent();
+        assertEquals(childNodes.length ,50);
+        Collection coll = registry.get("/test/c1", 0, 20);
+        assertEquals(coll.getChildCount() ,50);
+        childNodes = coll.getChildren();
+        assertEquals(childNodes.length ,20);
+    }
+}



More information about the Registry-dev mailing list