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;
47 // ==============================================================================================================================
49 // ==============================================================================================================================
52 * Initialize the action. Get selected study from the session.
54 * @return SUCCESS if no exceptions
56 public String doInitialize() {
57 mystudy = getOpenStudy();
62 * Add a new or update an existing knowledge element of the selected scenario in the open study.
64 * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
66 public String doSetKnowledge() {
68 User user = getConnectedUser();
69 mystudy = getOpenStudy();
71 Step step = mystudy.getSelectedStep();
72 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
74 if (title != null && value != null) { // Addition of a new Knowledge Element
75 KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
76 KnowledgeElementType ktype = getKnowledgeElementTypeService()
77 .selectType(Integer.valueOf(type));
78 kprop.setType(ktype).setTitle(title).setValue(value).setAuthor(
80 mystudy.add(getScenarioService().addKnowledgeElement(scene,
82 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
83 } else if (title != null) { // Renaming of an existing Knowledge Element
84 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
86 getKnowledgeElementService().rename(kelm, title);
87 // Useless to update the open study
88 } else if (value != null) { // Edition of a knowledge
89 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
91 getKnowledgeElementService().update(kelm, value);
92 mystudy.update(kelm); // For updating the truncated value
95 } catch (RuntimeException saverror) {
96 logger.error("Reason:", saverror);
98 } catch (Exception error) {
104 * Delete a knowledge element from the current scenario.
106 * @return SUCCESS if no exceptions
108 public String doDeleteKnowledge() {
109 mystudy = getOpenStudy();
110 Step step = mystudy.getSelectedStep();
111 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
113 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
115 getScenarioService().removeKnowledgeElement(scene, kelm); // The knowledge element necessarily exists
117 mystudy.remove(kelm);
118 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
123 // ==============================================================================================================================
124 // Getters and setters
125 // ==============================================================================================================================
128 * Get the type of the modified knowledge element.
130 * @return the knowledge type name
132 public String getKnowledgeType() {
133 // ---------------------------------
138 * Get the id of the modified knowledge element.
140 * @return the knowledge element id
142 public String getSelectedKnowledge() {
143 // -------------------------------------
148 * Set the type of the modified knowledge element.
151 * the knowledge type name
153 public void setKnowledgeType(String type) {
154 // ------------------------------------------
159 * Set the title of the modified knowledge element.
162 * the new knowledge title
164 public void setKnowledgeTitle(String title) {
165 // --------------------------------------------
170 * Set the value of the modified knowledge element.
173 * the knowledge value
175 public void setKnowledgeValue(String value) {
176 // --------------------------------------------
181 * Get the scenarioService.
183 * @return the scenarioService
185 public ScenarioService getScenarioService() {
186 return _scenarioService;
190 * Set the scenarioService.
192 * @param scenarioService
193 * the scenarioService to set
195 public void setScenarioService(ScenarioService scenarioService) {
196 _scenarioService = scenarioService;
200 * Get the knowledgeElementService.
202 * @return the knowledgeElementService
204 public KnowledgeElementService getKnowledgeElementService() {
205 return _knowledgeElementService;
209 * Set the knowledgeElementService.
211 * @param knowledgeElementService
212 * the knowledgeElementService to set
214 public void setKnowledgeElementService(
215 KnowledgeElementService knowledgeElementService) {
216 _knowledgeElementService = knowledgeElementService;
220 * Get the knowledgeElementTypeService.
221 * @return the knowledgeElementTypeService
223 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
224 return _knowledgeElementTypeService;
228 * Set the knowledgeElementTypeService.
229 * @param knowledgeElementTypeService the knowledgeElementTypeService to set
231 public void setKnowledgeElementTypeService(
232 KnowledgeElementTypeService knowledgeElementTypeService) {
233 _knowledgeElementTypeService = knowledgeElementTypeService;