]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/NewStudyAction.java
Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / NewStudyAction.java
1 package org.splat.simer;
2
3 import java.util.List;
4 import java.util.ResourceBundle;
5
6 import org.splat.dal.bo.som.Scenario;
7 import org.splat.dal.bo.som.SimulationContext;
8 import org.splat.dal.bo.som.SimulationContextType;
9 import org.splat.dal.bo.som.Study;
10 import org.splat.service.ScenarioService;
11 import org.splat.service.SimulationContextService;
12 import org.splat.service.StudyService;
13
14 public class NewStudyAction extends Action {
15
16         private String title = null;
17         private List<SimulationContext> contelm = null;
18         private String context = null;
19
20         private static int number = 0;
21         /**
22          * Serial version ID.
23          */
24         private static final long serialVersionUID = 693943641800113782L;
25
26         /**
27          * The injected Study service.
28          */
29         private StudyService _studyService;
30         private SimulationContextService _simulationContextService;
31         /**
32          * Injected scenario service.
33          */
34         private ScenarioService _scenarioService;
35
36         // ==============================================================================================================================
37         // Action methods
38         // ==============================================================================================================================
39
40         // Fill the values of the drop-down list.
41         public String doInitialize() {
42
43                 // get the list of the simulation contexts of the study
44                 contelm = getSimulationContextService().getSimulationContextList();
45
46                 // set the default name of the new study
47                 ResourceBundle locale = ResourceBundle.getBundle("labels",
48                                 ApplicationSettings.getCurrentLocale());
49                 title = locale.getString("label.study") + " "
50                                 + String.valueOf(number + 1);
51
52                 return SUCCESS;
53         }
54
55         public String doCreate() throws Exception {
56                 String[] input = context.split(",");
57                 int valid = Integer.valueOf(input[0]);
58                 String value = ""; // input[1] if exists
59
60                 Study.Properties sprop = new Study.Properties();
61
62                 // Check arguments and creation of the study
63                 try {
64                         if (valid == -1)
65                                 throw new Exception();
66                         if (valid == 0) {
67                                 value = input[1].trim();
68                                 if (value.length() == 0)
69                                         return INPUT; // No need to reinitialize the list of existing products
70                         }
71                         sprop.setTitle(title).setManager(getConnectedUser());
72                         sprop.checkValidity();
73                         sprop.disableCheck();
74                 } catch (Exception error) {
75                         SimulationContext.Properties cprop = new SimulationContext.Properties();
76                         SimulationContextType product = getSimulationContextService()
77                                         .selectType("product");
78                         contelm = getSimulationContextService()
79                                         .selectSimulationContextsWhere(cprop.setType(product));
80                         return INPUT; // Title empty, simply wait for input without error message
81                 }
82                 try {
83                         Study study = getStudyService().createStudy(sprop);
84
85                         // Addition of a default scenario
86                         ResourceBundle locale = ResourceBundle.getBundle("labels",
87                                         ApplicationSettings.getCurrentLocale());
88                         Scenario.Properties oprop = new Scenario.Properties();
89                         oprop.setTitle(locale.getString("label.scenario") + " 1");
90                         getScenarioService().addScenario(study, oprop);
91
92                         // Addition of the entered project context
93                         if (valid == 0) { // Input of new project context
94                                 SimulationContext.Properties cprop = new SimulationContext.Properties();
95                                 cprop.setType(
96                                                 getSimulationContextService().selectType("product"))
97                                                 .setValue(value);
98                                 getStudyService().addProjectContext(study, cprop);
99                         } else { // Selection of existing project context
100                                 SimulationContext context = getSimulationContextService()
101                                                 .selectSimulationContext(valid);
102                                 getStudyService().addProjectContext(study, context);
103                         }
104                         // Update of the session
105                         number += 1;
106                         open(study); // Opens the study,
107                         return SUCCESS;
108                 } catch (Exception error) {
109                         logger.error("Unable to save the study, reason:", error);
110                         return ERROR;
111                 }
112         }
113
114         // ==============================================================================================================================
115         // Getters and setters
116         // ==============================================================================================================================
117
118         public String getProjectContext() {
119                 // ----------------------------------
120                 return context;
121         }
122
123         public List<SimulationContext> getProjectContextValues() {
124                 // ---------------------------------------------------------
125                 return contelm;
126         }
127
128         public String getTitle() {
129                 // ----------------------------
130                 return title;
131         }
132
133         public void setProjectContext(String value) {
134                 // --------------------------------------------
135                 this.context = value;
136         }
137
138         public void setTitle(String value) {
139                 // -----------------------------------
140                 this.title = value;
141         }
142
143         /**
144          * Get the studyService.
145          * 
146          * @return the studyService
147          */
148         public StudyService getStudyService() {
149                 return _studyService;
150         }
151
152         /**
153          * Set the studyService.
154          * 
155          * @param studyService
156          *            the studyService to set
157          */
158         public void setStudyService(StudyService studyService) {
159                 _studyService = studyService;
160         }
161
162         /**
163          * Get the simulationContextService.
164          * 
165          * @return the simulationContextService
166          */
167         public SimulationContextService getSimulationContextService() {
168                 return _simulationContextService;
169         }
170
171         /**
172          * Set the simulationContextService.
173          * 
174          * @param simulationContextService
175          *            the simulationContextService to set
176          */
177         public void setSimulationContextService(
178                         SimulationContextService simulationContextService) {
179                 _simulationContextService = simulationContextService;
180         }
181
182         /**
183          * Get the scenarioService.
184          * @return the scenarioService
185          */
186         public ScenarioService getScenarioService() {
187                 return _scenarioService;
188         }
189
190         /**
191          * Set the scenarioService.
192          * @param scenarioService the scenarioService to set
193          */
194         public void setScenarioService(ScenarioService scenarioService) {
195                 _scenarioService = scenarioService;
196         }
197 }