[jboss-svn-commits] JBL Code SVN: r26804 - labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jun 2 08:47:03 EDT 2009


Author: lkrzyzanek
Date: 2009-06-02 08:47:03 -0400 (Tue, 02 Jun 2009)
New Revision: 26804

Modified:
   labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java
Log:
modified correction of topic/reply date when is null or in future.
topic time is taken from topic post or from first reply with correct date.

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java	2009-06-02 11:26:55 UTC (rev 26803)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java	2009-06-02 12:47:03 UTC (rev 26804)
@@ -156,14 +156,33 @@
 
         // check topicPost time
         // some posts has null value but topic time is set
-        if (topicPost.getTime() == null) {
-          if (topic.getTime() != null) {
+        Date now = new Date();
+        if (topicPost.getTime() == null || topicPost.getTime().after(now)) {
+          if (topic.getTime() != null && topic.getTime().before(now)) {
             topicPost.setTime(topic.getTime());
           } else {
-            // should not occur, but if yes then set default time
-            log.info("Topic post and topic has no creation date. "
-                + "Setting to default");
-            topicPost.setTime(defaultTopicTime);
+            // try to retrieve thread time from replies
+            List<NukesForumsPostBean> replies = nukesForumsDAO
+                .getAllPostsByTopicID(topic.getTopicID(), topicPost.getPostID());
+            Date topicTime = null;
+            for (NukesForumsPostBean replyPost : replies) {
+              if (replyPost.getTime() != null
+                  && replyPost.getTime().before(now)) {
+                topicTime = replyPost.getTime();
+                break;
+              }
+            }
+            if (topicTime == null) {
+              // should not occur, but if yes then set default time
+              log.error("Topic has invalid creation date "
+                  + "(is null or is set to the future). "
+                  + "No reply founded with correct date. "
+                  + "Setting to default time: " + defaultTopicTime
+                  + ". topic_id: " + topic.getTopicID());
+              topicTime = defaultTopicTime;
+            }
+            topicPost.setTime(topicTime);
+            replies = null;
           }
         }
 
@@ -229,8 +248,11 @@
 
           replyMessage.setBody(replyBody);
           Date replyDate = reply.getTime();
-          if (replyDate == null) {
+          if (replyDate == null || replyDate.after(now)) {
             replyDate = new Date(topicPost.getTime().getTime() + 1);
+            log.warn("Correcting reply date. Original date: " + reply.getTime()
+                + ". New date: " + replyDate + ". Reply post_id: "
+                + reply.getPostID());
           }
           replyMessage.setCreationDate(replyDate);
           replyMessage.setModificationDate(replyDate);




More information about the jboss-svn-commits mailing list