Author: deepal
Date: Sun Feb 24 21:28:29 2008
New Revision: 14125

Log:

fixing user manager  dependency

First version of svn coyp  

Modified:
   trunk/registry/modules/core/pom.xml
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/RatingsDAO.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/TagsDAO.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/utils/RegistryClientUtils.java
   trunk/registry/modules/documentation/pom.xml
   trunk/registry/modules/webapps/pom.xml
   trunk/registry/pom.xml

Modified: trunk/registry/modules/core/pom.xml
==============================================================================
--- trunk/registry/modules/core/pom.xml (original)
+++ trunk/registry/modules/core/pom.xml Sun Feb 24 21:28:29 2008
@@ -85,6 +85,10 @@
             <artifactId>usermanager-core</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.wso2.commons.usermanager</groupId>
+            <artifactId>usermanager-configs</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.apache.abdera</groupId>
             <artifactId>abdera-client</artifactId>
         </dependency>

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
  Sun Feb 24 21:28:29 2008
@@ -367,7 +367,8 @@
                                                newPath,
                                                getConnection(),
                                                User.getCurrentUser(),
-                                               defaultRealm);
+                                               defaultRealm,
+                                               this);
 
                     logsDAO.addLog(resourceID, userID, LogEntry.RENAME, 
currentPath, conn);
 

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
       (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
       Sun Feb 24 21:28:29 2008
@@ -56,6 +56,17 @@
         return null;
     }
 
+    public void copyComments(String path ,
+                             long resourceID ,
+                             Connection connection) throws SQLException{
+      Comment [] commnets = getComments(path ,connection);
+        for (int i = 0; i < commnets.length; i++) {
+            Comment commnet = commnets[i];
+            addComment(resourceID ,commnet.getUser(),commnet,connection);
+        }
+
+    }
+
     public void updateComment(long commentId, String text, Connection conn)
             throws SQLException {
 

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/RatingsDAO.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/RatingsDAO.java
        (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/RatingsDAO.java
        Sun Feb 24 21:28:29 2008
@@ -45,6 +45,26 @@
         s.executeUpdate();
     }
 
+    public void copyRatings(long fromResourceID , long toResourceId , 
Connection conn) throws SQLException {
+        String SQL  = "SELECT USER_ID , RATING , RATED_TIME FROM RATINGS WHERE 
AID=?";
+        PreparedStatement s = conn.prepareStatement(SQL);
+        s.setLong(1, fromResourceID);
+
+        ResultSet result = s.executeQuery();
+        ArrayList list = new ArrayList();
+        if (result.next()) {
+            RatingDO rate = new RatingDO();
+            rate.setRatedUserName(result.getString(1));
+            rate.setRating(result.getInt(2));
+            rate.setRatedTime(result.getDate(3));
+            list.add(rate);
+        }
+        for (int i = 0; i < list.size(); i++) {
+            RatingDO ratingDO = (RatingDO) list.get(i);
+            addRating(toResourceId , ratingDO.getRatedUserName() 
,ratingDO.getRating() ,conn);
+        }
+    }
+
     public void updateRating(long artifactID, String userID, int rating, 
Connection conn)
             throws SQLException {
 

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/TagsDAO.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/TagsDAO.java
   (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/TagsDAO.java
   Sun Feb 24 21:28:29 2008
@@ -47,6 +47,26 @@
         s.executeUpdate();
     }
 
+    public void copyTags(long fromResourceID , long toResourceID , Connection 
connection)
+            throws SQLException{
+        String SQL = "SELECT TAG_NAME , USER_ID , TAGGED_TIME FROM TAGS WHERE 
AID=?";
+        PreparedStatement s = connection.prepareStatement(SQL);
+        s.setLong(1, fromResourceID);
+        ResultSet result = s.executeQuery();
+        ArrayList tagList = new ArrayList();
+        if (result.next()) {
+            TaggingDO  taggingDO = new TaggingDO();
+            taggingDO.setTagName(result.getString(1));
+            taggingDO.setTaggedUserName(result.getString(2));
+            taggingDO.setTaggedTime(result.getDate(3));
+            tagList.add(taggingDO);
+        }
+        for (int i = 0; i < tagList.size(); i++) {
+            TaggingDO taggingDO = (TaggingDO) tagList.get(i);
+            addTagging(taggingDO.getTagName() ,toResourceID , 
taggingDO.getTaggedUserName() ,connection);
+        }
+    }
+
     public boolean taggingExist(String tagName, long resourceID, String 
userID, Connection conn)
             throws SQLException {
 

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
      Sun Feb 24 21:28:29 2008
@@ -18,10 +18,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.wso2.registry.RegistryConstants;
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.Resource;
-import org.wso2.registry.User;
+import org.wso2.registry.*;
 import org.wso2.registry.jdbc.DatabaseConstants;
 import org.wso2.registry.users.UserRealm;
 import org.wso2.registry.utils.AuthorizationUtil;
@@ -664,7 +661,8 @@
                                String newPath,
                                Connection conn,
                                String userId,
-                               UserRealm realm) throws SQLException, 
RegistryException {
+                               UserRealm realm ,
+                               Registry registry) throws SQLException, 
RegistryException {
 
         Resource resource = getLatestVersion(oldPath, conn);
         String resourcePath = resource.getPath();
@@ -674,7 +672,7 @@
         // if the resource is a directory then need to populate the dependecy 
table with
         // the new resource id , while keeping the old one as it is
         if (resource.isDirectory()) {
-            throw new RegistryException("Resource rename does not support for 
collections");
+            copyResource(oldPath,newPath  , registry , false , conn);
         } else {
             // Then its just need to add the resource and no need to update 
any of the
             // dependecy tables
@@ -688,15 +686,79 @@
             long newResourceID = getResourceID(newPath, conn);
             resource.setId(newResourceID);
             addResourceVersion(resource, conn);
+            resource.setPath(resourcePath);
+            resource.setId(resourceID);
+            markDeleted(resourcePath, conn);
+            deleteResource(resource, conn);
         }
-        resource.setPath(resourcePath);
-        resource.setId(resourceID);
-        markDeleted(resourcePath, conn);
-        deleteResource(resource, conn);
         //prepareToDelete(resource.getId(), conn);
         //resourceDAO.delete(resource.getResourcePath(), conn);
     }
 
+
+    /**
+     * This method use to copy a resource from given location to some other 
location
+     * When we do so all the resource properties , tags  ,
+     * comments and everything will be copy into new location
+     * @param fromPath : Which collection to copy
+     * @param toPath : Where to copy
+     * @param registry : Instance of a registry
+     * @param useOrginal : to indicate whether firt time call or not
+     * @throws RegistryException
+     */
+    private void copyResource(String fromPath,
+                             String toPath ,
+                             Registry registry ,
+                             boolean useOrginal ,
+                             Connection conn) throws RegistryException {
+        Resource resource = registry.get(fromPath);
+        if (resource != null) {
+
+            String resourcePath = resource.getPath();
+            int verionIndex = resourcePath.indexOf("?");
+            if (verionIndex >0) {
+                resourcePath = resourcePath.substring(0,verionIndex);
+            }
+            int slashIndex = resourcePath.lastIndexOf("/");
+            //getting only the last part of the resource path
+            resourcePath = 
resourcePath.substring(slashIndex,resourcePath.length());
+
+            String currentPath ;
+            if (!useOrginal) {
+                currentPath = toPath + resourcePath;
+            } else {
+                currentPath = toPath;
+            }
+
+            if (resource.isDirectory()) {
+                String childNodes[] = (String[])resource.getContent();
+                for (String childNode : childNodes) {
+                    copyResource(childNode, currentPath, registry ,false  
,conn);
+                }
+            }
+            resource.setPath(currentPath);
+            registry.put(currentPath,resource);
+            try {
+                long resourceId = getResourceID(currentPath , conn);
+                long fromResourceId = getResourceID(fromPath , conn);
+                //copying the comments
+                CommentsDAO commentsDAO = new CommentsDAO();
+                commentsDAO.copyComments(fromPath ,resourceId ,conn);
+                //coping the tags
+                TagsDAO tags = new TagsDAO();
+                tags.copyTags(fromResourceId , resourceId ,conn);
+
+                // copy ratings
+                RatingsDAO ratingsDAO = new RatingsDAO();
+                ratingsDAO.copyRatings(fromResourceId ,resourceId ,conn);
+            } catch (SQLException e) {
+                log.info(e);
+            }
+        } else {
+            log.info("No resource found for : "  + fromPath);
+        }
+    }
+
     public long addResourceVersion(Resource resource, Connection connection)
             throws SQLException, RegistryException {
 

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryClientUtils.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryClientUtils.java
  (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryClientUtils.java
  Sun Feb 24 21:28:29 2008
@@ -72,7 +72,7 @@
      * @param registry : Registry instance
      * @throws RegistryException : If something went wrong
      */
-    public void exportFromRegistry(File toFile, String path, Registry registry)
+    public static void exportFromRegistry(File toFile, String path, Registry 
registry)
             throws RegistryException {
         try {
             processExport(path, toFile, registry);
@@ -105,8 +105,8 @@
         }
     }
 
-    public static  void processExport(String resourcePath,
-                               File toFile, Registry registry) throws 
RegistryException {
+    private static  void processExport(String resourcePath,
+                                       File toFile, Registry registry) throws 
RegistryException {
         Resource resource = registry.get(resourcePath);
         if (resource != null) {
             if (resource.isDirectory()) {

Modified: trunk/registry/modules/documentation/pom.xml
==============================================================================
--- trunk/registry/modules/documentation/pom.xml        (original)
+++ trunk/registry/modules/documentation/pom.xml        Sun Feb 24 21:28:29 2008
@@ -123,6 +123,11 @@
             <groupId>org.wso2.commons.usermanager</groupId>
             <artifactId>usermanager-core</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.wso2.commons.usermanager</groupId>
+            <artifactId>usermanager-configs</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.apache.abdera</groupId>
             <artifactId>abdera-client</artifactId>

Modified: trunk/registry/modules/webapps/pom.xml
==============================================================================
--- trunk/registry/modules/webapps/pom.xml      (original)
+++ trunk/registry/modules/webapps/pom.xml      Sun Feb 24 21:28:29 2008
@@ -143,15 +143,13 @@
             <groupId>commons-digester</groupId>
             <artifactId>commons-digester</artifactId>
         </dependency>
-        <dependency>
+         <dependency>
             <groupId>org.wso2.commons.usermanager</groupId>
             <artifactId>usermanager-core</artifactId>
-             <exclusions>
-                
<exclusion><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId></exclusion>
-                
<exclusion><groupId>tomcat</groupId><artifactId>naming-factory</artifactId></exclusion>
-                
<exclusion><groupId>tomcat</groupId><artifactId>naming-factory-dbcp</artifactId></exclusion>
-                
<exclusion><groupId>tomcat</groupId><artifactId>naming-resources</artifactId></exclusion>
-            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.commons.usermanager</groupId>
+            <artifactId>usermanager-configs</artifactId>
         </dependency>
 
         <!-- Struts and tiles dependencies -->

Modified: trunk/registry/pom.xml
==============================================================================
--- trunk/registry/pom.xml      (original)
+++ trunk/registry/pom.xml      Sun Feb 24 21:28:29 2008
@@ -173,6 +173,11 @@
             </dependency>
 
             <dependency>
+                <groupId>org.wso2.commons.usermanager</groupId>
+                <artifactId>usermanager-configs</artifactId>
+                <version>${usermanager.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>javax.mail</groupId>
                 <artifactId>mail</artifactId>
                 <version>${javamail.version}</version>

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

Reply via email to