root/head/ambra/webapp/src/main/java/org/topazproject/ambra/annotation/action/CreateReplyAction.java @ 6940

Revision 6940, 4.2 KB (checked in by dragisak, 21 months ago)

Get rid of static calls to AmbraUser?.geCurrentUser(). Remove dependency on servlet session from POJO's.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id HeadURL Revision
Line 
1/* $HeadURL::                                                                            $
2 * $Id:CreateReplyAction.java 722 2006-10-02 16:42:45Z viru $
3 *
4 * Copyright (c) 2006-2007 by Topaz, Inc.
5 * http://topazproject.org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.topazproject.ambra.annotation.action;
20
21import java.util.List;
22
23import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
25import org.springframework.beans.factory.annotation.Required;
26import org.springframework.transaction.annotation.Transactional;
27import org.springframework.transaction.interceptor.TransactionAspectSupport;
28import org.topazproject.ambra.action.BaseSessionAwareActionSupport;
29import org.topazproject.ambra.annotation.service.ReplyService;
30import org.topazproject.ambra.util.ProfanityCheckingService;
31import org.topazproject.ambra.user.AmbraUser;
32
33import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
34
35/**
36 * Action for creating a reply.
37 */
38@SuppressWarnings("serial")
39public class CreateReplyAction extends BaseSessionAwareActionSupport {
40  private String replyId;
41  private String root;
42  private String inReplyTo;
43  private String commentTitle;
44  private String mimeType = "text/plain";
45  private String comment;
46
47  private ProfanityCheckingService profanityCheckingService;
48  protected ReplyService replyService;
49
50  private static final Log log = LogFactory.getLog(CreateReplyAction.class);
51
52  @Transactional(rollbackFor = { Throwable.class })
53  @Override
54  public String execute() throws Exception {
55    try {
56      final List<String> profaneWordsInTitle = profanityCheckingService.validate(commentTitle);
57      final List<String> profaneWordsInBody = profanityCheckingService.validate(comment);
58
59      if (profaneWordsInBody.isEmpty() && profaneWordsInTitle.isEmpty()) {
60        replyId = replyService.createReply(root, inReplyTo, commentTitle, mimeType, comment, getCurrentUser());
61      } else {
62        addProfaneMessages(profaneWordsInBody, "comment", "comment");
63        addProfaneMessages(profaneWordsInTitle, "commentTitle", "title");
64        return INPUT;
65      }
66    } catch (Exception e) {
67      log.error("Could not create reply to root: " + root + " and inReplyTo: " + inReplyTo, e);
68      addActionError("Reply creation failed with error message: " + e.getMessage());
69      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
70      return ERROR;
71    }
72    addActionMessage("Reply created with id:" + replyId);
73
74    return SUCCESS;
75  }
76
77  public String getReplyId() {
78    return replyId;
79  }
80
81  public void setRoot(final String root) {
82    this.root = root;
83  }
84
85  public void setInReplyTo(final String inReplyTo) {
86    this.inReplyTo = inReplyTo;
87  }
88
89  public void setCommentTitle(final String commentTitle) {
90    this.commentTitle = commentTitle;
91  }
92
93  public void setMimeType(final String mimeType) {
94    this.mimeType = mimeType;
95  }
96
97  public void setComment(final String comment) {
98    this.comment = comment;
99  }
100
101  @RequiredStringValidator(message = "The annotation id to which it applies is required")
102  public String getRoot() {
103    return root;
104  }
105
106  @RequiredStringValidator(message = "The annotation/reply id to which it applies is required")
107  public String getInReplyTo() {
108    return inReplyTo;
109  }
110
111  @RequiredStringValidator(message = "A title is required")
112  public String getCommentTitle() {
113  return commentTitle;
114  }
115
116  @RequiredStringValidator(message = "A reply is required")
117  public String getComment() {
118  return comment;
119  }
120
121  public void setProfanityCheckingService(final ProfanityCheckingService profanityCheckingService) {
122    this.profanityCheckingService = profanityCheckingService;
123  }
124
125  @Required
126  public void setReplyService(final ReplyService replyService) {
127    this.replyService = replyService;
128  }
129}
Note: See TracBrowser for help on using the browser.