Salome HOME
Creation of a new study from an existing one is implemented.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditDocumentAction.java
index ca7baa1c7a7c3d531ee20255a0a266e29f2ca7a4..135444c2cbeae4300d52fd8e31f2a12731a889aa 100644 (file)
@@ -3,10 +3,11 @@ package org.splat.simer;
 import java.io.File;
 import java.util.Calendar;
 
-import org.splat.kernel.InvalidPropertyException;
 import org.splat.dal.bo.kernel.User;
-import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.ConvertsRelation;
+import org.splat.dal.bo.som.Publication;
+import org.splat.exception.DocumentIsUsedException;
+import org.splat.kernel.InvalidPropertyException;
 import org.splat.service.PublicationService;
 import org.splat.service.StepService;
 import org.splat.service.technical.RepositoryService;
@@ -22,9 +23,9 @@ public class EditDocumentAction extends DisplayStudyStepAction {
         */
        private static final long serialVersionUID = 4573036736137033679L;
 
-       private String index = null;
-       private String title = null;
-       private String filename = null;
+       private transient String _index = null;
+       private transient String _title = null;
+       private transient String _filename = null;
        /**
         * Injected publication service.
         */
@@ -55,47 +56,52 @@ public class EditDocumentAction extends DisplayStudyStepAction {
         * @return SUCCESS
         */
        public String doInitialize() {
-               mystudy = getOpenStudy();
+               _openStudy = getOpenStudy();
+               setMenu();
                return SUCCESS;
        }
 
        public String doSetDocument() {
+
+               setMenu();
+
                try {
-                       mystudy = getOpenStudy();
+                       _openStudy = getOpenStudy();
 
-                       Execute todo = Execute.valueOf(action);
-                       Step step = mystudy.getSelectedStep();
-                       Publication doc = step.getDocument(Integer.valueOf(index));
+                       Execute todo = Execute.valueOf(_action);
+                       Step step = _openStudy.getSelectedStep();
+                       Publication doc = step.getDocument(Integer.valueOf(_index));
 
                        if (todo == Execute.renameDocument) {
-                               getPublicationService().rename(doc, title);
+                               getPublicationService().rename(doc, _title);
                                // Useless to update the document presentation
+                               setAction(null);
                        } else if (todo == Execute.accept) {
                                getPublicationService().actualize(doc);
-                               mystudy.update(doc);
+                               _openStudy.update(doc);
                        } else if (todo == Execute.promote) {
                                getPublicationService().promote(doc,
                                                Calendar.getInstance().getTime());
-                               mystudy.update(doc);
+                               _openStudy.update(doc);
                        } else if (todo == Execute.demote) {
                                getPublicationService().demote(doc);
-                               mystudy.update(doc);
+                               _openStudy.update(doc);
                        } else if (todo == Execute.review) {
                                getPublicationService().review(doc,
                                                Calendar.getInstance().getTime());
-                               mystudy.update(doc);
+                               _openStudy.update(doc);
                        } else if (todo == Execute.invalidate) {
                                getPublicationService().invalidate(doc);
-                               mystudy.update(doc);
+                               _openStudy.update(doc);
                        } else if (todo == Execute.approve) {
                                getPublicationService().approve(doc,
                                                Calendar.getInstance().getTime());
-                               mystudy.update(doc);
-                               mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
+                               _openStudy.update(doc);
+                               _openStudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
                        }
                        return SUCCESS;
                } catch (RuntimeException saverror) {
-                       logger.error("Reason:", saverror);
+                       LOG.error("Reason:", saverror);
                        return ERROR;
                } catch (InvalidPropertyException error) {
                        return INPUT;
@@ -103,69 +109,74 @@ public class EditDocumentAction extends DisplayStudyStepAction {
        }
 
        public String doAttach() {
-               // -------------------------
-//             Session connex = Database.getCurSession();
-//             Transaction transax = connex.beginTransaction();
+
+               setMenu();
+
                try {
                        // Getting user inputs
-                       mystudy = getOpenStudy();
+                       _openStudy = getOpenStudy();
                        User user = getConnectedUser();
-                       Step step = mystudy.getSelectedStep();
+                       Step step = _openStudy.getSelectedStep();
                        File updir = getRepositoryService().getDownloadDirectory(user);
-                       File upfile = new File(updir.getPath() + "/" + filename);
-                       String[] parse = filename.split("\\x2E");
+                       File upfile = new File(updir.getPath() + "/" + _filename);
+                       String[] parse = _filename.split("\\x2E");
 
-                       Publication edited = step.getDocument(Integer.valueOf(index));
-                       ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
+                       Publication edited = step.getDocument(Integer.valueOf(_index));
+                       ConvertsRelation export = getPublicationService().attach(edited,
+                                       parse[parse.length - 1]);
 
-                       if (logger.isInfoEnabled())
-                               logger.info("Moving \"" + upfile.getName() + "\" to \""
+                       if (LOG.isInfoEnabled()) {
+                               LOG.info("Moving \"" + upfile.getName() + "\" to \""
                                                + updir.getPath() + "\".");
+                       }
                        upfile.renameTo(export.getTo().asFile());
 
-                       mystudy.update(edited);
-//                     transax.commit();
+                       _openStudy.update(edited);
                        return SUCCESS;
                } catch (Exception error) {
-                       logger.error("Reason:", error);
+                       LOG.error("Reason:", error);
                        return ERROR;
                }
        }
 
-       public String doDeleteDocument() {
-               try {
-                       mystudy = getOpenStudy();
-
-                       Step step = mystudy.getSelectedStep();
-                       Publication doctag = step.getDocument(Integer.valueOf(index));
+       /**
+        * Remove the selected document from the current activity.
+        * 
+        * @return SUCCESS
+        * @throws DocumentIsUsedException
+        *             if the document is used by other document(s)
+        * @throws NumberFormatException
+        *             if the document id can not be transformed to number
+        */
+       public String doDeleteDocument() throws DocumentIsUsedException,
+                       NumberFormatException {
 
-                       getStepService().removeDocument(step, doctag); // Updates the data structure
+               setMenu();
+               _openStudy = getOpenStudy();
+               Step step = _openStudy.getSelectedStep();
+               Publication doctag = step.getDocument(Integer.valueOf(_index));
 
-                       mystudy.remove(doctag); // Updates the presentation
-                       return SUCCESS;
-               } catch (RuntimeException saverror) {
-                       logger.error("Reason:", saverror);
-                       return ERROR;
+               if (getStepService().removeDocument(step, Long.valueOf(_index))) { // Updates the data structure
+                       _openStudy.remove(doctag); // Updates the presentation
                }
+               return SUCCESS;
        }
 
        // ==============================================================================================================================
        // Getters and setters
        // ==============================================================================================================================
 
-       public void setDocumentTitle(String title) {
-               // -------------------------------------------
-               this.title = title;
+       public void setDocumentTitle(final String title) {
+               this._title = title;
        }
 
-       public void setFileName(String filename) {
-               // -----------------------------------------
-               this.filename = filename;
+       public void setFileName(final String filename) {
+               this._filename = filename;
        }
 
-       public void setIndex(String index) {
-               // -----------------------------------
-               this.index = index;
+       @Override
+       public void setIndex(final String index) {
+               this._index = index;
        }
 
        /**
@@ -183,7 +194,8 @@ public class EditDocumentAction extends DisplayStudyStepAction {
         * @param publicationService
         *            the publicationService to set
         */
-       public void setPublicationService(PublicationService publicationService) {
+       public void setPublicationService(
+                       final PublicationService publicationService) {
                _publicationService = publicationService;
        }
 
@@ -202,12 +214,13 @@ public class EditDocumentAction extends DisplayStudyStepAction {
         * @param repositoryService
         *            the repositoryService to set
         */
-       public void setRepositoryService(RepositoryService repositoryService) {
+       public void setRepositoryService(final RepositoryService repositoryService) {
                _repositoryService = repositoryService;
        }
 
        /**
         * Get the stepService.
+        * 
         * @return the stepService
         */
        public StepService getStepService() {
@@ -216,9 +229,11 @@ public class EditDocumentAction extends DisplayStudyStepAction {
 
        /**
         * Set the stepService.
-        * @param stepService the stepService to set
+        * 
+        * @param stepService
+        *            the stepService to set
         */
-       public void setStepService(StepService stepService) {
+       public void setStepService(final StepService stepService) {
                _stepService = stepService;
        }
 }
\ No newline at end of file