Salome HOME
10156f5b71f4f1e843fdd73012b9eb72b7ed2397
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / CopyStudyAction.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   19.03.2013
6  * @author         $Author$
7  * @version        $Revision$
8  * @copyright      OPEN CASCADE 2012-2014
9  *****************************************************************************/
10
11 package org.splat.simer;
12
13 import java.io.IOException;
14 import java.util.LinkedHashMap;
15 import java.util.List;
16 import java.util.Map;
17
18 import org.splat.exception.BusinessException;
19 import org.splat.service.SearchService;
20 import org.splat.service.dto.Proxy;
21 import org.splat.service.dto.ScenarioDTO;
22 import org.splat.service.dto.StudySearchFilterDTO;
23 import org.splat.service.technical.ProjectSettingsService;
24 import org.splat.service.technical.StepsConfigService;
25
26 /**
27  * Create a new study from existing one.
28  * 
29  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
30  */
31 public class CopyStudyAction extends NewStudyAction {
32         /**
33          * Serial version ID.
34          */
35         private static final long serialVersionUID = -3733439553634251282L;
36         /**
37          * List of source studies.
38          */
39         private transient final Map<Long, String> _studies = new LinkedHashMap<Long, String>();
40         /**
41          * List of the selected source study scenarios.
42          */
43         private transient final Map<Long, String> _scenarios = new LinkedHashMap<Long, String>();
44         /**
45          * List of source studies steps.
46          */
47         private transient final Map<Integer, String> _steps = new LinkedHashMap<Integer, String>();
48         /**
49          * The selected source study id.
50          */
51         private long _fromStudyId = 0;
52         /**
53          * The selected source scenario id.
54          */
55         private long _fromScenarioId = 0;
56
57         /**
58          * The selected source study id.
59          */
60         private int _finalStep = 0;
61         /**
62          * Injected search service.
63          */
64         private SearchService _searchService;
65         /**
66          * Injected StepsConfigService service.
67          */
68         private StepsConfigService _stepsConfigService;
69
70         /**
71          * {@inheritDoc}
72          * 
73          * @throws IOException
74          * 
75          * @see org.splat.simer.NewStudyAction#doCreate()
76          */
77         @Override
78         public String doCreate() throws BusinessException, IOException {
79                 String res = super.doCreate();
80                 if (SUCCESS.equals(res)) {
81                         // Copy content from the selected study
82                         getScenarioService().copyStudyContent(_fromStudyId,
83                                         _fromScenarioId, _finalStep, getOpenStudy().getIndex());
84                 } else {
85                         doInitialize();
86                 }
87                 return res;
88         }
89
90         /**
91          * {@inheritDoc}
92          * 
93          * @see org.splat.simer.NewStudyAction#doInitialize()
94          */
95         @Override
96         public String doInitialize() {
97                 // Initialize contexts list, study title and menus.
98                 super.doInitialize();
99
100                 // Initialize source studies list, scenarios list and steps list
101
102                 // Get visible studies
103                 StudySearchFilterDTO filter = new StudySearchFilterDTO();
104                 if (getConnectedUser() != null) {
105                         filter.setConnectedUserId(getConnectedUser().getIndex());
106                 }
107                 List<Proxy> studies = getSearchService().selectStudiesWhere(filter);
108
109                 // Fill the studies list
110                 _studies.put(null, "");
111                 for (Proxy study : studies) {
112                         _studies.put(study.getIndex(), study.getTitle());
113                 }
114
115                 // Fill lists of scenarios and steps according to the selected study
116                 if (_fromStudyId > 0 && _studies.containsKey(_fromStudyId)) {
117                         // Get scenarios from the selected study
118                         List<ScenarioDTO> scens = getScenarioService().getStudyScenarios(
119                                         _fromStudyId);
120                         for (ScenarioDTO scen : scens) {
121                                 _scenarios.put(scen.getIndex(), scen.getTitle());
122                         }
123                         // Fill steps
124                         for (ProjectSettingsService.Step step : getStepsConfigService()
125                                         .getSteps()) {
126                                 _steps.put(step.getNumber(),
127                                                 getText("folder.step." + step.getNumber()));
128                         }
129                 }
130
131                 return SUCCESS;
132         }
133
134         /**
135          * Get the studies.
136          * 
137          * @return the studies
138          */
139         public Map<Long, String> getStudies() {
140                 return _studies;
141         }
142
143         /**
144          * Get the searchService.
145          * 
146          * @return the searchService
147          */
148         public SearchService getSearchService() {
149                 return _searchService;
150         }
151
152         /**
153          * Set the searchService.
154          * 
155          * @param searchService
156          *            the searchService to set
157          */
158         public void setSearchService(final SearchService searchService) {
159                 _searchService = searchService;
160         }
161
162         /**
163          * Get the scenarios.
164          * 
165          * @return the scenarios
166          */
167         public Map<Long, String> getScenarios() {
168                 return _scenarios;
169         }
170
171         /**
172          * Get the steps.
173          * 
174          * @return the steps
175          */
176         public Map<Integer, String> getSteps() {
177                 return _steps;
178         }
179
180         /**
181          * Get the fromStudyId.
182          * 
183          * @return the fromStudyId
184          */
185         public long getFromStudyId() {
186                 return _fromStudyId;
187         }
188
189         /**
190          * Set the fromStudyId.
191          * 
192          * @param fromStudyId
193          *            the fromStudyId to set
194          */
195         public void setFromStudyId(final long fromStudyId) {
196                 _fromStudyId = fromStudyId;
197         }
198
199         /**
200          * Get the stepsConfigService.
201          * 
202          * @return the stepsConfigService
203          */
204         public StepsConfigService getStepsConfigService() {
205                 return _stepsConfigService;
206         }
207
208         /**
209          * Set the stepsConfigService.
210          * 
211          * @param stepsConfigService
212          *            the stepsConfigService to set
213          */
214         public void setStepsConfigService(
215                         final StepsConfigService stepsConfigService) {
216                 _stepsConfigService = stepsConfigService;
217         }
218
219         /**
220          * Get the fromScenarioId.
221          * 
222          * @return the fromScenarioId
223          */
224         public long getFromScenarioId() {
225                 return _fromScenarioId;
226         }
227
228         /**
229          * Set the fromScenarioId.
230          * 
231          * @param fromScenarioId
232          *            the fromScenarioId to set
233          */
234         public void setFromScenarioId(final long fromScenarioId) {
235                 _fromScenarioId = fromScenarioId;
236         }
237
238         /**
239          * Get the finalStep.
240          * 
241          * @return the finalStep
242          */
243         public int getFinalStep() {
244                 return _finalStep;
245         }
246
247         /**
248          * Set the finalStep.
249          * 
250          * @param finalStep
251          *            the finalStep to set
252          */
253         public void setFinalStep(final int finalStep) {
254                 _finalStep = finalStep;
255         }
256 }