]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/EditStudyAction.java
Salome HOME
Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditStudyAction.java
1 package org.splat.simer;
2
3 import org.hibernate.HibernateException;
4 import org.hibernate.Session;
5 import org.hibernate.Transaction;
6 import org.splat.dal.dao.som.Database;
7 import org.splat.dal.bo.som.Study;
8 import org.splat.service.StudyService;
9
10
11 public class EditStudyAction extends DisplayStudyStepAction {
12     
13         /**
14          * Serial version ID.
15          */
16     private static final long serialVersionUID = -4865668290514118396L;
17
18         private enum Execute { publish, promote }
19
20         private StudyService _studyService;
21
22 //  ==============================================================================================================================
23 //  Action methods
24 //  ==============================================================================================================================
25
26     public String doEdition () {
27 //  --------------------------
28       Session      connex  = Database.getSession();
29           Transaction  transax = connex.beginTransaction();
30           try {
31         mystudy = getOpenStudy();
32
33         Execute  todo   = Execute.valueOf(action);
34         Study    study  = mystudy.getStudyObject();
35         
36         if      (todo == Execute.publish) getStudyService().moveToPublic(study);
37         else if (todo == Execute.promote) getStudyService().moveToReference(study);
38         mystudy.getPopup().setContext("study", mystudy.getStudyRights());   // The context has changed
39
40 //      Useless to update the open study
41         transax.commit();
42         return SUCCESS;
43           }
44       catch (RuntimeException saverror) {
45         logger.error("Reason:", saverror);
46         if (transax != null && transax.isActive()) {
47 //        Second try-catch as the rollback could fail as well
48           try {
49             transax.rollback();
50           } catch (HibernateException backerror) {
51             logger.debug("Error rolling back transaction", backerror);
52           }
53         }
54         return ERROR;
55       }
56     }
57         /**
58          * Get the studyService.
59          * 
60          * @return the studyService
61          */
62         public StudyService getStudyService() {
63                 return _studyService;
64         }
65
66         /**
67          * Set the studyService.
68          * 
69          * @param studyService
70          *            the studyService to set
71          */
72         public void setStudyService(StudyService studyService) {
73                 _studyService = studyService;
74         }
75 }