Author: chathura
Date: Sat Dec 15 06:36:37 2007
New Revision: 11162

Log:


Added a ordering parameter to getLogs(...) method of the Registry interface.
Now it possible to order the activity search results using this parameter.



Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProvider.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/client/RegistryClient.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.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/dao/LogsDAO.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/JDBCRegistryTest.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/RecentActivityAction.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/UserDetailsAction.java

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   
Sat Dec 15 06:36:37 2007
@@ -211,10 +211,13 @@
      * @param to If given, logs for activities occured before the given date 
will be returned. If
      * null, there will not be a bound for the ending date.
      *
+     * @param descending If true, returned activities will be in the 
descending order. If false,
+     * returned activities will be in the ascending order.
+     *
      * @return Array of LogEntry objects representing the logs
      *
      * @throws RegistryException if there is a problem
      */
-    LogEntry[] getLogs(String resourcePath, int action, String userName, Date 
from, Date to)
+    LogEntry[] getLogs(String resourcePath, int action, String userName, Date 
from, Date to, boolean descending)
             throws RegistryException;
 }

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProvider.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProvider.java
   (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAtomProvider.java
   Sat Dec 15 06:36:37 2007
@@ -658,7 +658,7 @@
                                         String author,
                                         String action) throws 
RegistryException {
         LogEntry[] entries = registry.getLogs(
-                path, Integer.parseInt(action), author, from, to);
+                path, Integer.parseInt(action), author, from, to, true);
         Factory factory = abdera.getFactory();
         Feed feed = factory.newFeed();
         feed.setId("http://wso2.org/registry,2007:tags";);

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
 Sat Dec 15 06:36:37 2007
@@ -403,7 +403,9 @@
                               int action,
                               String userName,
                               Date from,
-                              Date to) throws RegistryException {
+                              Date to,
+                              boolean descending) throws RegistryException {
+        
         Abdera abdera = new Abdera();
         AbderaClient abderaClient = new AbderaClient(abdera);
         Entry entry = abdera.getFactory().newEntry();

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/client/RegistryClient.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/client/RegistryClient.java
      (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/client/RegistryClient.java
      Sat Dec 15 06:36:37 2007
@@ -133,7 +133,7 @@
         return null;  //To change body of implemented methods use File | 
Settings | File Templates.
     }
 
-    public LogEntry[] getLogs(String resourcePath, int action, String 
userName, Date from, Date to)
+    public LogEntry[] getLogs(String resourcePath, int action, String 
userName, Date from, Date to, boolean descending)
             throws RegistryException {
         return new LogEntry[0];  //To change body of implemented methods use 
File | Settings | File Templates.
     }

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
  (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
  Sat Dec 15 06:36:37 2007
@@ -297,7 +297,7 @@
         resourceMap.remove(resourcePath);
     }
 
-    public LogEntry[] getLogs(String resourcePath, int action, String 
userName, Date from, Date to)
+    public LogEntry[] getLogs(String resourcePath, int action, String 
userName, Date from, Date to, boolean descending)
             throws RegistryException {
         throw new UnsupportedOperationException(
                 "Logs are not supported in HashMap based in-memory registry.");

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
  Sat Dec 15 06:36:37 2007
@@ -948,14 +948,15 @@
     public LogEntry[] getLogs(String resourcePath,
                               int action,
                               String userName,
-                              Date from, Date to) throws RegistryException {
+                              Date from, Date to, boolean descending) throws 
RegistryException {
 
         Connection conn = connectionFactory.getConnection();
 
         List logEntryList;
 
         try {
-            logEntryList = logsDAO.getLogs(resourcePath, action, userName, 
from, to, conn);
+            logEntryList =
+                    logsDAO.getLogs(resourcePath, action, userName, from, to, 
descending, conn);
 
         } catch (SQLException e) {
             String msg = "Could not get logs. Caused by: " + e.getMessage();

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/LogsDAO.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/LogsDAO.java
   (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/LogsDAO.java
   Sat Dec 15 06:36:37 2007
@@ -43,7 +43,7 @@
     }
 
     public List getLogs(String resourcePath, int action,
-                        String userName, Date from, Date to, Connection conn) 
throws SQLException {
+                        String userName, Date from, Date to, boolean 
descending, Connection conn) throws SQLException {
 
         VersionedResourceDAO resourceDAO = new VersionedResourceDAO();
 
@@ -75,6 +75,10 @@
             sql = sql + " AND L.ACTION=?";
         }
 
+        if (descending) {
+            sql = sql + " ORDER BY L.LOGGED_TIME DESC";
+        }
+
         PreparedStatement s = conn.prepareStatement(sql);
 
         int paramNumber = 1;
@@ -110,7 +114,7 @@
             LogEntry logEntry = new LogEntry();
             
logEntry.setResourcePath(results.getString(DatabaseConstants.PATH_FIELD));
             
logEntry.setUserName(results.getString(DatabaseConstants.USER_ID_FIELD));
-            logEntry.setDate(new 
java.sql.Date(results.getTimestamp(DatabaseConstants.LOGGED_TIME_FIELD).getTime()));
+            logEntry.setDate(new 
Date(results.getTimestamp(DatabaseConstants.LOGGED_TIME_FIELD).getTime()));
             logEntry.setAction(results.getInt(DatabaseConstants.ACTION_FIELD));
             
logEntry.setActionData(results.getString(DatabaseConstants.ACTION_DATA_FIELD));
 

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
      Sat Dec 15 06:36:37 2007
@@ -323,9 +323,9 @@
         return registry.executeQuery(path, parameters);
     }
 
-    public LogEntry[] getLogs(String resourcePath, int action, String 
userName, Date from, Date to)
+    public LogEntry[] getLogs(String resourcePath, int action, String 
userName, Date from, Date to, boolean descending)
             throws RegistryException {
         User.setCurrentUser(userID);
-        return registry.getLogs(resourcePath, action, userName, from, to);
+        return registry.getLogs(resourcePath, action, userName, from, to, 
descending);
     }
 }

Modified: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
==============================================================================
--- 
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
      (original)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
      Sat Dec 15 06:36:37 2007
@@ -864,13 +864,13 @@
 
         registry.rateResource("/r200", 5);
 
-        LogEntry[] logs = registry.getLogs("/r200", -1, null, null, null);
+        LogEntry[] logs = registry.getLogs("/r200", -1, null, null, null, 
true);
 
-        LogEntry l1 = logs[0];
+        LogEntry l1 = logs[1];
         assertEquals("Log for adding /r200 is not added properly.", 
LogEntry.UPDATE, l1.getAction());
         assertEquals("Log for adding /r200 is not added properly.", "/r200", 
l1.getResourcePath());
 
-        LogEntry l2 = logs[1];
+        LogEntry l2 = logs[0];
         assertEquals("Log for rating /r200 is not added properly.", 
LogEntry.RATING, l2.getAction());
         assertEquals("Log for rating /r200 is not added properly.", "5", 
l2.getActionData());
     }

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/RecentActivityAction.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/RecentActivityAction.java
        (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/RecentActivityAction.java
        Sat Dec 15 06:36:37 2007
@@ -75,7 +75,7 @@
         }
 
         SecureRegistry secureRegistry = (SecureRegistry) getRegistry();
-        LogEntry[] logs = secureRegistry.getLogs(resourcePath, filterValue, 
userName, null, null);
+        LogEntry[] logs = secureRegistry.getLogs(resourcePath, filterValue, 
userName, null, null, true);
 
         for (int i = 0; i < logs.length; i++) {
 

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/UserDetailsAction.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/UserDetailsAction.java
   (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/UserDetailsAction.java
   Sat Dec 15 06:36:37 2007
@@ -57,7 +57,7 @@
             allRoles.add(roleNamesArray[i]);
         }
 
-        LogEntry[] userLogs = secureRegistry.getLogs(null, -1, userName, null, 
null);
+        LogEntry[] userLogs = secureRegistry.getLogs(null, -1, userName, null, 
null, true);
         for (int i = 0; i < userLogs.length && i < 10; i++) {
 
             LogEntry logEntry = userLogs[i];

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

Reply via email to