1 /*****************************************************************************
5 * Creation date 19.03.2013
8 * @copyright OPEN CASCADE 2012-2014
9 *****************************************************************************/
11 package org.splat.simer;
13 import java.io.IOException;
14 import java.util.LinkedHashMap;
15 import java.util.List;
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;
27 * Create a new study from existing one.
29 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
31 public class CopyStudyAction extends NewStudyAction {
35 private static final long serialVersionUID = -3733439553634251282L;
37 * List of source studies.
39 private transient final Map<Long, String> _studies = new LinkedHashMap<Long, String>();
41 * List of the selected source study scenarios.
43 private transient final Map<Long, String> _scenarios = new LinkedHashMap<Long, String>();
45 * List of source studies steps.
47 private transient final Map<Integer, String> _steps = new LinkedHashMap<Integer, String>();
49 * The selected source study id.
51 private long _fromStudyId = 0;
53 * The selected source scenario id.
55 private long _fromScenarioId = 0;
58 * The selected source study id.
60 private int _finalStep = 0;
62 * Injected search service.
64 private SearchService _searchService;
66 * Injected StepsConfigService service.
68 private StepsConfigService _stepsConfigService;
75 * @see org.splat.simer.NewStudyAction#doCreate()
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());
93 * @see org.splat.simer.NewStudyAction#doInitialize()
96 public String doInitialize() {
97 // Initialize contexts list, study title and menus.
100 // Initialize source studies list, scenarios list and steps list
102 // Get visible studies
103 StudySearchFilterDTO filter = new StudySearchFilterDTO();
104 if (getConnectedUser() != null) {
105 filter.setConnectedUserId(getConnectedUser().getIndex());
107 List<Proxy> studies = getSearchService().selectStudiesWhere(filter);
109 // Fill the studies list
110 _studies.put(null, "");
111 for (Proxy study : studies) {
112 _studies.put(study.getIndex(), study.getTitle());
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(
120 for (ScenarioDTO scen : scens) {
121 _scenarios.put(scen.getIndex(), scen.getTitle());
124 for (ProjectSettingsService.Step step : getStepsConfigService()
126 _steps.put(step.getNumber(),
127 getText("folder.step." + step.getNumber()));
137 * @return the studies
139 public Map<Long, String> getStudies() {
144 * Get the searchService.
146 * @return the searchService
148 public SearchService getSearchService() {
149 return _searchService;
153 * Set the searchService.
155 * @param searchService
156 * the searchService to set
158 public void setSearchService(final SearchService searchService) {
159 _searchService = searchService;
165 * @return the scenarios
167 public Map<Long, String> getScenarios() {
176 public Map<Integer, String> getSteps() {
181 * Get the fromStudyId.
183 * @return the fromStudyId
185 public long getFromStudyId() {
190 * Set the fromStudyId.
193 * the fromStudyId to set
195 public void setFromStudyId(final long fromStudyId) {
196 _fromStudyId = fromStudyId;
200 * Get the stepsConfigService.
202 * @return the stepsConfigService
204 public StepsConfigService getStepsConfigService() {
205 return _stepsConfigService;
209 * Set the stepsConfigService.
211 * @param stepsConfigService
212 * the stepsConfigService to set
214 public void setStepsConfigService(
215 final StepsConfigService stepsConfigService) {
216 _stepsConfigService = stepsConfigService;
220 * Get the fromScenarioId.
222 * @return the fromScenarioId
224 public long getFromScenarioId() {
225 return _fromScenarioId;
229 * Set the fromScenarioId.
231 * @param fromScenarioId
232 * the fromScenarioId to set
234 public void setFromScenarioId(final long fromScenarioId) {
235 _fromScenarioId = fromScenarioId;
241 * @return the finalStep
243 public int getFinalStep() {
251 * the finalStep to set
253 public void setFinalStep(final int finalStep) {
254 _finalStep = finalStep;