1 /*****************************************************************************
5 * Creation date Nov 21, 2012
8 *****************************************************************************/
10 package org.splat.simer;
12 import java.util.Date;
13 import java.util.List;
15 import org.splat.exception.InvalidParameterException;
16 import org.splat.service.StepService;
17 import org.splat.service.dto.StepCommentDTO;
18 import org.splat.wapp.PopupMenu;
20 * Step comment creation/modification action.
23 public class EditStepCommentAction extends DisplayStudyStepAction {
28 private static final long serialVersionUID = 6467920934724352021L;
33 private List<StepCommentDTO> _comments = null;
36 * The value of the comment.
38 private String _commentValue;
41 * The value of the comment.
43 private String _commentToEditValue;
46 * The title of the comment.
48 private String _commentTitle;
53 private Long _commentId;
58 private transient PopupMenu _commentPopup = null;
61 * Injected Step Service.
63 private StepService _stepService;
65 // ==============================================================================================================================
67 // ==============================================================================================================================
70 * Display step comments.
73 public String doDisplayComments() {
75 _comments = getStepService().getStepComments(getOpenStudy().getSelectedStep());
76 _commentPopup = getApplicationSettings().getPopupMenu("comment");
78 for(StepCommentDTO comment : _comments) {
79 comment.getUser().setDisplayName(
80 comment.getUser().getDisplayName());
82 } catch(InvalidParameterException exception) {
84 LOG.debug("Error while trying to load comments: " + exception.getMessage());
90 * Creation of a new comment.
93 public String doCreate() {
94 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()
95 && _commentValue!=null && _commentValue.length()>0
96 && _commentTitle!=null && _commentTitle.length()>0) {
98 StepCommentDTO stepCommentDTO = new StepCommentDTO(
99 null, //id must be null
101 getOpenStudy().getSelectedStep().getOwner().getIndex(),
102 getOpenStudy().getSelectedStep().getNumber(),
103 new Date(), //current date and time
104 getConnectedUser().getRid(),
105 null, //userName is unnecessary
109 getStepService().addStepComment(stepCommentDTO);
110 } catch (InvalidParameterException error) {
111 LOG.debug("Error while trying to add comment: " + error.getMessage());
122 public String doEdit() {
124 if(_stepService.isCommentMadeByUser(_commentId, getConnectedUser().getIndex())) {
125 getStepService().editStepComment(_commentId, _commentToEditValue, _commentTitle);
127 } catch(InvalidParameterException error) {
128 LOG.debug("Error while trying to remove comment: " + error.getMessage());
135 * Removal of a comment.
138 public String doRemove() {
140 if(_stepService.isCommentMadeByUser(_commentId, getConnectedUser().getIndex())) {
141 getStepService().removeStepComment(_commentId);
143 } catch(InvalidParameterException error) {
144 LOG.debug("Error while trying to remove comment: " + error.getMessage());
151 * Get the commentValue.
152 * @return the commentValue
154 public String getCommentValue() {
155 return _commentValue;
159 * Set the commentValue.
160 * @param commentValue the commentValue to set
162 public void setCommentValue(final String commentValue) {
163 _commentValue = commentValue;
167 * Get the commentTitle.
168 * @return the commentTitle
170 public String getCommentTitle() {
171 return _commentTitle;
175 * Set the commentTitle.
176 * @param commentTitle the commentTitle to set
178 public void setCommentTitle(final String commentTitle) {
179 _commentTitle = commentTitle;
184 * @return the comments
186 public List<StepCommentDTO> getComments() {
192 * @param comments the comments to set
194 public void setComments(final List<StepCommentDTO> comments) {
195 _comments = comments;
199 * Get the stepService.
200 * @return the stepService
202 public StepService getStepService() {
207 * Set the stepService.
208 * @param stepService the stepService to set
210 public void setStepService(final StepService stepService) {
211 _stepService = stepService;
215 * Get the commentPopup. Should have this exact name since it is used in menupopup.jsp.
216 * @return the commentPopup
219 public PopupMenu getPopup() {
220 return _commentPopup;
225 * @return the commentId
227 public Long getCommentId() {
233 * @param commentId the commentId to set
235 public void setCommentId(final Long commentId) {
236 _commentId = commentId;
240 * Get the commentToEditValue.
241 * @return the commentToEditValue
243 public String getCommentToEditValue() {
244 return _commentToEditValue;
248 * Set the commentToEditValue.
249 * @param commentToEditValue the commentToEditValue to set
251 public void setCommentToEditValue(final String commentToEditValue) {
252 _commentToEditValue = commentToEditValue;