| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | package org.topazproject.ambra.annotation.action; |
|---|
| 20 | |
|---|
| 21 | import java.util.List; |
|---|
| 22 | |
|---|
| 23 | import org.apache.commons.logging.Log; |
|---|
| 24 | import org.apache.commons.logging.LogFactory; |
|---|
| 25 | import org.springframework.beans.factory.annotation.Required; |
|---|
| 26 | import org.springframework.transaction.annotation.Transactional; |
|---|
| 27 | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|---|
| 28 | import org.topazproject.ambra.action.BaseSessionAwareActionSupport; |
|---|
| 29 | import org.topazproject.ambra.annotation.service.ReplyService; |
|---|
| 30 | import org.topazproject.ambra.util.ProfanityCheckingService; |
|---|
| 31 | import org.topazproject.ambra.user.AmbraUser; |
|---|
| 32 | |
|---|
| 33 | import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | @SuppressWarnings("serial") |
|---|
| 39 | public 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 | } |
|---|