1 /*****************************************************************************
5 * Creation date 19.03.2013
8 * @copyright OPEN CASCADE 2012
9 *****************************************************************************/
11 package org.splat.simer;
13 import java.util.LinkedHashMap;
14 import java.util.List;
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;
28 * Create a new study from existing one.
30 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
32 public class CopyStudyAction extends NewStudyAction {
36 private static final long serialVersionUID = -3733439553634251282L;
38 * List of source studies.
40 private transient final Map<Long, String> _studies = new LinkedHashMap<Long, String>();
42 * List of the selected source study scenarios.
44 private transient final Map<Long, String> _scenarios = new LinkedHashMap<Long, String>();
46 * List of source studies steps.
48 private transient final Map<Integer, String> _steps = new LinkedHashMap<Integer, String>();
50 * The selected source study id.
52 private long _fromStudyId = 0;
54 * Injected search service.
56 private SearchService _searchService;
58 * Injected StepsConfigService service.
60 private StepsConfigService _stepsConfigService;
65 * @see org.splat.simer.NewStudyAction#doCreate()
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
80 * @see org.splat.simer.NewStudyAction#doInitialize()
83 public String doInitialize() {
84 // Initialize contexts list, study title and menus.
87 // Initialize source studies list, scenarios list and steps list
89 // Get visible studies
90 StudySearchFilterDTO filter = new StudySearchFilterDTO();
91 if (getConnectedUser() != null) {
92 filter.setConnectedUserId(getConnectedUser().getIndex());
94 List<Proxy> studies = getSearchService().selectStudiesWhere(filter);
96 // Fill the studies list
97 for (Proxy study: studies) {
98 _studies.put(study.getIndex(), study.getTitle());
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());
109 for (ProjectSettingsService.Step step: getStepsConfigService().getSteps()) {
110 _steps.put(step.getNumber(), getText("folder.step." + step.getNumber()));
120 * @return the studies
122 public Map<Long, String> getStudies() {
127 * Get the searchService.
129 * @return the searchService
131 public SearchService getSearchService() {
132 return _searchService;
136 * Set the searchService.
138 * @param searchService
139 * the searchService to set
141 public void setSearchService(final SearchService searchService) {
142 _searchService = searchService;
148 * @return the scenarios
150 public Map<Long, String> getScenarios() {
159 public Map<Integer, String> getSteps() {
164 * Get the fromStudyId.
166 * @return the fromStudyId
168 public long getFromStudyId() {
173 * Set the fromStudyId.
176 * the fromStudyId to set
178 public void setFromStudyId(final long fromStudyId) {
179 _fromStudyId = fromStudyId;
183 * Get the stepsConfigService.
185 * @return the stepsConfigService
187 public StepsConfigService getStepsConfigService() {
188 return _stepsConfigService;
192 * Set the stepsConfigService.
194 * @param stepsConfigService
195 * the stepsConfigService to set
197 public void setStepsConfigService(
198 final StepsConfigService stepsConfigService) {
199 _stepsConfigService = stepsConfigService;