1 11 package org.jboss.portlet.forums.commands.post; 12 13 14 import org.jboss.portal.common.command.result.Result; 15 import org.jboss.portal.common.command.result.SimpleResult; 16 import org.jboss.portal.core.modules.ModuleException; 17 import org.jboss.portlet.forums.commands.ValidationException; 18 import org.jboss.portlet.forums.model.Post; 19 import org.jboss.portlet.forums.model.AuthType; 20 import org.jboss.portlet.JBossActionRequest; 21 import org.jboss.portlet.JBossActionResponse; 22 23 27 public class DeletePostCommand 28 extends PostCommand 29 { 30 31 public boolean pd_first_post; 32 33 34 public boolean pd_last_post; 35 36 public DeletePostCommand(JBossActionRequest request, JBossActionResponse response) 37 { 38 super(request, response); 39 } 40 41 46 public int authType() 47 { 48 return AuthType.DELETE; 49 } 50 51 56 protected void prepare() 57 throws ValidationException 58 { 59 60 super.prepare(); 61 71 pd_first_post = topic.getFirstPost().getID() == post.getID(); 72 pd_last_post = topic.getLastPost().getID() == post.getID(); 73 74 } 75 76 81 protected Result __execute() 82 { 83 try 84 { 85 Integer postId = post.getID(); 86 if (pd_last_post && pd_first_post) 87 { 88 forumsModule.removeTopic(post.getTopic()); 94 forum.setPostCount(forum.getPostCount() - 1); 95 forum.setTopicCount(forum.getTopicCount() - 1); 96 forum.setLastPost(forumsModule.findLastPost(forum)); 97 } 98 else 99 { 100 forumsModule.removePost(post); 101 topic.setReplies(topic.getReplies() - 1); 102 forum.setPostCount(forum.getPostCount() - 1); 103 if (pd_first_post) 104 { 105 topic.setFirstPost(forumsModule.findFirstPost(topic)); 106 } 107 else if (pd_last_post) 108 { 109 Post lastPost = forumsModule.findLastPost(topic); 110 topic.setLastPost(lastPost); 111 topic.setLastPostDate(lastPost.getCreateDate()); 112 forum.setLastPost(forumsModule.findLastPost(topic)); 113 } 114 } 115 SimpleResult result = new SimpleResult(TYPE_POST_DELETED); 116 result.put("POST_ID", postId); 117 return result; 118 } 119 catch(ModuleException e) 120 { 121 log.error("Error in removing post", e); 122 return TYPE_ERROR_IN_DELETING_POST; 123 } 124 } 125 } | Popular Tags |