1 package org.splat.simer;
3 import org.hibernate.HibernateException;
4 import org.hibernate.Session;
5 import org.hibernate.Transaction;
6 import org.splat.dal.bo.kernel.User;
7 import org.splat.dal.dao.som.Database;
8 import org.splat.dal.bo.som.KnowledgeElement;
9 import org.splat.dal.bo.som.KnowledgeElementType;
10 import org.splat.dal.bo.som.Scenario;
11 import org.splat.service.KnowledgeElementService;
12 import org.splat.service.ScenarioService;
13 import org.splat.som.Step;
16 public class EditKnowledgeElementAction extends DisplayStudyStepAction {
18 private String type = null; // Edited knowledge type
19 private String title = null;
20 private String value = null;
21 private ScenarioService _scenarioService;
22 private KnowledgeElementService _knowledgeElementService;
27 private static final long serialVersionUID = 4636919137087687068L;
29 // ==============================================================================================================================
31 // ==============================================================================================================================
33 public String doInitialize () {
34 // -----------------------------
35 // Session connex = Database.getSession();
36 // Transaction transax = connex.beginTransaction();
38 mystudy = getOpenStudy();
44 public String doSetKnowledge () {
45 // -------------------------------
46 Session connex = Database.getSession();
47 Transaction transax = connex.beginTransaction();
49 User user = getConnectedUser();
50 mystudy = getOpenStudy();
52 Step step = mystudy.getSelectedStep();
53 Scenario scene = (Scenario)step.getOwner(); // It is necessarily a Scenario
55 if (title != null && value != null) { // Addition of a new Knowledge Element
56 KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
57 KnowledgeElementType ktype = KnowledgeElement.selectType(Integer.valueOf(type));
62 mystudy.add( getScenarioService().addKnowledgeElement(scene, kprop) );
63 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
65 if (title != null) { // Renaming of an existing Knowledge Element
66 KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
67 getKnowledgeElementService().rename(kelm, title);
68 // Useless to update the open study
70 if (value != null) { // Edition of a knowledge
71 KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
73 mystudy.update(kelm); // For updating the truncated value
78 catch (RuntimeException saverror) {
79 logger.error("Reason:", saverror);
80 if (transax != null && transax.isActive()) {
81 // Second try-catch as the rollback could fail as well
84 } catch (HibernateException backerror) {
85 logger.debug("Error rolling back transaction", backerror);
90 catch (Exception error) {
96 public String doDeleteKnowledge () {
97 // ----------------------------------
98 Session connex = Database.getSession();
99 Transaction transax = connex.beginTransaction();
101 mystudy = getOpenStudy();
102 Step step = mystudy.getSelectedStep();
103 Scenario scene = (Scenario)step.getOwner(); // It is necessarily a Scenario
105 KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(myindex));
106 scene.removeKnowledgeElement(kelm); // The knowledge element necessarily exists
108 mystudy.remove(kelm);
109 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
114 catch (RuntimeException saverror) {
115 logger.error("Reason:", saverror);
116 if (transax != null && transax.isActive()) {
117 // Second try-catch as the rollback could fail as well
120 } catch (HibernateException backerror) {
121 logger.debug("Error rolling back transaction", backerror);
128 // ==============================================================================================================================
129 // Getters and setters
130 // ==============================================================================================================================
132 public String getKnowledgeType () {
133 // ---------------------------------
136 public String getSelectedKnowledge () {
137 // -------------------------------------
141 public void setKnowledgeType (String type) {
142 // ------------------------------------------
145 public void setKnowledgeTitle (String title) {
146 // --------------------------------------------
149 public void setKnowledgeValue (String value) {
150 // --------------------------------------------
154 * Get the scenarioService.
155 * @return the scenarioService
157 public ScenarioService getScenarioService() {
158 return _scenarioService;
162 * Set the scenarioService.
163 * @param scenarioService the scenarioService to set
165 public void setScenarioService(ScenarioService scenarioService) {
166 _scenarioService = scenarioService;
170 * Get the knowledgeElementService.
171 * @return the knowledgeElementService
173 public KnowledgeElementService getKnowledgeElementService() {
174 return _knowledgeElementService;
178 * Set the knowledgeElementService.
179 * @param knowledgeElementService the knowledgeElementService to set
181 public void setKnowledgeElementService(
182 KnowledgeElementService knowledgeElementService) {
183 _knowledgeElementService = knowledgeElementService;