You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/11/27 16:10:09 UTC

svn commit: r479649 - in /incubator/roller/trunk: src/org/apache/roller/business/hibernate/ src/org/apache/roller/pojos/ src/org/apache/roller/ui/rendering/model/ tests/org/apache/roller/business/

Author: snoopdave
Date: Mon Nov 27 07:10:08 2006
New Revision: 479649

URL: http://svn.apache.org/viewvc?view=rev&rev=479649
Log:
Adding weblogHandle to StatCount object

Modified:
    incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
    incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
    incubator/roller/trunk/src/org/apache/roller/pojos/StatCount.java
    incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java
    incubator/roller/trunk/tests/org/apache/roller/business/WeblogStatsTest.java

Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java?view=diff&rev=479649&r1=479648&r2=479649
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateUserManagerImpl.java Mon Nov 27 07:10:08 2006
@@ -915,7 +915,7 @@
             if (startDate != null) {
                 sb.append("and c.weblogEntry.pubTime > :startDate ");
             }  
-            sb.append("group by c.weblogEntry.website.id, c.weblogEntry.website.name, c.weblogEntry.website.description order by col_0_0_ desc");
+            sb.append("group by c.weblogEntry.website.id, c.weblogEntry.website.handle, c.weblogEntry.website.name order by col_0_0_ desc");
             Query query = session.createQuery(sb.toString());
             query.setParameter("endDate", endDate);
             if (startDate != null) {
@@ -930,12 +930,14 @@
             List results = new ArrayList();
             for (Iterator iter = query.list().iterator(); iter.hasNext();) {
                 Object[] row = (Object[]) iter.next();
-                results.add(new StatCount(
-                    (String)row[1], 
-                    (String)row[2], 
-                    (String)row[3], 
-                    "statCount.weblogCommentCountType", 
-                    new Long(((Integer)row[0]).intValue()).longValue()));
+                StatCount statCount = new StatCount(
+                    (String)row[1],                     // website id
+                    (String)row[2],                     // website handle
+                    (String)row[3],                     // website name
+                    "statCount.weblogCommentCountType", // stat type 
+                    new Long(((Integer)row[0]).intValue()).longValue()); // # comments
+                statCount.setWeblogHandle((String)row[2]);
+                results.add(statCount);
             }
             return results;
         } catch (Throwable pe) {

Modified: incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java?view=diff&rev=479649&r1=479648&r2=479649
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java Mon Nov 27 07:10:08 2006
@@ -27,7 +27,6 @@
 import java.util.Date;
 import java.util.Hashtable;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
@@ -52,7 +51,6 @@
 import org.apache.roller.pojos.WeblogEntryTagAggregateData;
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.util.DateUtil;
-import org.apache.roller.util.Utilities;
 import org.hibernate.Criteria;
 import org.hibernate.HibernateException;
 import org.hibernate.Query;
@@ -62,6 +60,11 @@
 import org.hibernate.criterion.MatchMode;
 import org.hibernate.criterion.Order;
 import org.hibernate.criterion.Restrictions;
+import org.hibernate.dialect.DerbyDialect;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.OracleDialect;
+import org.hibernate.dialect.SQLServerDialect;
+import org.hibernate.engine.SessionFactoryImplementor;
 
 
 /**
@@ -920,8 +923,7 @@
             }
             
             // now just do simple lookup by path
-            Session session = ((HibernatePersistenceStrategy)this.strategy).getSession();
-            
+            Session session = ((HibernatePersistenceStrategy)this.strategy).getSession();            
             Criteria criteria = session.createCriteria(WeblogCategoryData.class);
             criteria.add(Expression.eq("path", catPath));
             criteria.add(Expression.eq("website", website));
@@ -1041,11 +1043,11 @@
         return map;
     }
     
-    public List getMostCommentedWeblogEntries(
+    public List getMostCommentedWeblogEntries( 
             WebsiteData website, Date startDate, Date endDate, int offset, int length) 
             throws RollerException {
         // TODO: ATLAS getMostCommentedWeblogEntries DONE
-        String msg = "Getting most commented weblog entres";
+        String msg = "Getting most commented weblog entries";
         if (endDate == null) endDate = new Date();
         try {      
             Session session = 
@@ -1053,12 +1055,13 @@
             Query query = null;
             if (website != null) {
                 StringBuffer sb = new StringBuffer();
-                sb.append("select count(distinct c), c.weblogEntry.id, c.weblogEntry.anchor, c.weblogEntry.title from CommentData c ");
+                sb.append("select count(distinct c), c.weblogEntry.website.handle, c.weblogEntry.anchor, c.weblogEntry.title ");
+                sb.append("from CommentData c ");
                 sb.append("where c.weblogEntry.website=:website and c.weblogEntry.pubTime < :endDate ");
                 if (startDate != null) {
                     sb.append("and c.weblogEntry.pubTime > :startDate ");
                 }                   
-                sb.append("group by c.weblogEntry.id, c.weblogEntry.anchor, c.weblogEntry.title ");
+                sb.append("group by c.weblogEntry.website.handle, c.weblogEntry.anchor, c.weblogEntry.title ");
                 sb.append("order by col_0_0_ desc");
                 query = session.createQuery(sb.toString());
                 query.setParameter("website", website);
@@ -1068,17 +1071,19 @@
                 }   
             } else {
                 StringBuffer sb = new StringBuffer();
-                sb.append("select count(distinct c), c.weblogEntry.id, c.weblogEntry.anchor, c.weblogEntry.title ");
-                sb.append("from CommentData c group by c.weblogEntry.id, c.weblogEntry.anchor, c.weblogEntry.title ");
+                sb.append("select count(distinct c),   c.weblogEntry.website.handle, c.weblogEntry.anchor, c.weblogEntry.title ");
+                sb.append("from CommentData c ");
                 sb.append("where c.weblogEntry.pubTime < :endDate ");
                 if (startDate != null) {
                     sb.append("and c.weblogEntry.pubTime > :startDate ");
                 } 
-                sb.append("order by col_0_0_ desc");
+                sb.append("group by c.weblogEntry.website.handle, c.weblogEntry.anchor, c.weblogEntry.title ");
+                sb.append("order by col_0_0_ desc ");
                 query = session.createQuery(sb.toString());
+                query.setParameter("endDate", endDate);
                 if (startDate != null) {
                     query.setParameter("startDate", startDate);
-                }   
+                } 
             }
             if (offset != 0) {
                 query.setFirstResult(offset);
@@ -1089,12 +1094,14 @@
             List results = new ArrayList();
             for (Iterator iter = query.list().iterator(); iter.hasNext();) {
                 Object[] row = (Object[]) iter.next();
-                results.add(new StatCount(
-                    (String)row[1], 
-                    (String)row[2], 
-                    (String)row[3], 
-                    "statCount.weblogEntryCommentCountType", 
-                    new Long(((Integer)row[0]).intValue()).longValue()));
+                StatCount statCount = new StatCount(
+                    (String)row[1],                             // entry id
+                    (String)row[2],                             // entry anchor
+                    (String)row[3],                             // entry title
+                    "statCount.weblogEntryCommentCountType",    // stat desc
+                    new Long(((Integer)row[0]).intValue()).longValue()); // count
+                
+                results.add(statCount);
             }
             return results;
         } catch (Throwable pe) {

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/StatCount.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/StatCount.java?view=diff&rev=479649&r1=479648&r2=479649
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/StatCount.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/StatCount.java Mon Nov 27 07:10:08 2006
@@ -20,53 +20,79 @@
 /**
  * Represents a statistical count.
  */
-public class StatCount {    
+public class StatCount { 
+    
     /** Id of the subject of the statistic */
     private String subjectId;
+    
     /** Short name of the subject of the statistic */
     private String subjectNameShort;
+    
     /** Long name of the subject of the statistic */
     private String subjectNameLong; 
+    
     /** I18N key that describes the type of statistic */
-    private String typeKey;      
+    private String typeKey;
+    
     /** The statistical count */    
     private long count;
     
+    /** Weblog handle of weblog that stat is associated with, or null if none */
+    private String weblogHandle = null;
+
     public StatCount(String subjectId, String subjectNameShort, String subjectNameLong, String typeKey, long count) {
         this.setSubjectId(subjectId);
         this.setSubjectNameShort(subjectNameShort);
         this.setSubjectNameLong(subjectNameLong);
         this.setTypeKey(typeKey);
         this.setCount(count);
-    }    
+    } 
+    
     public String getTypeKey() {
         return typeKey;
     }
+    
     public void setTypeKey(String typeKey) {
         this.typeKey = typeKey;
     }
+    
     public long getCount() {
         return count;
     }
+    
     public void setCount(long count) {
         this.count = count;
     }
+    
     public String getSubjectId() {
         return subjectId;
     }
+    
     public void setSubjectId(String subjectId) {
         this.subjectId = subjectId;
     }
+    
     public String getSubjectNameShort() {
         return subjectNameShort;
     }
+    
     public void setSubjectNameShort(String subjectNameShort) {
         this.subjectNameShort = subjectNameShort;
     }
+    
     public String getSubjectNameLong() {
         return subjectNameLong;
     }
+    
     public void setSubjectNameLong(String subjectNameLong) {
         this.subjectNameLong = subjectNameLong;
+    }
+
+    public String getWeblogHandle() {
+        return weblogHandle;
+    }
+
+    public void setWeblogHandle(String weblogHandle) {
+        this.weblogHandle = weblogHandle;
     }
 }

Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java?view=diff&rev=479649&r1=479648&r2=479649
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java Mon Nov 27 07:10:08 2006
@@ -404,13 +404,14 @@
             Iterator hitCounts = hotBlogs.iterator();
             while (hitCounts.hasNext()) {
                 HitCountData hitCount = (HitCountData) hitCounts.next();
-                
-                results.add(new StatCount(
+                StatCount statCount = new StatCount(
                     hitCount.getWeblog().getId(),
                     hitCount.getWeblog().getHandle(),
                     hitCount.getWeblog().getName(),
                     "statCount.weblogDayHits",
-                    hitCount.getDailyHits()));              
+                    hitCount.getDailyHits());
+                statCount.setWeblogHandle(hitCount.getWeblog().getHandle());
+                results.add(statCount);              
             }
             
         } catch (Exception e) {

Modified: incubator/roller/trunk/tests/org/apache/roller/business/WeblogStatsTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/business/WeblogStatsTest.java?view=diff&rev=479649&r1=479648&r2=479649
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/WeblogStatsTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/WeblogStatsTest.java Mon Nov 27 07:10:08 2006
@@ -63,12 +63,15 @@
         StatCount s1 = (StatCount)list.get(0);
         assertEquals(website1.getId(), s1.getSubjectId());
         assertEquals(3L, s1.getCount());   
+        assertEquals(website1.getHandle(), s1.getSubjectNameShort());
+        assertEquals(website1.getHandle(), s1.getWeblogHandle());
         
         StatCount s2 = (StatCount)list.get(1);
         assertEquals(website2.getId(), s2.getSubjectId());
         assertEquals(1L, s2.getCount());   
     }
-    public void testGetMostCommentedWeblogEntries() throws Exception {        
+    public void testGetMostCommentedWeblogEntries() throws Exception {
+        
         WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();      
         List list = mgr.getMostCommentedWeblogEntries(null, null, null, 0, -1);
         
@@ -78,7 +81,9 @@
         StatCount s1 = (StatCount)list.get(0);
         assertEquals(2L, s1.getCount()); 
         assertEquals(entry11.getId(), s1.getSubjectId());
-        
+        assertEquals(entry11.getAnchor(), s1.getSubjectNameShort());
+        assertEquals(entry11.getWebsite().getHandle(), s1.getWeblogHandle());
+               
         StatCount s2 = (StatCount)list.get(1);
         assertEquals(1L, s2.getCount());   
     }