Salome HOME
The draft of the "Copy from existing study" action is added. The YACS step is introdu...
[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
9  *****************************************************************************/
10
11 package org.splat.simer;
12
13 import java.util.LinkedHashMap;
14 import java.util.List;
15 import java.util.Map;
16
17 import org.splat.kernel.InvalidPropertyException;
18 import org.splat.kernel.MissedPropertyException;
19 import org.splat.kernel.MultiplyDefinedException;
20 import org.splat.service.SearchService;
21 import org.splat.service.dto.Proxy;
22 import org.splat.service.dto.ScenarioDTO;
23 import org.splat.service.dto.StudySearchFilterDTO;
24 import org.splat.service.technical.ProjectSettingsService;
25 import org.splat.service.technical.StepsConfigService;
26
27 /**
28  * Create a new study from existing one.
29  * 
30  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
31  */
32 public class CopyStudyAction extends NewStudyAction {
33         /**
34          * Serial version ID.
35          */
36         private static final long serialVersionUID = -3733439553634251282L;
37         /**
38          * List of source studies.
39          */
40         private transient final Map<Long, String> _studies = new LinkedHashMap<Long, String>();
41         /**
42          * List of the selected source study scenarios.
43          */
44         private transient final Map<Long, String> _scenarios = new LinkedHashMap<Long, String>();
45         /**
46          * List of source studies steps.
47          */
48         private transient final Map<Integer, String> _steps = new LinkedHashMap<Integer, String>();
49         /**
50          * The selected source study id.
51          */
52         private long _fromStudyId = 0;
53         /**
54          * Injected search service.
55          */
56         private SearchService _searchService;
57         /**
58          * Injected StepsConfigService service.
59          */
60         private StepsConfigService _stepsConfigService;
61
62         /**
63          * {@inheritDoc}
64          * 
65          * @see org.splat.simer.NewStudyAction#doCreate()
66          */
67         @Override
68         public String doCreate() throws InvalidPropertyException,
69                         MissedPropertyException, MultiplyDefinedException {
70                 String res = super.doCreate();
71                 if (SUCCESS.equals(res)) {
72                         // Copy content from the selected study
73                 }
74                 return res;
75         }
76
77         /**
78          * {@inheritDoc}
79          * 
80          * @see org.splat.simer.NewStudyAction#doInitialize()
81          */
82         @Override
83         public String doInitialize() {
84                 // Initialize contexts list, study title and menus.
85                 super.doInitialize();
86                 
87                 // Initialize source studies list, scenarios list and steps list
88                 
89                 // Get visible studies
90                 StudySearchFilterDTO filter = new StudySearchFilterDTO();
91                 if (getConnectedUser() != null) {
92                         filter.setConnectedUserId(getConnectedUser().getIndex());
93                 }
94                 List<Proxy> studies = getSearchService().selectStudiesWhere(filter);
95                 
96                 // Fill the studies list
97                 for (Proxy study: studies) {
98                         _studies.put(study.getIndex(), study.getTitle());
99                 }
100                 
101                 // Fill lists of scenarios and steps according to the selected study
102                 if (_fromStudyId > 0 && _studies.containsKey(_fromStudyId)) {
103                         // Get scenarios from the selected study
104                         List<ScenarioDTO> scens = getScenarioService().getStudyScenarios(_fromStudyId);
105                         for (ScenarioDTO scen: scens) {
106                                 _scenarios.put(scen.getIndex(), scen.getTitle());
107                         }
108                         // Fill steps
109                         for (ProjectSettingsService.Step step: getStepsConfigService().getSteps()) {
110                                 _steps.put(step.getNumber(), getText("folder.step." + step.getNumber()));
111                         }
112                 }
113
114                 return SUCCESS;
115         }
116
117         /**
118          * Get the studies.
119          * 
120          * @return the studies
121          */
122         public Map<Long, String> getStudies() {
123                 return _studies;
124         }
125
126         /**
127          * Get the searchService.
128          * 
129          * @return the searchService
130          */
131         public SearchService getSearchService() {
132                 return _searchService;
133         }
134
135         /**
136          * Set the searchService.
137          * 
138          * @param searchService
139          *            the searchService to set
140          */
141         public void setSearchService(final SearchService searchService) {
142                 _searchService = searchService;
143         }
144
145         /**
146          * Get the scenarios.
147          * 
148          * @return the scenarios
149          */
150         public Map<Long, String> getScenarios() {
151                 return _scenarios;
152         }
153
154         /**
155          * Get the steps.
156          * 
157          * @return the steps
158          */
159         public Map<Integer, String> getSteps() {
160                 return _steps;
161         }
162
163         /**
164          * Get the fromStudyId.
165          * 
166          * @return the fromStudyId
167          */
168         public long getFromStudyId() {
169                 return _fromStudyId;
170         }
171
172         /**
173          * Set the fromStudyId.
174          * 
175          * @param fromStudyId
176          *            the fromStudyId to set
177          */
178         public void setFromStudyId(final long fromStudyId) {
179                 _fromStudyId = fromStudyId;
180         }
181
182         /**
183          * Get the stepsConfigService.
184          * 
185          * @return the stepsConfigService
186          */
187         public StepsConfigService getStepsConfigService() {
188                 return _stepsConfigService;
189         }
190
191         /**
192          * Set the stepsConfigService.
193          * 
194          * @param stepsConfigService
195          *            the stepsConfigService to set
196          */
197         public void setStepsConfigService(
198                         final StepsConfigService stepsConfigService) {
199                 _stepsConfigService = stepsConfigService;
200         }
201 }