Salome HOME
Show and Edit comments functionalities are implemented
[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
14 import org.splat.exception.InvalidParameterException;
15 import org.splat.service.dto.StepCommentDTO;
16 /**
17  * Step comment creation/modification action.
18  *
19  */
20 public class EditStepCommentAction extends DisplayStudyStepAction {
21
22         /**
23          * Serial version ID.
24          */
25         private static final long serialVersionUID = 6467920934724352021L;
26
27         /**
28          * The value of the comment.
29          */
30         private String _commentValue;
31
32         /**
33          * The title of the comment.
34          */
35         private String _commentTitle;
36
37         // ==============================================================================================================================
38         // Action methods
39         // ==============================================================================================================================
40
41         /**
42          * Creation of a new comment.
43          * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
44          */
45         public String doCreate() {
46                 String res = INPUT;
47                 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()
48                                 && _commentValue!=null  && _commentValue.length()>0
49                                 && _commentTitle!=null  && _commentTitle.length()>0) {
50
51                         StepCommentDTO stepCommentDTO = new StepCommentDTO(
52                                         null,   //id must be null
53                                         _commentValue,
54                                         getOpenStudy().getSelectedStep().getOwner().getIndex(),
55                                         getOpenStudy().getSelectedStep().getNumber(),
56                                         new Date(),     //current date and time
57                                         getConnectedUser().getRid(),
58                                         null,   //userName is unnecessary
59                                         _commentTitle
60                                 );
61                         try {
62                                 getStepService().addStepComment(stepCommentDTO);
63                                 res = SUCCESS;
64                         } catch (InvalidParameterException error) {
65                                 LOG.debug("Error while trying to add comment: " + error.getMessage());
66                                 res = INPUT;
67                         }
68                 }
69                 loadComments();
70                 return res;
71         }
72
73         /**
74          * Get the commentValue.
75          * @return the commentValue
76          */
77         public String getCommentValue() {
78                 return _commentValue;
79         }
80
81         /**
82          * Set the commentValue.
83          * @param commentValue the commentValue to set
84          */
85         public void setCommentValue(final String commentValue) {
86                 _commentValue = commentValue;
87         }
88
89         /**
90          * Get the commentTitle.
91          * @return the commentTitle
92          */
93         public String getCommentTitle() {
94                 return _commentTitle;
95         }
96
97         /**
98          * Set the commentTitle.
99          * @param commentTitle the commentTitle to set
100          */
101         public void setCommentTitle(final String commentTitle) {
102                 _commentTitle = commentTitle;
103         }
104 }