portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r331669 - in /portals/jetspeed-2/trunk: applications/pam/src/java/org/apache/jetspeed/portlets/statistics/ applications/pam/src/webapp/WEB-INF/view/statistics/ components/statistics/ components/statistics/src/java/org/apache/jetspeed/statis...
Date Tue, 08 Nov 2005 02:11:25 GMT
Author: taylor
Date: Mon Nov  7 18:10:56 2005
New Revision: 331669

URL: http://svn.apache.org/viewcvs?rev=331669&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-362
made test run
cleaned up formatting on portlet
changed milliseconds to minutes for user view
added a tiny bit more infrastructure

Modified:
    portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/statistics/StatisticsPortlet.java
    portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/statistics/statistics.vm
    portals/jetspeed-2/trunk/components/statistics/project.xml
    portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
    portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java
    portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
    portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/statistics/StatisticsQueryCriteria.java

Modified: portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/statistics/StatisticsPortlet.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/statistics/StatisticsPortlet.java?rev=331669&r1=331668&r2=331669&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/statistics/StatisticsPortlet.java
(original)
+++ portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/statistics/StatisticsPortlet.java
Mon Nov  7 18:10:56 2005
@@ -87,6 +87,9 @@
                 sqc = new StatisticsQueryCriteriaImpl();
                 sqc.setQueryType(PortalStatistics.QUERY_TYPE_PORTLET);
                 sqc.setTimePeriod("1");
+                sqc.setListsize("5");
+                sqc.setSorttype("count");
+                sqc.setSortorder("desc");
                 session.setAttribute(SESSION_CRITERIA, sqc);
 
                 try
@@ -120,6 +123,10 @@
         {
             timeperiod = "all";
         }
+        criteria.setListsize("5");
+        criteria.setSorttype("count");
+        criteria.setSortorder("desc");
+
         criteria.setTimePeriod(timeperiod);
         String queryType = request.getParameter("queryType");
 

Modified: portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/statistics/statistics.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/statistics/statistics.vm?rev=331669&r1=331668&r2=331669&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/statistics/statistics.vm
(original)
+++ portals/jetspeed-2/trunk/applications/pam/src/webapp/WEB-INF/view/statistics/statistics.vm
Mon Nov  7 18:10:56 2005
@@ -107,14 +107,16 @@
 	</td></tr>
 	</table>
 	<table><tr><td>
-	<table class="class="portlet-section-body" >
+	<center>stats for all ${criteria.queryType}s</center>
+    <table class="class="portlet-section-body" >
 	<tr class="portlet-section-subheader"><TH><b>stat name</b></TH><TH><b
align="right" >value</b></TH></TR>
 	<tr class="portlet-section-alternate"><TD>total hits</TD><TD align="right"
>$!results.hitCount</TD></TR>
-	<tr class="portlet-section-body"><TD>max processing time</TD><TD align="right"
>$!results.maxProcessingTime</TD></TR>
-	<tr class="portlet-section-alternate"><TD>avg processing time</TD><TD
align="right" >$!results.avgProcessingTime</TD></TR>
-	<tr class="portlet-section-body"><TD>min processing time</TD><TD align="right"
>$!results.minProcessingTime</TD></TR>
+	<tr class="portlet-section-body"><TD>max time</TD><TD align="right"
>$!results.maxProcessingTime</TD></TR>
+	<tr class="portlet-section-alternate"><TD>avg time</TD><TD align="right"
>$!results.avgProcessingTime</TD></TR>
+	<tr class="portlet-section-body"><TD>min time</TD><TD align="right"
>$!results.minProcessingTime</TD></TR>
     </table>
     </td><td>
+    <center>Top $criteria.listsize ${criteria.queryType}s sorted by $criteria.sorttype
$criteria.sortorder</center>
     <table class="class="portlet-section-body" >
 	<tr class="portlet-section-subheader">
 		<TH><b>$criteria.queryType</b>
@@ -135,7 +137,13 @@
   	#end
     </table>
     </td></tr>
-    <tr><td colspan="2" align="center"> <font size="-1" >all times in milliseconds</font></td></tr>
+    <tr><td colspan="2" align="center"> <font size="-1" >
+    #if($criteria.queryType == "user") 
+    	all times in minutes
+    #else
+    	all times in milliseconds
+    #end
+    </font></td></tr>
     </table>
     </form>
 	

Modified: portals/jetspeed-2/trunk/components/statistics/project.xml
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/project.xml?rev=331669&r1=331668&r2=331669&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/project.xml (original)
+++ portals/jetspeed-2/trunk/components/statistics/project.xml Mon Nov  7 18:10:56 2005
@@ -61,6 +61,14 @@
             </properties>
         </dependency>
         
+        <dependency>
+            <id>jetspeed-security</id>
+            <groupId>jetspeed2</groupId>
+            <version>${jetspeed.version}</version>
+            <properties>
+                <war.bundle>false</war.bundle>
+            </properties>
+        </dependency>
         <!-- test only -->
         <dependency>
             <id>jetspeed-cm</id>

Modified: portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java?rev=331669&r1=331668&r2=331669&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
Mon Nov  7 18:10:56 2005
@@ -43,6 +43,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.components.rdbms.ojb.ConnectionRepositoryEntry;
+import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.statistics.AggregateStatistics;
 import org.apache.jetspeed.statistics.InvalidCriteriaException;
@@ -194,7 +195,6 @@
         return ds;
     }
 
-    
     public void logPortletAccess(RequestContext request, String portletName,
             String statusCode, long msElapsedTime)
     {
@@ -210,8 +210,18 @@
 
             record.setPortletName(portletName);
             record.setUserName(userName);
-            record.setIpAddress(req.getRemoteAddr());
-            record.setPagePath(request.getPage().getPath());
+            if (req.getRemoteAddr() != null)
+            {
+                record.setIpAddress(req.getRemoteAddr());
+            }
+            ContentPage cp = request.getPage();
+            if (cp != null)
+            {
+                if (cp.getPath() != null)
+                {
+                    record.setPagePath(cp.getPath());
+                }
+            }
             record.setStatus(Integer.parseInt(statusCode));
             record.setTimeStamp(timestamp);
             record.setMsElapsedTime(msElapsedTime);
@@ -325,7 +335,14 @@
 
             record.setUserName(userName);
             record.setIpAddress(req.getRemoteAddr());
-            record.setPagePath(request.getPage().getPath());
+            ContentPage cp = request.getPage();
+            if (cp != null)
+            {
+                if (cp.getPath() != null)
+                {
+                    record.setPagePath(cp.getPath());
+                }
+            }
             record.setStatus(Integer.parseInt(statusCode));
             record.setTimeStamp(timestamp);
             record.setMsElapsedTime(msElapsedTime);
@@ -350,30 +367,33 @@
     {
         try
         {
-            currentUserCount = currentUserCount - 1;
 
             if (userName == null)
             {
                 userName = "guest";
             }
 
-            synchronized (currentUsers)
+            if (!"guest".equals(userName))
             {
-                UserStats userStats = (UserStats) currentUsers.get(userName);
-                if (userStats == null)
-                {
-                    //log.warn("Trying to log out a user that was never logged
-                    // in!");
-                    userStats = new UserStatsImpl();
-                    userStats.setNumberOfSession(0);
-                    userStats.setUsername(userName);
-                    currentUsers.put(userName, userStats);
-                }
-                userStats
-                        .setNumberOfSession(userStats.getNumberOfSessions() - 1);
-                if (userStats.getNumberOfSessions() <= 0)
+                currentUserCount = currentUserCount - 1;
+
+                synchronized (currentUsers)
                 {
-                    currentUsers.remove(userName);
+                    UserStats userStats = (UserStats) currentUsers
+                            .get(userName);
+                    if (userStats == null)
+                    {
+                        userStats = new UserStatsImpl();
+                        userStats.setNumberOfSession(0);
+                        userStats.setUsername(userName);
+                        currentUsers.put(userName, userStats);
+                    }
+                    userStats.setNumberOfSession(userStats
+                            .getNumberOfSessions() - 1);
+                    if (userStats.getNumberOfSessions() <= 0)
+                    {
+                        currentUsers.remove(userName);
+                    }
                 }
             }
 
@@ -411,7 +431,6 @@
     {
         try
         {
-            currentUserCount = currentUserCount + 1;
 
             HttpServletRequest req = request.getRequest();
             Principal principal = req.getUserPrincipal();
@@ -420,21 +439,24 @@
             Timestamp timestamp = new Timestamp(System.currentTimeMillis());
             UserLogRecord record = new UserLogRecord();
 
-            synchronized (currentUsers)
+            if (!"guest".equals(userName))
             {
-                UserStats userStats = (UserStats) currentUsers.get(userName);
-                if (userStats == null)
-                {
-                    //log.warn("Trying to log out a user that was never logged
-                    // in!");
-                    userStats = new UserStatsImpl();
-                    userStats.setNumberOfSession(0);
-                    userStats.setUsername(userName);
-                    currentUsers.put(userName, userStats);
+                currentUserCount = currentUserCount + 1;
 
+                synchronized (currentUsers)
+                {
+                    UserStats userStats = (UserStats) currentUsers
+                            .get(userName);
+                    if (userStats == null)
+                    {
+                        userStats = new UserStatsImpl();
+                        userStats.setNumberOfSession(0);
+                        userStats.setUsername(userName);
+                        currentUsers.put(userName, userStats);
+                    }
+                    userStats.setNumberOfSession(userStats
+                            .getNumberOfSessions() + 1);
                 }
-                userStats
-                        .setNumberOfSession(userStats.getNumberOfSessions() + 1);
             }
 
             record.setUserName(userName);
@@ -459,7 +481,6 @@
 
     }
 
-    
     /**
      * @see org.springframework.beans.factory.DisposableBean#destroy()
      */
@@ -595,6 +616,15 @@
         Date start = getStartDateFromPeriod(criteria.getTimePeriod(), end);
 
         String queryType = criteria.getQueryType();
+        String listsizeStr = criteria.getListsize();
+        int listsize = 5;
+        try
+        {
+            listsize = Integer.parseInt(listsizeStr);
+        } catch (NumberFormatException e1)
+        {
+        }
+
         if (PortalStatistics.QUERY_TYPE_USER.equals(queryType))
         {
             tableName = "USER_STATISTICS";
@@ -626,7 +656,7 @@
                     + "from " + tableName
                     + " where time_stamp > ? and time_stamp < ? group by "
                     + groupColumn + "  order by " + orderColumn + " " + ascDesc
-                    + " limit 5";
+                    + " limit " + listsize;
         } else
         {
             query = "select count(*) as count , MIN(ELAPSED_TIME),AVG(ELAPSED_TIME),MAX(ELAPSED_TIME)
from "
@@ -639,7 +669,7 @@
                     + tableName
                     + " where time_stamp > ? and time_stamp < ? and status = 2 group
by "
                     + groupColumn + "  order by " + orderColumn + " " + ascDesc
-                    + " limit 5";
+                    + " limit " + listsize;
         }
         try
         {
@@ -648,12 +678,23 @@
             pstmt.setTimestamp(1, new Timestamp(start.getTime()));
             pstmt.setTimestamp(2, new Timestamp(end.getTime()));
             ResultSet rs = pstmt.executeQuery();
+            float denominator = 1.0f;
+            if (PortalStatistics.QUERY_TYPE_USER.equals(queryType))
+            {
+                denominator = 1000f * 60f; // this should convert from mS to
+                                           // minutes
+            }
             if (rs.next())
             {
                 as.setHitCount(rs.getInt("count"));
-                as.setMinProcessingTime(rs.getFloat("MIN(ELAPSED_TIME)"));
-                as.setAvgProcessingTime(rs.getFloat("AVG(ELAPSED_TIME)"));
-                as.setMaxProcessingTime(rs.getFloat("MAX(ELAPSED_TIME)"));
+
+                as.setMinProcessingTime(rs.getFloat("MIN(ELAPSED_TIME)")
+                        / denominator);
+                as.setAvgProcessingTime(rs.getFloat("AVG(ELAPSED_TIME)")
+                        / denominator);
+                as.setMaxProcessingTime(rs.getFloat("MAX(ELAPSED_TIME)")
+                        / denominator);
+
             }
             PreparedStatement pstmt2 = con.prepareStatement(query2);
             pstmt2.setTimestamp(1, new Timestamp(start.getTime()));
@@ -666,14 +707,22 @@
                 row.put("count", "" + rs2.getInt("count"));
                 String col = rs2.getString(groupColumn);
                 int maxColLen = 35;
-                if(col.length() > maxColLen ) {
-                    col = col.substring(0,maxColLen);
+                if (col != null)
+                {
+
+                    if (col.length() > maxColLen)
+                    {
+                        col = col.substring(0, maxColLen);
+                    }
                 }
-                
+
                 row.put("groupColumn", col);
-                row.put("min", "" + floatFormatter(rs2.getFloat("min")));
-                row.put("avg", "" + floatFormatter(rs2.getFloat("avg")));
-                row.put("max", "" + floatFormatter(rs2.getFloat("max")));
+                row.put("min", ""
+                        + floatFormatter(rs2.getFloat("min") / denominator));
+                row.put("avg", ""
+                        + floatFormatter(rs2.getFloat("avg") / denominator));
+                row.put("max", ""
+                        + floatFormatter(rs2.getFloat("max") / denominator));
                 as.addRow(row);
             }
 
@@ -685,11 +734,13 @@
         return as;
     }
 
-    private String floatFormatter(float f) {
+    private String floatFormatter(float f)
+    {
         // for now we'll just truncate as int
         int f2 = new Float(f).intValue();
         return Integer.toString(f2);
     }
+
     /*
      * (non-Javadoc)
      * 

Modified: portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java?rev=331669&r1=331668&r2=331669&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/StatisticsQueryCriteriaImpl.java
Mon Nov  7 18:10:56 2005
@@ -5,11 +5,17 @@
 public class StatisticsQueryCriteriaImpl implements StatisticsQueryCriteria
 {
 
-    String user;
+    private String user;
 
-    String timePeriod;
+    private String timePeriod;
 
-    String queryType;
+    private String queryType;
+
+    private String listsize;
+
+    private String sorttype;
+
+    private String sortorder;
 
     /**
      * @return Returns the ipAddress.
@@ -64,5 +70,55 @@
     public void setQueryType(String queryType)
     {
         this.queryType = queryType;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.StatisticsQueryCriteria#getListsize()
+     */
+    public String getListsize()
+    {
+        return this.listsize;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.StatisticsQueryCriteria#getSorttype()
+     */
+    public String getSorttype()
+    {
+        return this.sorttype;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.StatisticsQueryCriteria#setListsize(java.lang.String)
+     */
+    public void setListsize(String listsize)
+    {
+        this.listsize = listsize;
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.StatisticsQueryCriteria#setSorttype(java.lang.String)
+     */
+    public void setSorttype(String sorttype)
+    {
+        this.sorttype = sorttype;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.StatisticsQueryCriteria#getSortorder()
+     */
+    public String getSortorder()
+    {
+        return this.sortorder;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.statistics.StatisticsQueryCriteria#setSortorder(java.lang.String)
+     */
+    public void setSortorder(String sortorder)
+    {
+        this.sortorder = sortorder;
+
     }
 }

Modified: portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java?rev=331669&r1=331668&r2=331669&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
(original)
+++ portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
Mon Nov  7 18:10:56 2005
@@ -15,6 +15,7 @@
  */
 package org.apache.jetspeed.statistics;
 
+import java.security.Principal;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -29,6 +30,7 @@
 import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
 import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
 import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.security.impl.UserPrincipalImpl;
 import org.apache.jetspeed.statistics.impl.StatisticsQueryCriteriaImpl;
 
 import com.mockrunner.mock.web.MockHttpServletRequest;
@@ -250,12 +252,23 @@
         System.out.println("testing Query System");
         StatisticsQueryCriteria sqc = new StatisticsQueryCriteriaImpl();
         sqc.setQueryType(PortalStatistics.QUERY_TYPE_USER);
+        sqc.setListsize("5");
+        sqc.setSorttype("count");
+        sqc.setSortorder("desc");
         AggregateStatistics as = statistics.queryStatistics(sqc);
         System.out.println("user = " + as);
+
         sqc.setQueryType(PortalStatistics.QUERY_TYPE_PORTLET);
+        sqc.setListsize("5");
+        sqc.setSorttype("count");
+        sqc.setSortorder("desc");
         as = statistics.queryStatistics(sqc);
         System.out.println("user = " + as);
+
         sqc.setQueryType(PortalStatistics.QUERY_TYPE_PAGE);
+        sqc.setListsize("5");
+        sqc.setSorttype("count");
+        sqc.setSortorder("desc");
         as = statistics.queryStatistics(sqc);
         System.out.println("user = " + as);
 
@@ -266,6 +279,10 @@
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockHttpServletResponse response = new MockHttpServletResponse();
         MockHttpSession session = new MockHttpSession();
+
+        Principal p = new UserPrincipalImpl("anotherFaker");
+
+        request.setUserPrincipal(p);
 
         request.setRemoteAddr("192.168.2.3");
         request.setSession(session);

Modified: portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/statistics/StatisticsQueryCriteria.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/statistics/StatisticsQueryCriteria.java?rev=331669&r1=331668&r2=331669&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/statistics/StatisticsQueryCriteria.java
(original)
+++ portals/jetspeed-2/trunk/jetspeed-api/src/java/org/apache/jetspeed/statistics/StatisticsQueryCriteria.java
Mon Nov  7 18:10:56 2005
@@ -37,4 +37,16 @@
     public void setQueryType(String queryType);
 
     public String getQueryType();
+
+    public String getListsize();
+
+    public String getSorttype();
+
+    public void setListsize(String listsize);
+
+    public void setSorttype(String sorttype);
+
+    public void setSortorder(String sortorder);
+
+    public String getSortorder();
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message