[jboss-svn-commits] JBL Code SVN: r29091 - 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
Thu Aug 27 07:12:57 EDT 2009
Author: lkrzyzanek
Date: 2009-08-27 07:12:57 -0400 (Thu, 27 Aug 2009)
New Revision: 29091
Modified:
labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java
Log:
Added to statistis count of failedTopics.
Surrounded handling of topic by try/catch to prevent unexpected exception.
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-08-27 10:56:23 UTC (rev 29090)
+++ labs/jbosslabs/labs-3.0-build/integration/cs-nfm/trunk/src/main/java/org/jboss/labs/clearspace/plugin/nfm/DbNukesForumsManager.java 2009-08-27 11:12:57 UTC (rev 29091)
@@ -197,6 +197,7 @@
long topicsCount = 0;
long postsCount = 0;
int newUsersCount = 0;
+ int failedTopics = 0;
log.trace("Unregistering activity listeners. "
+ "Activities are handled by hand.");
@@ -210,6 +211,9 @@
forumIndex++;
log.error("INFO: Migrate topics for forum with ID: " + forumID + ", ("
+ forumIndex + "/" + forumMapping.size() + ")");
+ log.error("INFO: Actual state of migration. Migrated posts: "
+ + postsCount + ". New users: " + newUsersCount + ". Failed topics: "
+ + failedTopics);
Collection<ActivityBean> activitiesFromMigration = new LinkedBlockingQueue<ActivityBean>();
Long communityID = forumMapping.get(forumID);
@@ -224,238 +228,261 @@
.getAllTopicsByForumID(forumID);
for (NukesForumsTopicBean topic : topics) {
- // log.debug("Migrate posts for topic with ID: " + topic.getTopicID());
+ // log.debug("Migrate posts for topic with ID: " +
+ // topic.getTopicID());
// log.trace("get First post for postID: " + topic.getFirstPostID());
- NukesForumsPostBean topicPost;
try {
- topicPost = nukesForumsDAO.getPostByID(topic.getFirstPostID());
- } catch (EmptyResultDataAccessException e) {
- List<NukesForumsPostBean> replies = nukesForumsDAO
- .getAllPostsByTopicID(topic.getTopicID(), null);
- if (replies.isEmpty()) {
- log.error("Topic has no firstPostID and also no replies, "
- + "topic_id: " + topic.getTopicID() + ". Going to next topic");
- continue;
+ NukesForumsPostBean topicPost;
+ try {
+ topicPost = nukesForumsDAO.getPostByID(topic.getFirstPostID());
+ } catch (EmptyResultDataAccessException e) {
+ List<NukesForumsPostBean> replies = nukesForumsDAO
+ .getAllPostsByTopicID(topic.getTopicID(), null);
+ if (replies.isEmpty()) {
+ log
+ .error("Topic has no firstPostID and also no replies, "
+ + "topic_id: " + topic.getTopicID()
+ + ". Going to next topic");
+ failedTopics++;
+ continue;
+ }
+ topicPost = replies.get(0);
}
- topicPost = replies.get(0);
- }
- // check topicPost time
- // some posts has null value but topic time is set
- 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 {
- // 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;
+ // check topicPost time
+ // some posts has null value but topic time is set
+ 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 {
+ // 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;
}
- 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;
}
- }
- User rootMessageUser = findUser(topicPost.getPosterUsername(),
- topicPost.getPosterEmail());
+ User rootMessageUser = findUser(topicPost.getPosterUsername(),
+ topicPost.getPosterEmail());
- if (rootMessageUser == null) {
- log.error("Unknkown user for topic_id: " + topic.getTopicID()
- + " username: '" + topicPost.getPosterUsername()
- + "'. Going to create new CS user");
- try {
- rootMessageUser = nukesUserManager.createUserFromNukes(topicPost
- .getPosterUsername());
- } catch (UserAlreadyExistsException e) {
- throw new RuntimeException(
- "User already exists, but we're sure that doesn't", e);
+ if (rootMessageUser == null) {
+ log.error("Unknkown user for topic_id: " + topic.getTopicID()
+ + " username: '" + topicPost.getPosterUsername()
+ + "'. Going to create new CS user");
+ try {
+ rootMessageUser = nukesUserManager.createUserFromNukes(topicPost
+ .getPosterUsername());
+ } catch (UserAlreadyExistsException e) {
+ throw new RuntimeException(
+ "User already exists, but we're sure that doesn't", e);
+ }
+ newUsersCount++;
}
- 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);
+ if (topic.isAnnouncement()) {
+ try {
+ boolean success = createAnnouncement(topic, topicPost,
+ rootMessageUser, community);
+ if (!success) {
+ failedTopics++;
+ }
+ } catch (UnauthorizedException e) {
+ throw new RuntimeException("Cannot create an Announcement.", e);
+ } catch (RejectedException e) {
+ throw new RuntimeException("Cannot create an Announcement.", e);
+ }
+ continue;
}
- continue;
- }
- ForumThread thread = null;
- Poll poll = null;
- if (!topic.isContainsPoll()) {
- try {
- thread = createForumThread(community, rootMessageUser, topic,
- topicPost);
- // add activity
- ActivityBean activity = createActivity(thread, thread
- .getJiveContainer(), thread.getUser(), Activity.Type.created,
- thread.getCreationDate());
+ ForumThread thread = null;
+ Poll poll = null;
+ if (!topic.isContainsPoll()) {
+ try {
+ thread = createForumThread(community, rootMessageUser, topic,
+ topicPost);
+ // add activity
+ ActivityBean activity = createActivity(thread, thread
+ .getJiveContainer(), thread.getUser(), Activity.Type.created,
+ thread.getCreationDate());
- activitiesFromMigration.add(activity);
+ activitiesFromMigration.add(activity);
- postsCount++;
- } catch (Exception e) {
- log.error("Cannot create forum thread. Going to next topic");
- continue;
- }
+ postsCount++;
+ } catch (Exception e) {
+ log.error("Cannot create forum thread. Going to next topic");
+ failedTopics++;
+ continue;
+ }
- } else {
- log.trace("Migrate poll");
- NukesPollBean nukesPoll = nukesForumsDAO.loadPoll(topic.getTopicID());
- poll = createPoll(nukesPoll, topicPost, rootMessageUser, community);
+ } else {
+ log.trace("Migrate poll");
+ NukesPollBean nukesPoll;
+ try {
+ nukesPoll = nukesForumsDAO.loadPoll(topic.getTopicID());
+ } catch (Exception e) {
+ log.error("Topic is signed as poll but poll doesn't exist."
+ + "Going to next topic. topic_id: " + topic.getTopicID());
+ failedTopics++;
+ continue;
+ }
+ poll = createPoll(nukesPoll, topicPost, rootMessageUser, community);
- // add activity
- ActivityBean activity = createActivity(poll, community, poll
- .getUser(), Activity.Type.created, poll.getStartDate());
+ // add activity
+ ActivityBean activity = createActivity(poll, community, poll
+ .getUser(), Activity.Type.created, poll.getStartDate());
- activitiesFromMigration.add(activity);
+ activitiesFromMigration.add(activity);
- if (topic.isContainsPoll()) {
- log.trace("Add vote activities");
+ if (topic.isContainsPoll()) {
+ log.trace("Add vote activities");
- List<String[]> voters = nukesForumsDAO.getVoters(nukesPoll
- .getPollID());
- for (String[] userDetail : voters) {
- User user = findUser(userDetail[0], userDetail[1]);
- if (user == null) {
- log.error("Unknkown user for poll vote, poll_id: "
- + nukesPoll.getPollID() + " username: '" + userDetail[0]
- + "'. Going to create new CS user");
- try {
- user = nukesUserManager.createUserFromNukes(userDetail[0]);
- } catch (UserAlreadyExistsException e) {
- throw new RuntimeException(
- "User already exists, but we're sure that doesn't", e);
+ List<String[]> voters = nukesForumsDAO.getVoters(nukesPoll
+ .getPollID());
+ for (String[] userDetail : voters) {
+ User user = findUser(userDetail[0], userDetail[1]);
+ if (user == null) {
+ log.error("Unknkown user for poll vote, poll_id: "
+ + nukesPoll.getPollID() + " username: '" + userDetail[0]
+ + "'. Going to create new CS user");
+ try {
+ user = nukesUserManager.createUserFromNukes(userDetail[0]);
+ } catch (UserAlreadyExistsException e) {
+ throw new RuntimeException(
+ "User already exists, but we're sure that doesn't", e);
+ }
}
- }
- activity = createActivity(poll, community, user,
- Activity.Type.voted, poll.getStartDate());
+ activity = createActivity(poll, community, user,
+ Activity.Type.voted, poll.getStartDate());
- activitiesFromMigration.add(activity);
+ activitiesFromMigration.add(activity);
+ }
}
}
- }
- log.trace("Migrate replies");
- List<NukesForumsPostBean> replies = nukesForumsDAO
- .getAllPostsByTopicID(topic.getTopicID(), topicPost.getPostID());
- for (NukesForumsPostBean reply : replies) {
- User replyUser = findUser(reply.getPosterUsername(), reply
- .getPosterEmail());
- if (replyUser == null) {
- log.error("Unknkown user for reply_id: " + reply.getPostID()
- + " username: '" + reply.getPosterUsername()
- + "'. Going to create new CS user");
+ log.trace("Migrate replies");
+ List<NukesForumsPostBean> replies = nukesForumsDAO
+ .getAllPostsByTopicID(topic.getTopicID(), topicPost.getPostID());
+ for (NukesForumsPostBean reply : replies) {
+ User replyUser = findUser(reply.getPosterUsername(), reply
+ .getPosterEmail());
+ if (replyUser == null) {
+ log.error("Unknkown user for reply_id: " + reply.getPostID()
+ + " username: '" + reply.getPosterUsername()
+ + "'. Going to create new CS user");
+ try {
+ replyUser = nukesUserManager.createUserFromNukes(reply
+ .getPosterUsername());
+ } catch (UserAlreadyExistsException e) {
+ throw new RuntimeException(
+ "User already exists, but we're sure that doesn't", e);
+ }
+ newUsersCount++;
+ }
+
+ org.w3c.dom.Document replyBody;
try {
- replyUser = nukesUserManager.createUserFromNukes(reply
- .getPosterUsername());
- } catch (UserAlreadyExistsException e) {
- throw new RuntimeException(
- "User already exists, but we're sure that doesn't", e);
+ replyBody = createDocument(reply.getBody());
+ } catch (Exception e) {
+ log.error("Cannot parse reply body for thread reply. "
+ + "Going to next reply. post_id: " + reply.getPostID());
+ log.error("Post body: " + reply.getBody());
+ failedTopics++;
+ continue;
}
- newUsersCount++;
- }
+ Date replyDate = reply.getTime();
+ if (replyDate == null || replyDate.after(now)) {
+ replyDate = new Date(topicPost.getTime().getTime() + 1);
+ log.error("Correcting reply date. Original date: "
+ + reply.getTime() + ". New date: " + replyDate
+ + ". Reply post_id: " + reply.getPostID());
+ }
- org.w3c.dom.Document replyBody;
- try {
- replyBody = createDocument(reply.getBody());
- } catch (Exception e) {
- log.error("Cannot parse reply body for thread reply. "
- + "Going to next reply. post_id: " + reply.getPostID());
- log.error("Post body: " + reply.getBody());
- continue;
- }
- Date replyDate = reply.getTime();
- if (replyDate == null || replyDate.after(now)) {
- replyDate = new Date(topicPost.getTime().getTime() + 1);
- log.error("Correcting reply date. Original date: "
- + reply.getTime() + ". New date: " + replyDate
- + ". Reply post_id: " + reply.getPostID());
- }
+ if (!topic.isContainsPoll()) {
+ ForumMessage replyMessage = forumManager.createMessage(community,
+ replyUser);
+ replyMessage.setBody(replyBody);
+ replyMessage.setCreationDate(replyDate);
+ replyMessage.setModificationDate(replyDate);
+ replyMessage.setSubject(reply.getSubject());
- if (!topic.isContainsPoll()) {
- ForumMessage replyMessage = forumManager.createMessage(community,
- replyUser);
- replyMessage.setBody(replyBody);
- replyMessage.setCreationDate(replyDate);
- replyMessage.setModificationDate(replyDate);
- replyMessage.setSubject(reply.getSubject());
+ try {
+ forumManager.addMessage(thread, thread.getRootMessage(),
+ replyMessage);
- try {
- forumManager.addMessage(thread, thread.getRootMessage(),
- replyMessage);
+ nukesForumsMappingDAO.savePostMapping(reply.getPostID(),
+ replyMessage.getID());
- nukesForumsMappingDAO.savePostMapping(reply.getPostID(),
- replyMessage.getID());
+ // add activity
+ ActivityBean activity = createActivity(replyMessage
+ .getForumThread(), replyMessage.getJiveContainer(),
+ replyMessage.getUser(), Activity.Type.replied, replyMessage
+ .getCreationDate());
- // add activity
- ActivityBean activity = createActivity(replyMessage
- .getForumThread(), replyMessage.getJiveContainer(),
- replyMessage.getUser(), Activity.Type.replied, replyMessage
- .getCreationDate());
+ activitiesFromMigration.add(activity);
- activitiesFromMigration.add(activity);
+ } catch (RejectedException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ CommentDelegator commentDelegator = poll.getCommentDelegator();
+ try {
+ Comment comment = commentDelegator.createComment(replyUser,
+ replyBody);
+ comment.setCreationDate(replyDate);
+ comment.setModificationDate(replyDate);
- } catch (RejectedException e) {
- throw new RuntimeException(e);
- }
- } else {
- CommentDelegator commentDelegator = poll.getCommentDelegator();
- try {
- Comment comment = commentDelegator.createComment(replyUser,
- replyBody);
- comment.setCreationDate(replyDate);
- comment.setModificationDate(replyDate);
+ commentDelegator.addComment(comment);
- commentDelegator.addComment(comment);
+ nukesForumsMappingDAO.savePostMapping(reply.getPostID(), (poll
+ .getID() * -1));
- nukesForumsMappingDAO.savePostMapping(reply.getPostID(), (poll
- .getID() * -1));
+ // add activity
+ ActivityBean activity = createActivity(poll, community, comment
+ .getUser(), Activity.Type.commented, comment
+ .getCreationDate());
- // add activity
- ActivityBean activity = createActivity(poll, community, comment
- .getUser(), Activity.Type.commented, comment
- .getCreationDate());
-
- activitiesFromMigration.add(activity);
- } catch (RejectedException e) {
- throw new RuntimeException("Cannot create poll comment", e);
+ activitiesFromMigration.add(activity);
+ } catch (RejectedException e) {
+ throw new RuntimeException("Cannot create poll comment", e);
+ }
}
+ postsCount++;
}
- postsCount++;
- }
- if (!topic.isContainsPoll() && topic.getViewCount() > 0) {
- viewCountManager.clearCount(thread);
- viewCountDAO.insertViewCount(JiveConstants.THREAD, thread.getID(),
- community.getID(), topic.getViewCount());
+ if (!topic.isContainsPoll() && topic.getViewCount() > 0) {
+ viewCountManager.clearCount(thread);
+ viewCountDAO.insertViewCount(JiveConstants.THREAD, thread.getID(),
+ community.getID(), topic.getViewCount());
+ }
+ migrateTopicWatches(topic.getTopicID(), thread);
+ topicsCount++;
+ } catch (Exception e) {
+ log.error("Some unexpected error occur. "
+ + "Going to next topic. topic_id" + forumID, e);
+ failedTopics++;
}
-
- migrateTopicWatches(topic.getTopicID(), thread);
-
- topicsCount++;
}
migrateForumWatches(forumID, community);
@@ -480,8 +507,10 @@
final long timeConsumed = (System.currentTimeMillis() - start) / 1000;
log.error("INFO: Migration completed, time taken: " + (long) timeConsumed
/ 60 + " minutes.");
+ log.error("INFO: Count of topics migrated: " + topicsCount);
log.error("INFO: Count of posts migrated: " + postsCount);
- log.error("INFO: Count of topics migrated: " + topicsCount);
+ log.error("INFO: Count of failed posts due to their inconsistency: "
+ + failedTopics);
log.error("INFO: New users created: " + newUsersCount);
return result;
@@ -494,10 +523,12 @@
* @param topicPost
* @param user
* @param jiveContainer
+ * @return true if announcement was successfully created if some error occur
+ * then false
* @throws UnauthorizedException
* @throws RejectedException
*/
- private void createAnnouncement(NukesForumsTopicBean topic,
+ private boolean createAnnouncement(NukesForumsTopicBean topic,
NukesForumsPostBean topicPost, User user, JiveContainer jiveContainer)
throws UnauthorizedException, RejectedException {
Announcement announcement = announcementManager.createAnnouncement(user,
@@ -510,7 +541,7 @@
log.error("Cannot parse topic body for announcement. "
+ "Going to next topic. topic_id: " + topic.getTopicID());
log.error("Topic body: " + topicPost.getBody());
- return;
+ return false;
}
announcement.setBody(topicBody);
announcement.setStartDate(topicPost.getTime());
@@ -528,6 +559,7 @@
}
announcementManager.addAnnouncement(announcement);
+ return true;
}
private ForumThread createForumThread(Community community,
@@ -655,6 +687,8 @@
} catch (UserNotFoundException e) {
log.error("Unknown user for watching forum " + forumID + " username: "
+ username + ". Ommiting this watch.");
+ } catch (Exception e) {
+ log.error("Some unexpected exception. Going to next forum watch", e);
}
}
}
More information about the jboss-svn-commits
mailing list