Salome HOME
NewStudyAction is improved. Specific business method for creation of a new study...
[tools/siman.git] / Workspace / Siman / src / org / splat / module / SaveDocumentAction.java
index a534902b1aefc45cb2979bb862d475de690cd774..878975b33dfe3db0c9905bf78078d31624482284 100644 (file)
@@ -11,6 +11,7 @@ import org.hibernate.Session;
 import org.hibernate.Transaction;
 import org.splat.kernel.Do;
 import org.splat.dal.bo.kernel.User;
+import org.splat.service.DocumentTypeService;
 import org.splat.service.PublicationService;
 import org.splat.service.ScenarioService;
 import org.splat.service.SimulationContextService;
@@ -58,6 +59,10 @@ public class SaveDocumentAction extends Action {
         * Injected step service.
         */
        private StepService _stepService;
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
        /**
         * Injected repository service.
         */
@@ -73,18 +78,18 @@ public class SaveDocumentAction extends Action {
 
        public String doSave() {
                // -----------------------
-               Session connex = Database.getSession();
+               Session connex = Database.getCurSession();
                Transaction transax = connex.beginTransaction();
                try {
                        // Getting user inputs
                        mystudy = getOpenStudy();
                        User user = getConnectedUser();
                        Step step = mystudy.getSelectedStep();
-                       DocumentType type = Document.selectType(doctype);
+                       DocumentType type = getDocumentTypeService().selectType(doctype);
                        // File updir = Database.getDownloadDirectory(user);
                        // File upfile = new File(updir.getPath() + "/" + filename);
                        String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
-                                                                                                                                               // between users
+                       // between users
                        File upfile = new File(upath + filename);
                        String[] table = filename.split("\\x2E");
                        String format = table[table.length - 1];
@@ -120,7 +125,8 @@ public class SaveDocumentAction extends Action {
                        // 1. Conversion of the document to internal format, if required
                        // TODO: The following code is temporary, waiting for the support of converters
                        if (format.equals("part")) {
-                               ConvertsRelation export = credoc.attach("brep");
+                               ConvertsRelation export = getPublicationService().attach(
+                                               credoc, "brep");
 
                                target = export.getTo().asFile();
                                if (target.exists())
@@ -243,7 +249,7 @@ public class SaveDocumentAction extends Action {
 
        public String doVersion() {
                // --------------------------
-               Session connex = Database.getSession();
+               Session connex = Database.getCurSession();
                Transaction transax = connex.beginTransaction();
                try {
                        // Getting user inputs
@@ -253,7 +259,7 @@ public class SaveDocumentAction extends Action {
                        // File updir = Database.getDownloadDirectory(user);
                        // File upfile = new File(updir.getPath() + "/" + filename);
                        String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
-                                                                                                                                               // between users
+                       // between users
                        File upfile = new File(upath + filename);
                        String[] table = filename.split("\\x2E");
                        String format = table[table.length - 1];
@@ -291,7 +297,8 @@ public class SaveDocumentAction extends Action {
                        // 1. Conversion of the document to internal format, if required
                        // TODO: The following code is temporary, waiting for the support of converters
                        if (format.equals("part")) {
-                               ConvertsRelation export = next.attach("brep");
+                               ConvertsRelation export = getPublicationService().attach(next,
+                                               "brep");
                                String fname = table[0];
 
                                for (int i = 1; i < table.length - 1; i++)
@@ -358,7 +365,6 @@ public class SaveDocumentAction extends Action {
        // ==============================================================================================================================
 
        private void setupDefaultUses(DocumentType type) {
-               // -------------------------------------------------
                Set<DocumentType> uses = type.getDefaultUses();
 
                for (Iterator<DocumentType> i = uses.iterator(); i.hasNext();) {
@@ -409,4 +415,23 @@ public class SaveDocumentAction extends Action {
                        SimulationContextService simulationContextService) {
                _simulationContextService = simulationContextService;
        }
+
+       /**
+        * Get the documentTypeService.
+        * 
+        * @return the documentTypeService
+        */
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
+       }
+
+       /**
+        * Set the documentTypeService.
+        * 
+        * @param documentTypeService
+        *            the documentTypeService to set
+        */
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
+       }
 }
\ No newline at end of file