[jboss-svn-commits] JBL Code SVN: r26654 - in labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main: java/org/jboss/labs/clearspace/plugin/nfm/dao and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu May 21 10:56:03 EDT 2009
Author: lkrzyzanek
Date: 2009-05-21 10:56:03 -0400 (Thu, 21 May 2009)
New Revision: 26654
Added:
labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsPostBean.java
labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsTopicBean.java
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/NukesForumsDAO.java
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/web/admin/nukes-forums-migration.ftl
Log:
added migration implementation
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-05-21 13:41:31 UTC (rev 26653)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java 2009-05-21 14:56:03 UTC (rev 26654)
@@ -21,6 +21,7 @@
*/
package org.jboss.labs.clearspace.plugin.nfm;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -31,8 +32,22 @@
import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsDAO;
import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsForumBean;
import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsMappingDAO;
+import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsPostBean;
+import org.jboss.labs.clearspace.plugin.nfm.dao.NukesForumsTopicBean;
import org.springframework.dao.DataIntegrityViolationException;
+import com.jivesoftware.base.User;
+import com.jivesoftware.base.UserManager;
+import com.jivesoftware.base.UserNotFoundException;
+import com.jivesoftware.base.wiki.WikiContentHelper;
+import com.jivesoftware.community.Community;
+import com.jivesoftware.community.CommunityManager;
+import com.jivesoftware.community.CommunityNotFoundException;
+import com.jivesoftware.community.ForumManager;
+import com.jivesoftware.community.ForumMessage;
+import com.jivesoftware.community.ForumThread;
+import com.jivesoftware.community.RejectedException;
+
/**
* Db implementation
*
@@ -48,6 +63,12 @@
private NukesForumsDAO nukesForumsDAO;
+ private ForumManager forumManager;
+
+ private CommunityManager communityManager;
+
+ private UserManager userManager;
+
Map<Long, Long> categoryMappings = null;
Map<Long, Long> forumMappings = null;
@@ -80,10 +101,110 @@
}
public Map<String, Long> migrateForums2Clearspace() {
+ final long start = System.currentTimeMillis();
+ log.info("Migration of forums to clearspace started");
Map<String, Long> result = new HashMap<String, Long>();
- result.put("topicsCount", new Long(0));
- result.put("postsCount", new Long(0));
+ Map<Long, Long> forumMapping = getForumMappings();
+ long topicsCount = 0;
+ long postsCount = 0;
+ for (Long forumID : forumMapping.keySet()) {
+ log.info("Migrate topics for forum with ID: " + forumID);
+ Long communityID = forumMapping.get(forumID);
+
+ List<NukesForumsTopicBean> topics = nukesForumsDAO
+ .getAllTopicsByForumID(forumID);
+
+ for (NukesForumsTopicBean topic : topics) {
+ // log.debug("Migrate posts for topic with ID: " + topic.getTopicID());
+
+ // log.trace("get First post for postID: " + topic.getFirstPostID());
+ NukesForumsPostBean topicPost = nukesForumsDAO.getPostByID(topic
+ .getFirstPostID());
+
+ // check topic time
+ if (topic.getTime() == null) {
+ if (topicPost.getTime() != null) {
+ topic.setTime(topicPost.getTime());
+ } else {
+ // should not occure
+ throw new RuntimeException();
+ }
+ }
+
+ User rootMessageUser = null;
+ try {
+ rootMessageUser = userManager.getUser("lkrzyzanek");
+ } catch (UserNotFoundException e) {
+ log.error(e);
+ }
+
+ Community community;
+ try {
+ community = communityManager.getCommunity(communityID);
+ } catch (CommunityNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ ForumMessage rootMessage = forumManager.createMessage(community,
+ rootMessageUser);
+ org.w3c.dom.Document topicBody = WikiContentHelper
+ .unknownContentToJiveDoc(topicPost.getBody());
+ rootMessage.setBody(topicBody);
+ rootMessage.setCreationDate(topic.getTime());
+ rootMessage.setSubject(topic.getTitle());
+
+ ForumThread thread = forumManager.createThread(community, rootMessage);
+ thread.setCreationDate(topic.getTime());
+
+ try {
+ forumManager.addThread(community, thread);
+ postsCount++;
+ } catch (RejectedException e) {
+ throw new RuntimeException(e);
+ }
+
+ // log.trace("Migrate replies");
+ List<NukesForumsPostBean> replies = nukesForumsDAO
+ .getAllPostsByTopicID(topic.getTopicID(), topicPost.getPostID());
+ for (NukesForumsPostBean reply : replies) {
+ User replyUser = null;
+ try {
+ replyUser = userManager.getUser("lkrzyzanek");
+ } catch (UserNotFoundException e) {
+ log.error(e);
+ }
+ ForumMessage replyMessage = forumManager.createMessage(community,
+ replyUser);
+ org.w3c.dom.Document replyBody = WikiContentHelper
+ .unknownContentToJiveDoc(reply.getBody());
+
+ replyMessage.setBody(replyBody);
+ replyMessage.setCreationDate(reply.getTime() != null ? reply
+ .getTime() : new Date(topic.getTime().getTime() + 1));
+ replyMessage.setSubject(reply.getSubject());
+
+ try {
+ forumManager.addMessage(thread, rootMessage, replyMessage);
+ } catch (RejectedException e) {
+ throw new RuntimeException(e);
+ }
+ postsCount++;
+ }
+
+ // nukesForumsMappingDAO.saveTopicMapping(topic.getTopicID(),
+ // discussionID);
+
+ topicsCount++;
+ }
+
+ }
+
+ result.put("topicsCount", topicsCount);
+ result.put("postsCount", postsCount);
+
+ final long timeConsumed = (System.currentTimeMillis() - start) / 1000;
+ log.info("Migration completed, time taken: " + timeConsumed + " sec.");
+
return result;
}
@@ -136,4 +257,16 @@
this.nukesForumsDAO = nukesForumsDAO;
}
+ public void setForumManager(ForumManager forumManager) {
+ this.forumManager = forumManager;
+ }
+
+ public void setCommunityManager(CommunityManager communityManager) {
+ this.communityManager = communityManager;
+ }
+
+ public void setUserManager(UserManager userManager) {
+ this.userManager = userManager;
+ }
+
}
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-05-21 13:41:31 UTC (rev 26653)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/DbNukesForumsDAOImpl.java 2009-05-21 14:56:03 UTC (rev 26654)
@@ -39,11 +39,70 @@
private static final String SELECT_FORUMS_BY_CATEGORYID = "SELECT forum_id, forum_name, forum_desc, forum_status FROM phpbb_forums WHERE cat_id = ?";
+ // CASE in selects is workaround (hack) to omit jdbc exception during
+ // 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"
+ + " FROM phpbb_topics WHERE forum_id = ?";
+
+ private static final String SELECT_FROM_POST = "SELECT post_id, topic_id, forum_id, poster_id, poster_id, CASE WHEN post_time = \"0000-00-00 00:00:00\" THEN null ELSE post_time END as post_time, post_subject, post_text FROM phpbb_posts";
+
+ private static final String SELECT_POST_BY_ID = SELECT_FROM_POST
+ + " WHERE post_id = ?";
+
+ private static final String SELECT_POSTS_BY_TOPICID = SELECT_FROM_POST
+ + " WHERE topic_id = ?";
+
public List<NukesForumsForumBean> getAllForumsByCategoryID(Long categoryID) {
return getSimpleJdbcTemplate().query(SELECT_FORUMS_BY_CATEGORYID,
new NukesForumsForumBeanMapper(categoryID), categoryID);
}
+ public List<NukesForumsTopicBean> getAllTopicsByForumID(Long forumID) {
+ return getSimpleJdbcTemplate().query(SELECT_TOPICS_BY_FORUMID,
+ new NukesForumsTopicBeanMapper(forumID), forumID);
+ }
+
+ public NukesForumsPostBean getPostByID(Long postID) {
+ return getSimpleJdbcTemplate().queryForObject(SELECT_POST_BY_ID,
+ new NukesForumsPostBeanMapper(), postID);
+ }
+
+ public List<NukesForumsPostBean> getAllPostsByTopicID(Long topicID,
+ Long exceptPostID) {
+ if (exceptPostID != null) {
+ return getSimpleJdbcTemplate().query(
+ SELECT_POSTS_BY_TOPICID + " and post_id != ?",
+ new NukesForumsPostBeanMapper(), topicID, exceptPostID);
+ } else {
+ return getSimpleJdbcTemplate().query(SELECT_POSTS_BY_TOPICID,
+ new NukesForumsPostBeanMapper(), topicID);
+ }
+ }
+
+ class NukesForumsPostBeanMapper implements
+ ParameterizedRowMapper<NukesForumsPostBean> {
+
+ public NukesForumsPostBean mapRow(ResultSet rs, int rowNum)
+ throws SQLException {
+ NukesForumsPostBean bean = new NukesForumsPostBean();
+ bean.setPostID(rs.getLong("post_id"));
+ bean.setTopicID(rs.getLong("post_id"));
+ bean.setForumID(rs.getLong("post_id"));
+ bean.setPosterID(rs.getLong("poster_id"));
+ bean.setTime(rs.getDate("post_time"));
+ bean.setSubject(rs.getString("post_subject"));
+ bean.setBody(rs.getString("post_text"));
+ return bean;
+ }
+ }
+
+ /**
+ * Mapping for forum bean
+ *
+ * @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
+ */
class NukesForumsForumBeanMapper implements
ParameterizedRowMapper<NukesForumsForumBean> {
@@ -67,4 +126,31 @@
}
+ /**
+ * Mapping for Topic Bean
+ *
+ * @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
+ */
+ class NukesForumsTopicBeanMapper implements
+ ParameterizedRowMapper<NukesForumsTopicBean> {
+ private Long forumID;
+
+ public NukesForumsTopicBeanMapper(Long forumID) {
+ this.forumID = forumID;
+ }
+
+ public NukesForumsTopicBean mapRow(ResultSet rs, int rowNum)
+ throws SQLException {
+ NukesForumsTopicBean bean = new NukesForumsTopicBean(forumID);
+ bean.setTopicID(rs.getLong("topic_id"));
+ bean.setTitle(rs.getString("topic_title"));
+ bean.setPosterID(rs.getLong("topic_poster"));
+ bean.setTime(rs.getDate("topic_time"));
+ bean.setStatus(rs.getInt("topic_status"));
+ bean.setFirstPostID(rs.getLong("topic_first_post_id"));
+
+ return bean;
+ }
+ }
+
}
Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsDAO.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsDAO.java 2009-05-21 13:41:31 UTC (rev 26653)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsDAO.java 2009-05-21 14:56:03 UTC (rev 26654)
@@ -35,7 +35,35 @@
* Get all forums by category ID
*
* @param categoryID
+ * @return list of forums
*/
public List<NukesForumsForumBean> getAllForumsByCategoryID(Long categoryID);
+ /**
+ * Get all topics by forum ID
+ *
+ * @param forumID
+ * @return list of topics
+ */
+ public List<NukesForumsTopicBean> getAllTopicsByForumID(Long forumID);
+
+ /**
+ * Get post by their ID
+ *
+ * @param postID
+ * @return
+ */
+ public NukesForumsPostBean getPostByID(Long postID);
+
+ /**
+ * Get all posts by topic ID
+ *
+ * @param topicID
+ * @param exceptPostID
+ * exclude post from select. If null all rows are returned
+ * @return list of posts
+ */
+ public List<NukesForumsPostBean> getAllPostsByTopicID(Long topicID,
+ Long exceptPostID);
+
}
Added: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsPostBean.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsPostBean.java (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsPostBean.java 2009-05-21 14:56:03 UTC (rev 26654)
@@ -0,0 +1,111 @@
+/*
+ * JBoss.org http://jboss.org/
+ *
+ * Copyright (c) 2009 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Libor Krzyzanek
+ */
+package org.jboss.labs.clearspace.plugin.nfm.dao;
+
+import java.util.Date;
+
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+/**
+ * Post bean
+ *
+ * @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
+ *
+ */
+public class NukesForumsPostBean {
+
+ private Long postID;
+
+ private Long topicID;
+
+ private Long forumID;
+
+ private Long posterID;
+
+ private Date time;
+
+ private String subject;
+
+ private String body;
+
+ public int hashCode() {
+ return new HashCodeBuilder(2077501835, -1691890021).append(this.postID)
+ .toHashCode();
+ }
+
+ public Long getPostID() {
+ return postID;
+ }
+
+ public void setPostID(Long postID) {
+ this.postID = postID;
+ }
+
+ public Long getTopicID() {
+ return topicID;
+ }
+
+ public void setTopicID(Long topicID) {
+ this.topicID = topicID;
+ }
+
+ public Long getForumID() {
+ return forumID;
+ }
+
+ public void setForumID(Long forumID) {
+ this.forumID = forumID;
+ }
+
+ public Long getPosterID() {
+ return posterID;
+ }
+
+ public void setPosterID(Long posterID) {
+ this.posterID = posterID;
+ }
+
+ public Date getTime() {
+ return time;
+ }
+
+ public void setTime(Date time) {
+ this.time = time;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public void setBody(String body) {
+ this.body = body;
+ }
+
+}
Property changes on: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsPostBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsTopicBean.java 2009-05-21 14:56:03 UTC (rev 26654)
@@ -0,0 +1,115 @@
+/*
+ * JBoss.org http://jboss.org/
+ *
+ * Copyright (c) 2009 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Libor Krzyzanek
+ */
+package org.jboss.labs.clearspace.plugin.nfm.dao;
+
+import java.util.Date;
+
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+/**
+ * Topic bean
+ *
+ * @author <a href="mailto:lkrzyzan at redhat.com">Libor Krzyzanek</a>
+ *
+ */
+public class NukesForumsTopicBean {
+
+ private Long topicID;
+
+ private Long forumID;
+
+ private Long posterID;
+
+ private String title;
+
+ private Date time;
+
+ private Long firstPostID;
+
+ private Integer status;
+
+ public NukesForumsTopicBean(Long forumID) {
+ this.forumID = forumID;
+ }
+
+ public int hashCode() {
+ return new HashCodeBuilder(-1570887203, -335907903).append(this.topicID)
+ .toHashCode();
+ }
+
+ public Long getTopicID() {
+ return topicID;
+ }
+
+ public void setTopicID(Long topicID) {
+ this.topicID = topicID;
+ }
+
+ public Long getForumID() {
+ return forumID;
+ }
+
+ public void setForumID(Long forumID) {
+ this.forumID = forumID;
+ }
+
+ public Long getPosterID() {
+ return posterID;
+ }
+
+ public void setPosterID(Long posterID) {
+ this.posterID = posterID;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public Date getTime() {
+ return time;
+ }
+
+ public void setTime(Date time) {
+ this.time = time;
+ }
+
+ public Long getFirstPostID() {
+ return firstPostID;
+ }
+
+ public void setFirstPostID(Long firstPostID) {
+ this.firstPostID = firstPostID;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+}
Property changes on: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/dao/NukesForumsTopicBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-05-21 13:41:31 UTC (rev 26653)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/resources/spring.xml 2009-05-21 14:56:03 UTC (rev 26654)
@@ -9,6 +9,9 @@
class="org.jboss.labs.clearspace.plugin.nfm.DbNukesForumsManager">
<property name="nukesForumsMappingDAO" ref="nukesForumsMappingDAO" />
<property name="nukesForumsDAO" ref="nukesForumsDAO" />
+ <property name="communityManager" ref="communityManager" />
+ <property name="forumManager" ref="forumManager" />
+ <property name="userManager" ref="userManager" />
</bean>
<bean id="nukesForumsMappingDAO"
Modified: labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/web/admin/nukes-forums-migration.ftl
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/web/admin/nukes-forums-migration.ftl 2009-05-21 13:41:31 UTC (rev 26653)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/web/admin/nukes-forums-migration.ftl 2009-05-21 14:56:03 UTC (rev 26654)
@@ -6,8 +6,7 @@
<content tag="pageID">system-nfm</content>
</head>
<body>
- <@s.actionmessage />
- <@s.fielderror />
+ <#include "/template/global/include/form-message.ftl" />
<h3><@s.text name="plugin.nfm.admin.nfm.refresh-category-mapping.name" /></h3>
<@s.form theme="simple" action="nukes-forums-refresh-category-mapping">
More information about the jboss-svn-commits
mailing list