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.service.dto.KnowledgeElementDTO;
11 import org.splat.som.Step;
14 * Action for addition and modification of knowledge elements in the selected scenario.
16 public class EditKnowledgeElementAction extends DisplayStudyStepAction {
21 private static final long serialVersionUID = 4636919137087687068L;
24 * Edited knowledge element type.
26 private String type = null; // Edited knowledge type
28 * Edited knowledge element title.
30 private String title = null;
32 * Edited knowledge element value.
34 private String value = null;
36 * Injected scenario service.
38 private ScenarioService _scenarioService;
40 * Injected knowledge element service.
42 private KnowledgeElementService _knowledgeElementService;
44 * Injected knowledge element type service.
46 private KnowledgeElementTypeService _knowledgeElementTypeService;
49 * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
51 private String _menuProperty;
54 * Value of the title bar property. It can be: study, knowledge.
56 private String _titleProperty;
59 * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up
60 * menu also can be called. It is necessary for correct building the title bar.
62 private String _editDisabledProperty = "false";
65 * Value of the tool bar property. It can be: none, standard, study, back.
67 private String _toolProperty;
70 * Value of the left menu property. It can be: open, study, knowledge, scenario.
72 private String _leftMenuProperty;
74 // ==============================================================================================================================
76 // ==============================================================================================================================
79 * Initialize the action. Get selected study from the session.
81 * @return SUCCESS if no exceptions
83 public String doInitialize() {
84 mystudy = getOpenStudy();
86 setMenuProperty("study");
87 setTitleProperty("study");
88 if ("true".equals(getWriteAccess())
89 && getUserRights().canCreateDocument()) {
90 setToolProperty("study");
92 setToolProperty("standard");
94 setLeftMenuProperty("study");
95 initializationFullScreenContext(_menuProperty, _titleProperty,
96 _editDisabledProperty, _toolProperty, _leftMenuProperty);
102 * Add a new or update an existing knowledge element of the selected scenario in the open study.
104 * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
106 public String doSetKnowledge() {
108 setMenuProperty("study");
109 setTitleProperty("study");
110 if ("true".equals(getWriteAccess())
111 && getUserRights().canCreateDocument()) {
112 setToolProperty("study");
114 setToolProperty("standard");
116 setLeftMenuProperty("study");
117 initializationFullScreenContext(_menuProperty, _titleProperty,
118 _editDisabledProperty, _toolProperty, _leftMenuProperty);
121 User user = getConnectedUser();
122 mystudy = getOpenStudy();
124 Step step = mystudy.getSelectedStep();
125 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
127 if ((title == null) || (value == null)) {
128 KnowledgeElementDTO kelm = new KnowledgeElementDTO(Integer
129 .valueOf(type), title, value);
130 if (value == null) { // Renaming of an existing Knowledge Element
131 getKnowledgeElementService().rename(kelm, title);
132 } else { // Edition of a knowledge
133 getKnowledgeElementService().update(kelm, value);
135 mystudy.update(kelm); // For updating the truncated value
136 } else { // Addition of a new Knowledge Element
137 KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
138 KnowledgeElementType ktype = getKnowledgeElementTypeService()
139 .selectType(Integer.valueOf(type));
140 kprop.setType(ktype).setTitle(title).setValue(value).setAuthor(
142 mystudy.add(getScenarioService().addKnowledgeElement(scene,
144 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
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())
219 && getUserRights().canCreateDocument()) {
220 setToolProperty("study");
222 setToolProperty("standard");
224 setLeftMenuProperty("study");
225 initializationFullScreenContext(_menuProperty, _titleProperty,
226 _editDisabledProperty, _toolProperty, _leftMenuProperty);
230 // ==============================================================================================================================
231 // Getters and setters
232 // ==============================================================================================================================
235 * Get the type of the modified knowledge element.
237 * @return the knowledge type name
239 public String getKnowledgeType() {
240 // ---------------------------------
245 * Get the id of the modified knowledge element.
247 * @return the knowledge element id
249 public String getSelectedKnowledge() {
250 // -------------------------------------
255 * Set the type of the modified knowledge element.
258 * the knowledge type name
260 public void setKnowledgeType(final String type) {
261 // ------------------------------------------
266 * Set the title of the modified knowledge element.
269 * the new knowledge title
271 public void setKnowledgeTitle(final String title) {
272 // --------------------------------------------
277 * Set the value of the modified knowledge element.
280 * the knowledge value
282 public void setKnowledgeValue(final String value) {
283 // --------------------------------------------
288 * Get the scenarioService.
290 * @return the scenarioService
292 public ScenarioService getScenarioService() {
293 return _scenarioService;
297 * Set the scenarioService.
299 * @param scenarioService
300 * the scenarioService to set
302 public void setScenarioService(final ScenarioService scenarioService) {
303 _scenarioService = scenarioService;
307 * Get the knowledgeElementService.
309 * @return the knowledgeElementService
311 public KnowledgeElementService getKnowledgeElementService() {
312 return _knowledgeElementService;
316 * Set the knowledgeElementService.
318 * @param knowledgeElementService
319 * the knowledgeElementService to set
321 public void setKnowledgeElementService(
322 final KnowledgeElementService knowledgeElementService) {
323 _knowledgeElementService = knowledgeElementService;
327 * Get the knowledgeElementTypeService.
329 * @return the knowledgeElementTypeService
331 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
332 return _knowledgeElementTypeService;
336 * Set the knowledgeElementTypeService.
338 * @param knowledgeElementTypeService
339 * the knowledgeElementTypeService to set
341 public void setKnowledgeElementTypeService(
342 final KnowledgeElementTypeService knowledgeElementTypeService) {
343 _knowledgeElementTypeService = knowledgeElementTypeService;
347 * Get the menuProperty.
349 * @return the menuProperty
352 public String getMenuProperty() {
353 return _menuProperty;
357 * Set the menuProperty.
359 * @param menuProperty
360 * the menuProperty to set
363 public void setMenuProperty(final String menuProperty) {
364 this._menuProperty = menuProperty;
368 * Get the _titleProperty.
370 * @return the _titleProperty
373 public String getTitleProperty() {
374 return _titleProperty;
378 * Set the titleProperty.
380 * @param titleProperty
381 * the titleProperty to set
384 public void setTitleProperty(final String titleProperty) {
385 _titleProperty = titleProperty;
389 * Get the editDisabledProperty.
391 * @return the editDisabledProperty
394 public String getEditDisabledProperty() {
395 return _editDisabledProperty;
399 * Set the editDisabledProperty.
401 * @param editDisabledProperty
402 * the editDisabledProperty to set
405 public void setEditDisabledProperty(final String editDisabledProperty) {
406 _editDisabledProperty = editDisabledProperty;
410 * Get the toolProperty.
412 * @return the toolProperty
415 public String getToolProperty() {
416 return _toolProperty;
420 * Set the toolProperty.
422 * @param toolProperty
423 * the toolProperty to set
426 public void setToolProperty(final String toolProperty) {
427 _toolProperty = toolProperty;
431 * Get the leftMenuProperty.
433 * @return the leftMenuProperty
436 public String getLeftMenuProperty() {
437 return _leftMenuProperty;
441 * Set the leftMenuProperty.
443 * @param leftMenuProperty
444 * the leftMenuProperty to set
447 public void setLeftMenuProperty(final String leftMenuProperty) {
448 _leftMenuProperty = leftMenuProperty;