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 4ff25593894746fdfc16784287192c0006e479ee..878975b33dfe3db0c9905bf78078d31624482284 100644 (file)
@@ -11,9 +11,12 @@ 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;
 import org.splat.service.StepService;
+import org.splat.service.technical.RepositoryService;
 import org.splat.simer.Action;
 import org.splat.simer.OpenStudy;
 import org.splat.dal.bo.som.ConvertsRelation;
@@ -29,6 +32,14 @@ import org.splat.som.Step;
 
 public class SaveDocumentAction extends Action {
 
+       /**
+        * Serial version ID.
+        */
+       private static final long serialVersionUID = -3364960833373200115L;
+
+       /**
+        * Current open study.
+        */
        private OpenStudy mystudy = null;
        private int doctype = 0;
        private String filename = null;
@@ -36,11 +47,30 @@ public class SaveDocumentAction extends Action {
        private ProgressState state = null;
        private List<Document> defuses = null;
        private String summary = null; // Summary of changes in the new version
+       /**
+        * Injected scenario service.
+        */
        private ScenarioService _scenarioService;
+       /**
+        * Injected publication service.
+        */
        private PublicationService _publicationService;
+       /**
+        * Injected step service.
+        */
        private StepService _stepService;
-
-       private static final long serialVersionUID = -3364960833373200115L;
+       /**
+        * Injected document type service.
+        */
+       private DocumentTypeService _documentTypeService;
+       /**
+        * Injected repository service.
+        */
+       private RepositoryService _repositoryService;
+       /**
+        * Injected simulation context service.
+        */
+       private SimulationContextService _simulationContextService;
 
        // ==============================================================================================================================
        // Action methods
@@ -48,17 +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 = Database.getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file between users
+                       String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
+                       // between users
                        File upfile = new File(upath + filename);
                        String[] table = filename.split("\\x2E");
                        String format = table[table.length - 1];
@@ -68,8 +99,10 @@ public class SaveDocumentAction extends Action {
                        connex.flush();
 
                        Document.Properties dprop = new Document.Properties();
-                       Publication credoc = step.createDocument(dprop.setName(docname)
-                                       .setType(type).setFormat(format).setAuthor(user));
+                       Publication credoc = getStepService().createDocument(
+                                       step,
+                                       dprop.setName(docname).setType(type).setFormat(format)
+                                                       .setAuthor(user));
                        // Writing the uploaded file into the created document
                        File target = credoc.getSourceFile().asFile();
                        if (target.exists())
@@ -92,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())
@@ -102,26 +136,28 @@ public class SaveDocumentAction extends Action {
                        // 2. Addition of simulation contexts
                        if (type.equals("model")) { // Set the characteristics of the mesh
                                SimulationContext.Properties cprop = new SimulationContext.Properties();
-                               SimulationContextType ctype = SimulationContext
+                               SimulationContextType ctype = getSimulationContextService()
                                                .selectType("model");
-                               SimulationContext context = Database.selectSimulationContext(
-                                               ctype, "Éléments finis");
+                               SimulationContext context = getSimulationContextService()
+                                               .selectSimulationContext(ctype, "Éléments finis");
                                if (context == null) {
                                        getStepService().addSimulationContext(step,
                                                        cprop.setType(ctype).setValue("Éléments finis"));
                                } else {
                                        getStepService().addSimulationContext(step, context);
                                }
-                               ctype = SimulationContext.selectType("element");
-                               context = Database.selectSimulationContext(ctype, "Surfacique");
+                               ctype = getSimulationContextService().selectType("element");
+                               context = getSimulationContextService()
+                                               .selectSimulationContext(ctype, "Surfacique");
                                if (context == null) {
                                        getStepService().addSimulationContext(step,
                                                        cprop.setType(ctype).setValue("Surfacique"));
                                } else {
                                        getStepService().addSimulationContext(step, context);
                                }
-                               ctype = SimulationContext.selectType("shape");
-                               context = Database.selectSimulationContext(ctype, "Triangles");
+                               ctype = getSimulationContextService().selectType("shape");
+                               context = getSimulationContextService()
+                                               .selectSimulationContext(ctype, "Triangles");
                                if (context == null) {
                                        getStepService().addSimulationContext(step,
                                                        cprop.setType(ctype).setValue("Triangles"));
@@ -213,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
@@ -222,7 +258,8 @@ public class SaveDocumentAction extends Action {
                        Step step = mystudy.getSelectedStep();
                        // File updir = Database.getDownloadDirectory(user);
                        // File upfile = new File(updir.getPath() + "/" + filename);
-                       String upath = Database.getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file between users
+                       String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
+                       // between users
                        File upfile = new File(upath + filename);
                        String[] table = filename.split("\\x2E");
                        String format = table[table.length - 1];
@@ -234,7 +271,8 @@ public class SaveDocumentAction extends Action {
                        if (summary.length() > 0)
                                dprop.setDescription(summary);
 
-                       Publication next = step.versionDocument(current, dprop);
+                       Publication next = getStepService().versionDocument(step, current,
+                                       dprop);
 
                        // Writing the uploaded file into the created document
                        File target = next.getSourceFile().asFile();
@@ -259,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++)
@@ -326,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();) {
@@ -338,4 +376,62 @@ public class SaveDocumentAction extends Action {
                                defuses.addAll(usedoc);
                }
        }
+
+       /**
+        * Get the repositoryService.
+        * 
+        * @return the repositoryService
+        */
+       public RepositoryService getRepositoryService() {
+               return _repositoryService;
+       }
+
+       /**
+        * Set the repositoryService.
+        * 
+        * @param repositoryService
+        *            the repositoryService to set
+        */
+       public void setRepositoryService(RepositoryService repositoryService) {
+               _repositoryService = repositoryService;
+       }
+
+       /**
+        * Get the simulationContextService.
+        * 
+        * @return the simulationContextService
+        */
+       public SimulationContextService getSimulationContextService() {
+               return _simulationContextService;
+       }
+
+       /**
+        * Set the simulationContextService.
+        * 
+        * @param simulationContextService
+        *            the simulationContextService to set
+        */
+       public void setSimulationContextService(
+                       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