[Registry-dev] svn commit r13249 - in branches/registry/1_0/modules: core/src/main/java/org/wso2/registry/jdbc core/src/main/java/org/wso2/registry/jdbc/mediatypes core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils core/src/main/java/org/wso2/registry/utils webapps/src/main/java/org/wso2/registry/web/actions webapps/src/main/webapp/admin

svn at wso2.org svn at wso2.org
Mon Feb 4 23:31:54 PST 2008


Author: chathura
Date: Mon Feb  4 23:31:30 2008
New Revision: 13249

Log:


Refactored media type handlers to return the saved path for import actions.
This allows media type handlers to save the imported files to any preferred location and return the saved location back to the client.

Fixed the activity report problem in wsdl imports.
Added filters for restore and delete actions.



Modified:
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeHandler.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/Axis2RepositoryMediaTypeHandler.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SQLQueryMediaTypeHandler.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SynapseRepositoryMediaTypeHandler.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/WSDLFileProcessor.java
   branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
   branches/registry/1_0/modules/webapps/src/main/java/org/wso2/registry/web/actions/RecentActivityAction.java
   branches/registry/1_0/modules/webapps/src/main/webapp/admin/recent-activity.jsp

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java	Mon Feb  4 23:31:30 2008
@@ -297,15 +297,19 @@
             throws RegistryException {
 
         suggestedPath = preparePath(suggestedPath);
-        mediaTypeManager.importResource(suggestedPath, sourceURL, metadata);
+
+        String savedPath = mediaTypeManager.importResource(suggestedPath, sourceURL, metadata);
 
         Connection conn = getConnection();
 
         try {
             conn.setAutoCommit(false);
 
-            long resourceID = resourceDAO.getResourceID(suggestedPath, conn);
-            logsDAO.addLog(resourceID, User.getCurrentUser(), LogEntry.UPDATE, null, conn);
+            long resourceID = resourceDAO.getResourceID(savedPath, conn);
+
+            if (resourceID != -1) {
+                logsDAO.addLog(resourceID, User.getCurrentUser(), LogEntry.UPDATE, null, conn);
+            }
 
             conn.commit();
 

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeHandler.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeHandler.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeHandler.java	Mon Feb  4 23:31:30 2008
@@ -114,7 +114,7 @@
      *         importResource(...) method of the DefaultMediaTypeHandler will be invoked.
      * @throws RegistryException
      */
-    public abstract boolean importResource(String path, String sourceURL, Resource metadata)
+    public abstract String importResource(String path, String sourceURL, Resource metadata)
             throws RegistryException;
 
     /**

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java	Mon Feb  4 23:31:30 2008
@@ -185,10 +185,12 @@
         }
     }
 
-    public void importResource(String path, String sourceURL, Resource metadata)
+    public String importResource(String path, String sourceURL, Resource metadata)
             throws RegistryException {
 
         String parentPath = getParentPath(path);
+        String savedPath = null;
+
         if (parentPath != null) {
             Resource parentCollection = defaultMediaTypeHandler.get(parentPath, null);
 
@@ -212,14 +214,22 @@
                     (MediaTypeHandler)mediaTypeHandlers.get(metadata.getMediaType());
 
             if (mediaTypeHandler != null) {
-                if (!mediaTypeHandler.importResource(path, sourceURL, metadata)) {
-                    defaultMediaTypeHandler.importResource(path, sourceURL, metadata);
+                if ((savedPath =
+                        mediaTypeHandler.importResource(path, sourceURL, metadata)) == null) {
+                    
+                    savedPath = defaultMediaTypeHandler.importResource(path, sourceURL, metadata);
                 }
             } else {
-                defaultMediaTypeHandler.importResource(path, sourceURL, metadata);
+                savedPath = defaultMediaTypeHandler.importResource(path, sourceURL, metadata);
             }
         } else {
-            defaultMediaTypeHandler.importResource(path, sourceURL, metadata);
+            savedPath = defaultMediaTypeHandler.importResource(path, sourceURL, metadata);
+        }
+
+        if (savedPath != null) {
+            return savedPath;
+        } else {
+            return path;
         }
     }
 

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/Axis2RepositoryMediaTypeHandler.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/Axis2RepositoryMediaTypeHandler.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/Axis2RepositoryMediaTypeHandler.java	Mon Feb  4 23:31:30 2008
@@ -73,9 +73,9 @@
         return true;
     }
 
-    public boolean importResource(String path, String sourceURL, Resource metadata)
+    public String importResource(String path, String sourceURL, Resource metadata)
             throws RegistryException {
-        return false;
+        return null;
     }
 
     public boolean delete(String path) throws RegistryException {

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/DefaultMediaTypeHandler.java	Mon Feb  4 23:31:30 2008
@@ -295,7 +295,7 @@
         }
     }
 
-    public boolean importResource(String path, String sourceURL, Resource metadata)
+    public String importResource(String path, String sourceURL, Resource metadata)
             throws RegistryException {
 
         URL url;
@@ -333,7 +333,7 @@
             String msg = "Could not read from the given URL: " + sourceURL;
             throw new RegistryException(msg, e);
         }
-        return false;
+        return path;
     }
 
     public boolean delete(String path) throws RegistryException {

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SQLQueryMediaTypeHandler.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SQLQueryMediaTypeHandler.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SQLQueryMediaTypeHandler.java	Mon Feb  4 23:31:30 2008
@@ -57,9 +57,9 @@
         return true;
     }
 
-    public boolean importResource(String path, String sourceURL, Resource metadata)
+    public String importResource(String path, String sourceURL, Resource metadata)
             throws RegistryException {
-        return false;
+        return null;
     }
 
     public boolean delete(String path) throws RegistryException {

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SynapseRepositoryMediaTypeHandler.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SynapseRepositoryMediaTypeHandler.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/SynapseRepositoryMediaTypeHandler.java	Mon Feb  4 23:31:30 2008
@@ -95,9 +95,9 @@
         return true;
     }
 
-    public boolean importResource(String path, String sourceURL, Resource metadata)
+    public String importResource(String path, String sourceURL, Resource metadata)
             throws RegistryException {
-        return false;
+        return null;
     }
 
     public boolean delete(String path) throws RegistryException {

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java	Mon Feb  4 23:31:30 2008
@@ -19,6 +19,7 @@
 import org.wso2.registry.RegistryConstants;
 import org.wso2.registry.RegistryException;
 import org.wso2.registry.Resource;
+import org.wso2.registry.utils.AuthorizationUtil;
 import org.wso2.registry.jdbc.mediatypes.MediaTypeHandler;
 import org.wso2.registry.jdbc.mediatypes.MediaTypeManager;
 import org.wso2.registry.jdbc.mediatypes.utils.WSDLFileProcessor;
@@ -50,11 +51,17 @@
         return false;
     }
 
-    public boolean importResource(String path, String sourceURL, Resource metadata)
+    public String importResource(String path, String sourceURL, Resource metadata)
             throws RegistryException {
 
-        wsdlFileProcessor.saveWSDLFileToRegistry(sourceURL, getParentPath(path), true, metadata);
-        return true;
+        String savedName = wsdlFileProcessor.saveWSDLFileToRegistry(sourceURL, getParentPath(path), true, metadata);
+        String parentPath = AuthorizationUtil.getParentPath(path);
+
+        if (parentPath.endsWith(RegistryConstants.PATH_SEPARATOR)) {
+            return parentPath + savedName;
+        } else {
+            return parentPath + RegistryConstants.PATH_SEPARATOR + savedName;
+        }
     }
 
     public boolean delete(String path) throws RegistryException {

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java	Mon Feb  4 23:31:30 2008
@@ -51,12 +51,12 @@
         return false;
     }
 
-    public boolean importResource(String path, String sourceURL, Resource metadata)
+    public String importResource(String path, String sourceURL, Resource metadata)
             throws RegistryException {
 
         schemaFileProcessor
                 .saveSchemaFileToRegistry(sourceURL, getParentPath(path), true, metadata);
-        return true;
+        return path;
     }
 
     public boolean delete(String path) throws RegistryException {

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/WSDLFileProcessor.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/WSDLFileProcessor.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/WSDLFileProcessor.java	Mon Feb  4 23:31:30 2008
@@ -58,12 +58,13 @@
      * @param location
      * @throws WSDLException
      */
-    public void saveWSDLFileToRegistry(String location,
-                                       String registryBasePath,
-                                       boolean processImports,
-                                       Resource metadata)
+    public String saveWSDLFileToRegistry(String location,
+                                         String registryBasePath,
+                                         boolean processImports,
+                                         Resource metadata)
             throws RegistryException {
         WSDLReader wsdlReader = null;
+        String fileNameToSave = null;
 
         try {
             wsdlReader = WSDLFactory.newInstance().newWSDLReader();
@@ -77,17 +78,22 @@
 
         try {
             wsdlDefinition = wsdlReader.readWSDL(location);
+            String baseUri = wsdlDefinition.getDocumentBaseURI();
+            String wsdlFileName = baseUri.substring(baseUri.lastIndexOf("/") + 1);
+            fileNameToSave = wsdlFileName.substring(0, wsdlFileName.indexOf(".")) + ".wsdl";
         } catch (WSDLException e) {
             String msg = "Could not read the wsdl at location " + location + ". Caused by: " +
-                         e.getMessage();
+                    e.getMessage();
             throw new RegistryException(msg);
         }
 
         Map processedWSDLMap = new HashMap();
         calculateWSDLNamesAndChangeTypes(wsdlDefinition, processedWSDLMap, new HashMap(),
-                                         new HashSet(), registryBasePath, processImports);
+                new HashSet(), registryBasePath, processImports);
         saveWSDLFileToRegistry(wsdlDefinition, processedWSDLMap, new HashSet(), registryBasePath,
-                               processImports, metadata);
+                processImports, metadata);
+
+        return fileNameToSave;
     }
 
     /**
@@ -203,7 +209,7 @@
                     if (!visitedWSDLs.contains(innerDefinition.getDocumentBaseURI())) {
                         // we have not process this wsdl file earlier
                         saveWSDLFileToRegistry(innerDefinition, processedWSDLMap, visitedWSDLs,
-                                               registryBasePath, processImports, null);
+                                registryBasePath, processImports, null);
                     }
                     // set the import location according to the new location
                     wsdlImport.setLocationURI((String)processedWSDLMap.get(
@@ -213,8 +219,7 @@
         }
 
         // after processing the defintions save this to the registry
-        // TODO: save this to the registry for the moment save this to the
-        // folder and omit any exception occurs.
+        // save this to the registry
         String importedResourceName =
                 (String)processedWSDLMap.get(wsdlDefinition.getDocumentBaseURI());
         try {

Modified: branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
==============================================================================
--- branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java	(original)
+++ branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java	Mon Feb  4 23:31:30 2008
@@ -262,7 +262,7 @@
         }
     }
 
-    private static String getParentPath(String childPath) {
+    public static String getParentPath(String childPath) {
 
         if (childPath.equals(RegistryConstants.ROOT_PATH)) {
             return null;

Modified: branches/registry/1_0/modules/webapps/src/main/java/org/wso2/registry/web/actions/RecentActivityAction.java
==============================================================================
--- branches/registry/1_0/modules/webapps/src/main/java/org/wso2/registry/web/actions/RecentActivityAction.java	(original)
+++ branches/registry/1_0/modules/webapps/src/main/java/org/wso2/registry/web/actions/RecentActivityAction.java	Mon Feb  4 23:31:30 2008
@@ -75,6 +75,9 @@
 
         } else if (filter.equals("restore")) {
             filterValue = LogEntry.RESTORE;
+
+        } else if (filter.equals("delete")) {
+            filterValue = LogEntry.DELETE_RESOURCE;
         }
 
         SecureRegistry secureRegistry = (SecureRegistry) getRegistry();

Modified: branches/registry/1_0/modules/webapps/src/main/webapp/admin/recent-activity.jsp
==============================================================================
--- branches/registry/1_0/modules/webapps/src/main/webapp/admin/recent-activity.jsp	(original)
+++ branches/registry/1_0/modules/webapps/src/main/webapp/admin/recent-activity.jsp	Mon Feb  4 23:31:30 2008
@@ -114,7 +114,9 @@
                     <td>
                         <select name="filter">
                             <option value ="all">All</option>
-                            <option value ="resourceActions">Resource Actions</option>
+                            <option value ="resourceActions">Resource Updates</option>
+                            <option value ="delete">Resource Deletes</option>
+                            <option value ="restore">Resource Restores</option>
                             <option value ="commentings">Comments</option>
                             <option value ="taggings">Tagging</option>
                             <option value ="ratings">Ratings</option>



More information about the Registry-dev mailing list