[Registry-dev] svn commit r15485 - in trunk/registry/modules: core/src/main/java/org/wso2/registry core/src/main/java/org/wso2/registry/app core/src/main/java/org/wso2/registry/jdbc core/src/main/java/org/wso2/registry/jdbc/dao core/src/main/java/org/wso2/registry/jdbc/hsql core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin core/src/main/java/org/wso2/registry/secure core/src/test/java/org/wso2/registry/jdbc webapps/src/main/java/org/wso2/registry/web webapps/src/main/java/org/wso2/registry/web/actions webapps/src/main/java/org/wso2/registry/web/utils

svn at wso2.org svn at wso2.org
Wed Apr 2 03:38:37 PDT 2008


Author: deepal
Date: Wed Apr  2 03:37:53 2008
New Revision: 15485

Log:

completed the Association support part1
Need to code for APP 
Sometime web ui will not with changes , will fix that soon

Added:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Association.java
Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Aspect.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/hsql/DBUtils.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
   trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/DependencyTest.java
   trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java
   trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/DependenciesUtil.java

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Aspect.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Aspect.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Aspect.java	Wed Apr  2 03:37:53 2008
@@ -1,3 +1,21 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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;
 
 import org.wso2.registry.Resource;

Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/Association.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Association.java	Wed Apr  2 03:37:53 2008
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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;
+
+/**
+ * This class is to store resource associations
+ */
+public class Association {
+    private String sourcePath;
+    private String destinationPath;
+    private String associationType;
+    public static final String DEPENDENCY = "dependency";
+    public static final String DEPENDENENT = "dependent";
+
+
+    public String getSourcePath() {
+        return sourcePath;
+    }
+
+    public void setSourcePath(String sourcePath) {
+        this.sourcePath = sourcePath;
+    }
+
+    public String getDestinationPath() {
+        return destinationPath;
+    }
+
+    public void setDestinationPath(String destinationPath) {
+        this.destinationPath = destinationPath;
+    }
+
+    public String getAssociationType() {
+        return associationType;
+    }
+
+    public void setAssociationType(String associationType) {
+        this.associationType = associationType;
+    }
+}

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java	Wed Apr  2 03:37:53 2008
@@ -74,39 +74,50 @@
      */
     void restoreVersion(String versionPath) throws RegistryException;
 
+
+    ////////////////////////////////////////////////////////
+    // Associations
+    ////////////////////////////////////////////////////////
     /**
-     * Adds a dependency stating that the resource at "dependentPath" depends on the resource at
-     * "dependencyPath". Paths may be the resource paths of the current versions or paths of the old
+     * Adds an association stating that the resource at "associationPath" associate on the resource at
+     * "associationPath". Paths may be the resource paths of the current versions or paths of the old
      * versions. If a path refers to the current version, it should contain the path in the form
      * /c1/c2/r1. If it refers to an old version, it should be in the form /c1/c2/r1?v=2.
      *
-     * @param dependentPath   Path of the dependent resource
-     * @param dependencyPaths Paths of dependency resources
+     * @param sourcePath   Path of the dependent resource
+     * @param associationPaths Paths of dependency resources
+     * @param associationType : Type of the association
      * @throws RegistryException Depends on the implementation
      */
-    void addDependencies(String dependentPath, String[] dependencyPaths) throws RegistryException;
+    void addAssociation(String sourcePath,
+                        String associationPaths,
+                        String associationType) throws RegistryException;
 
     /**
-     * Get all dependencies of the given resource. This is a chain of dependencies starting from the
-     * given resource. This is useful to analyse how changes to other resources would affect the
+     * Get all associations of the given resource. This is a chain of association starting from the
+     * given resource both upwards (source to destination) and downwards (destination to source). T
+     * his is useful to analyse how changes to other resources would affect the
      * given resource.
      *
-     * @param resourcePath Path of the resource to analyse dependencies. This can be a path of a
-     *                     current resource or an old verion of a resource.
-     * @return Chain of dependencies
-     */
-    DependencyChain[] getAllDependencies(String resourcePath) throws RegistryException;
-
-    /**
-     * Get all dependents of the given resource. This is a chain of dependents starting from the
-     * given resource. This is useful to analyse how changes to the given resources would affect
-     * other resources.
+     * @param resourcePath Path of the resource to analyse associations.
+     * @throws RegistryException  : If something went wrong
+     * @return  List of Association
+     */
+    Association[] getAllAssociation(String resourcePath) throws RegistryException;
+    /**
+     * Get all associations of the given resource for a give association type.
+     * This is a chain of association starting from the
+     * given resource both upwards (source to destination) and downwards (destination to source). T
+     * his is useful to analyse how changes to other resources would affect the
+     * given resource.
      *
-     * @param resourcePath Path of the resource to analyse dependents. This can be a path of a
-     *                     current resource or an old verion of a resource.
-     * @return Chain of dependents
+     * @param resourcePath Path of the resource to analyse associations.
+     * @throws RegistryException  : If something went wrong
+     * @return  List of Association
+     * @param associationType : Type of the association , that could be dependecy , or some other type
      */
-    DependentChain[] getAllDependents(String resourcePath) throws RegistryException;
+    Association[] getAllAssociation(String resourcePath , String associationType) throws RegistryException;
+    
 
     ////////////////////////////////////////////////////////
     // Tagging

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java	Wed Apr  2 03:37:53 2008
@@ -61,18 +61,6 @@
 
     String getLastUpdaterUserName();
 
-    String[] getDependents();
-
-    void setDependents(String[] dependents);
-
-    void addDependent(String dependentPath);
-
-    String[] getDependencies();
-
-    void setDependencies(String[] dependencies);
-
-    void addDependency(String dependencyPath);
-
     InputStream getContentStream() throws RegistryException;
 
     void setContentStream(InputStream contentStream);

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java	Wed Apr  2 03:37:53 2008
@@ -22,7 +22,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.registry.jdbc.dao.VersionedResourceDAO;
-import org.wso2.registry.Aspect;
 
 import javax.sql.DataSource;
 import java.sql.Timestamp;
@@ -125,18 +124,6 @@
     protected Properties properties = new Properties();
 
     /**
-     * Paths of the resources on which this resource depends on. This feature is not implemented
-     * currently.
-     */
-    protected List<String> dependencies = new ArrayList();
-
-    /**
-     * Paths of the resources that depends on this resource. This feature is not implemented
-     * currently.
-     */
-    protected List<String> dependents = new ArrayList();
-
-    /**
      * Content of the resource. Object and the type stored in this field depends on the resource
      * type. If the resource is a file with no special media type handling, this contains an array
      * of bytes (byte[]) conatining the raw bytes of the file. If the resource is a collection, this
@@ -435,34 +422,6 @@
         return directory;
     }
 
-    public String[] getDependents() {
-        return dependents.toArray(new String[dependents.size()]);
-    }
-
-    public void setDependents(String[] dependents) {
-        this.dependents = new ArrayList();
-
-        this.dependents.addAll(Arrays.asList(dependents));
-    }
-
-    public void addDependent(String dependentPath) {
-        dependents.add(dependentPath);
-    }
-
-    public String[] getDependencies() {
-        return dependencies.toArray(new String[dependencies.size()]);
-    }
-
-    public void setDependencies(String[] dependencies) {
-        this.dependencies = new ArrayList();
-
-        this.dependencies.addAll(Arrays.asList(dependencies));
-    }
-
-    public void addDependency(String dependencyPath) {
-        dependencies.add(dependencyPath);
-    }
-
     public boolean isContentModified() {
         return contentModified;
     }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java	Wed Apr  2 03:37:53 2008
@@ -1091,7 +1091,6 @@
         }
         if (registry instanceof SecureRegistry) {
             UserRealm userRealm  = ((SecureRegistry)registry).getUserRealm();
-
             userRealm.getUserStoreAdmin().addUser(userName, password);
 
             Map currentProperties = userRealm.getUserStoreAdmin().getUserProperties(userName);

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	Wed Apr  2 03:37:53 2008
@@ -452,17 +452,18 @@
         }
     }
 
-    public void addDependencies(String dependentPath, String[] dependencyPaths)
+    public void addAssociation(String sourcePath, String associationPaths, String associationType)
             throws RegistryException {
-        // TODO - implement
+        throw new UnsupportedOperationException();
     }
 
-    public DependencyChain[] getAllDependencies(String resourcePath) throws RegistryException {
-        return new DependencyChain[0];  //To change body of implemented methods use File | Settings | File Templates.
+
+    public Association[] getAllAssociation(String resourcePath) throws RegistryException {
+        throw new UnsupportedOperationException();
     }
 
-    public DependentChain[] getAllDependents(String resourcePath) throws RegistryException {
-        return new DependentChain[0];  //To change body of implemented methods use File | Settings | File Templates.
+    public Association[] getAllAssociation(String resourcePath, String associationType) throws RegistryException {
+        throw new UnsupportedOperationException();
     }
 
     public void applyTag(String resourcePath, String tag) throws RegistryException {

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	Wed Apr  2 03:37:53 2008
@@ -40,7 +40,6 @@
 import org.wso2.registry.users.UserRealm;
 import org.wso2.registry.utils.AuthorizationUtil;
 import org.wso2.registry.utils.RegistryUtils;
-import org.wso2.registry.utils.VersionedPath;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
@@ -616,37 +615,23 @@
         }
     }
 
-    public void addDependencies(String dependentPath, String[] dependencyPaths)
+    public void addAssociation(String sourcePath, String associationPath, String associationType)
             throws RegistryException {
-
-        VersionedPath versionedPath = RegistryUtils.getVersionedPath(dependentPath);
-
         Connection conn = null;
-
         try {
             conn = getConnection();
-            long dependentID = resourceDAO.getResourceID(versionedPath.getPath(), conn);
-
-            if (versionedPath.getVersion() == -1) {
-                versionedPath.setVersion(
-                        resourceDAO.getCurrentVersionNumber(versionedPath.getPath(), conn));
-            }
-
-            resourceDAO.addDependencies(
-                    dependentID, versionedPath.getVersion(), dependencyPaths, conn);
-
+            long sourceResourceID = resourceDAO.getResourceID(sourcePath, conn);
+            long destinationResourceID = resourceDAO.getResourceID(associationPath, conn);
+            resourceDAO.addAssociation(sourceResourceID , destinationResourceID , associationType ,conn);
         } catch (SQLException e) {
-            String msg = "Failed to add dependencies for the resource: " + dependentPath;
+            String msg = "Failed to add dependencies for the resource: " + sourcePath;
             log.error(msg, e);
-
             try {
                 conn.rollback();
             } catch (SQLException e1) {
                 log.error(e1);
             }
-
             throw new RegistryException(msg, e);
-
         } finally {
             if (conn != null) {
                 try {
@@ -658,28 +643,20 @@
         }
     }
 
-    public DependencyChain[] getAllDependencies(String resourcePath) throws RegistryException {
-
-        DependencyChain[] dependencies = null;
-
+    public Association[] getAllAssociation(String resourcePath) throws RegistryException {
         Connection conn = null;
         try {
             conn = getConnection();
-
-            dependencies = resourceDAO.getDependencies(resourcePath, conn);
-
+            return  resourceDAO.getAllAssociations(resourcePath ,conn);
         } catch (SQLException e) {
-            String msg = "Failed to get dependencies of the resource: " + resourcePath;
+            String msg = "Failed to get association for the resource: " + resourcePath;
             log.error(msg, e);
-
             try {
                 conn.rollback();
             } catch (SQLException e1) {
                 log.error(e1);
             }
-
             throw new RegistryException(msg, e);
-
         } finally {
             if (conn != null) {
                 try {
@@ -689,32 +666,22 @@
                 }
             }
         }
-
-        return dependencies;
     }
 
-    public DependentChain[] getAllDependents(String resourcePath) throws RegistryException {
-
-        DependentChain[] dependents = null;
-
-        Connection conn = null;
+    public Association[] getAllAssociation(String resourcePath, String associationType) throws RegistryException {
+          Connection conn = null;
         try {
             conn = getConnection();
-
-            dependents = resourceDAO.getDependents(resourcePath, conn);
-
+            return  resourceDAO.getAllAssociationsForType(resourcePath , associationType ,conn);
         } catch (SQLException e) {
-            String msg = "Failed to get dependents of the resource: " + resourcePath;
+            String msg = "Failed to add association for the resource: " + resourcePath;
             log.error(msg, e);
-
             try {
                 conn.rollback();
             } catch (SQLException e1) {
                 log.error(e1);
             }
-
             throw new RegistryException(msg, e);
-
         } finally {
             if (conn != null) {
                 try {
@@ -724,8 +691,6 @@
                 }
             }
         }
-
-        return dependents;
     }
 
     ////////////////////////////////////////////////////////

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java	Wed Apr  2 03:37:53 2008
@@ -181,8 +181,9 @@
 
                 long resourceID = resourceDAO.getResourceID(preparedPath, conn);
                 long currentVersion = resourceDAO.getCurrentVersionNumber(preparedPath, conn);
-                resourceDAO.addDependencies(
-                        resourceID, currentVersion, resource.getDependencies(), conn);
+                //TODO Chathure add associations correctly
+//                resourceDAO.addDependencies(
+//                        resourceID, currentVersion, resource.getDependencies(), conn);
 
             } else {
 
@@ -206,8 +207,9 @@
 
                 long resourceID = resourceDAO.getResourceID(preparedPath, conn);
                 long currentVersion = resourceDAO.getCurrentVersionNumber(preparedPath, conn);
-                resourceDAO.addDependencies(
-                        resourceID, currentVersion, resource.getDependencies(), conn);
+                //TODO Chathure add associations correctly
+//                resourceDAO.addDependencies(
+//                        resourceID, currentVersion, resource.getDependencies(), conn);
             }
 
             conn.commit();

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java	Wed Apr  2 03:37:53 2008
@@ -19,20 +19,17 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.registry.*;
+import org.wso2.registry.Collection;
 import org.wso2.registry.jdbc.DatabaseConstants;
 import org.wso2.registry.users.UserRealm;
 import org.wso2.registry.utils.AuthorizationUtil;
-import org.wso2.registry.utils.RegistryUtils;
-import org.wso2.registry.utils.VersionedPath;
 
 import javax.activation.DataHandler;
 import javax.sql.DataSource;
 import java.io.*;
 import java.sql.*;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
+import java.sql.Date;
+import java.util.*;
 
 public class VersionedResourceDAO {
 
@@ -116,13 +113,80 @@
             resource.setContent(children);
         }
 
-        resource.setDependencies(getDependencies(resource.getId(), versionNumber, conn));
-        resource.setDependents(getDependents(resource.getId(), versionNumber, conn));
 
         // get resource properties
         return getResourceWithProperties(conn, resource);
     }
 
+    /////////////////////////////////////////////////////////////
+    //////              Association      ////////////////////////
+    /////////////////////////////////////////////////////////////
+
+    public void addAssociation(long sourceID ,
+                               long associationID ,
+                               String associationType ,
+                               Connection con) throws SQLException {
+        String propSQL = "INSERT INTO ASSOCIATION (RID1, RID2, ASSOCIATION_TYPE) VALUES (?,?,?)";
+        PreparedStatement statement = con.prepareStatement(propSQL);
+        statement.setLong(1, sourceID);
+        statement.setLong(2,associationID);
+        statement.setString(3,associationType);
+        statement.executeUpdate();
+    }
+
+    public Association[] getAllAssociations(String resourcePath, Connection con) throws SQLException{
+        long resourceID = getResourceID(resourcePath , con);
+        String propSQL = "SELECT RID2 , ASSOCIATION_TYPE FROM ASSOCIATION WHERE RID1=?";
+        PreparedStatement statement = con.prepareStatement(propSQL);
+        statement.setLong(1,resourceID);
+        ResultSet result = statement.executeQuery();
+        ArrayList arrayList = new ArrayList();
+        while(result.next()) {
+            Association association = new Association();
+            association.setSourcePath(resourcePath);
+            long destinationID = result.getLong("RID2");
+            association.setDestinationPath(getResourcePath(destinationID ,con));
+            association.setAssociationType(result.getString("ASSOCIATION_TYPE"));
+            arrayList.add(association);
+        }
+        Association associations [] = new Association[arrayList.size()];
+        for (int i = 0; i < arrayList.size(); i++) {
+            associations[i] = (Association) arrayList.get(i);
+        }
+        return associations;
+    }
+
+     public Association[] getAllAssociationsForType(String resourcePath ,
+                                                    String associationType,
+                                                    Connection con) throws SQLException{
+        long resourceID = getResourceID(resourcePath , con);
+        String propSQL = "SELECT RID2 , ASSOCIATION_TYPE FROM ASSOCIATION WHERE RID1=? AND ASSOCIATION_TYPE=?";
+        PreparedStatement statement = con.prepareStatement(propSQL);
+        statement.setLong(1,resourceID);
+        statement.setString(2,associationType);
+        ResultSet result = statement.executeQuery();
+        ArrayList arrayList = new ArrayList();
+        while(result.next()) {
+            Association association = new Association();
+            association.setSourcePath(resourcePath);
+            long destinationID = result.getLong("RID2");
+            association.setDestinationPath(getResourcePath(destinationID ,con));
+            association.setAssociationType(associationType);
+            arrayList.add(association);
+        }
+        Association associations [] = new Association[arrayList.size()];
+        for (int i = 0; i < arrayList.size(); i++) {
+            associations[i] = (Association) arrayList.get(i);
+        }
+        return associations;
+    }
+
+
+
+
+
+
+
     public ResourceImpl getResourceByID(
             long artifactID, long versionNumber, Connection conn)
             throws SQLException, IOException {
@@ -192,8 +256,6 @@
         }
 
         // get resource properties
-        resource.setDependencies(getDependencies(resource.getId(), versionNumber, conn));
-        resource.setDependents(getDependents(resource.getId(), versionNumber, conn));
         return getResourceWithProperties(conn, resource);
     }
 
@@ -240,158 +302,6 @@
         return resource;
     }
 
-    private String[] getDependencies(long resourceID, long version, Connection conn)
-            throws SQLException {
-
-        String depSQL = "SELECT A.PATH, D.DAID, D.DVN FROM ARTIFACTS A, DEPENDENCY_MANAGEMENT D " +
-                "WHERE D.AID=? AND D.VN=? AND D.DTYPE=? AND A.AID=D.DAID";
-
-        PreparedStatement depSt = conn.prepareStatement(depSQL);
-        depSt.setLong(1, resourceID);
-        depSt.setLong(2, version);
-        depSt.setString(3, RegistryConstants.DEFAULT_DEPENDENCY);
-
-        List<String> depList = new ArrayList();
-        ResultSet depResults = depSt.executeQuery();
-        while (depResults.next()) {
-            String dependencyPath = depResults.getString(DatabaseConstants.PATH_FIELD);
-            long dependencyVersion = depResults.getLong("DVN");
-            String fullDependencyPath = dependencyPath + "?v=" + dependencyVersion;
-
-            depList.add(fullDependencyPath);
-        }
-
-        depResults.close();
-
-        return depList.toArray(new String[depList.size()]);
-    }
-
-    private DependencyChain[] getOneLevelDependencies(long resourceID,
-                                                      long version,
-                                                      Connection conn)
-            throws SQLException {
-
-        String depSQL = "SELECT A.PATH, D.DAID, D.DVN FROM ARTIFACTS A, DEPENDENCY_MANAGEMENT D " +
-                "WHERE D.AID=? AND D.VN=? AND D.DTYPE=? AND A.AID=D.DAID";
-
-        PreparedStatement depSt = conn.prepareStatement(depSQL);
-        depSt.setLong(1, resourceID);
-        depSt.setLong(2, version);
-        depSt.setString(3, RegistryConstants.DEFAULT_DEPENDENCY);
-
-        List<DependencyChain> depList = new ArrayList();
-        ResultSet depResults = depSt.executeQuery();
-        while (depResults.next()) {
-            String dependencyPath = depResults.getString(DatabaseConstants.PATH_FIELD);
-            long dependencyVersion = depResults.getLong("DVN");
-            String fullDependencyPath = dependencyPath + "?v=" + dependencyVersion;
-
-            DependencyChain dependency = new DependencyChain();
-            dependency.setDependencyPath(fullDependencyPath);
-            depList.add(dependency);
-        }
-
-        depResults.close();
-
-        return depList.toArray(new DependencyChain[depList.size()]);
-    }
-
-    public DependencyChain[] getDependencies(String resourcePath, Connection conn)
-            throws SQLException, RegistryException {
-
-        VersionedPath versionedPath = RegistryUtils.getVersionedPath(resourcePath);
-
-        if (versionedPath.getVersion() == -1) {
-            versionedPath.setVersion(getCurrentVersionNumber(versionedPath.getPath(), conn));
-        }
-        long resourceID = getResourceID(versionedPath.getPath(), conn);
-
-        DependencyChain[] dependencies =
-                getOneLevelDependencies(resourceID, versionedPath.getVersion(), conn);
-
-        for (DependencyChain dependency : dependencies) {
-            DependencyChain[] sDependencies = getDependencies(dependency.getDependencyPath(), conn);
-            dependency.setDependencies(sDependencies);
-        }
-
-        return dependencies;
-    }
-
-    private String[] getDependents(long resourceID, long version, Connection conn)
-            throws SQLException {
-
-        String depSQL = "SELECT A.PATH, D.AID, D.VN FROM ARTIFACTS A, DEPENDENCY_MANAGEMENT D " +
-                "WHERE D.DAID=? AND D.DVN=? AND D.DTYPE=? AND A.AID=D.AID";
-
-        PreparedStatement depSt = conn.prepareStatement(depSQL);
-        depSt.setLong(1, resourceID);
-        depSt.setLong(2, version);
-        depSt.setString(3, RegistryConstants.DEFAULT_DEPENDENCY);
-
-        List<String> depList = new ArrayList();
-        ResultSet depResults = depSt.executeQuery();
-        while (depResults.next()) {
-            String dependentPath = depResults.getString(DatabaseConstants.PATH_FIELD);
-            long dependentVersion = depResults.getLong("VN");
-            String fullDependentPath = dependentPath + "?v=" + dependentVersion;
-
-            depList.add(fullDependentPath);
-        }
-
-        depResults.close();
-
-        return depList.toArray(new String[depList.size()]);
-    }
-
-    private DependentChain[] getOneLevelDependents(long resourceID, long version, Connection conn)
-            throws SQLException {
-
-        String depSQL = "SELECT A.PATH, D.AID, D.VN FROM ARTIFACTS A, DEPENDENCY_MANAGEMENT D " +
-                "WHERE D.DAID=? AND D.DVN=? AND D.DTYPE=? AND A.AID=D.AID";
-
-        PreparedStatement depSt = conn.prepareStatement(depSQL);
-        depSt.setLong(1, resourceID);
-        depSt.setLong(2, version);
-        depSt.setString(3, RegistryConstants.DEFAULT_DEPENDENCY);
-
-        List<DependentChain> depList = new ArrayList();
-        ResultSet depResults = depSt.executeQuery();
-        while (depResults.next()) {
-            String dependentPath = depResults.getString(DatabaseConstants.PATH_FIELD);
-            long dependentVersion = depResults.getLong("VN");
-            String fullDependentPath = dependentPath + "?v=" + dependentVersion;
-
-            DependentChain dependents = new DependentChain();
-            dependents.setDependentPath(fullDependentPath);
-            depList.add(dependents);
-        }
-
-        depResults.close();
-
-        return depList.toArray(new DependentChain[depList.size()]);
-    }
-
-    public DependentChain[] getDependents(String resourcePath, Connection conn)
-            throws SQLException, RegistryException {
-
-        VersionedPath versionedPath = RegistryUtils.getVersionedPath(resourcePath);
-
-        if (versionedPath.getVersion() == -1) {
-            versionedPath.setVersion(getCurrentVersionNumber(versionedPath.getPath(), conn));
-        }
-        long resourceID = getResourceID(versionedPath.getPath(), conn);
-
-        DependentChain[] dependents =
-                getOneLevelDependents(resourceID, versionedPath.getVersion(), conn);
-
-        for (DependentChain dependent : dependents) {
-            DependentChain[] sDependents = getDependents(dependent.getDependentPath(), conn);
-            dependent.setDependents(sDependents);
-        }
-
-        return dependents;
-    }
-
     /**
      * Returns the latest (current) version of an artifact. If artifact is a collection, all child
      * paths will be added as latest paths in the form /a/b
@@ -469,10 +379,6 @@
                     getCurrentVersionNumber(path, conn), conn);
             resource.setContent(children);
         }
-
-        resource.setDependencies(getDependencies(resource.getId(), latestVersionNumber, conn));
-        resource.setDependents(getDependents(resource.getId(), latestVersionNumber, conn));
-
         // get resource properties
         return getResourceWithProperties(conn, resource);
     }
@@ -806,105 +712,6 @@
         }
     }
 
-    /**
-     * Adds dependencyPaths to the given version of a resource. If dependency path does not contain
-     * a version number, latest version of the dependency will be used.
-     */
-    public void addDependencies(
-            long resourceID, long version, String[] dependencyPaths, Connection conn)
-            throws SQLException, RegistryException {
-
-        String depAddSQL = "INSERT INTO DEPENDENCY_MANAGEMENT (AID, VN, DAID, DVN, DTYPE) " +
-                "VALUES (?,?,?,?,?)";
-        PreparedStatement addSt = conn.prepareStatement(depAddSQL);
-
-        String checkSQL = "SELECT AID FROM DEPENDENCY_MANAGEMENT " +
-                "WHERE AID=? AND VN=? AND DAID=? AND DVN=? AND DTYPE=?";
-        PreparedStatement checkSt = conn.prepareStatement(checkSQL);
-
-        for (String dependencyPath : dependencyPaths) {
-
-            VersionedPath versionedPath = RegistryUtils.getVersionedPath(dependencyPath);
-            if (versionedPath.getVersion() == -1) {
-                versionedPath.setVersion(getCurrentVersionNumber(versionedPath.getPath(), conn));
-            }
-
-            long dependencyID = getResourceID(versionedPath.getPath(), conn);
-
-            checkSt.setLong(1, resourceID);
-            checkSt.setLong(2, version);
-            checkSt.setLong(3, dependencyID);
-            checkSt.setLong(4, versionedPath.getVersion());
-            checkSt.setString(5, RegistryConstants.DEFAULT_DEPENDENCY);
-
-            ResultSet result = checkSt.executeQuery();
-            if (!result.next()) {
-
-                addSt.setLong(1, resourceID);
-                addSt.setLong(2, version);
-                addSt.setLong(3, dependencyID);
-                addSt.setLong(4, versionedPath.getVersion());
-                addSt.setString(5, RegistryConstants.DEFAULT_DEPENDENCY);
-
-                addSt.executeUpdate();
-                addSt.clearParameters();
-            }
-
-            checkSt.clearParameters();
-        }
-    }
-
-    /**
-     * Adds dependencies to the given version of a resource. Note that only the first level
-     * dependencies are added as other dependencies are not associated with this resource.
-     */
-    public void addDependencies(long resourceID,
-                                long version,
-                                DependencyChain[] dependencies,
-                                Connection conn)
-            throws SQLException, RegistryException {
-
-        String depAddSQL =
-                "INSERT INTO DEPENDENCY_MANAGEMENT (AID, VN, DAID, DVN, DTYPE) VALUES (?,?,?,?,?)";
-        PreparedStatement addSt = conn.prepareStatement(depAddSQL);
-
-        String checkSQL =
-                "SELECT AID FROM DEPENDENCY_MANAGEMENT WHERE AID=? AND VN=? AND DAID=? AND DVN=? AND DTYPE=?";
-        PreparedStatement checkSt = conn.prepareStatement(checkSQL);
-
-        for (DependencyChain dependency : dependencies) {
-
-            VersionedPath versionedPath =
-                    RegistryUtils.getVersionedPath(dependency.getDependencyPath());
-            if (versionedPath.getVersion() == -1) {
-                versionedPath.setVersion(getCurrentVersionNumber(versionedPath.getPath(), conn));
-            }
-
-            long dependencyID = getResourceID(versionedPath.getPath(), conn);
-
-            checkSt.setLong(1, resourceID);
-            checkSt.setLong(2, version);
-            checkSt.setLong(3, dependencyID);
-            checkSt.setLong(4, versionedPath.getVersion());
-            checkSt.setString(5, RegistryConstants.DEFAULT_DEPENDENCY);
-
-            ResultSet result = checkSt.executeQuery();
-            if (!result.next()) {
-
-                addSt.setLong(1, resourceID);
-                addSt.setLong(2, version);
-                addSt.setLong(3, dependencyID);
-                addSt.setLong(4, versionedPath.getVersion());
-                addSt.setString(5, RegistryConstants.DEFAULT_DEPENDENCY);
-
-                addSt.executeUpdate();
-                addSt.clearParameters();
-            }
-
-            checkSt.clearParameters();
-        }
-    }
-
     public void removeProperties(long resourceID, Connection conn) throws SQLException {
 
         String removePropsSQL = "DELETE FROM PROPERTIES WHERE AID=?";
@@ -992,7 +799,6 @@
         Connection conn = dataSource.getConnection();
         ResourceImpl resource = getLatestVersion(oldPath, conn);
         String resourcePath = resource.getPath();
-        long resourceID = resource.getId();
         //to see whether the patent node is there in the table , if not need to add that
         createParentCollections(newPath, conn, userId, realm);
         // if the resource is a directory then need to populate the dependecy table with

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/hsql/DBUtils.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/hsql/DBUtils.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/hsql/DBUtils.java	Wed Apr  2 03:37:53 2008
@@ -119,6 +119,15 @@
                                                   "FOREIGN KEY (DAID) REFERENCES ARTIFACTS (AID)," +
                                                   "FOREIGN KEY (AID) REFERENCES ARTIFACTS (AID));";
 
+    private static final String associationTable =  "CREATE TABLE ASSOCIATION (" +
+            "ASSOCIATION_ID INTEGER GENERATED BY DEFAULT AS IDENTITY," +
+            "RID1 INTEGER  NOT NULL," +
+            "RID2 INTEGER  NOT NULL," +
+            "ASSOCIATION_TYPE VARCHAR (20) NOT NULL," +
+            "UNIQUE (RID1, RID2, ASSOCIATION_TYPE)," +
+            "FOREIGN KEY (RID1) REFERENCES ARTIFACTS (AID)," +
+            "FOREIGN KEY (RID2) REFERENCES ARTIFACTS (AID));";
+
     public void initializeDatabase(Connection conn) throws SQLException {
 
         DatabaseMetaData metaData = conn.getMetaData();
@@ -140,10 +149,10 @@
         s.executeUpdate(commentsTable);
         s.executeUpdate(ratingsTable);
         s.executeUpdate(logsTable);
-
         // creating version related tables
         s.executeUpdate(versionTable);
         s.executeUpdate(dependencyTable);
         s.executeUpdate(dependencyManagementTable);
+        s.executeUpdate(associationTable);
     }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java	Wed Apr  2 03:37:53 2008
@@ -153,8 +153,9 @@
 
                 long resourceID = resourceDAO.getResourceID(path, conn);
                 long currentVersion = resourceDAO.getCurrentVersionNumber(path, conn);
-                resourceDAO.addDependencies(
-                        resourceID, currentVersion, resource.getDependencies(), conn);
+                //TODO Chathure add associations correctly
+//                resourceDAO.addDependencies(
+//                        resourceID, currentVersion, resource.getDependencies(), conn);
 
             } else {
 
@@ -178,8 +179,9 @@
 
                 long resourceID = resourceDAO.getResourceID(path, conn);
                 long currentVersion = resourceDAO.getCurrentVersionNumber(path, conn);
-                resourceDAO.addDependencies(
-                        resourceID, currentVersion, resource.getDependencies(), conn);
+                //TODO Chathure add associations correctly
+//                resourceDAO.addDependencies(
+//                        resourceID, currentVersion, resource.getDependencies(), conn);
             }
 
             conn.commit();

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java	Wed Apr  2 03:37:53 2008
@@ -67,7 +67,7 @@
     // private RegistryUserManager userManager;
 
     public SecureRegistry(String userID, String password, Registry registry,
-            UserRealm defaultRealm) throws RegistryException {
+                          UserRealm defaultRealm) throws RegistryException {
 
         UserRealm userRealm;
         try {
@@ -89,16 +89,16 @@
                 log.info(msg);
                 throw new RegistryException(msg);
             }
-        } catch (AuthenticatorException e){
+        } catch (AuthenticatorException e) {
             String msg = "Could not check authentication. \nCaused by "
                     + e.getMessage();
             log.error(msg, e);
             throw new RegistryException(msg, e);
-        } catch (UserStoreException e){
+        } catch (UserStoreException e) {
             String msg = "Could not check authentication. \nCaused by "
-                + e.getMessage();
+                    + e.getMessage();
             log.error(msg, e);
-        throw new RegistryException(msg, e);
+            throw new RegistryException(msg, e);
         }
 
         this.userID = userID;
@@ -109,13 +109,10 @@
     /**
      * Non-authenticating constructor. Use this constructor if the user is
      * already authenticated outside the secure registry.
-     * 
-     * @param userID
-     *            user name of the user of the secure registry.
-     * @param registry
-     *            core registry to use by the secure registry.
-     * @param defaultRealm
-     *            default (non-authorizing) realm.
+     *
+     * @param userID       user name of the user of the secure registry.
+     * @param registry     core registry to use by the secure registry.
+     * @param defaultRealm default (non-authorizing) realm.
      * @throws RegistryException
      */
     public SecureRegistry(String userID, Registry registry, UserRealm defaultRealm)
@@ -213,11 +210,9 @@
      * Then sets the default permissions for newly created paths. i.e. in the
      * above sample, default permissions are set for "/d1/d2/d3" and
      * "/d1/d2/d3/r1".
-     * 
-     * @param suggestedPath
-     *            the path which we'd like to use for the new resource.
-     * @param resource
-     *            New resource
+     *
+     * @param suggestedPath the path which we'd like to use for the new resource.
+     * @param resource      New resource
      * @throws RegistryException
      */
     public String put(String suggestedPath, Resource resource)
@@ -294,7 +289,7 @@
     }
 
     public String importResource(String suggestedPath, String sourceURL,
-            Resource metadata) throws RegistryException {
+                                 Resource metadata) throws RegistryException {
 
         // find the existing ascendent path of the given path
         isUuserAllowToAddResource(suggestedPath);
@@ -430,22 +425,21 @@
      * Checks if the current user has PUT permission for the dependentPath. User should have write
      * permission to specify a resourceis dependent on another resource.
      *
-     * @param dependentPath   Path of the dependent resource
-     * @param dependencyPaths a String[] of the dependencies to add
-     * @throws RegistryException On authorizing error or an error caused by the underlying core
-     *                           registry impl.
+     * @param sourcePath
+     * @param associationPaths
+     * @param associationType  @throws RegistryException On authorizing error or an error caused by the underlying core
      */
-    public void addDependencies(String dependentPath, String[] dependencyPaths)
+    public void addAssociation(String sourcePath, String associationPaths, String associationType)
             throws RegistryException {
 
-        String authPath = getAuthorizationPath(dependentPath);
+        String authPath = getAuthorizationPath(sourcePath);
 
         try {
             if (!authorizer.isUserAuthorized(userID, authPath, ActionConstants.PUT)) {
                 String msg =
                         "User: " + userID + " does not have write permission on the resource: " +
-                        authPath + ". Users should have write permission to specify that " +
-                        "resource is dependent on another resource.";
+                                authPath + ". Users should have write permission to specify that " +
+                                "resource is dependent on another resource.";
                 log.info(msg);
                 throw new AuthorizationFailedException(msg);
             }
@@ -455,22 +449,9 @@
             throw new RegistryException(msg, e);
         }
 
-        registry.addDependencies(dependentPath, dependencyPaths);
+        registry.addAssociation(sourcePath, associationPaths, associationType);
     }
 
-    public DependencyChain[] getAllDependencies(String resourcePath) throws RegistryException {
-
-        // todo: stop the dependency chain whenever a resource without the read permission is encountered.
-        
-        return registry.getAllDependencies(resourcePath);
-    }
-
-    public DependentChain[] getAllDependents(String resourcePath) throws RegistryException {
-
-        // todo: stop the dependent chain whenever a resource without the read permission is encountered.
-
-        return registry.getAllDependents(resourcePath);
-    }
 
     public void applyTag(String resourcePath, String tag) throws RegistryException {
 
@@ -688,7 +669,7 @@
     }
 
     public LogEntry[] getLogs(String resourcePath, int action, String userName,
-            Date from, Date to, boolean recentFirst) throws RegistryException {
+                              Date from, Date to, boolean recentFirst) throws RegistryException {
 
         User.setCurrentUser(userID);
 
@@ -719,9 +700,8 @@
      * to refer metadata about resources. But we always store the authorization
      * for resources against the pure resource path, stored in the ARTIFACTS
      * table. This methods extracts that pure resource path from a given path.
-     * 
-     * @param resourcePath
-     *            A path string, which may contain extensions
+     *
+     * @param resourcePath A path string, which may contain extensions
      * @return pure resource path for the given path
      */
     private String getAuthorizationPath(String resourcePath) {
@@ -767,4 +747,13 @@
             throws RegistryException {
         return registry.getAspectActions(resourcePath, aspectName);
     }
+
+
+    public Association[] getAllAssociation(String resourcePath) throws RegistryException {
+        return registry.getAllAssociation(resourcePath);
+    }
+
+    public Association[] getAllAssociation(String resourcePath, String associationType) throws RegistryException {
+        return registry.getAllAssociation(resourcePath, associationType);
+    }
 }

Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/DependencyTest.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/DependencyTest.java	(original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/DependencyTest.java	Wed Apr  2 03:37:53 2008
@@ -45,14 +45,33 @@
 
         Resource r2 = registry.newResource();
         r2.setContent("this is dependent on r1".getBytes());
-        r2.addDependency("/depTest/test1/r1");
         registry.put("/depTest/test1/r2", r2);
+        registry.addAssociation(r2.getPath() ,"/depTest/test1/r1" , Association.DEPENDENCY);
+        registry.addAssociation(r1.getPath() ,"/depTest/test1/r2" , Association.DEPENDENENT);
+
 
         Resource r21 = registry.get("/depTest/test1/r1");
         Resource r22 = registry.get("/depTest/test1/r2");
-
-        assertTrue(containsString(r21.getDependents(), "/depTest/test1/r2"));
-        assertTrue(containsString(r22.getDependencies(), "/depTest/test1/r1"));
+        Association association [] = registry.getAllAssociation(r21.getPath()) ;
+        assertNotNull(association);
+        boolean found = false;
+        for (int i = 0; i < association.length; i++) {
+            Association association1 = association[i];
+            if ("/depTest/test1/r2".equals(association1.getDestinationPath())){
+                 found = true;
+            }
+        }
+        assertTrue(found);
+        association = registry.getAllAssociation(r22.getPath()) ;
+        assertNotNull(association);
+        found = false;
+        for (int i = 0; i < association.length; i++) {
+            Association association1 = association[i];
+            if ("/depTest/test1/r1".equals(association1.getDestinationPath())){
+                 found = true;
+            }
+        }
+        assertTrue(found);
     }
 
     public void testSettingDependenciesFromAPI() throws RegistryException {
@@ -65,113 +84,33 @@
         r2.setContent("this is dependent on r2".getBytes());
         registry.put("/depTest/test2/r2", r2);
 
-        registry.addDependencies("/depTest/test2/r2", new String[] {"/depTest/test2/r1"});
+        registry.addAssociation("/depTest/test2/r2", "/depTest/test2/r1", Association.DEPENDENCY);
+        registry.addAssociation("/depTest/test2/r1" ,"/depTest/test2/r2", Association.DEPENDENENT);
 
         Resource r21 = registry.get("/depTest/test2/r1");
         Resource r22 = registry.get("/depTest/test2/r2");
-
-        assertTrue(containsString(r21.getDependents(), "/depTest/test2/r2"));
-        assertTrue(containsString(r22.getDependencies(), "/depTest/test2/r1"));
-    }
-
-    public void testDependencyChainAnalysis() throws RegistryException {
-
-        Resource r1 = registry.newResource();
-        r1.setContent("some content for second r1".getBytes());
-        registry.put("/depTest/test3/r1", r1);
-
-        Resource r2 = registry.newResource();
-        r2.setContent("this is dependent on r2".getBytes());
-        registry.put("/depTest/test3/r2", r2);
-
-        Resource r3 = registry.newResource();
-        r3.setContent("some content for second r3".getBytes());
-        registry.put("/depTest/test3/r3", r3);
-
-        Resource r4 = registry.newResource();
-        r4.setContent("this is dependent on r4".getBytes());
-        registry.put("/depTest/test3/r4", r4);
-
-        Resource r5 = registry.newResource();
-        r5.setContent("this is dependent on r5".getBytes());
-        registry.put("/depTest/test3/r5", r5);
-
-        registry.addDependencies("/depTest/test3/r1", new String[] {"/depTest/test3/r2"});
-        registry.addDependencies("/depTest/test3/r2", new String[] {"/depTest/test3/r3"});
-        registry.addDependencies("/depTest/test3/r3", new String[] {"/depTest/test3/r4"});
-        registry.addDependencies("/depTest/test3/r3", new String[] {"/depTest/test3/r5"});
-
-        DependencyChain[] dependencies1 = registry.getAllDependencies("/depTest/test3/r1");
-        
-        assertEquals("There should be one dependency for the resource: /depTest/test3/r1",
-                1, dependencies1.length);
-
-        assertTrue("/depTest/test3/r2 should be a dependency of /depTest/test3/r1",
-                dependencies1[0].getDependencyPath().startsWith("/depTest/test3/r2"));
-
-        DependencyChain[] dependencies2 = dependencies1[0].getDependencies();
-
-        assertEquals("There should be one dependency for the resource: /depTest/test3/r2",
-                1, dependencies2.length);
-
-        assertTrue("/depTest/test3/r3 should be a dependency of /depTest/test3/r2",
-                dependencies2[0].getDependencyPath().startsWith("/depTest/test3/r3"));
-
-        DependencyChain[] dependencies3 = dependencies2[0].getDependencies();
-
-        assertEquals("There should be two dependencies for the resource: /depTest/test3/r3",
-                2, dependencies3.length);
-
-        boolean r4Found = false;
-        boolean r5Found = false;
-        for (DependencyChain dependency : dependencies3) {
-            if (dependency.getDependencyPath().startsWith("/depTest/test3/r4")) {
-                r4Found = true;
-            } else if (dependency.getDependencyPath().startsWith("/depTest/test3/r5")) {
-                r5Found = true;
+        Association association [] = registry.getAllAssociation(r21.getPath()) ;
+        assertNotNull(association);
+        boolean found = false;
+        for (int i = 0; i < association.length; i++) {
+            Association association1 = association[i];
+            if ("/depTest/test2/r2".equals(association1.getDestinationPath())){
+                 found = true;
             }
         }
-
-        assertTrue("/depTest/test3/r4 should be a dependency of /depTest/test3/r3", r4Found);
-        assertTrue("/depTest/test3/r5 should be a dependency of /depTest/test3/r3", r5Found);
-
-        DependentChain[] dependents1 = registry.getAllDependents("/depTest/test3/r5");
-
-        assertEquals("There should be one dependent for the resource: /depTest/test3/r5",
-                1, dependents1.length);
-
-        assertTrue("/depTest/test3/r3 should be a dependent of /depTest/test3/r5",
-                dependents1[0].getDependentPath().startsWith("/depTest/test3/r3"));
-
-        DependentChain[] dependents2 = dependents1[0].getDependents();
-
-        assertEquals("There should be one dependent for the resource: /depTest/test3/r3",
-                1, dependents2.length);
-
-        assertTrue("/depTest/test3/r2 should be a dependent of /depTest/test3/r3",
-                dependents2[0].getDependentPath().startsWith("/depTest/test3/r2"));
-
-        DependentChain[] dependents3 = dependents2[0].getDependents();
-
-        assertEquals("There should be one dependent for the resource: /depTest/test3/r2",
-                1, dependents3.length);
-
-        assertTrue("/depTest/test3/r1 should be a dependent of /depTest/test3/r2",
-                dependents3[0].getDependentPath().startsWith("/depTest/test3/r1"));
-    }
-
-    private boolean containsString(String[] array, String value) {
-
-        boolean found = false;
-        for (String anArray : array) {
-            if (anArray.startsWith(value)) {
-                found = true;
-                break;
+        assertTrue(found);
+        association = registry.getAllAssociation(r22.getPath()) ;
+        assertNotNull(association);
+        found = false;
+        for (int i = 0; i < association.length; i++) {
+            Association association1 = association[i];
+            if ("/depTest/test2/r1".equals(association1.getDestinationPath())){
+                 found = true;
             }
         }
-
-        return found;
+        assertTrue(found);
     }
 
 
+
 }

Modified: trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
==============================================================================
--- trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java	(original)
+++ trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java	Wed Apr  2 03:37:53 2008
@@ -288,7 +288,7 @@
 
                 PropertiesUtil.updateProperty(request, response);
 
-            } else if(command.equals("/addDependencies")) {
+            } else if(command.equals("/addAssociation")) {
                 try {
                     DependenciesUtil.addDependency(request,response);
                 } catch (Exception e) {

Modified: trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java
==============================================================================
--- trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java	(original)
+++ trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java	Wed Apr  2 03:37:53 2008
@@ -223,7 +223,7 @@
         this.mediaType = resource.getMediaType();
         this.averageRating = registry.getAverageRating(resource.getPath());
         this.properties = resource.getProperties();
-        this.dependencies = resource.getDependencies();
+//        this.dependencies = resource.getDependencies();
         List<String> aspects = resource.getAspects();
         if (aspects != null) {
             for (String aspect : aspects) {

Modified: trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/DependenciesUtil.java
==============================================================================
--- trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/DependenciesUtil.java	(original)
+++ trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/DependenciesUtil.java	Wed Apr  2 03:37:53 2008
@@ -3,8 +3,8 @@
 import org.wso2.registry.DependencyChain;
 import org.wso2.registry.Registry;
 import org.wso2.registry.RegistryException;
+import org.wso2.registry.Association;
 import org.wso2.registry.web.UIConstants;
-import org.wso2.registry.web.actions.ResourceDetailsAction;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -32,17 +32,17 @@
             String dependecyPath = request.getParameter("dependency");
             Registry registry = CommonUtil.getUserRegistry(request);
             //System.out.println("I am here.");
-            registry.addDependencies(dependentPath, new String[] {dependecyPath});
+            registry.addAssociation(dependentPath, dependecyPath, Association.DEPENDENCY);
             //System.out.println("I am here2");
             //response.sendRedirect(new StringBuilder().append("/wso2registry/web").append(dependentPath).toString());
 
-            DependencyChain[] deps=registry.getAllDependencies(dependentPath);
-            List depList=new ArrayList();
-            for(DependencyChain dependency:deps){
-                depList.add(dependency.getDependencyPath());
-            }
-
-            request.getSession().setAttribute(UIConstants.AJAX_DEPENDENCIES_LIST, depList);
+//            DependencyChain[] deps=registry.getAllAssociation(dependentPath , Association.DEPENDENCY);
+//            List depList=new ArrayList();
+//            for(DependencyChain dependency:deps){
+//                depList.add(dependency.getDependencyPath());
+//            }
+//
+//            request.getSession().setAttribute(UIConstants.AJAX_DEPENDENCIES_LIST, depList);
 
         } catch (RegistryException e) {
             request.getSession().setAttribute(UIConstants.ERROR_MESSAGE, e.getMessage());



More information about the Registry-dev mailing list