KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > commands > post > DeletePostCommand


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Forums JBoss Portlet *
6  * *
7  * Distributable under GPL license. *
8  * See terms of license at gnu.org. *
9  * *
10  *****************************************/

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 /**
24  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
25  * @version $Revision: 1.5 $
26  */

27 public class DeletePostCommand
28    extends PostCommand
29 {
30    /** DOCUMENT_ME */
31    public boolean pd_first_post;
32
33    /** DOCUMENT_ME */
34    public boolean pd_last_post;
35
36    public DeletePostCommand(JBossActionRequest request, JBossActionResponse response)
37    {
38       super(request, response);
39    }
40
41    /**
42     * DOCUMENT_ME
43     *
44     * @return DOCUMENT_ME
45     */

46    public int authType()
47    {
48       return AuthType.DELETE;
49    }
50
51    /**
52     * DOCUMENT_ME
53     *
54     * @throws ValidationException DOCUMENT_ME
55     */

56    protected void prepare()
57    throws ValidationException
58    {
59       
60          super.prepare();
61 /*
62          if (!isAuthMod && !EJB.areIdentical(post..getPoster().getUser(), getPoster().getUser()))
63          {
64             throw new ValidationException(TYPE_CANNOT_XXX_OTHER_POST_WHEN_NOT_MODERATOR);
65          }
66          if (!pd_last_post && !isAuthMod)
67          {
68             throw new ValidationException(TYPE_CANNOT_DELETE_REPLIED);
69          }
70 */

71          pd_first_post = topic.getFirstPost().getID() == post.getID();
72          pd_last_post = topic.getLastPost().getID() == post.getID();
73        
74    }
75
76    /**
77     * DOCUMENT_ME
78     *
79     * @return DOCUMENT_ME
80     */

81    protected Result __execute()
82    {
83          try
84          {
85             Integer JavaDoc postId = post.getID();
86             if (pd_last_post && pd_first_post)
87             {
88                // cascade delete will take care of removing
89
// the post
90
// the watches
91
// the poll
92
// the links
93
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