1 package org.splat.simer;
3 import org.splat.dal.bo.kernel.User;
4 import org.splat.dal.bo.som.KnowledgeElement;
5 import org.splat.dal.bo.som.KnowledgeElementType;
6 import org.splat.dal.bo.som.Scenario;
7 import org.splat.service.KnowledgeElementService;
8 import org.splat.service.KnowledgeElementTypeService;
9 import org.splat.service.ScenarioService;
10 import org.splat.som.Step;
13 * Action for addition and modification of knowledge elements in the selected scenario.
15 public class EditKnowledgeElementAction extends DisplayStudyStepAction {
20 private static final long serialVersionUID = 4636919137087687068L;
23 * Edited knowledge element type.
25 private String type = null; // Edited knowledge type
27 * Edited knowledge element title.
29 private String title = null;
31 * Edited knowledge element value.
33 private String value = null;
35 * Injected scenario service.
37 private ScenarioService _scenarioService;
39 * Injected knowledge element service.
41 private KnowledgeElementService _knowledgeElementService;
43 * Injected knowledge element type service.
45 private KnowledgeElementTypeService _knowledgeElementTypeService;
48 * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
50 private String _menuProperty;
53 * Value of the title bar property.
54 * It can be: study, knowledge.
56 private String _titleProperty;
59 * Property that indicates whether the current open study is editable or not.
60 * On the screen it looks like pen on the status icon, pop-up menu also can be called.
61 * It is necessary for correct building the title bar.
63 private String _editDisabledProperty = "false";
66 * Value of the tool bar property.
67 * It can be: none, standard, study, back.
69 private String _toolProperty;
72 * Value of the left menu property.
73 * It can be: open, study, knowledge, scenario.
75 private String _leftMenuProperty;
77 // ==============================================================================================================================
79 // ==============================================================================================================================
82 * Initialize the action. Get selected study from the session.
84 * @return SUCCESS if no exceptions
86 public String doInitialize() {
87 mystudy = getOpenStudy();
89 setMenuProperty("study");
90 setTitleProperty("study");
91 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
92 setToolProperty("study");
94 setToolProperty("standard");
96 setLeftMenuProperty("study");
97 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
103 * Add a new or update an existing knowledge element of the selected scenario in the open study.
105 * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
107 public String doSetKnowledge() {
109 setMenuProperty("study");
110 setTitleProperty("study");
111 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
112 setToolProperty("study");
114 setToolProperty("standard");
116 setLeftMenuProperty("study");
117 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
120 User user = getConnectedUser();
121 mystudy = getOpenStudy();
123 Step step = mystudy.getSelectedStep();
124 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
126 if (title != null && value != null) { // Addition of a new Knowledge Element
127 KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
128 KnowledgeElementType ktype = getKnowledgeElementTypeService()
129 .selectType(Integer.valueOf(type));
130 kprop.setType(ktype).setTitle(title).setValue(value).setAuthor(
132 mystudy.add(getScenarioService().addKnowledgeElement(scene,
134 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
135 } else if (title != null) { // Renaming of an existing Knowledge Element
136 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
138 getKnowledgeElementService().rename(kelm, title);
139 // Useless to update the open study
140 } else if (value != null) { // Edition of a knowledge
141 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
143 getKnowledgeElementService().update(kelm, value);
144 mystudy.update(kelm); // For updating the truncated value
147 } catch (RuntimeException saverror) {
148 logger.error("Reason:", saverror);
150 } catch (Exception error) {
151 logger.error("Exception while saving a knowledge: ", error);
157 * Delete a knowledge element from the current scenario.
159 * @return SUCCESS if no exceptions
161 public String doDeleteKnowledge() {
162 mystudy = getOpenStudy();
163 Step step = mystudy.getSelectedStep();
164 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
166 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
168 getScenarioService().removeKnowledgeElement(scene, kelm); // The knowledge element necessarily exists
170 mystudy.remove(kelm);
177 * Promote a knowledge element from the current scenario.
179 * @return SUCCESS if no exceptions
181 public String doPromoteKnowledge() {
182 getKnowledgeElementService().promote(getKnowledgeElement()); // The knowledge element necessarily exists
188 * Demote a knowledge element from the current scenario.
190 * @return SUCCESS if no exceptions
192 public String doDemoteKnowledge() {
193 getKnowledgeElementService().demote(getKnowledgeElement()); // The knowledge element necessarily exists
199 * Get selected knowledge element.
201 * @return the selected knowledge element
203 private KnowledgeElement getKnowledgeElement() {
204 mystudy = getOpenStudy();
205 Step step = mystudy.getSelectedStep();
206 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
207 return scene.getKnowledgeElement(Integer.valueOf(myindex));
211 * Update current menu.
213 private void updateMenu() {
214 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
216 setMenuProperty("study");
217 setTitleProperty("study");
218 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
219 setToolProperty("study");
221 setToolProperty("standard");
223 setLeftMenuProperty("study");
224 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
228 // ==============================================================================================================================
229 // Getters and setters
230 // ==============================================================================================================================
233 * Get the type of the modified knowledge element.
235 * @return the knowledge type name
237 public String getKnowledgeType() {
238 // ---------------------------------
243 * Get the id of the modified knowledge element.
245 * @return the knowledge element id
247 public String getSelectedKnowledge() {
248 // -------------------------------------
253 * Set the type of the modified knowledge element.
256 * the knowledge type name
258 public void setKnowledgeType(String type) {
259 // ------------------------------------------
264 * Set the title of the modified knowledge element.
267 * the new knowledge title
269 public void setKnowledgeTitle(String title) {
270 // --------------------------------------------
275 * Set the value of the modified knowledge element.
278 * the knowledge value
280 public void setKnowledgeValue(String value) {
281 // --------------------------------------------
286 * Get the scenarioService.
288 * @return the scenarioService
290 public ScenarioService getScenarioService() {
291 return _scenarioService;
295 * Set the scenarioService.
297 * @param scenarioService
298 * the scenarioService to set
300 public void setScenarioService(ScenarioService scenarioService) {
301 _scenarioService = scenarioService;
305 * Get the knowledgeElementService.
307 * @return the knowledgeElementService
309 public KnowledgeElementService getKnowledgeElementService() {
310 return _knowledgeElementService;
314 * Set the knowledgeElementService.
316 * @param knowledgeElementService
317 * the knowledgeElementService to set
319 public void setKnowledgeElementService(
320 KnowledgeElementService knowledgeElementService) {
321 _knowledgeElementService = knowledgeElementService;
325 * Get the knowledgeElementTypeService.
327 * @return the knowledgeElementTypeService
329 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
330 return _knowledgeElementTypeService;
334 * Set the knowledgeElementTypeService.
336 * @param knowledgeElementTypeService
337 * the knowledgeElementTypeService to set
339 public void setKnowledgeElementTypeService(
340 KnowledgeElementTypeService knowledgeElementTypeService) {
341 _knowledgeElementTypeService = knowledgeElementTypeService;
345 * Get the menuProperty.
347 * @return the menuProperty
349 public String getMenuProperty() {
350 return _menuProperty;
354 * Set the menuProperty.
356 * @param menuProperty
357 * the menuProperty to set
359 public void setMenuProperty(final String menuProperty) {
360 this._menuProperty = menuProperty;
364 * Get the _titleProperty.
366 * @return the _titleProperty
368 public String getTitleProperty() {
369 return _titleProperty;
373 * Set the titleProperty.
375 * @param titleProperty
376 * the titleProperty to set
378 public void setTitleProperty(final String titleProperty) {
379 _titleProperty = titleProperty;
383 * Get the editDisabledProperty.
385 * @return the editDisabledProperty
387 public String getEditDisabledProperty() {
388 return _editDisabledProperty;
392 * Set the editDisabledProperty.
394 * @param editDisabledProperty
395 * the editDisabledProperty to set
397 public void setEditDisabledProperty(final String editDisabledProperty) {
398 _editDisabledProperty = editDisabledProperty;
402 * Get the toolProperty.
404 * @return the toolProperty
406 public String getToolProperty() {
407 return _toolProperty;
411 * Set the toolProperty.
413 * @param toolProperty
414 * the toolProperty to set
416 public void setToolProperty(final String toolProperty) {
417 _toolProperty = toolProperty;
421 * Get the leftMenuProperty.
422 * @return the leftMenuProperty
424 public String getLeftMenuProperty() {
425 return _leftMenuProperty;
429 * Set the leftMenuProperty.
430 * @param leftMenuProperty the leftMenuProperty to set
432 public void setLeftMenuProperty(final String leftMenuProperty) {
433 _leftMenuProperty = leftMenuProperty;