portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r331611 - /portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/statistics/StatisticsPortlet.java
Date Mon, 07 Nov 2005 22:02:15 GMT
Author: taylor
Date: Mon Nov  7 14:02:03 2005
New Revision: 331611

URL: http://svn.apache.org/viewcvs?rev=331611&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-362
statistics portlet query and user support

Modified:
    portals/jetspeed-2/trunk/applications/pam/src/java/org/apache/jetspeed/portlets/statistics/StatisticsPortlet.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=331611&r1=331610&r2=331611&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 14:02:03 2005
@@ -17,6 +17,8 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.CommonPortletServices;
 import org.apache.jetspeed.statistics.AggregateStatistics;
 import org.apache.jetspeed.statistics.InvalidCriteriaException;
@@ -27,87 +29,103 @@
 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
 import org.apache.velocity.context.Context;
 
-
 /**
  * Statistics Portlet
  * 
- * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer</a>
+ * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer </a>
  * @version $Id: $
  */
 public class StatisticsPortlet extends GenericVelocityPortlet
 {
+
     private PortalStatistics statistics;
-    
+
     private static final String SESSION_CRITERIA = "criteria";
+
     private static final String SESSION_RESULTS = "results";
-    
+
+    private static final String SESSION_TOTALSESSIONS = "totalsessions";
+
+    /* CLF logger */
+    protected final Log logger = LogFactory.getLog(this.getClass());
+
     public void init(PortletConfig config) throws PortletException
     {
         super.init(config);
         PortletContext context = getPortletContext();
-        statistics = (PortalStatistics)context.getAttribute(CommonPortletServices.CPS_PORTAL_STATISTICS);
+        statistics = (PortalStatistics) context
+                .getAttribute(CommonPortletServices.CPS_PORTAL_STATISTICS);
         if (statistics == null)
-            throw new PortletException("Could not get instance of portal statistics component");
+                throw new PortletException(
+                        "Could not get instance of portal statistics component");
     }
 
-    public void doView(RenderRequest request, RenderResponse response) throws PortletException,
IOException
+    public void doView(RenderRequest request, RenderResponse response)
+            throws PortletException, IOException
     {
         Context velocityContext = getContext(request);
         PortletSession session = request.getPortletSession();
-        
-        
-        StatisticsQueryCriteria test = (StatisticsQueryCriteria) session.getAttribute(SESSION_CRITERIA);
-        if(test == null) {
-            test = new StatisticsQueryCriteriaImpl();
-            test.setQueryType("user");
-        }
-        session.setAttribute(SESSION_CRITERIA,test);
-        
-        StatisticsQueryCriteria sqc = (StatisticsQueryCriteria)session.getAttribute(SESSION_CRITERIA);
-        AggregateStatistics stats = (AggregateStatistics)session.getAttribute(SESSION_RESULTS);
-        if(stats == null) {
-            if(sqc != null) {
+
+        StatisticsQueryCriteria sqc = (StatisticsQueryCriteria) session
+                .getAttribute(SESSION_CRITERIA);
+        AggregateStatistics stats = (AggregateStatistics) session
+                .getAttribute(SESSION_RESULTS);
+        if (stats == null)
+        {
+            if (sqc == null)
+            {
+                // if we get here, we're on the first startup.
+                sqc = new StatisticsQueryCriteriaImpl();
+                sqc.setQueryType("portlets");
+                sqc.setTimePeriod("all");
+                session.setAttribute(SESSION_CRITERIA, sqc);
+
                 try
                 {
                     stats = statistics.queryStatistics(sqc);
                 } catch (InvalidCriteriaException e)
                 {
-                    //TODO:  need to handle situation where we pass in invalid criteria also
SQL problem will come in here
+                    logger.warn("unable to complete a statistics query ", e);
                 }
+                session.setAttribute(SESSION_RESULTS, stats);
+
             }
         }
+        velocityContext.put(SESSION_TOTALSESSIONS, ""
+                + statistics.getNumberOfCurrentUsers());
+        velocityContext.put(SESSION_RESULTS, stats);
         velocityContext.put(SESSION_CRITERIA, sqc);
-        velocityContext.put(SESSION_RESULTS,stats);
-        velocityContext.put("mytest","this is a test");
         super.doView(request, response);
     }
 
-    public void processAction(ActionRequest request, ActionResponse actionResponse) throws
PortletException, IOException
+    public void processAction(ActionRequest request,
+            ActionResponse actionResponse) throws PortletException, IOException
     {
         PortletSession session = request.getPortletSession();
-        // TODO: build query
         StatisticsQueryCriteria criteria = new StatisticsQueryCriteriaImpl();
         String user = request.getParameter("user");
         criteria.setUser(user);
         String timeperiod = request.getParameter("timeperiod");
+        if (timeperiod == null)
+        {
+            timeperiod = "all";
+        }
         criteria.setTimePeriod(timeperiod);
         String queryType = request.getParameter("queryType");
-        
+
         criteria.setQueryType(queryType);
-        // TODO: validate
-            // this copy will probalby get tosses.
         AggregateStatistics stats = new AggregateStatisticsImpl();
         try
         {
             stats = statistics.queryStatistics(criteria);
         } catch (InvalidCriteriaException e)
         {
-            //TODO:  need to handle situation where we pass in invalid criteria also SQL
problem will come in here
+            logger.warn("unable to complete a statistics query ", e);
         }
         // save this to session for later display/edit
-        session.setAttribute(SESSION_CRITERIA,criteria);
-        session.setAttribute(SESSION_RESULTS,stats);
-        
+        session.setAttribute(SESSION_CRITERIA, criteria);
+        session.setAttribute(SESSION_RESULTS, stats);
+
     }
-    
+
 }



---------------------------------------------------------------------
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