Salome HOME
Copyrights update 2015.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / CheckoutAction.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   02.12.2012
6  * @author         $Author$
7  * @version        $Revision$
8  * @copyright      OPEN CASCADE 2012-2015
9  *****************************************************************************/
10
11 package org.splat.simer;
12
13 import org.splat.exception.BusinessException;
14 import org.splat.log.AppLogger;
15 import org.splat.service.ScenarioService;
16
17 import com.opensymphony.xwork2.ActionSupport;
18
19 /**
20  * Action to checkout a scenario.
21  * 
22  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
23  */
24 public class CheckoutAction extends ActionSupport {
25
26         /**
27          * Serialization version id.
28          */
29         private static final long serialVersionUID = 6140789360802711199L;
30
31         /**
32          * Action logger.
33          */
34         protected static final AppLogger LOG = AppLogger
35                         .getLogger(CheckoutAction.class);
36
37         /**
38          * Result message. If the scenario is successfully checked out then result is "true", otherwise it contains the error message.
39          */
40         private String _result;
41         /**
42          * Scenario id action parameter. Defines the scenario to check out.
43          */
44         private long _scenario;
45         /**
46          * User login name action parameter. Defines the user who performs check out.
47          */
48         private long _user;
49         /**
50          * Injected scenario service.
51          */
52         private ScenarioService _scenarioService;
53
54         /**
55          * Mark the currently selected scenario as checked out. If the scenario is successfully checked out then result is "true", otherwise it
56          * contains the error message.
57          * 
58          * @return SUCCESS
59          */
60         public String doCheckout() {
61                 try {
62                         getScenarioService().checkout(getScenario(), getUser());
63                         setResult("true");
64                 } catch (BusinessException e) {
65                         setResult(e.getMessage());
66                 }
67                 if (LOG.isDebugEnabled()) {
68                         LOG.debug("Can checkout scenario #" + getScenario()
69                                         + " by the user " + getUser() + ": " + getResult());
70                 }
71                 return SUCCESS;
72         }
73
74         /**
75          * Get the scenarioService.
76          * 
77          * @return the scenarioService
78          */
79         public ScenarioService getScenarioService() {
80                 return _scenarioService;
81         }
82
83         /**
84          * Set the scenarioService.
85          * 
86          * @param scenarioService
87          *            the scenarioService to set
88          */
89         public void setScenarioService(final ScenarioService scenarioService) {
90                 _scenarioService = scenarioService;
91         }
92
93         /**
94          * Result message. If the scenario is successfully checked out then result is "true", otherwise it contains the error message.
95          * 
96          * @return the result
97          */
98         public String getResult() {
99                 return _result;
100         }
101
102         /**
103          * Set the result.
104          * 
105          * @param result
106          *            the result to set
107          */
108         public void setResult(final String result) {
109                 _result = result;
110         }
111
112         /**
113          * Get the scenario.
114          * 
115          * @return the scenario
116          */
117         public long getScenario() {
118                 return _scenario;
119         }
120
121         /**
122          * Set the scenario.
123          * 
124          * @param scenario
125          *            the scenario to set
126          */
127         public void setScenario(final long scenario) {
128                 _scenario = scenario;
129         }
130
131         /**
132          * Get the user.
133          * 
134          * @return the user
135          */
136         public long getUser() {
137                 return _user;
138         }
139
140         /**
141          * Set the user.
142          * 
143          * @param user
144          *            the user to set
145          */
146         public void setUser(final long user) {
147                 _user = user;
148         }
149 }