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())
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());
114 doOpen(); //update all project elements, as comments are their attributes
123 public String doEdit() {
125 if(_stepService.isCommentMadeByUser(_commentId, getConnectedUser().getIndex())) {
126 getStepService().editStepComment(_commentId, _commentToEditValue, _commentTitle);
128 } catch(InvalidParameterException error) {
129 LOG.debug("Error while trying to remove comment: " + error.getMessage());
131 doOpen(); //update all project elements, as comments are their attributes
137 * Removal of a comment.
140 public String doRemove() {
142 if(_stepService.isCommentMadeByUser(_commentId, getConnectedUser().getIndex())) {
143 getStepService().removeStepComment(_commentId);
145 } catch(InvalidParameterException error) {
146 LOG.debug("Error while trying to remove comment: " + error.getMessage());
148 doOpen(); //update all project elements, as comments are their attributes
154 * Get the commentValue.
155 * @return the commentValue
157 public String getCommentValue() {
158 return _commentValue;
162 * Set the commentValue.
163 * @param commentValue the commentValue to set
165 public void setCommentValue(final String commentValue) {
166 _commentValue = commentValue;
170 * Get the commentTitle.
171 * @return the commentTitle
173 public String getCommentTitle() {
174 return _commentTitle;
178 * Set the commentTitle.
179 * @param commentTitle the commentTitle to set
181 public void setCommentTitle(final String commentTitle) {
182 _commentTitle = commentTitle;
187 * @return the comments
189 public List<StepCommentDTO> getComments() {
195 * @param comments the comments to set
197 public void setComments(final List<StepCommentDTO> comments) {
198 _comments = comments;
202 * Get the stepService.
203 * @return the stepService
205 public StepService getStepService() {
210 * Set the stepService.
211 * @param stepService the stepService to set
213 public void setStepService(final StepService stepService) {
214 _stepService = stepService;
218 * Get the commentPopup. Should have this exact name since it is used in menupopup.jsp.
219 * @return the commentPopup
222 public PopupMenu getPopup() {
223 return _commentPopup;
228 * @return the commentId
230 public Long getCommentId() {
236 * @param commentId the commentId to set
238 public void setCommentId(final Long commentId) {
239 _commentId = commentId;
243 * Get the commentToEditValue.
244 * @return the commentToEditValue
246 public String getCommentToEditValue() {
247 return _commentToEditValue;
251 * Set the commentToEditValue.
252 * @param commentToEditValue the commentToEditValue to set
254 public void setCommentToEditValue(final String commentToEditValue) {
255 _commentToEditValue = commentToEditValue;