roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gma...@apache.org
Subject svn commit: r1585243 - in /roller/trunk/app/src: main/java/org/apache/roller/weblogger/business/ main/java/org/apache/roller/weblogger/business/jpa/ main/java/org/apache/roller/weblogger/pojos/ main/java/org/apache/roller/weblogger/ui/rendering/model/ ...
Date Sun, 06 Apr 2014 04:20:35 GMT
Author: gmazza
Date: Sun Apr  6 04:20:35 2014
New Revision: 1585243

URL: http://svn.apache.org/r1585243
Log:
Create new CommentSearchCriteria class to simplify comment queries and remove Sonar complaints
about trailing comments that would otherwise be needed for documentation.

Added:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/CommentSearchCriteria.java
      - copied, changed from r1585238, roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntrySearchCriteria.java
Modified:
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/model/URLModel.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/pagers/CommentsPager.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/GlobalCommentManagement.java
    roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java
    roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/CommentTest.java

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/WeblogEntryManager.java
Sun Apr  6 04:20:35 2014
@@ -22,6 +22,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import org.apache.roller.weblogger.WebloggerException;
+import org.apache.roller.weblogger.pojos.CommentSearchCriteria;
 import org.apache.roller.weblogger.pojos.StatCount;
 import org.apache.roller.weblogger.pojos.TagStat;
 import org.apache.roller.weblogger.pojos.Weblog;
@@ -198,28 +199,10 @@ public interface WeblogEntryManager {
        
     /**
      * Generic comments query method.
-     * @param website    Website or null for all comments on site
-     * @param entry      Entry or null to include all comments
-     * @param startDate  Start date or null for no restriction
-     * @param endDate    End date or null for no restriction
-     * @param status     The status of the comment, or null for any
-     * @param reverseChrono True for results in reverse chrono order
-     * @param offset     Offset into results for paging
-     * @param length     Max comments to return (or -1 for no limit)
+     * @param csc CommentSearchCriteria object with fields indicating search criteria
+     * @return list of comments fitting search criteria
      */
-    List<WeblogEntryComment> getComments(
-            
-            Weblog          website,
-            WeblogEntry     entry,
-            String          searchString,
-            Date            startDate,
-            Date            endDate,
-            String          status,
-            boolean         reverseChrono,
-            int             offset,
-            int             length
-            
-            ) throws WebloggerException;
+    List<WeblogEntryComment> getComments(CommentSearchCriteria csc) throws WebloggerException;
 
     /**
      * Deletes comments that match paramters.

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAUserManagerImpl.java
Sun Apr  6 04:20:35 2014
@@ -29,7 +29,6 @@ import org.apache.roller.weblogger.busin
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogEntryManagerImpl.java
Sun Apr  6 04:20:35 2014
@@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.roller.util.RollerConstants;
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.Weblogger;
+import org.apache.roller.weblogger.pojos.CommentSearchCriteria;
 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
 import org.apache.roller.weblogger.pojos.WeblogEntrySearchCriteria;
 import org.apache.roller.weblogger.pojos.WeblogHitCount;
@@ -238,19 +239,12 @@ public class JPAWeblogEntryManagerImpl i
         for (Object obj : referers) {
             this.strategy.remove(obj);
         }
-        
-        // remove comments
-        List<WeblogEntryComment> comments = getComments(
-                null,  // website
-                entry,
-                null,  // search String
-                null,  // startDate
-                null,  // endDate
-                null,  // status
-                true,  // reverse chrono order (not that it matters)
-                0,     // offset
-                -1);   // no limit
 
+        CommentSearchCriteria csc = new CommentSearchCriteria();
+        csc.setEntry(entry);
+
+        // remove comments
+        List<WeblogEntryComment> comments = getComments(csc);
         for (WeblogEntryComment comment : comments) {
             this.strategy.remove(comment);
         }
@@ -633,16 +627,7 @@ public class JPAWeblogEntryManagerImpl i
     /**
      * @inheritDoc
      */
-    public List<WeblogEntryComment> getComments(
-            Weblog     website,
-            WeblogEntry entry,
-            String          searchString,
-            Date            startDate,
-            Date            endDate,
-            String          status,
-            boolean         reverseChrono,
-            int             offset,
-            int             length) throws WebloggerException {
+    public List<WeblogEntryComment> getComments(CommentSearchCriteria csc) throws WebloggerException
{
         
         List<Object> params = new ArrayList<Object>();
         int size = 0;
@@ -650,43 +635,43 @@ public class JPAWeblogEntryManagerImpl i
         queryString.append("SELECT c FROM WeblogEntryComment c ");
         
         StringBuilder whereClause = new StringBuilder();
-        if (entry != null) {
-            params.add(size++, entry);
+        if (csc.getEntry() != null) {
+            params.add(size++, csc.getEntry());
             whereClause.append("c.weblogEntry = ?").append(size);
-        } else if (website != null) {
-            params.add(size++, website);
+        } else if (csc.getWeblog() != null) {
+            params.add(size++, csc.getWeblog());
             whereClause.append("c.weblogEntry.website = ?").append(size);
         }
         
-        if (searchString != null) {
-            params.add(size++, "%" + searchString + "%");
+        if (csc.getSearchText() != null) {
+            params.add(size++, "%" + csc.getSearchText() + "%");
             appendConjuctionToWhereclause(whereClause, "(c.url LIKE ?")
                 .append(size).append(" OR c.content LIKE ?").append(size).append(")");
         }
         
-        if (startDate != null) {
-            Timestamp start = new Timestamp(startDate.getTime());
+        if (csc.getStartDate() != null) {
+            Timestamp start = new Timestamp(csc.getStartDate().getTime());
             params.add(size++, start);
             appendConjuctionToWhereclause(whereClause, "c.postTime >= ?").append(size);
         }
         
-        if (endDate != null) {
-            Timestamp end = new Timestamp(endDate.getTime());
+        if (csc.getEndDate() != null) {
+            Timestamp end = new Timestamp(csc.getEndDate().getTime());
             params.add(size++, end);
             appendConjuctionToWhereclause(whereClause, "c.postTime <= ?").append(size);
         }
         
-        if (status != null) {
+        if (csc.getStatus() != null) {
             String comparisonOperator;
-            if("ALL_IGNORE_SPAM".equals(status)) {
+            if("ALL_IGNORE_SPAM".equals(csc.getStatus())) {
                 // we want all comments, except spam
                 // so that means where status != SPAM
-                status = WeblogEntryComment.SPAM;
+                csc.setStatus(WeblogEntryComment.SPAM);
                 comparisonOperator = " <> ";
             } else {
                 comparisonOperator = " = ";
             }
-            params.add(size++, status);
+            params.add(size++, csc.getStatus());
             appendConjuctionToWhereclause(whereClause, "c.status ")
                 .append(comparisonOperator).append('?').append(size);
         }
@@ -694,18 +679,18 @@ public class JPAWeblogEntryManagerImpl i
         if(whereClause.length() != 0) {
             queryString.append(" WHERE ").append(whereClause);
         }
-        if (reverseChrono) {
+        if (csc.isReverseChrono()) {
             queryString.append(" ORDER BY c.postTime DESC");
         } else {
             queryString.append(" ORDER BY c.postTime ASC");
         }
         
         Query query = strategy.getDynamicQuery(queryString.toString());
-        if (offset != 0) {
-            query.setFirstResult(offset);
+        if (csc.getOffset() != 0) {
+            query.setFirstResult(csc.getOffset());
         }
-        if (length != -1) {
-            query.setMaxResults(length);
+        if (csc.getMaxResults() != -1) {
+            query.setMaxResults(csc.getMaxResults());
         }
         for (int i=0; i<params.size(); i++) {
             query.setParameter(i+1, params.get(i));
@@ -719,7 +704,7 @@ public class JPAWeblogEntryManagerImpl i
      * @inheritDoc
      */
     public int removeMatchingComments(
-            Weblog     website,
+            Weblog     weblog,
             WeblogEntry entry,
             String  searchString,
             Date    startDate,
@@ -730,9 +715,15 @@ public class JPAWeblogEntryManagerImpl i
         // but MySQL says "General error, message from server: "You can't
         // specify target table 'roller_comment' for update in FROM clause"
         
-        List<WeblogEntryComment> comments = getComments(
-                website, entry, searchString, startDate, endDate,
-                status, true, 0, -1);
+        CommentSearchCriteria csc = new CommentSearchCriteria();
+        csc.setWeblog(weblog);
+        csc.setEntry(entry);
+        csc.setSearchText(searchString);
+        csc.setStartDate(startDate);
+        csc.setEndDate(endDate);
+        csc.setStatus(status);
+
+        List<WeblogEntryComment> comments = getComments(csc);
         int count = 0;
         for (WeblogEntryComment comment : comments) {
             removeComment(comment);

Copied: roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/CommentSearchCriteria.java
(from r1585238, roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntrySearchCriteria.java)
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/CommentSearchCriteria.java?p2=roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/CommentSearchCriteria.java&p1=roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntrySearchCriteria.java&r1=1585238&r2=1585243&rev=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntrySearchCriteria.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/CommentSearchCriteria.java
Sun Apr  6 04:20:35 2014
@@ -18,41 +18,28 @@
 package org.apache.roller.weblogger.pojos;
 
 import java.util.Date;
-import java.util.List;
 
-public class WeblogEntrySearchCriteria {
+public class CommentSearchCriteria {
 
-    public enum SortOrder {ASCENDING, DESCENDING}
-    public enum SortBy {PUBLICATION_TIME, UPDATE_TIME}
+    // TODO: Change status to an enum (either here or in WeblogEntryComment)
 
-    // TODO: See if can switch from name of Category to Category object
-    // TODO: Change status to an enum (either here or in WeblogEntry)
-
-    // Weblog or null to get for all weblogs.
+    // Weblog or null to get comments on all blogs
     private Weblog weblog;
-    // User or null to get for all users.
-    private User user;
-    // Start date or null for no start date.
+    // Entry or null to include all comments
+    private WeblogEntry entry;
+    // Text appearing in comment, or null for all
+    private String searchText;
+    // Start date or null for no restriction
     private Date startDate;
-    // End date or null for no end date.
+    // End date or null for no restriction
     private Date endDate;
-    // Category name or null for all categories.
-    private String catName;
-    // If provided, array of tags to search blog entries for, just one needs to match to
retrieve entry
-    private List<String> tags;
-    // WeblogEntry constants of DRAFT, PENDING, PUBLISHED, SCHEDULED
+    // Comment status as defined in WeblogEntryComment, or null for any
     private String status;
-    // Text appearing in the text or summary, or null for all
-    private String text;
-    // Date field to sort by
-    private SortBy sortBy = SortBy.PUBLICATION_TIME;
-    // Order of sort
-    private SortOrder sortOrder = SortOrder.DESCENDING;
-
-    private String locale;
+    // True for results in reverse chrono order
+    private boolean reverseChrono = false;
     // Offset into results for paging
     private int offset = 0;
-
+    // Max comments to return (or -1 for no limit)
     private int maxResults = -1;
 
     public Weblog getWeblog() {
@@ -63,12 +50,20 @@ public class WeblogEntrySearchCriteria {
         this.weblog = weblog;
     }
 
-    public User getUser() {
-        return user;
+    public WeblogEntry getEntry() {
+        return entry;
+    }
+
+    public void setEntry(WeblogEntry entry) {
+        this.entry = entry;
+    }
+
+    public String getSearchText() {
+        return searchText;
     }
 
-    public void setUser(User user) {
-        this.user = user;
+    public void setSearchText(String searchText) {
+        this.searchText = searchText;
     }
 
     public Date getStartDate() {
@@ -87,22 +82,6 @@ public class WeblogEntrySearchCriteria {
         this.endDate = endDate;
     }
 
-    public String getCatName() {
-        return catName;
-    }
-
-    public void setCatName(String catName) {
-        this.catName = catName;
-    }
-
-    public List<String> getTags() {
-        return tags;
-    }
-
-    public void setTags(List<String> tags) {
-        this.tags = tags;
-    }
-
     public String getStatus() {
         return status;
     }
@@ -111,36 +90,12 @@ public class WeblogEntrySearchCriteria {
         this.status = status;
     }
 
-    public String getText() {
-        return text;
-    }
-
-    public void setText(String text) {
-        this.text = text;
-    }
-
-    public SortBy getSortBy() {
-        return sortBy;
-    }
-
-    public void setSortBy(SortBy sortBy) {
-        this.sortBy = sortBy;
-    }
-
-    public SortOrder getSortOrder() {
-        return sortOrder;
-    }
-
-    public void setSortOrder(SortOrder sortOrder) {
-        this.sortOrder = sortOrder;
-    }
-
-    public String getLocale() {
-        return locale;
+    public boolean isReverseChrono() {
+        return reverseChrono;
     }
 
-    public void setLocale(String locale) {
-        this.locale = locale;
+    public void setReverseChrono(boolean reverseChrono) {
+        this.reverseChrono = reverseChrono;
     }
 
     public int getOffset() {

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java Sun Apr 
6 04:20:35 2014
@@ -830,16 +830,12 @@ public class Weblog implements Serializa
         }
         try {
             WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
-            recentComments = wmgr.getComments(
-                    
-                    this,
-                    null,          // weblog entry
-                    null,          // search String
-                    null,          // startDate
-                    null,WeblogEntryComment.APPROVED,
-                    true,          // we want reverse chrono order
-                    0,             // offset
-                    length);
+            CommentSearchCriteria csc = new CommentSearchCriteria();
+            csc.setWeblog(this);
+            csc.setStatus(WeblogEntryComment.APPROVED);
+            csc.setReverseChrono(true);
+            csc.setMaxResults(length);
+            recentComments = wmgr.getComments(csc);
         } catch (WebloggerException e) {
             log.error("ERROR: getting recent comments", e);
         }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java (original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/pojos/WeblogEntry.java Sun
Apr  6 04:20:35 2014
@@ -737,16 +737,12 @@ public class WeblogEntry implements Seri
         List<WeblogEntryComment> list = new ArrayList<WeblogEntryComment>();
         try {
             WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
-            return wmgr.getComments(
-                    getWebsite(),
-                    this,
-                    null,  // search String
-                    null,  // startDate
-                    null,
-                    approvedOnly ? WeblogEntryComment.APPROVED : null,
-                    false, // we want chrono order
-                    0,    // offset
-                    -1);   // no limit
+
+            CommentSearchCriteria csc = new CommentSearchCriteria();
+            csc.setWeblog(getWebsite());
+            csc.setEntry(this);
+            csc.setStatus(approvedOnly ? WeblogEntryComment.APPROVED : null);
+            return wmgr.getComments(csc);
         } catch (WebloggerException alreadyLogged) {}
         return list;
     }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/model/URLModel.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/model/URLModel.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/model/URLModel.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/model/URLModel.java
Sun Apr  6 04:20:35 2014
@@ -1,6 +1,6 @@
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
+ * contributor license agreements.  The ASF licenses this file to You
  * under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License.
  * You may obtain a copy of the License at

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/pagers/CommentsPager.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/pagers/CommentsPager.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/pagers/CommentsPager.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/rendering/pagers/CommentsPager.java
Sun Apr  6 04:20:35 2014
@@ -29,6 +29,7 @@ import org.apache.roller.weblogger.busin
 import org.apache.roller.weblogger.business.Weblogger;
 import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.business.WeblogEntryManager;
+import org.apache.roller.weblogger.pojos.CommentSearchCriteria;
 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
 import org.apache.roller.weblogger.pojos.Weblog;
 import org.apache.roller.weblogger.pojos.wrapper.WeblogEntryCommentWrapper;
@@ -92,12 +93,20 @@ public class CommentsPager extends Abstr
             try {
                 Weblogger roller = WebloggerFactory.getWeblogger();
                 WeblogEntryManager wmgr = roller.getWeblogEntryManager();
-                List<WeblogEntryComment> entries = wmgr.getComments(
-                        weblog, null, null, startDate, null, WeblogEntryComment.APPROVED,
true, offset, length + 1);
+
+                CommentSearchCriteria csc = new CommentSearchCriteria();
+                csc.setWeblog(weblog);
+                csc.setStartDate(startDate);
+                csc.setStatus(WeblogEntryComment.APPROVED);
+                csc.setReverseChrono(true);
+                csc.setOffset(offset);
+                csc.setMaxResults(length + 1);
+
+                List<WeblogEntryComment> comments = wmgr.getComments(csc);
                 
                 // wrap the results
                 int count = 0;
-                for (WeblogEntryComment comment : entries) {
+                for (WeblogEntryComment comment : comments) {
                     if (count++ < length) {
                         results.add(WeblogEntryCommentWrapper.wrap(comment, urlStrategy));
                     } else {

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/GlobalCommentManagement.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/GlobalCommentManagement.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/GlobalCommentManagement.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/GlobalCommentManagement.java
Sun Apr  6 04:20:35 2014
@@ -31,6 +31,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.business.WeblogEntryManager;
+import org.apache.roller.weblogger.pojos.CommentSearchCriteria;
 import org.apache.roller.weblogger.pojos.GlobalPermission;
 import org.apache.roller.weblogger.pojos.Weblog;
 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
@@ -97,16 +98,17 @@ public class GlobalCommentManagement ext
         boolean hasMore = false;
         try {
             WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
-            List<WeblogEntryComment> rawComments = wmgr.getComments(
-                    null,
-                    null,
-                    getBean().getSearchString(),
-                    getBean().getStartDate(),
-                    getBean().getEndDate(),
-                    getBean().getStatus(),
-                    true,
-                    getBean().getPage() * COUNT,
-                    COUNT + 1);
+
+            CommentSearchCriteria csc = new CommentSearchCriteria();
+            csc.setSearchText(getBean().getSearchString());
+            csc.setStartDate(getBean().getStartDate());
+            csc.setEndDate(getBean().getEndDate());
+            csc.setStatus(getBean().getStatus());
+            csc.setReverseChrono(true);
+            csc.setOffset(getBean().getPage() * COUNT);
+            csc.setMaxResults(COUNT+1);
+
+            List<WeblogEntryComment> rawComments = wmgr.getComments(csc);
             comments = new ArrayList<WeblogEntryComment>();
             comments.addAll(rawComments);   
             
@@ -182,17 +184,16 @@ public class GlobalCommentManagement ext
         
         try {
             WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
-            List allMatchingComments = wmgr.getComments(
-                    null,
-                    null,
-                    getBean().getSearchString(),
-                    getBean().getStartDate(),
-                    getBean().getEndDate(),
-                    getBean().getStatus(),
-                    true,
-                    0,
-                    -1);
-            
+
+            CommentSearchCriteria csc = new CommentSearchCriteria();
+            csc.setSearchText(getBean().getSearchString());
+            csc.setStartDate(getBean().getStartDate());
+            csc.setEndDate(getBean().getEndDate());
+            csc.setStatus(getBean().getStatus());
+            csc.setReverseChrono(true);
+
+            List allMatchingComments = wmgr.getComments(csc);
+
             if(allMatchingComments.size() > COUNT) {
                 setBulkDeleteCount(allMatchingComments.size());
             }

Modified: roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java
(original)
+++ roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Comments.java
Sun Apr  6 04:20:35 2014
@@ -35,6 +35,7 @@ import org.apache.roller.weblogger.busin
 import org.apache.roller.weblogger.business.WeblogEntryManager;
 import org.apache.roller.weblogger.business.search.IndexManager;
 import org.apache.roller.weblogger.config.WebloggerConfig;
+import org.apache.roller.weblogger.pojos.CommentSearchCriteria;
 import org.apache.roller.weblogger.pojos.WeblogEntry;
 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
 import org.apache.roller.weblogger.pojos.WeblogPermission;
@@ -101,22 +102,28 @@ public class Comments extends UIAction {
                 setQueryEntry(wmgr.getWeblogEntry(getBean().getEntryId()));
             }
 
-            // query for comments (reverse chrono order)
-            List<WeblogEntryComment> rawComments = wmgr.getComments(
-                    getActionWeblog(), getQueryEntry(), getBean()
-                            .getSearchString(), getBean().getStartDate(),
-                    getBean().getEndDate(), getBean().getStatus(), true,
-                    getBean().getPage() * COUNT, COUNT + 1);
+            CommentSearchCriteria csc = new CommentSearchCriteria();
+            csc.setWeblog(getActionWeblog());
+            csc.setEntry(getQueryEntry());
+            csc.setSearchText(getBean().getSearchString());
+            csc.setStartDate(getBean().getStartDate());
+            csc.setEndDate(getBean().getEndDate());
+            csc.setStatus(getBean().getStatus());
+            csc.setReverseChrono(true);
+            csc.setOffset(getBean().getPage() * COUNT);
+            csc.setMaxResults(COUNT + 1);
+
+            List<WeblogEntryComment> rawComments = wmgr.getComments(csc);
             comments = new ArrayList<WeblogEntryComment>();
             comments.addAll(rawComments);
-            if (comments != null && comments.size() > 0) {
+            if (comments.size() > 0) {
                 if (comments.size() > COUNT) {
                     comments.remove(comments.size() - 1);
                     hasMore = true;
                 }
 
-                setFirstComment((WeblogEntryComment) comments.get(0));
-                setLastComment((WeblogEntryComment) comments.get(comments
+                setFirstComment(comments.get(0));
+                setLastComment(comments.get(comments
                         .size() - 1));
             }
         } catch (WebloggerException ex) {
@@ -189,12 +196,15 @@ public class Comments extends UIAction {
             WeblogEntryManager wmgr = WebloggerFactory.getWeblogger()
                     .getWeblogEntryManager();
 
-            // reverse chrono order
-            List<WeblogEntryComment> allMatchingComments = wmgr.getComments(
-                    getActionWeblog(), null, getBean().getSearchString(),
-                    getBean().getStartDate(), getBean().getEndDate(), getBean()
-                            .getStatus(), true, 0, -1);
+            CommentSearchCriteria csc = new CommentSearchCriteria();
+            csc.setWeblog(getActionWeblog());
+            csc.setSearchText(getBean().getSearchString());
+            csc.setStartDate(getBean().getStartDate());
+            csc.setEndDate(getBean().getEndDate());
+            csc.setStatus(getBean().getStatus());
+            csc.setReverseChrono(true);
 
+            List<WeblogEntryComment> allMatchingComments = wmgr.getComments(csc);
             if (allMatchingComments.size() > COUNT) {
                 setBulkDeleteCount(allMatchingComments.size());
             }
@@ -221,12 +231,17 @@ public class Comments extends UIAction {
             // comments that have been deleted, so build a list of those entries
             Set<WeblogEntry> reindexEntries = new HashSet<WeblogEntry>();
             if (WebloggerConfig.getBooleanProperty("search.enabled")) {
-                List<WeblogEntryComment> targetted = (List<WeblogEntryComment>)
wmgr
-                        .getComments(getActionWeblog(), getQueryEntry(),
-                                getBean().getSearchString(), getBean()
-                                        .getStartDate(),
-                                getBean().getEndDate(), getBean().getStatus(),
-                                true, 0, -1);
+
+                CommentSearchCriteria csc = new CommentSearchCriteria();
+                csc.setWeblog(getActionWeblog());
+                csc.setEntry(getQueryEntry());
+                csc.setSearchText(getBean().getSearchString());
+                csc.setStartDate(getBean().getStartDate());
+                csc.setEndDate(getBean().getEndDate());
+                csc.setStatus(getBean().getStatus());
+                csc.setReverseChrono(true);
+
+                List<WeblogEntryComment> targetted = wmgr.getComments(csc);
                 for (WeblogEntryComment comment : targetted) {
                     reindexEntries.add(comment.getWeblogEntry());
                 }
@@ -280,7 +295,7 @@ public class Comments extends UIAction {
 
             // delete all comments with delete box checked
             List<String> deletes = Arrays.asList(getBean().getDeleteComments());
-            if (deletes != null && deletes.size() > 0) {
+            if (deletes.size() > 0) {
                 log.debug("Processing deletes - " + deletes.size());
 
                 WeblogEntryComment deleteComment = null;

Modified: roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/CommentTest.java
URL: http://svn.apache.org/viewvc/roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/CommentTest.java?rev=1585243&r1=1585242&r2=1585243&view=diff
==============================================================================
--- roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/CommentTest.java (original)
+++ roller/trunk/app/src/test/java/org/apache/roller/weblogger/business/CommentTest.java Sun
Apr  6 04:20:35 2014
@@ -28,6 +28,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.TestUtils;
+import org.apache.roller.weblogger.pojos.CommentSearchCriteria;
 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
 import org.apache.roller.weblogger.pojos.User;
 import org.apache.roller.weblogger.pojos.WeblogEntry;
@@ -114,7 +115,6 @@ public class CommentTest extends TestCas
         TestUtils.endSession(true);
         
         // make sure comment was created
-        comment = null;
         comment = mgr.getComment(id);
         assertNotNull(comment);
         assertEquals("this is a test comment", comment.getContent());
@@ -125,7 +125,6 @@ public class CommentTest extends TestCas
         TestUtils.endSession(true);
         
         // make sure comment was updated
-        comment = null;
         comment = mgr.getComment(id);
         assertNotNull(comment);
         assertEquals("testtest", comment.getContent());
@@ -135,7 +134,6 @@ public class CommentTest extends TestCas
         TestUtils.endSession(true);
         
         // make sure comment was deleted
-        comment = null;
         comment = mgr.getComment(id);
         assertNull(comment);
     }
@@ -147,7 +145,7 @@ public class CommentTest extends TestCas
     public void testCommentLookups() throws Exception {
         
         WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
-        List comments = null;
+        List comments;
         
         // we need some comments to play with
         testEntry = TestUtils.getManagedWeblogEntry(testEntry);
@@ -157,15 +155,15 @@ public class CommentTest extends TestCas
         TestUtils.endSession(true);
         
         // get all comments
-        comments = null;
-        comments = mgr.getComments(null, null, null, null, null, null, false, 0, -1);
+        CommentSearchCriteria csc = new CommentSearchCriteria();
+        comments = mgr.getComments(csc);
         assertNotNull(comments);
         assertEquals(3, comments.size());
         
         // get all comments for entry
         testEntry = TestUtils.getManagedWeblogEntry(testEntry);
-        comments = null;
-        comments = mgr.getComments(null, testEntry, null, null, null, null, false, 0, -1);
+        csc.setEntry(testEntry);
+        comments = mgr.getComments(csc);
         assertNotNull(comments);
         assertEquals(3, comments.size());
         
@@ -176,20 +174,22 @@ public class CommentTest extends TestCas
         TestUtils.endSession(true);
         
         // get pending comments
-        comments = null;
-        comments = mgr.getComments(null, null, null, null, null, WeblogEntryComment.PENDING,
false, 0, -1);
+        csc.setEntry(null);
+        csc.setStatus(WeblogEntryComment.PENDING);
+        comments = mgr.getComments(csc);
         assertNotNull(comments);
         assertEquals(1, comments.size());
         
         // get approved comments
-        comments = null;
-        comments = mgr.getComments(null, null, null, null, null, WeblogEntryComment.APPROVED,
false, 0, -1);
+        csc.setStatus(WeblogEntryComment.APPROVED);
+        comments = mgr.getComments(csc);
         assertNotNull(comments);
         assertEquals(2, comments.size());
         
         // get comments with offset
-        comments = null;
-        comments = mgr.getComments(null, null, null, null, null, null, false, 1, -1);
+        csc.setStatus(null);
+        csc.setOffset(1);
+        comments = mgr.getComments(csc);
         assertNotNull(comments);
         assertEquals(2, comments.size());
         



Mime
View raw message