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;
24 private static final long serialVersionUID = 4636919137087687068L;
26 // ==============================================================================================================================
28 // ==============================================================================================================================
30 public String doInitialize () {
31 // -----------------------------
32 // Session connex = Database.getSession();
33 // Transaction transax = connex.beginTransaction();
35 mystudy = getOpenStudy();
41 public String doSetKnowledge () {
42 // -------------------------------
43 Session connex = Database.getSession();
44 Transaction transax = connex.beginTransaction();
46 User user = getConnectedUser();
47 mystudy = getOpenStudy();
49 Step step = mystudy.getSelectedStep();
50 Scenario scene = (Scenario)step.getOwner(); // It is necessarily a Scenario
52 if (title != null && value != null) { // Addition of a new Knowledge Element
53 KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
54 KnowledgeElementType ktype = KnowledgeElement.selectType(Integer.valueOf(type));
59 mystudy.add( getScenarioService().addKnowledgeElement(scene, kprop) );
60 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
62 if (title != null) { // Renaming of an existing Knowledge Element
63 KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
64 getKnowledgeElementService().rename(kelm, title);
65 // Useless to update the open study
67 if (value != null) { // Edition of a knowledge
68 KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
70 mystudy.update(kelm); // For updating the truncated value
75 catch (RuntimeException saverror) {
76 logger.error("Reason:", saverror);
77 if (transax != null && transax.isActive()) {
78 // Second try-catch as the rollback could fail as well
81 } catch (HibernateException backerror) {
82 logger.debug("Error rolling back transaction", backerror);
87 catch (Exception error) {
93 public String doDeleteKnowledge () {
94 // ----------------------------------
95 Session connex = Database.getSession();
96 Transaction transax = connex.beginTransaction();
98 mystudy = getOpenStudy();
99 Step step = mystudy.getSelectedStep();
100 Scenario scene = (Scenario)step.getOwner(); // It is necessarily a Scenario
102 KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(myindex));
103 scene.removeKnowledgeElement(kelm); // The knowledge element necessarily exists
105 mystudy.remove(kelm);
106 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
111 catch (RuntimeException saverror) {
112 logger.error("Reason:", saverror);
113 if (transax != null && transax.isActive()) {
114 // Second try-catch as the rollback could fail as well
117 } catch (HibernateException backerror) {
118 logger.debug("Error rolling back transaction", backerror);
125 // ==============================================================================================================================
126 // Getters and setters
127 // ==============================================================================================================================
129 public String getKnowledgeType () {
130 // ---------------------------------
133 public String getSelectedKnowledge () {
134 // -------------------------------------
138 public void setKnowledgeType (String type) {
139 // ------------------------------------------
142 public void setKnowledgeTitle (String title) {
143 // --------------------------------------------
146 public void setKnowledgeValue (String value) {
147 // --------------------------------------------
151 * Get the scenarioService.
152 * @return the scenarioService
154 public ScenarioService getScenarioService() {
155 return _scenarioService;
159 * Set the scenarioService.
160 * @param scenarioService the scenarioService to set
162 public void setScenarioService(ScenarioService scenarioService) {
163 _scenarioService = scenarioService;
167 * Get the knowledgeElementService.
168 * @return the knowledgeElementService
170 public KnowledgeElementService getKnowledgeElementService() {
171 return _knowledgeElementService;
175 * Set the knowledgeElementService.
176 * @param knowledgeElementService the knowledgeElementService to set
178 public void setKnowledgeElementService(
179 KnowledgeElementService knowledgeElementService) {
180 _knowledgeElementService = knowledgeElementService;