1 package org.splat.simer;
3 import org.hibernate.HibernateException;
4 import org.hibernate.Session;
5 import org.hibernate.Transaction;
6 import org.splat.kernel.User;
7 import org.splat.som.Database;
8 import org.splat.som.KnowledgeElement;
9 import org.splat.som.KnowledgeElementType;
10 import org.splat.som.Scenario;
11 import org.splat.som.Step;
14 public class EditKnowledgeElementAction extends DisplayStudyStepAction {
16 private String type = null; // Edited knowledge type
17 private String title = null;
18 private String value = null;
20 private static final long serialVersionUID = 4636919137087687068L;
22 // ==============================================================================================================================
24 // ==============================================================================================================================
26 public String doInitialize () {
27 // -----------------------------
28 // Session connex = Database.getSession();
29 // Transaction transax = connex.beginTransaction();
31 mystudy = getOpenStudy();
37 public String doSetKnowledge () {
38 // -------------------------------
39 Session connex = Database.getSession();
40 Transaction transax = connex.beginTransaction();
42 User user = getConnectedUser();
43 mystudy = getOpenStudy();
45 Step step = mystudy.getSelectedStep();
46 Scenario scene = (Scenario)step.getOwner(); // It is necessarily a Scenario
48 if (title != null && value != null) { // Addition of a new Knowledge Element
49 KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
50 KnowledgeElementType ktype = KnowledgeElement.selectType(Integer.valueOf(type));
55 mystudy.add( scene.addKnowledgeElement(kprop) );
56 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of first added document
58 if (title != null) { // Renaming of an existing Knowledge Element
59 KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
61 // Useless to update the open study
63 if (value != null) { // Edition of a knowledge
64 KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(type));
66 mystudy.update(kelm); // For updating the truncated value
71 catch (RuntimeException saverror) {
72 logger.error("Reason:", saverror);
73 if (transax != null && transax.isActive()) {
74 // Second try-catch as the rollback could fail as well
77 } catch (HibernateException backerror) {
78 logger.debug("Error rolling back transaction", backerror);
83 catch (Exception error) {
89 public String doDeleteKnowledge () {
90 // ----------------------------------
91 Session connex = Database.getSession();
92 Transaction transax = connex.beginTransaction();
94 mystudy = getOpenStudy();
95 Step step = mystudy.getSelectedStep();
96 Scenario scene = (Scenario)step.getOwner(); // It is necessarily a Scenario
98 KnowledgeElement kelm = scene.getKnowledgeElement(Integer.valueOf(myindex));
99 scene.removeKnowledgeElement(kelm); // The knowledge element necessarily exists
101 mystudy.remove(kelm);
102 getMenu("study").selects(mystudy.getSelection()); // Updates the menu icon, in case of last removed document
107 catch (RuntimeException saverror) {
108 logger.error("Reason:", saverror);
109 if (transax != null && transax.isActive()) {
110 // Second try-catch as the rollback could fail as well
113 } catch (HibernateException backerror) {
114 logger.debug("Error rolling back transaction", backerror);
121 // ==============================================================================================================================
122 // Getters and setters
123 // ==============================================================================================================================
125 public String getKnowledgeType () {
126 // ---------------------------------
129 public String getSelectedKnowledge () {
130 // -------------------------------------
134 public void setKnowledgeType (String type) {
135 // ------------------------------------------
138 public void setKnowledgeTitle (String title) {
139 // --------------------------------------------
142 public void setKnowledgeValue (String value) {
143 // --------------------------------------------