Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / OpenStudy.java
index dd9937e34ec299c5d64a047d9e67e8cc1c27632b..d572a408ee47b067239ad5eb8adb559a32269ec0 100644 (file)
@@ -15,18 +15,15 @@ import java.util.List;
 import java.util.ResourceBundle;
 
 import org.apache.log4j.Logger;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.splat.kernel.Do;
 import org.splat.dal.bo.kernel.User;
 import org.splat.manox.Toolbox;
 import org.splat.manox.Writer;
-import org.splat.dal.dao.som.Database;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.ProgressState;
+import org.splat.service.DocumentService;
 import org.splat.service.DocumentTypeService;
 import org.splat.service.StepService;
 import org.splat.service.StudyService;
@@ -67,7 +64,10 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
         * Injected document type service.
         */
        private DocumentTypeService _documentTypeService;
-
+       /**
+        * Injected document service.
+        */
+       private DocumentService _documentService;
        /**
         * The injected Study service.
         */
@@ -235,8 +235,8 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
                if (!template.exists())
                        return null;
 
-               Session connex = Database.getSession();
-               Transaction transax = connex.beginTransaction();
+//             Session connex = Database.getCurSession();
+//             Transaction transax = connex.beginTransaction();
                try {
                        File udir = getRepositoryService().getDownloadDirectory(author);
                        File credoc = new File(udir.getPath() + "/" + filename);
@@ -248,7 +248,7 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
                        Document medoc = getStepService().createDocument(step,
                                        dprop.setType(type).setFormat("xml").setAuthor(author))
                                        .value();
-                       transax.commit();
+//                     transax.commit();
 
                        // Instantiation of the template into the user download directory
                        if (!udir.exists())
@@ -288,14 +288,6 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
                                        + filename);
                } catch (Exception saverror) {
                        logger.error("Reason:", saverror);
-                       if (transax != null && transax.isActive()) {
-                               // Second try-catch as the rollback could fail as well
-                               try {
-                                       transax.rollback();
-                               } catch (HibernateException backerror) {
-                                       logger.debug("Error rolling back transaction", backerror);
-                               }
-                       }
                        return null;
                }
        }
@@ -306,21 +298,10 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
 
                if (docurl.startsWith(prefix))
                        try {
-                               Session connex = Database.getSession();
-                               Transaction transax = connex.beginTransaction();
                                String path = docurl.substring(prefix.length());
-                               String[] parse = path.split("'");
-
-                               path = parse[0];
-                               for (int i = 1; i < parse.length; i++)
-                                       path = path + "''" + parse[i];
-                               // Better call Database.selectDocument(path), but this service does not exist (overloading issue)
-                               String query = "from Document where path='" + path + "'";
-                               Document value = (Document) Database.getSession().createQuery(
-                                               query).uniqueResult();
+                               Document value = getDocumentService().getDocumentByPath(path);
 
                                selecdoc = ustep.getDocument(value.getIndex());
-                               transax.commit();
                        } catch (Exception error) {
                                logger.error("Reason:", error);
                        }
@@ -576,4 +557,20 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
        public void setStudyService(StudyService studyService) {
                _studyService = studyService;
        }
+
+       /**
+        * Get the documentService.
+        * @return the documentService
+        */
+       public DocumentService getDocumentService() {
+               return _documentService;
+       }
+
+       /**
+        * Set the documentService.
+        * @param documentService the documentService to set
+        */
+       public void setDocumentService(DocumentService documentService) {
+               _documentService = documentService;
+       }
 }
\ No newline at end of file