1 package org.splat.simer;
3 import org.splat.dal.bo.som.KnowledgeElement;
4 import org.splat.dal.bo.som.KnowledgeElementType;
5 import org.splat.dal.bo.som.Scenario;
6 import org.splat.service.KnowledgeElementService;
7 import org.splat.service.KnowledgeElementTypeService;
8 import org.splat.service.ScenarioService;
9 import org.splat.service.dto.KnowledgeElementDTO;
10 import org.splat.som.Step;
11 import org.splat.wapp.Constants;
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 _knowledgeType = null; // Edited knowledge type
28 * Edited knowledge element title.
30 private String _knowledgeTitle = null;
32 * Edited knowledge element value.
34 private String _knowledgeValue = 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;
48 // ==============================================================================================================================
50 // ==============================================================================================================================
53 * Initialize the action. Get selected study from the session.
55 * @return SUCCESS if no exceptions
57 public String doInitialize() {
58 _openStudy = getOpenStudy();
64 * Add a new or update an existing knowledge element of the selected scenario in the open study.
66 * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
68 public String doSetKnowledge() {
74 _openStudy = getOpenStudy();
76 if ((_knowledgeTitle == null) || (_knowledgeValue == null)) {
77 KnowledgeElementDTO kelm = new KnowledgeElementDTO(Integer
78 .valueOf(_knowledgeType), _knowledgeTitle,
80 if (_knowledgeValue == null) { // Renaming of an existing Knowledge Element
81 getKnowledgeElementService().rename(kelm, _knowledgeTitle);
82 } else { // Edition of a knowledge
83 getKnowledgeElementService().update(kelm, _knowledgeValue);
85 _openStudy.update(kelm); // For updating the truncated value
86 } else { // Addition of a new Knowledge Element
87 KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
88 KnowledgeElementType ktype = getKnowledgeElementTypeService()
89 .selectType(Integer.valueOf(_knowledgeType));
90 kprop.setType(ktype).setTitle(_knowledgeTitle).setValue(
91 _knowledgeValue).setAuthor(getConnectedUser());
92 _openStudy.add(getScenarioService().addKnowledgeElement(
93 (Scenario) _openStudy.getSelectedStep().getOwner(),
95 getMenu(Constants.STUDY_MENU)
96 .selects(_openStudy.getSelection()); // Updates the menu icon, in case of first added document
98 } catch (RuntimeException saverror) {
99 LOG.error("Reason:", saverror);
101 } catch (Exception error) {
102 LOG.error("Exception while saving a knowledge: ", error);
109 * Delete a knowledge element from the current scenario.
111 * @return SUCCESS if no exceptions
113 public String doDeleteKnowledge() {
114 _openStudy = getOpenStudy();
115 _openStudy.updateCurrentStep();
116 Step step = _openStudy.getSelectedStep();
117 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
119 KnowledgeElement kelm = scene.getKnowledgeElement(Integer
121 getScenarioService().removeKnowledgeElement(scene, kelm); // The knowledge element necessarily exists
123 if (_selection == null) { // Opening a study just newed
124 _selection = _openStudy.getSelection(); // Default selection
126 _openStudy = open(getStudyService().selectStudy(
127 _openStudy.getIndex())); // Closes the previously open study
128 _openStudy.setSelection(_selection);
134 * Promote a knowledge element from the current scenario.
136 * @return SUCCESS if no exceptions
138 public String doPromoteKnowledge() {
139 getKnowledgeElementService().promote(getKnowledgeElement()); // The knowledge element necessarily exists
145 * Demote a knowledge element from the current scenario.
147 * @return SUCCESS if no exceptions
149 public String doDemoteKnowledge() {
150 getKnowledgeElementService().demote(getKnowledgeElement()); // The knowledge element necessarily exists
156 * Get selected knowledge element.
158 * @return the selected knowledge element
160 private KnowledgeElement getKnowledgeElement() {
161 _openStudy = getOpenStudy();
162 Step step = _openStudy.getSelectedStep();
163 Scenario scene = (Scenario) step.getOwner(); // It is necessarily a Scenario
164 return scene.getKnowledgeElement(Integer.valueOf(_myindex));
168 * Update current menu.
170 private void updateMenu() {
171 getMenu(Constants.STUDY_MENU).selects(_openStudy.getSelection()); // Updates the menu icon, in case of last removed document
175 // ==============================================================================================================================
176 // Getters and setters
177 // ==============================================================================================================================
180 * Get the type of the modified knowledge element.
182 * @return the knowledge type name
184 public String getKnowledgeType() {
185 return _knowledgeType;
189 * Get the id of the modified knowledge element.
191 * @return the knowledge element id
193 public String getSelectedKnowledge() {
198 * Set the type of the modified knowledge element.
201 * the knowledge type name
203 public void setKnowledgeType(final String type) {
204 this._knowledgeType = type;
208 * Set the title of the modified knowledge element.
211 * the new knowledge title
213 public void setKnowledgeTitle(final String title) {
214 this._knowledgeTitle = title;
218 * Set the value of the modified knowledge element.
221 * the knowledge value
223 public void setKnowledgeValue(final String value) {
224 this._knowledgeValue = value;
228 * Get the scenarioService.
230 * @return the scenarioService
232 public ScenarioService getScenarioService() {
233 return _scenarioService;
237 * Set the scenarioService.
239 * @param scenarioService
240 * the scenarioService to set
242 public void setScenarioService(final ScenarioService scenarioService) {
243 _scenarioService = scenarioService;
247 * Get the knowledgeElementService.
249 * @return the knowledgeElementService
251 public KnowledgeElementService getKnowledgeElementService() {
252 return _knowledgeElementService;
256 * Set the knowledgeElementService.
258 * @param knowledgeElementService
259 * the knowledgeElementService to set
261 public void setKnowledgeElementService(
262 final KnowledgeElementService knowledgeElementService) {
263 _knowledgeElementService = knowledgeElementService;
267 * Get the knowledgeElementTypeService.
269 * @return the knowledgeElementTypeService
271 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
272 return _knowledgeElementTypeService;
276 * Set the knowledgeElementTypeService.
278 * @param knowledgeElementTypeService
279 * the knowledgeElementTypeService to set
281 public void setKnowledgeElementTypeService(
282 final KnowledgeElementTypeService knowledgeElementTypeService) {
283 _knowledgeElementTypeService = knowledgeElementTypeService;
287 * Get the knowledgeValue.
289 * @return the knowledgeValue
291 public String getKnowledgeValue() {
292 return _knowledgeValue;
296 * Get the knowledgeTitle.
298 * @return the knowledgeTitle
300 public String getKnowledgeTitle() {
301 return _knowledgeTitle;