]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/EditStepCommentAction.java
Salome HOME
fix for issue: after versioning operation and import operation the comments are lost
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditStepCommentAction.java
1 /*****************************************************************************
2  * Company         EURIWARE
3  * Application     SIMAN
4  * File            $Id$
5  * Creation date   Nov 21, 2012
6  * @author         $Author$
7  * @version        $Revision$
8  *****************************************************************************/
9
10 package org.splat.simer;
11
12 import java.util.Date;
13 import java.util.List;
14
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;
19 /**
20  * Step comment creation/modification action.
21  *
22  */
23 public class EditStepCommentAction extends DisplayStudyStepAction {
24
25         /**
26          * Serial version ID.
27          */
28         private static final long serialVersionUID = 6467920934724352021L;
29
30         /**
31          * Step comments.
32          */
33         private List<StepCommentDTO> _comments = null;
34
35         /**
36          * The value of the comment.
37          */
38         private String _commentValue;
39
40         /**
41          * The value of the comment.
42          */
43         private String _commentToEditValue;
44
45         /**
46          * The title of the comment.
47          */
48         private String _commentTitle;
49
50         /**
51          * Step comment id.
52          */
53         private Long _commentId;
54         
55         /**
56          * Comment popup menu.
57          */
58         private transient PopupMenu _commentPopup = null;
59
60         /**
61          * Injected Step Service.
62          */
63         private StepService _stepService;
64
65         // ==============================================================================================================================
66         // Action methods
67         // ==============================================================================================================================
68
69         /**
70          * Display step comments.
71          * @return SUCCESS
72          */
73         public String doDisplayComments() {
74                 try {
75                         _comments = getStepService().getStepComments(getOpenStudy().getSelectedStep());
76                         _commentPopup = getApplicationSettings().getPopupMenu("comment");
77                         
78                         for(StepCommentDTO comment : _comments) {
79                                 comment.getUser().setDisplayName(
80                                                 comment.getUser().getDisplayName());
81                         }
82                 } catch(InvalidParameterException exception) {
83                         _comments = null;
84                         LOG.debug("Error while trying to load comments: " + exception.getMessage());
85                 }
86                 return SUCCESS;
87         }
88         
89         /**
90          * Creation of a new comment.
91          * @return SUCCESS
92          */
93         public String doCreate() {
94                 if ("true".equals(getWriteAccess())
95                                 && _commentValue!=null  && _commentValue.length()>0
96                                 && _commentTitle!=null  && _commentTitle.length()>0) {
97
98                         StepCommentDTO stepCommentDTO = new StepCommentDTO(
99                                         null,   //id must be null
100                                         _commentValue,
101                                         getOpenStudy().getSelectedStep().getOwner().getIndex(),
102                                         getOpenStudy().getSelectedStep().getNumber(),
103                                         new Date(),     //current date and time
104                                         getConnectedUser().getRid(),
105                                         null,   //userName is unnecessary
106                                         _commentTitle
107                                 );
108                         try {
109                                 getStepService().addStepComment(stepCommentDTO);
110                         } catch (InvalidParameterException error) {
111                                 LOG.debug("Error while trying to add comment: " + error.getMessage());
112                         }
113                 }
114                 doOpen();       //update all project elements, as comments are their attributes
115                 doDisplayComments();
116                 return SUCCESS;
117         }
118         
119         /**
120          * Edit a comment.
121          * @return SUCCESS
122          */
123         public String doEdit() {
124                 try {
125                         if(_stepService.isCommentMadeByUser(_commentId, getConnectedUser().getIndex())) {
126                                 getStepService().editStepComment(_commentId, _commentToEditValue, _commentTitle);
127                         }
128                 } catch(InvalidParameterException error) {
129                         LOG.debug("Error while trying to remove comment: " + error.getMessage());
130                 }
131                 doOpen();       //update all project elements, as comments are their attributes
132                 doDisplayComments();
133                 return SUCCESS;
134         }
135         
136         /**
137          * Removal of a comment.
138          * @return SUCCESS
139          */
140         public String doRemove() {
141                 try {
142                         if(_stepService.isCommentMadeByUser(_commentId, getConnectedUser().getIndex())) {
143                                 getStepService().removeStepComment(_commentId);
144                         }
145                 } catch(InvalidParameterException error) {
146                         LOG.debug("Error while trying to remove comment: " + error.getMessage());
147                 }
148                 doOpen();       //update all project elements, as comments are their attributes
149                 doDisplayComments();
150                 return SUCCESS;
151         }
152
153         /**
154          * Get the commentValue.
155          * @return the commentValue
156          */
157         public String getCommentValue() {
158                 return _commentValue;
159         }
160
161         /**
162          * Set the commentValue.
163          * @param commentValue the commentValue to set
164          */
165         public void setCommentValue(final String commentValue) {
166                 _commentValue = commentValue;
167         }
168
169         /**
170          * Get the commentTitle.
171          * @return the commentTitle
172          */
173         public String getCommentTitle() {
174                 return _commentTitle;
175         }
176
177         /**
178          * Set the commentTitle.
179          * @param commentTitle the commentTitle to set
180          */
181         public void setCommentTitle(final String commentTitle) {
182                 _commentTitle = commentTitle;
183         }
184
185         /**
186          * Get the comments.
187          * @return the comments
188          */
189         public List<StepCommentDTO> getComments() {
190                 return _comments;
191         }
192
193         /**
194          * Set the comments.
195          * @param comments the comments to set
196          */
197         public void setComments(final List<StepCommentDTO> comments) {
198                 _comments = comments;
199         }
200
201         /**
202          * Get the stepService.
203          * @return the stepService
204          */
205         public StepService getStepService() {
206                 return _stepService;
207         }
208
209         /**
210          * Set the stepService.
211          * @param stepService the stepService to set
212          */
213         public void setStepService(final StepService stepService) {
214                 _stepService = stepService;
215         }
216         
217         /**
218          * Get the commentPopup. Should have this exact name since it is used in menupopup.jsp.
219          * @return the commentPopup
220          */
221         @Override
222         public PopupMenu getPopup() {
223                 return _commentPopup;
224         }
225
226         /**
227          * Get the commentId.
228          * @return the commentId
229          */
230         public Long getCommentId() {
231                 return _commentId;
232         }
233
234         /**
235          * Set the commentId.
236          * @param commentId the commentId to set
237          */
238         public void setCommentId(final Long commentId) {
239                 _commentId = commentId;
240         }
241
242         /**
243          * Get the commentToEditValue.
244          * @return the commentToEditValue
245          */
246         public String getCommentToEditValue() {
247                 return _commentToEditValue;
248         }
249
250         /**
251          * Set the commentToEditValue.
252          * @param commentToEditValue the commentToEditValue to set
253          */
254         public void setCommentToEditValue(final String commentToEditValue) {
255                 _commentToEditValue = commentToEditValue;
256         }
257 }