[jboss-svn-commits] JBL Code SVN: r26996 - in labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main: java/org/jboss/labs/clearspace/plugin/nfm/dao and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jun 17 11:52:30 EDT 2009


Author: lkrzyzanek
Date: 2009-06-17 11:52:30 -0400 (Wed, 17 Jun 2009)
New Revision: 26996

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/dao/DbNukesForumsDAOImpl.java
   labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsTopicBean.java
   labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/resources/spring.xml
Log:
added Announcement migration capability

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-17 15:42:03 UTC (rev 26995)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java	2009-06-17 15:52:30 UTC (rev 26996)
@@ -23,6 +23,7 @@
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
@@ -43,6 +44,7 @@
 import org.springframework.dao.DataIntegrityViolationException;
 import org.springframework.dao.EmptyResultDataAccessException;
 
+import com.jivesoftware.base.UnauthorizedException;
 import com.jivesoftware.base.User;
 import com.jivesoftware.base.UserAlreadyExistsException;
 import com.jivesoftware.base.UserManager;
@@ -51,6 +53,8 @@
 import com.jivesoftware.base.wiki.WikiContentHelper;
 import com.jivesoftware.community.Activity;
 import com.jivesoftware.community.ActivityBean;
+import com.jivesoftware.community.Announcement;
+import com.jivesoftware.community.AnnouncementManager;
 import com.jivesoftware.community.Community;
 import com.jivesoftware.community.CommunityManager;
 import com.jivesoftware.community.CommunityNotFoundException;
@@ -58,6 +62,8 @@
 import com.jivesoftware.community.ForumMessage;
 import com.jivesoftware.community.ForumThread;
 import com.jivesoftware.community.JiveConstants;
+import com.jivesoftware.community.JiveContainer;
+import com.jivesoftware.community.JiveContentObject;
 import com.jivesoftware.community.JiveObject;
 import com.jivesoftware.community.QuestionManager;
 import com.jivesoftware.community.RejectedException;
@@ -103,6 +109,8 @@
 
   private ActivityListener activityListener;
 
+  private AnnouncementManager announcementManager;
+
   private NukesUserManager nukesUserManager;
 
   /**
@@ -251,6 +259,17 @@
           newUsersCount++;
         }
 
+        if (topic.isAnnouncement()) {
+          try {
+            createAnnouncement(topic, topicPost, rootMessageUser, community);
+          } catch (UnauthorizedException e) {
+            throw new RuntimeException("Cannot create an Announcement.", e);
+          } catch (RejectedException e) {
+            throw new RuntimeException("Cannot create an Announcement.", e);
+          }
+          continue;
+        }
+
         ForumMessage rootMessage = forumManager.createMessage(community,
             rootMessageUser);
         // creationDate taken from first post.
@@ -385,6 +404,41 @@
     return result;
   }
 
+  /**
+   * Create announcement from topic announcement
+   * 
+   * @param topic
+   * @param topicPost
+   * @param user
+   * @param jiveContainer
+   * @throws UnauthorizedException
+   * @throws RejectedException
+   */
+  private void createAnnouncement(NukesForumsTopicBean topic,
+      NukesForumsPostBean topicPost, User user, JiveContainer jiveContainer)
+      throws UnauthorizedException, RejectedException {
+    Announcement announcement = announcementManager.createAnnouncement(user,
+        jiveContainer);
+    announcement.setSubject(topicPost.getSubject());
+    org.w3c.dom.Document topicBody = createDocument(topicPost.getBody());
+    announcement.setBody(topicBody);
+    announcement.setStartDate(topicPost.getTime());
+
+    // handle end date (expiration)
+    Calendar cal = Calendar.getInstance();
+    cal.setTime(announcement.getStartDate());
+    cal.add(Calendar.MONTH, 3);
+    Date possibleEndDate = cal.getTime();
+
+    if (possibleEndDate.before(new Date())) {
+      // Announcement is too old - expire it
+      announcement.setEndDate(possibleEndDate);
+      announcement.setStatus(JiveContentObject.Status.EXPIRED);
+    }
+
+    announcementManager.addAnnouncement(announcement);
+  }
+
   private ActivityBean createActivity(JiveObject object, JiveObject parent,
       User user, Activity.Type activityType, Date creationDate) {
     ActivityBean bean = new ActivityBean();
@@ -681,4 +735,8 @@
     this.activityDAO = activityDAO;
   }
 
+  public void setAnnouncementManager(AnnouncementManager announcementManager) {
+    this.announcementManager = announcementManager;
+  }
+
 }

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/DbNukesForumsDAOImpl.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/DbNukesForumsDAOImpl.java	2009-06-17 15:42:03 UTC (rev 26995)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/DbNukesForumsDAOImpl.java	2009-06-17 15:52:30 UTC (rev 26996)
@@ -43,7 +43,7 @@
   // retrieving datetime. Mysql allow 0000-00-00 00:00:00 value which causes
   // exception
 
-  private static final String SELECT_TOPICS_BY_FORUMID = "SELECT topic_id, topic_title, topic_poster, CASE WHEN topic_time = \"0000-00-00 00:00:00\" THEN null ELSE topic_time END as topic_time, topic_status, topic_first_post_id, topic_views"
+  private static final String SELECT_TOPICS_BY_FORUMID = "SELECT topic_id, topic_title, topic_poster, CASE WHEN topic_time = \"0000-00-00 00:00:00\" THEN null ELSE topic_time END as topic_time, topic_status, topic_first_post_id, topic_views, topic_type"
       + " FROM phpbb_topics WHERE forum_id = ?";
 
   private static final String SELECT_FROM_POST = "SELECT p.post_id, p.topic_id, p.forum_id, nu.pn_uname, nu.pn_email, CASE WHEN post_time = \"0000-00-00 00:00:00\" THEN null ELSE post_time END as post_time, post_subject, post_text "
@@ -195,6 +195,7 @@
       bean.setStatus(rs.getInt("topic_status"));
       bean.setFirstPostID(rs.getLong("topic_first_post_id"));
       bean.setViewCount(rs.getInt("topic_views"));
+      bean.setType(rs.getInt("topic_type"));
 
       return bean;
     }

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsTopicBean.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsTopicBean.java	2009-06-17 15:42:03 UTC (rev 26995)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsTopicBean.java	2009-06-17 15:52:30 UTC (rev 26996)
@@ -33,6 +33,16 @@
  */
 public class NukesForumsTopicBean {
 
+  /**
+   * Sticky topic
+   */
+  public static final int TYPE_STICKY = 1;
+
+  /**
+   * Announcement
+   */
+  public static final int TYPE_ANNOUNCEMENT = 2;
+
   private Long topicID;
 
   private Long forumID;
@@ -46,9 +56,11 @@
   private Long firstPostID;
 
   private Integer status;
-  
+
   private Integer viewCount;
 
+  private Integer type;
+
   public NukesForumsTopicBean(Long forumID) {
     this.forumID = forumID;
   }
@@ -122,4 +134,28 @@
     return viewCount;
   }
 
+  public void setType(Integer type) {
+    this.type = type;
+  }
+
+  public Integer getType() {
+    return type;
+  }
+
+  public boolean isSticky() {
+    if (type != null && type == TYPE_STICKY) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  public boolean isAnnouncement() {
+    if (type != null && type == TYPE_ANNOUNCEMENT) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
 }

Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/resources/spring.xml
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/resources/spring.xml	2009-06-17 15:42:03 UTC (rev 26995)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/resources/spring.xml	2009-06-17 15:52:30 UTC (rev 26996)
@@ -26,6 +26,8 @@
     <property name="viewCountManager" ref="viewCountManager" />
     <property name="questionManager" ref="questionManager" />
     <property name="watchManager" ref="watchManager" />
+    <property name="announcementManager" ref="announcementManager" />
+    
     <property name="defaultTopicTimeStr" value="2002-01-01" />
 
     <property name="topicMappings" ref="topicMappings" />




More information about the jboss-svn-commits mailing list