File Source: Comments.java

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   *  contributor license agreements.  The ASF licenses this file to You
     4   * under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.  For additional information regarding
    15   * copyright in this work, please see the NOTICE file in the top level
    16   * directory of this distribution.
    17   */
    18  
    19  package org.apache.roller.weblogger.ui.struts2.editor;
    20  
    21  import java.util.ArrayList;
    22  import java.util.Arrays;
    23  import java.util.Collections;
    24  import java.util.HashMap;
    25  import java.util.HashSet;
    26  import java.util.List;
    27  import java.util.Map;
    28  import java.util.Set;
    29  import org.apache.commons.lang.StringUtils;
    30  import org.apache.commons.logging.Log;
    31  import org.apache.commons.logging.LogFactory;
    32  import org.apache.roller.weblogger.WebloggerException;
    33  import org.apache.roller.weblogger.business.WebloggerFactory;
    34  import org.apache.roller.weblogger.business.WeblogManager;
    35  import org.apache.roller.weblogger.business.search.IndexManager;
    36  import org.apache.roller.weblogger.config.WebloggerConfig;
    37  import org.apache.roller.weblogger.pojos.WeblogEntry;
    38  import org.apache.roller.weblogger.pojos.WeblogEntryComment;
    39  import org.apache.roller.weblogger.pojos.WeblogPermission;
    40  import org.apache.roller.weblogger.ui.struts2.pagers.CommentsPager;
    41  import org.apache.roller.weblogger.ui.struts2.util.KeyValueObject;
    42  import org.apache.roller.weblogger.util.cache.CacheManager;
    43  import org.apache.roller.weblogger.ui.struts2.util.UIAction;
    44  import org.apache.roller.weblogger.util.I18nMessages;
    45  import org.apache.roller.weblogger.util.MailUtil;
    46  import org.apache.roller.weblogger.util.Utilities;
    47  
    48  
    49  /**
    50   * Action for managing weblog comments.
    51   */
    52  public class Comments extends UIAction {
    53      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.struts2.editor.Comments__static_init
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    54      private static Log log = LogFactory.getLog(Comments.class);
    55      
    56      // number of comments to show per page
    57      private static final int COUNT = 30;
    58      
    59      // bean for managing submitted data
    60      private CommentsBean bean = new CommentsBean();
    61      
    62      // pager for the comments we are viewing
    63      private CommentsPager pager = null;
    64      
    65      // first comment in the list
    66      private WeblogEntryComment firstComment = null;
    67      
    68      // last comment in the list
    69      private WeblogEntryComment lastComment = null;
    70      
    71      // entry associated with comments or null if none
    72      private WeblogEntry queryEntry = null;
    73      
    74      // indicates number of comments that would be deleted by bulk removal
    75      // a non-zero value here indicates bulk removal is a valid option
    76      private int bulkDeleteCount = 0;
    77      
    78      
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.ui.struts2.editor.Comments()
              * 
              *  Postconditions:
              *    this.actionName == &"comments"
              *    this.bean == &new CommentsBean(Comments#1)
              *    this.bulkDeleteCount == 0
              *    this.bean.page == 0
              *    new String[](CommentsBean#1).length == 0
              *    new String[](CommentsBean#2).length == 0
              *    new String[](CommentsBean#3).length == 0
              *    this.desiredMenu == &"editor"
              *    this.firstComment == null
              *    this.lastComment == null
              *    ...
              */
    79      public Comments() {
    80          this.actionName = "comments";
    81          this.desiredMenu = "editor";
    82          this.pageTitle = "commentManagement.title";
    83      }
    84      
    85      
    86      @Override
    87      public short requiredWeblogPermissions() {
                 /* 
    P/P           *  Method: short requiredWeblogPermissions()
                  * 
                  *  Presumptions:
                  *    init'ed(org.apache.roller.weblogger.pojos.WeblogPermission.AUTHOR)
                  * 
                  *  Postconditions:
                  *    return_value == org.apache.roller.weblogger.pojos.WeblogPermission.AUTHOR
                  *    (soft) init'ed(return_value)
                  */
    88          return WeblogPermission.AUTHOR;
    89      }
    90      
    91      
    92      public void loadComments() {
    93          
                 /* 
    P/P           *  Method: void loadComments()
                  * 
                  *  Preconditions:
                  *    this.bean != null
                  *    init'ed(this.bean.endDateString)
                  *    init'ed(this.bean.entryId)
                  *    init'ed(this.bean.searchString)
                  *    init'ed(this.bean.startDateString)
                  *    (soft) log != null
                  *    (soft) init'ed(this.queryEntry)
                  *    (soft) this.bean.approvedString != null
                  *    (soft) this.bean.page in -71_582_788..143_165_576
                  *    (soft) this.bean.spamString != null
                  * 
                  *  Presumptions:
                  *    init'ed(java.util.Collections.EMPTY_LIST)
                  *    java.util.List:size(...)@118 >= -231+1
                  *    java.util.List:size(...)@123 >= -231+1
                  *    org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@97 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@97 != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.firstComment)
                  *    possibly_updated(this.lastComment)
                  *    this.pager == &new CommentsPager(loadComments#2)
                  *    init'ed(this.queryEntry)
                  *    new CommentsPager(loadComments#2) num objects == 1
                  * 
                  *  Test Vectors:
                  *    java.util.List:size(...)@116: {-231..0}, {1..232-1}
                  *    java.util.List:size(...)@117: {-231..30}, {31..232-1}
                  *    org.apache.commons.lang.StringUtils:isEmpty(...)@100: {1}, {0}
                  */
    94          List comments = Collections.EMPTY_LIST;
    95          boolean hasMore = false;
    96          try {
    97              WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
    98              
    99              // lookup weblog entry if necessary
   100              if(!StringUtils.isEmpty(getBean().getEntryId())) {
   101                  setQueryEntry(wmgr.getWeblogEntry(getBean().getEntryId()));
   102              }
   103              
   104              // query for comments
   105              List rawComments = wmgr.getComments(
   106                      getActionWeblog(),
   107                      getQueryEntry(),
   108                      getBean().getSearchString(),
   109                      getBean().getStartDate(),
   110                      getBean().getEndDate(),getBean().getStatus(),
   111                      true, // reverse  chrono order
   112                      getBean().getPage() * COUNT,
   113                      COUNT + 1);
   114              comments = new ArrayList();
   115              comments.addAll(rawComments);            
+  116              if(comments != null && comments.size() > 0) {
   117                  if(comments.size() > COUNT) {
   118                      comments.remove(comments.size()-1);
   119                      hasMore = true;
   120                  }
   121                  
   122                  setFirstComment((WeblogEntryComment)comments.get(0));
   123                  setLastComment((WeblogEntryComment)comments.get(comments.size()-1));
   124              }
   125          } catch (WebloggerException ex) {
   126              log.error("Error looking up comments", ex);
   127              // TODO: i18n
   128              addError("Error looking up comments");
   129          }
   130          
   131          // build comments pager
   132          String baseUrl = buildBaseUrl();
   133          setPager(new CommentsPager(baseUrl, getBean().getPage(), comments, hasMore));
   134      }
   135      
   136      
   137      // use the action data to build a url representing this action, including query data
   138      private String buildBaseUrl() {
   139          
                 /* 
    P/P           *  Method: String buildBaseUrl()
                  * 
                  *  Preconditions:
                  *    this.bean != null
                  *    init'ed(this.bean.approvedString)
                  *    init'ed(this.bean.endDateString)
                  *    init'ed(this.bean.entryId)
                  *    init'ed(this.bean.searchString)
                  *    init'ed(this.bean.spamString)
                  *    init'ed(this.bean.startDateString)
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.Weblogger:getUrlStrategy(...)@161 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@161 != null
                  *    org.apache.roller.weblogger.ui.struts2.editor.Comments:getActionWeblog(...)@161 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    org.apache.commons.lang.StringUtils:isEmpty(...)@142: {1}, {0}
                  *    org.apache.commons.lang.StringUtils:isEmpty(...)@145: {1}, {0}
                  *    org.apache.commons.lang.StringUtils:isEmpty(...)@148: {1}, {0}
                  *    org.apache.commons.lang.StringUtils:isEmpty(...)@151: {1}, {0}
                  *    org.apache.commons.lang.StringUtils:isEmpty(...)@154: {1}, {0}
                  *    org.apache.commons.lang.StringUtils:isEmpty(...)@157: {1}, {0}
                  */
   140          Map<String, String> params = new HashMap();
   141          
   142          if(!StringUtils.isEmpty(getBean().getEntryId())) {
   143              params.put("bean.entryId", getBean().getEntryId());
   144          }
   145          if(!StringUtils.isEmpty(getBean().getSearchString())) {
   146              params.put("bean.searchString", getBean().getSearchString());
   147          }
   148          if(!StringUtils.isEmpty(getBean().getStartDateString())) {
   149              params.put("bean.startDateString", getBean().getStartDateString());
   150          }
   151          if(!StringUtils.isEmpty(getBean().getEndDateString())) {
   152              params.put("bean.endDateString", getBean().getEndDateString());
   153          }
   154          if(!StringUtils.isEmpty(getBean().getApprovedString())) {
   155              params.put("bean.approvedString", getBean().getApprovedString());
   156          }
   157          if(!StringUtils.isEmpty(getBean().getSpamString())) {
   158              params.put("bean.spamString", getBean().getSpamString());
   159          }
   160          
   161          return WebloggerFactory.getWeblogger().getUrlStrategy().getActionURL("comments", "/roller-ui/authoring", 
   162                  getActionWeblog().getHandle(), params, false);
   163      }
   164      
   165      
   166      public String execute() {
   167          
   168          // load list of comments from query
                 /* 
    P/P           *  Method: String execute()
                  * 
                  *  Preconditions:
                  *    this.bean != null
                  *    init'ed(this.bean.endDateString)
                  *    init'ed(this.bean.entryId)
                  *    init'ed(this.bean.searchString)
                  *    init'ed(this.bean.startDateString)
                  *    (soft) log != null
                  *    (soft) init'ed(this.queryEntry)
                  *    (soft) this.bean.approvedString != null
                  *    (soft) this.bean.page in -71_582_788..143_165_576
                  *    (soft) this.bean.spamString != null
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.ui.struts2.pagers.CommentsPager:getItems(...)@172 != null
                  * 
                  *  Postconditions:
                  *    return_value == &"list"
                  *    init'ed(this.bean.approvedComments)
                  *    init'ed(this.bean.ids)
                  *    init'ed(this.bean.spamComments)
                  *    possibly_updated(this.firstComment)
                  *    possibly_updated(this.lastComment)
                  *    this.pager == &new CommentsPager(loadComments#2)
                  *    init'ed(this.queryEntry)
                  *    new CommentsPager(loadComments#2) num objects == 1
                  */
   169          loadComments();
   170          
   171          // load bean data using comments list
   172          getBean().loadCheckboxes(getPager().getItems());
   173          
   174          return LIST;
   175      }
   176      
   177      
   178      /**
   179       * Query for a specific subset of comments based on various criteria.
   180       */
   181      public String query() {
   182          
   183          // load list of comments from query
                 /* 
    P/P           *  Method: String query()
                  * 
                  *  Preconditions:
                  *    this.bean != null
                  *    init'ed(this.bean.entryId)
                  *    (soft) log != null
                  *    (soft) init'ed(this.queryEntry)
                  *    (soft) this.bean.approvedString != null
                  *    (soft) init'ed(this.bean.endDateString)
                  *    (soft) this.bean.page in -71_582_788..143_165_576
                  *    (soft) init'ed(this.bean.searchString)
                  *    (soft) this.bean.spamString != null
                  *    (soft) init'ed(this.bean.startDateString)
                  * 
                  *  Presumptions:
                  *    org.apache.roller.weblogger.business.WeblogManager:getComments(...)@191 != null
                  *    org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@190 != null
                  *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@190 != null
                  *    org.apache.roller.weblogger.ui.struts2.pagers.CommentsPager:getItems(...)@187 != null
                  * 
                  *  Postconditions:
                  *    return_value == &"list"
                  *    init'ed(this.bean.approvedComments)
                  *    init'ed(this.bean.ids)
                  *    init'ed(this.bean.spamComments)
                  *    possibly_updated(this.bulkDeleteCount)
                  *    possibly_updated(this.firstComment)
                  *    possibly_updated(this.lastComment)
                  *    this.pager == &new CommentsPager(loadComments#2)
                  *    init'ed(this.queryEntry)
                  *    new CommentsPager(loadComments#2) num objects == 1
                  * 
                  *  Test Vectors:
                  *    java.util.List:size(...)@202: {-231..30}, {31..232-1}
                  */
   184          loadComments();
   185          
   186          // load bean data using comments list
   187          getBean().loadCheckboxes(getPager().getItems());
   188          
   189          try {
   190              WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
   191              List allMatchingComments = wmgr.getComments(
   192                      getActionWeblog(),
   193                      null,
   194                      getBean().getSearchString(),
   195                      getBean().getStartDate(),
   196                      getBean().getEndDate(),
   197                      getBean().getStatus(),
   198                      true, // reverse  chrono order
   199                      0,
   200                      -1);
   201              
   202              if(allMatchingComments.size() > COUNT) {
   203                  setBulkDeleteCount(allMatchingComments.size());
   204              }
   205              
   206          } catch (WebloggerException ex) {
   207              log.error("Error looking up comments", ex);
   208              // TODO: i18n
   209              addError("Error looking up comments");
   210          }
   211          
   212          return LIST;
   213      }
   214      
   215      
   216      /**
   217       * Bulk delete all comments matching query criteria.
   218       */
   219      public String delete() {
   220          
   221          try {
                     /* 
    P/P               *  Method: String delete()
                      * 
                      *  Preconditions:
                      *    (soft) log != null
                      *    (soft) this.bean != null
                      *    (soft) init'ed(this.queryEntry)
                      *    (soft) this.bean.approvedString != null
                      *    (soft) init'ed(this.bean.endDateString)
                      *    (soft) init'ed(this.bean.searchString)
                      *    (soft) this.bean.spamString != null
                      *    (soft) init'ed(this.bean.startDateString)
                      * 
                      *  Presumptions:
                      *    java.util.Iterator:next(...)@237 != null
                      *    org.apache.roller.weblogger.business.WeblogManager:getComments(...)@228 != null
                      *    org.apache.roller.weblogger.business.Weblogger:getIndexManager(...)@252 != null
                      *    org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@222 != null
                      *    org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@222 != null
                      *    ...
                      * 
                      *  Postconditions:
                      *    return_value == &"list"
                      *    this.bean == One-of{&new CommentsBean(delete#2), old this.bean}
                      *    (soft) this.bean != null
                      *    init'ed(this.bean.approvedComments)
                      *    init'ed(this.bean.ids)
                      *    init'ed(this.bean.spamComments)
                      *    possibly_updated(this.firstComment)
                      *    possibly_updated(this.lastComment)
                      *    this.pager == One-of{&new CommentsPager(loadComments#2), old this.pager}
                      *    init'ed(this.queryEntry)
                      *    ...
                      * 
                      *  Test Vectors:
                      *    java.util.Iterator:hasNext(...)@237: {0}, {1}
                      *    java.util.Iterator:hasNext(...)@253: {0}, {1}
                      *    java.util.Set:isEmpty(...)@251: {1}, {0}
                      *    org.apache.roller.weblogger.config.WebloggerConfig:getBooleanProperty(...)@227: {0}, {1}
                      */
   222              WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
   223              
   224              // if search is enabled, we will need to re-index all entries with
   225              // comments that have been deleted, so build a list of those entries
   226              Set<WeblogEntry> reindexEntries = new HashSet<WeblogEntry>();
   227              if (WebloggerConfig.getBooleanProperty("search.enabled")) {                 
   228                  List<WeblogEntryComment> targetted = (List<WeblogEntryComment>)wmgr.getComments(
   229                      getActionWeblog(), 
   230                      getQueryEntry(), 
   231                      getBean().getSearchString(),
   232                      getBean().getStartDate(),
   233                      getBean().getEndDate(),
   234                      getBean().getStatus(), 
   235                      true, 
   236                      0, -1);
   237                  for (WeblogEntryComment comment : targetted) {
   238                      reindexEntries.add(comment.getWeblogEntry());
   239                  }
   240              }
   241              
   242              int deleted = wmgr.removeMatchingComments(
   243                      getActionWeblog(),
   244                      null,
   245                      getBean().getSearchString(),
   246                      getBean().getStartDate(),
   247                      getBean().getEndDate(),
   248                      getBean().getStatus());
   249              
   250              // if we've got entries to reindex then do so
   251              if (!reindexEntries.isEmpty()) {
   252                  IndexManager imgr = WebloggerFactory.getWeblogger().getIndexManager();
   253                  for (WeblogEntry entry : reindexEntries) {
   254                      imgr.addEntryReIndexOperation(entry);
   255                  }
   256              }
   257                      
   258              addMessage("commentManagement.deleteSuccess", Integer.toString(deleted));
   259              
   260              // reset form and load fresh comments list
   261              setBean(new CommentsBean());
   262              
   263              return execute();
   264              
   265          } catch (WebloggerException ex) {
   266              log.error("Error doing bulk delete", ex);
   267              // TODO: i18n
   268              addError("Bulk delete failed due to unexpected error");
   269          }
   270          
   271          return LIST;
   272      }
   273      
   274      
   275      /**
   276       * Update a list of comments.
   277       */
   278      public String update() {
   279          
   280          try {
                     /* 
    P/P               *  Method: String update()
                      * 
                      *  Preconditions:
                      *    log != null
                      *    (soft) this.bean != null
                      *    (soft) init'ed(this.bean.approvedComments)
                      *    (soft) init'ed(this.bean.ids)
                      *    (soft) init'ed(this.bean.spamComments)
                      *    (soft) init'ed(this.queryEntry)
                      *    (soft) init'ed(this.bean.deleteComments)
                      *    (soft) init'ed(this.bean.entryId)
                      * 
                      *  Presumptions:
                      *    ids.length@315 <= 232-1
                      *    java.util.Arrays:asList(...)@308 != null
                      *    java.util.Arrays:asList(...)@309 != null
                      *    org.apache.roller.weblogger.business.WeblogManager:getComment(...)@296 != null
                      *    org.apache.roller.weblogger.business.WeblogManager:getComment(...)@325 != null
                      *    ...
                      * 
                      *  Postconditions:
                      *    return_value == &"list"
                      *    this.bean == One-of{&new CommentsBean(update#11), old this.bean}
                      *    (soft) this.bean != null
                      *    init'ed(this.bean.approvedComments)
                      *    init'ed(this.bean.ids)
                      *    init'ed(this.bean.spamComments)
                      *    possibly_updated(this.firstComment)
                      *    possibly_updated(this.lastComment)
                      *    this.pager == One-of{&new CommentsPager(loadComments#2), old this.pager}
                      *    init'ed(this.queryEntry)
                      *    ...
                      * 
                      *  Test Vectors:
                      *    this.bean.entryId: Addr_Set{null}, Inverse{null}
                      *    java.lang.String:equals(...)@333: {0}, {1}
                      *    java.lang.String:equals(...)@352: {1}, {0}
                      *    java.util.Arrays:asList(...)@290: Addr_Set{null}, Inverse{null}
                      *    java.util.Iterator:hasNext(...)@295: {0}, {1}
                      *    java.util.Iterator:hasNext(...)@379: {0}, {1}
                      *    java.util.List:contains(...)@320: {0}, {1}
                      *    java.util.List:contains(...)@330: {0}, {1}
                      *    java.util.List:contains(...)@344: {0}, {1}
                      *    java.util.List:size(...)@291: {-231..0}, {1..232-1}
                      *    ...
                      */
   281              WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
   282              
   283              List<WeblogEntryComment> flushList = new ArrayList();
   284  
   285              // if search is enabled, we will need to re-index all entries with
   286              // comments that have been approved, so build a list of those entries
   287              Set<WeblogEntry> reindexList = new HashSet<WeblogEntry>();
   288              
   289              // delete all comments with delete box checked
   290              List<String> deletes = Arrays.asList(getBean().getDeleteComments());
   291              if(deletes != null && deletes.size() > 0) {
   292                  log.debug("Processing deletes - "+deletes.size());
   293                  
   294                  WeblogEntryComment deleteComment = null;
   295                  for(String deleteId : deletes) {
   296                      deleteComment = wmgr.getComment(deleteId);
   297                      
   298                      // make sure comment is tied to action weblog
   299                      if(getActionWeblog().equals(deleteComment.getWeblogEntry().getWebsite())) {
   300                          flushList.add(deleteComment);
   301                          reindexList.add(deleteComment.getWeblogEntry());
   302                          wmgr.removeComment(deleteComment);
   303                      }
   304                  }
   305              }
   306              
   307              // loop through IDs of all comments displayed on page
   308              List<String> approvedIds = Arrays.asList(getBean().getApprovedComments());
   309              List<String> spamIds = Arrays.asList(getBean().getSpamComments());
   310              log.debug(spamIds.size()+" comments marked as spam");
   311              
   312              // track comments approved via moderation
   313              List<WeblogEntryComment> approvedComments = new ArrayList();
   314              
   315              String[] ids = Utilities.stringToStringArray(getBean().getIds(),",");
   316              for (int i=0; i < ids.length; i++) {
   317                  log.debug("processing id - "+ ids[i]);
   318                  
   319                  // if we already deleted it then skip forward
   320                  if(deletes.contains(ids[i])) {
   321                      log.debug("Already deleted, skipping - "+ids[i]);
   322                      continue;
   323                  }
   324                  
   325                  WeblogEntryComment comment = wmgr.getComment(ids[i]);
   326                  
   327                  // make sure comment is tied to action weblog
   328                  if(getActionWeblog().equals(comment.getWeblogEntry().getWebsite())) {
   329                      // comment approvals and mark/unmark spam
   330                      if(approvedIds.contains(ids[i])) {
   331                          // if a comment was previously PENDING then this is
   332                          // it's first approval, so track it for notification
   333                          if(WeblogEntryComment.PENDING.equals(comment.getStatus())) {
   334                              approvedComments.add(comment);
   335                          }
   336                          
   337                          log.debug("Marking as approved - "+comment.getId());
   338                          comment.setStatus(WeblogEntryComment.APPROVED);
   339                          wmgr.saveComment(comment);
   340                          
   341                          flushList.add(comment);
   342                          reindexList.add(comment.getWeblogEntry());
   343                          
   344                      } else if(spamIds.contains(ids[i])) {
   345                          log.debug("Marking as spam - "+comment.getId());
   346                          comment.setStatus(WeblogEntryComment.SPAM);
   347                          wmgr.saveComment(comment);
   348                          
   349                          flushList.add(comment);
   350                          reindexList.add(comment.getWeblogEntry());
   351  
   352                      } else if(!WeblogEntryComment.DISAPPROVED.equals(comment.getStatus())) {
   353                          log.debug("Marking as disapproved - "+comment.getId());
   354                          comment.setStatus(WeblogEntryComment.DISAPPROVED);
   355                          wmgr.saveComment(comment);
   356                          
   357                          flushList.add(comment);
   358                          reindexList.add(comment.getWeblogEntry());
   359                      }
   360                  }
   361              }
   362              
   363              WebloggerFactory.getWeblogger().flush();
   364              
   365              // notify caches of changes by flushing whole site because we can't
   366              // invalidate deleted comment objects (JPA nulls the fields out).
   367              CacheManager.invalidate(getActionWeblog());
   368              
   369              // send notification for all comments changed
   370              if (MailUtil.isMailConfigured()) {
   371                  I18nMessages resources = 
   372                      I18nMessages.getMessages(getActionWeblog().getLocaleInstance());
   373                  MailUtil.sendEmailApprovalNotifications(approvedComments, resources);
   374              }
   375              
   376              // if we've got entries to reindex then do so
   377              if (!reindexList.isEmpty()) {
   378                  IndexManager imgr = WebloggerFactory.getWeblogger().getIndexManager();
   379                  for (WeblogEntry entry : reindexList) {
   380                      imgr.addEntryReIndexOperation(entry);
   381                  }
   382              }            
   383              
   384              addMessage("commentManagement.updateSuccess");
   385              
   386              // reset form and load fresh comments list
   387              CommentsBean freshBean = new CommentsBean();
   388              // but if we're editing an entry's comments stick with that entry
   389              if (bean.getEntryId() != null) {
   390                  freshBean.setEntryId(bean.getEntryId());
   391              }
   392              setBean(freshBean);
   393                          
   394              return execute();
   395              
   396          } catch (Exception ex) {
   397              log.error("ERROR updating comments", ex);
   398              addError("commentManagement.updateError", ex.toString());
   399          }
   400          
   401          return LIST;
   402      }
   403      
   404      
   405      public List getCommentStatusOptions() {
   406          
                 /* 
    P/P           *  Method: List getCommentStatusOptions()
                  * 
                  *  Postconditions:
                  *    return_value == &new ArrayList(getCommentStatusOptions#1)
                  *    new ArrayList(getCommentStatusOptions#1) num objects == 1
                  */
   407          List opts = new ArrayList();
   408          
   409          opts.add(new KeyValueObject("ALL", getText("commentManagement.all")));
   410          opts.add(new KeyValueObject("ONLY_PENDING", getText("commentManagement.onlyPending")));
   411          opts.add(new KeyValueObject("ONLY_APPROVED", getText("commentManagement.onlyApproved")));
   412          opts.add(new KeyValueObject("ONLY_DISAPPROVED", getText("commentManagement.onlyDisapproved")));
   413          
   414          return opts;
   415      }
   416      
   417      public List getSpamStatusOptions() {
   418          
                 /* 
    P/P           *  Method: List getSpamStatusOptions()
                  * 
                  *  Postconditions:
                  *    return_value == &new ArrayList(getSpamStatusOptions#1)
                  *    new ArrayList(getSpamStatusOptions#1) num objects == 1
                  */
   419          List opts = new ArrayList();
   420          
   421          opts.add(new KeyValueObject("ALL", getText("commentManagement.all")));
   422          opts.add(new KeyValueObject("NO_SPAM", getText("commentManagement.noSpam")));
   423          opts.add(new KeyValueObject("ONLY_SPAM", getText("commentManagement.onlySpam")));
   424          
   425          return opts;
   426      }
   427      
   428      
   429      public CommentsBean getBean() {
                 /* 
    P/P           *  Method: CommentsBean getBean()
                  * 
                  *  Preconditions:
                  *    init'ed(this.bean)
                  * 
                  *  Postconditions:
                  *    return_value == this.bean
                  *    init'ed(return_value)
                  */
   430          return bean;
   431      }
   432  
   433      public void setBean(CommentsBean bean) {
                 /* 
    P/P           *  Method: void setBean(CommentsBean)
                  * 
                  *  Postconditions:
                  *    this.bean == bean
                  *    init'ed(this.bean)
                  */
   434          this.bean = bean;
   435      }
   436  
   437      public int getBulkDeleteCount() {
                 /* 
    P/P           *  Method: int getBulkDeleteCount()
                  * 
                  *  Preconditions:
                  *    init'ed(this.bulkDeleteCount)
                  * 
                  *  Postconditions:
                  *    return_value == this.bulkDeleteCount
                  *    init'ed(return_value)
                  */
   438          return bulkDeleteCount;
   439      }
   440  
   441      public void setBulkDeleteCount(int bulkDeleteCount) {
                 /* 
    P/P           *  Method: void setBulkDeleteCount(int)
                  * 
                  *  Postconditions:
                  *    this.bulkDeleteCount == bulkDeleteCount
                  *    init'ed(this.bulkDeleteCount)
                  */
   442          this.bulkDeleteCount = bulkDeleteCount;
   443      }
   444  
   445      public WeblogEntryComment getFirstComment() {
                 /* 
    P/P           *  Method: WeblogEntryComment getFirstComment()
                  * 
                  *  Preconditions:
                  *    init'ed(this.firstComment)
                  * 
                  *  Postconditions:
                  *    return_value == this.firstComment
                  *    init'ed(return_value)
                  */
   446          return firstComment;
   447      }
   448  
   449      public void setFirstComment(WeblogEntryComment firstComment) {
                 /* 
    P/P           *  Method: void setFirstComment(WeblogEntryComment)
                  * 
                  *  Postconditions:
                  *    this.firstComment == firstComment
                  *    init'ed(this.firstComment)
                  */
   450          this.firstComment = firstComment;
   451      }
   452  
   453      public WeblogEntryComment getLastComment() {
                 /* 
    P/P           *  Method: WeblogEntryComment getLastComment()
                  * 
                  *  Preconditions:
                  *    init'ed(this.lastComment)
                  * 
                  *  Postconditions:
                  *    return_value == this.lastComment
                  *    init'ed(return_value)
                  */
   454          return lastComment;
   455      }
   456  
   457      public void setLastComment(WeblogEntryComment lastComment) {
                 /* 
    P/P           *  Method: void setLastComment(WeblogEntryComment)
                  * 
                  *  Postconditions:
                  *    this.lastComment == lastComment
                  *    init'ed(this.lastComment)
                  */
   458          this.lastComment = lastComment;
   459      }
   460  
   461      public CommentsPager getPager() {
                 /* 
    P/P           *  Method: CommentsPager getPager()
                  * 
                  *  Preconditions:
                  *    init'ed(this.pager)
                  * 
                  *  Postconditions:
                  *    return_value == this.pager
                  *    init'ed(return_value)
                  */
   462          return pager;
   463      }
   464  
   465      public void setPager(CommentsPager pager) {
                 /* 
    P/P           *  Method: void setPager(CommentsPager)
                  * 
                  *  Postconditions:
                  *    this.pager == pager
                  *    init'ed(this.pager)
                  */
   466          this.pager = pager;
   467      }
   468  
   469      public WeblogEntry getQueryEntry() {
                 /* 
    P/P           *  Method: WeblogEntry getQueryEntry()
                  * 
                  *  Preconditions:
                  *    init'ed(this.queryEntry)
                  * 
                  *  Postconditions:
                  *    return_value == this.queryEntry
                  *    init'ed(return_value)
                  */
   470          return queryEntry;
   471      }
   472  
   473      public void setQueryEntry(WeblogEntry queryEntry) {
                 /* 
    P/P           *  Method: void setQueryEntry(WeblogEntry)
                  * 
                  *  Postconditions:
                  *    this.queryEntry == queryEntry
                  *    init'ed(this.queryEntry)
                  */
   474          this.queryEntry = queryEntry;
   475      }    
   476  }








SofCheck Inspector Build Version : 2.18479
Comments.java 2009-Jan-02 14:24:58
Comments.class 2009-Sep-04 03:12:45