Salome HOME
Code is cleaned.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditDocumentAction.java
index d2e9c32d2f79e7c44245ccbecf6b6c554abd9089..ca7baa1c7a7c3d531ee20255a0a266e29f2ca7a4 100644 (file)
@@ -3,176 +3,222 @@ package org.splat.simer;
 import java.io.File;
 import java.util.Calendar;
 
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.splat.kernel.InvalidPropertyException;
-import org.splat.kernel.User;
-import org.splat.som.Database;
-import org.splat.som.Publication;
-import org.splat.som.ConvertsRelation;
+import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.Publication;
+import org.splat.dal.bo.som.ConvertsRelation;
+import org.splat.service.PublicationService;
+import org.splat.service.StepService;
+import org.splat.service.technical.RepositoryService;
 import org.splat.som.Step;
 
-
+/**
+ * Document modification action.
+ */
 public class EditDocumentAction extends DisplayStudyStepAction {
 
-    private String  index    = null;
-       private String  title    = null;
-    private String  filename = null;
-
+       /**
+        * Serial version ID.
+        */
        private static final long serialVersionUID = 4573036736137033679L;
 
-       private enum Execute { renameDocument, accept, promote, demote, review, invalidate, approve, disapprove };
-
-//  ==============================================================================================================================
-//  Action methods
-//  ==============================================================================================================================
-
-    public String doInitialize () {
-//  -----------------------------
-//    Session      connex  = Database.getSession();
-//       Transaction  transax = connex.beginTransaction();
-
-         mystudy = getOpenStudy();
-        
-//    transax.commit();
-      return SUCCESS;
-    }
-
-    public String doSetDocument () {
-//  ------------------------------
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-      try {
-           mystudy = getOpenStudy();
-
-        Execute      todo = Execute.valueOf(action);
-               Step         step = mystudy.getSelectedStep();
-               Publication  doc  = step.getDocument(Integer.valueOf(index));
-        
-        if (todo == Execute.renameDocument) {
-                 doc.rename(title);
-//        Useless to update the document presentation
-        } else
-        if (todo == Execute.accept) {
-          doc.actualize();
-          mystudy.update(doc);
-        } else
-        if (todo == Execute.promote) {
-          doc.promote(Calendar.getInstance().getTime());
-          mystudy.update(doc);
-        } else
-        if (todo == Execute.demote) {
-          doc.demote();
-          mystudy.update(doc);
-        } else
-        if (todo == Execute.review) {
-          doc.review(Calendar.getInstance().getTime());
-          mystudy.update(doc);
-        } else
-        if (todo == Execute.invalidate) {
-          doc.invalidate();
-          mystudy.update(doc);
-        } else
-        if (todo == Execute.approve) {
-          doc.approve(Calendar.getInstance().getTime());
-          mystudy.update(doc);
-          mystudy.getMenu().refreshSelectedItem();   // Updates the menu icon, in case of other documents in approved state
-        }
-        transax.commit();
-       return SUCCESS;
-         }
-      catch (RuntimeException 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 ERROR;
-         }
-      catch (InvalidPropertyException error) {
-        transax.commit();
-       return INPUT;
-      }
-    }
-
-    public String doAttach () {
-//  -------------------------
-      Session      connex  = Database.getSession();
-         Transaction  transax = connex.beginTransaction();
-      try {
-//      Getting user inputs
-                 mystudy = getOpenStudy();
-        User     user    = getConnectedUser();
-        Step     step    = mystudy.getSelectedStep();
-       File     updir   = Database.getDownloadDirectory(user);
-       File     upfile  = new File(updir.getPath() + "/" + filename);
-        String[] parse   = filename.split("\\x2E");
-
-        Publication       edited = step.getDocument(Integer.valueOf(index));
-        ConvertsRelation  export = edited.attach(parse[parse.length-1]);
-
-               if (logger.isInfoEnabled()) logger.info("Moving \"" + upfile.getName() + "\" to \"" + updir.getPath() + "\".");
-        upfile.renameTo(export.getTo().asFile());
-
-        mystudy.update(edited);
-        transax.commit();
-        return  SUCCESS;
-      }
-      catch (Exception error) {
-        logger.error("Reason:", error);
-        return ERROR;
-      }
-    }
-
-    public String doDeleteDocument () {
-//  ---------------------------------
-      Session     connex  = Database.getSession();
-         Transaction transax = connex.beginTransaction();
-         try {
-               mystudy = getOpenStudy();
-           
-               Step         step   = mystudy.getSelectedStep();
-        Publication  doctag = step.getDocument(Integer.valueOf(index));
-
-        step.removeDocument(doctag);   // Updates the data structure
-        transax.commit();
-
-        mystudy.remove(doctag);        // Updates the presentation
-        return SUCCESS;
-         }
-      catch (RuntimeException 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 ERROR;
-         }
-    }
-
-//  ==============================================================================================================================
-//  Getters and setters
-//  ==============================================================================================================================
-
-    public void setDocumentTitle (String title) {
-//  -------------------------------------------
-      this.title = title;
-    }
-    public void setFileName (String filename) {
-//  -----------------------------------------
-      this.filename = filename;
-    }
-    public void setIndex (String index) {
-//  -----------------------------------
-      this.index = index;
-    }
+       private String index = null;
+       private String title = null;
+       private String filename = null;
+       /**
+        * Injected publication service.
+        */
+       private PublicationService _publicationService;
+       /**
+        * Injected step service.
+        */
+       private StepService _stepService;
+       /**
+        * Injected repository service.
+        */
+       private RepositoryService _repositoryService;
+
+       /**
+        * Operations enumeration.
+        */
+       private enum Execute {
+               renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
+       };
+
+       // ==============================================================================================================================
+       // Action methods
+       // ==============================================================================================================================
+
+       /**
+        * Open a study.
+        * 
+        * @return SUCCESS
+        */
+       public String doInitialize() {
+               mystudy = getOpenStudy();
+               return SUCCESS;
+       }
+
+       public String doSetDocument() {
+               try {
+                       mystudy = getOpenStudy();
+
+                       Execute todo = Execute.valueOf(action);
+                       Step step = mystudy.getSelectedStep();
+                       Publication doc = step.getDocument(Integer.valueOf(index));
+
+                       if (todo == Execute.renameDocument) {
+                               getPublicationService().rename(doc, title);
+                               // Useless to update the document presentation
+                       } else if (todo == Execute.accept) {
+                               getPublicationService().actualize(doc);
+                               mystudy.update(doc);
+                       } else if (todo == Execute.promote) {
+                               getPublicationService().promote(doc,
+                                               Calendar.getInstance().getTime());
+                               mystudy.update(doc);
+                       } else if (todo == Execute.demote) {
+                               getPublicationService().demote(doc);
+                               mystudy.update(doc);
+                       } else if (todo == Execute.review) {
+                               getPublicationService().review(doc,
+                                               Calendar.getInstance().getTime());
+                               mystudy.update(doc);
+                       } else if (todo == Execute.invalidate) {
+                               getPublicationService().invalidate(doc);
+                               mystudy.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
+                       }
+                       return SUCCESS;
+               } catch (RuntimeException saverror) {
+                       logger.error("Reason:", saverror);
+                       return ERROR;
+               } catch (InvalidPropertyException error) {
+                       return INPUT;
+               }
+       }
+
+       public String doAttach() {
+               // -------------------------
+//             Session connex = Database.getCurSession();
+//             Transaction transax = connex.beginTransaction();
+               try {
+                       // Getting user inputs
+                       mystudy = getOpenStudy();
+                       User user = getConnectedUser();
+                       Step step = mystudy.getSelectedStep();
+                       File updir = getRepositoryService().getDownloadDirectory(user);
+                       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]);
+
+                       if (logger.isInfoEnabled())
+                               logger.info("Moving \"" + upfile.getName() + "\" to \""
+                                               + updir.getPath() + "\".");
+                       upfile.renameTo(export.getTo().asFile());
+
+                       mystudy.update(edited);
+//                     transax.commit();
+                       return SUCCESS;
+               } catch (Exception error) {
+                       logger.error("Reason:", error);
+                       return ERROR;
+               }
+       }
+
+       public String doDeleteDocument() {
+               try {
+                       mystudy = getOpenStudy();
+
+                       Step step = mystudy.getSelectedStep();
+                       Publication doctag = step.getDocument(Integer.valueOf(index));
+
+                       getStepService().removeDocument(step, doctag); // Updates the data structure
+
+                       mystudy.remove(doctag); // Updates the presentation
+                       return SUCCESS;
+               } catch (RuntimeException saverror) {
+                       logger.error("Reason:", saverror);
+                       return ERROR;
+               }
+       }
+
+       // ==============================================================================================================================
+       // Getters and setters
+       // ==============================================================================================================================
+
+       public void setDocumentTitle(String title) {
+               // -------------------------------------------
+               this.title = title;
+       }
+
+       public void setFileName(String filename) {
+               // -----------------------------------------
+               this.filename = filename;
+       }
+
+       public void setIndex(String index) {
+               // -----------------------------------
+               this.index = index;
+       }
+
+       /**
+        * Get the publicationService.
+        * 
+        * @return the publicationService
+        */
+       public PublicationService getPublicationService() {
+               return _publicationService;
+       }
+
+       /**
+        * Set the publicationService.
+        * 
+        * @param publicationService
+        *            the publicationService to set
+        */
+       public void setPublicationService(PublicationService publicationService) {
+               _publicationService = publicationService;
+       }
+
+       /**
+        * 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 stepService.
+        * @return the stepService
+        */
+       public StepService getStepService() {
+               return _stepService;
+       }
+
+       /**
+        * Set the stepService.
+        * @param stepService the stepService to set
+        */
+       public void setStepService(StepService stepService) {
+               _stepService = stepService;
+       }
 }
\ No newline at end of file