Salome HOME
Beans initialization is fixed. Document can be added to study now.
authorrkv <rkv@opencascade.com>
Wed, 10 Oct 2012 15:59:57 +0000 (15:59 +0000)
committerrkv <rkv@opencascade.com>
Wed, 10 Oct 2012 15:59:57 +0000 (15:59 +0000)
22 files changed:
Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/File.java
Workspace/Siman-Common/src/org/splat/service/DocumentService.java
Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/DocumentTypeServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/ScenarioServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StepService.java
Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java
Workspace/Siman-Common/src/org/splat/som/Step.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman/src/org/splat/module/SaveDocumentAction.java
Workspace/Siman/src/org/splat/simer/DocumentFacade.java
Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java
Workspace/Siman/src/org/splat/simer/OpenKnowledge.java
Workspace/Siman/src/org/splat/simer/OpenObject.java
Workspace/Siman/src/org/splat/simer/OpenStudy.java
Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java
Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java
Workspace/Siman/src/org/splat/simer/admin/SimulationContextFacade.java
Workspace/Siman/src/spring/applicationContext.xml

index 966917124af08f65d79d19284594bcb16c2c644b..4f664c98b3684c2af9d98b3086aa31885721f61a 100644 (file)
@@ -149,6 +149,14 @@ public class Document extends Entity {
                        return this;
                }
 
+               /**
+                * Get the date.
+                * @return the date
+                */
+               public Date getDate() {
+                       return date;
+               }
+
                public Properties setDescription(String summary)
                                throws InvalidPropertyException {
                        if (summary.length() == 0)
@@ -200,12 +208,19 @@ public class Document extends Entity {
                        this.name = name;
                        return this;
                }
+               
+               public String getName() {
+                       return this.name;
+               }
 
                public Properties setOwner(ProjectElement owner) {
                        this.owner = owner;
                        return this;
                }
 
+               public ProjectElement getOwner() {
+                       return this.owner;
+               }
                // Required only for passing search arguments
                public Properties setReference(String did)
                                throws InvalidPropertyException {
@@ -289,30 +304,10 @@ public class Document extends Entity {
                        state = ProgressState.inWORK; // Promoted when saving this document
                        version = new Revision().toString();
                }
-               Study owner = null;
-               if (dprop.owner instanceof Study)
-                       owner = (Study) dprop.owner;
-               else
-                       owner = ((Scenario) dprop.owner).getOwnerStudy();
-
-               ProjectSettingsService.Step step = ProjectSettingsServiceImpl
-                               .getStep(this.step);
-               SimpleDateFormat tostring = new SimpleDateFormat("yyyy");
-               String year = tostring.format(owner.getDate());
                if (name == null) { // Newed document
                        this.name = "%n"; // Named later at publication
                        this.history = -1; // Marks the document as undefined for future assignment
                }
-               String filename = generateEncodedName(owner);
-               String path;
-
-               path = owner.getReference();
-               did = new StringBuffer(path).append(".%").append(suformat).toString(); // Document reference
-               path = new StringBuffer(year).append("/").append(path).append("/")
-                               .append(step.getPath()) // File path relative to the repository vault
-                               .append(filename).append(".").append(myfile.getFormat()) // File name and extension
-                               .toString();
-               myfile.changePath(path);
        }
 
        // ==============================================================================================================================
@@ -345,6 +340,10 @@ public class Document extends Entity {
                // --------------------------------------
                return lasdate;
        }
+       
+       public void setLastModificationDate(Date aDate) {
+               lasdate = aDate;
+       }
 
        public String getFormat() {
                // --------------------------
@@ -446,6 +445,14 @@ public class Document extends Entity {
                else
                        return name;
        }
+       
+       /**
+        * Set document title.
+        * @param aTitle document title to set
+        */
+       public void setTitle(String aTitle) {
+               this.name = aTitle;
+       }
 
        public DocumentType getType() {
                // ------------------------------
@@ -454,9 +461,8 @@ public class Document extends Entity {
 
        /**
         * Returns the version number of this document. The version number, when exists, is either of the internal form (m.n.s) usable for
-        * building a Revision object, or any string in case of external document (document with EXTERN state).<br/>
-        * <br/>
-        * Note: document slots have a version number equal to "0.0.0".
+        * building a Revision object, or any string in case of external document (document with EXTERN state).<br/> <br/> Note: document slots
+        * have a version number equal to "0.0.0".
         * 
         * @return the version number of this document, or null if this is EXTERN.
         * @see #isUndefined()
@@ -579,9 +585,8 @@ public class Document extends Entity {
                        ProjectSettingsService.Step step) {
                // --------------------------------------------------------------------------
                Integer number = step.getNumber();
-               String query = new StringBuffer("from DocumentType")
-                               .append(" where step like '%-").append(number).append("-%'")
-                               .toString();
+               String query = new StringBuffer("from DocumentType").append(
+                               " where step like '%-").append(number).append("-%'").toString();
 
                List<DocumentType> types = Database.getSession().createQuery(query)
                                .list();
@@ -642,8 +647,8 @@ public class Document extends Entity {
                        return false;
                DecimalFormat tostring = new DecimalFormat(suformat);
 
-               did = did.replace("%" + suformat,
-                               tostring.format(scope.getLastLocalIndex()));
+               did = did.replace("%" + suformat, tostring.format(scope
+                               .getLastLocalIndex()));
                return true;
        }
 
@@ -688,44 +693,6 @@ public class Document extends Entity {
                        Database.getSession().update(this);
        }
 
-       /**
-        * Defines this document.
-        * 
-        * @param dprop
-        *            the properties of the document
-        * 
-        * @see Step#createDocument(Properties)
-        * @see #isUndefined()
-        */
-       public void initialize(Properties dprop) throws MissedPropertyException,
-                       InvalidPropertyException, NotApplicableException {
-               // --------------------------------------------
-               if (!this.isUndefined())
-                       throw new NotApplicableException(
-                                       "Cannot initialize an existing Document");
-               if (dprop.name == null)
-                       throw new MissedPropertyException("name");
-               if (dprop.name.length() == 0)
-                       throw new InvalidPropertyException("name");
-               if (dprop.owner == null)
-                       throw new MissedPropertyException("owner");
-               // if (dprop.owner instanceof Study && !ProjectSettings.getStep(step).appliesTo(Study.class)) {
-               // throw new InvalidPropertyException("step");
-               // }
-               name = dprop.name;
-               myfile.changePath(myfile.getRelativePath().replace("%n",
-                               getEncodedRootName((Study) dprop.owner)));
-               if (history == -1)
-                       history = 0;
-               if (dprop.date == null) {
-                       Calendar current = Calendar.getInstance();
-                       lasdate = current.getTime(); // Today
-               } else {
-                       lasdate = dprop.date;
-               }
-               Database.getSession().update(this);
-       }
-
        public boolean promote(Timestamp stamp) {
                // -------------------------------------------
                ProgressState newstate = null;
@@ -837,37 +804,6 @@ public class Document extends Entity {
        // TODO: Promote documents using this one
        // }
 
-       // ==============================================================================================================================
-       // Private services
-       // ==============================================================================================================================
-
-       private String generateEncodedName(Study scope) {
-               // ------------------------------------------------
-               StringBuffer encoding = new StringBuffer();
-               FileNaming scheme = getProjectSettingsService().getFileNamingScheme();
-               DecimalFormat tostring = new DecimalFormat(suformat);
-
-               int number = getStudyService().generateLocalIndex(scope);
-
-               if (scheme == FileNaming.encoded) {
-                       encoding.append(scope.getReference()).append(".")
-                                       .append(tostring.format(number));
-               } else { // title and (temporarily) asis
-                       encoding.append(name).append(".").append(tostring.format(number));
-               }
-               return encoding.toString();
-       }
-
-       private String getEncodedRootName(Study scope) {
-               // -----------------------------------------------
-               FileNaming scheme = getProjectSettingsService().getFileNamingScheme();
-
-               if (scheme == FileNaming.encoded)
-                       return scope.getReference();
-               else
-                       return name;
-       }
-
        /**
         * @return
         */
@@ -890,4 +826,68 @@ public class Document extends Entity {
        public void setStudyService(StudyService studyService) {
                _studyService = studyService;
        }
+
+       /**
+        * Get the step.
+        * @return the step
+        */
+       public int getStep() {
+               return step;
+       }
+
+       /**
+        * Set the step.
+        * @param step the step to set
+        */
+       public void setStep(int step) {
+               this.step = step;
+       }
+
+       /**
+        * Get the did.
+        * @return the did
+        */
+       public String getDid() {
+               return did;
+       }
+
+       /**
+        * Set the did.
+        * @param did the did to set
+        */
+       public void setDid(String did) {
+               this.did = did;
+       }
+
+       /**
+        * Get the myfile.
+        * @return the myfile
+        */
+       public File getFile() {
+               return myfile;
+       }
+
+       /**
+        * Set the myfile.
+        * @param myfile the myfile to set
+        */
+       public void setFile(File myfile) {
+               this.myfile = myfile;
+       }
+
+       /**
+        * Get the history.
+        * @return the history
+        */
+       public int getHistory() {
+               return history;
+       }
+
+       /**
+        * Set the history.
+        * @param history the history to set
+        */
+       public void setHistory(int history) {
+               this.history = history;
+       }
 }
\ No newline at end of file
index 9da39a7d126e2c6e32a953ee1a56e7d699ac6fdc..64f2998d4d42e0712e887d1575780f7d49860bf9 100644 (file)
@@ -102,7 +102,7 @@ public class File extends Persistent {
 //  Protected service
 //  ==============================================================================================================================
 
-    protected void changePath (String path) {
+    public void changePath (String path) {
 //  ---------------------------------------
       this.path   = path;
       this.myfile = null;
index d2b2218aab2b2e206dcabf9dc882f878c8b45001..a956b69b1e3991080b04cbce751c969dad27827c 100644 (file)
@@ -7,12 +7,34 @@
  * @version        $Revision$
  *****************************************************************************/
 
-package org.splat.service; 
+package org.splat.service;
+
+import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.Publication;
+import org.splat.dal.bo.som.Document.Properties;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.NotApplicableException;
+import org.splat.som.Step;
 
 /**
  * @author RKV
- *
+ * 
  */
 public interface DocumentService {
 
+       /**
+        * Defines this document.
+        * 
+        * @param dprop
+        *            the properties of the document
+        * 
+        * @see Step#createDocument(Properties)
+        * @see #isUndefined()
+        */
+       public void initialize(Document aDoc, Properties dprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       NotApplicableException;
+
+       public void generateDocumentId(Document aDoc, Properties dprop);
 }
index cd86e081ca0402935ad6339fd54b5933d2e81ea8..fef0b9931e8e160367f3a7df3a902348a4c151d5 100644 (file)
 
 package org.splat.service; 
 
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.Document.Properties;
+import org.splat.dal.dao.som.Database;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MissedPropertyException;
+import org.splat.kernel.NotApplicableException;
+import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.ProjectSettingsServiceImpl;
+import org.splat.service.technical.ProjectSettingsServiceImpl.FileNaming;
+import org.splat.som.Step;
+
 /**
  * @author RKV
  *
  */
 public class DocumentServiceImpl implements DocumentService {
 
+       private StudyService _studyService;
+       private ProjectSettingsService _projectSettingsService;
+
+       public void generateDocumentId(Document aDoc, Properties dprop) {
+               Study owner = null;
+               if (dprop.getOwner() instanceof Study)
+                       owner = (Study) dprop.getOwner();
+               else
+                       owner = ((Scenario) dprop.getOwner()).getOwnerStudy();
+
+               SimpleDateFormat tostring = new SimpleDateFormat("yyyy");
+               String year = tostring.format(owner.getDate());
+               String filename = generateEncodedName(aDoc, owner);
+               String path = owner.getReference();
+               ProjectSettingsService.Step step = ProjectSettingsServiceImpl
+                               .getStep(aDoc.getStep());
+               aDoc.setDid( new StringBuffer(path).append(".%").append(aDoc.suformat).toString()); // Document reference
+               path = new StringBuffer(year).append("/").append(path).append("/")
+                               .append(step.getPath()) // File path relative to the repository vault
+                               .append(filename).append(".").append(aDoc.getFile().getFormat()) // File name and extension
+                               .toString();
+               aDoc.getFile().changePath(path);
+       }
+
+       private String generateEncodedName(Document aDoc, Study scope) {
+               // ------------------------------------------------
+               StringBuffer encoding = new StringBuffer();
+               FileNaming scheme = getProjectSettings().getFileNamingScheme();
+               DecimalFormat tostring = new DecimalFormat(aDoc.suformat);
+
+               int number = getStudyService().generateLocalIndex(scope);
+
+               if (scheme == FileNaming.encoded) {
+                       encoding.append(scope.getReference()).append(".").append(
+                                       tostring.format(number));
+               } else { // title and (temporarily) asis
+                       encoding.append(aDoc.getTitle()).append(".").append(tostring.format(number));
+               }
+               return encoding.toString();
+       }
+
+       private String getEncodedRootName(Document aDoc, Study scope) {
+               // -----------------------------------------------
+               FileNaming scheme = getProjectSettings().getFileNamingScheme();
+
+               if (scheme == FileNaming.encoded)
+                       return scope.getReference();
+               else
+                       return aDoc.getTitle();
+       }
+
+       /**
+        * Defines this document.
+        * 
+        * @param dprop
+        *            the properties of the document
+        * 
+        * @see Step#createDocument(Properties)
+        * @see #isUndefined()
+        */
+       public void initialize(Document aDoc, Properties dprop) throws MissedPropertyException,
+                       InvalidPropertyException, NotApplicableException {
+               // --------------------------------------------
+               if (!aDoc.isUndefined())
+                       throw new NotApplicableException(
+                                       "Cannot initialize an existing Document");
+               if (dprop.getName() == null)
+                       throw new MissedPropertyException("name");
+               if (dprop.getName().length() == 0)
+                       throw new InvalidPropertyException("name");
+               if (dprop.getOwner() == null)
+                       throw new MissedPropertyException("owner");
+               // if (dprop.owner instanceof Study && !ProjectSettings.getStep(step).appliesTo(Study.class)) {
+               // throw new InvalidPropertyException("step");
+               // }
+               aDoc.setTitle(dprop.getName());
+               aDoc.getFile().changePath(aDoc.getFile().getRelativePath().replace("%n",
+                               getEncodedRootName(aDoc, (Study) dprop.getOwner())));
+               if (aDoc.getHistory() == -1)
+                       aDoc.setHistory( 0 );
+               if (dprop.getDate() == null) {
+                       Calendar current = Calendar.getInstance();
+                       aDoc.setLastModificationDate(current.getTime()); // Today
+               } else {
+                       aDoc.setLastModificationDate(dprop.getDate());
+               }
+               Database.getSession().update(aDoc);
+       }
+
+       /**
+        * Get the studyService.
+        * @return the studyService
+        */
+       public StudyService getStudyService() {
+               return _studyService;
+       }
+
+       /**
+        * Set the studyService.
+        * @param studyService the studyService to set
+        */
+       public void setStudyService(StudyService studyService) {
+               _studyService = studyService;
+       }
+
+       /**
+        * Get project settings.
+        * 
+        * @return Project settings service
+        */
+       private ProjectSettingsService getProjectSettings() {
+               return _projectSettingsService;
+       }
+
+       /**
+        * Set project settings service.
+        * 
+        * @param projectSettingsService
+        *            project settings service
+        */
+       public void setProjectSettings(ProjectSettingsService projectSettingsService) {
+               _projectSettingsService = projectSettingsService;
+       }
+
 }
index 5a717a1d74d043823c0189d65d888a1aff6e7701..c88ec88d9a22a923dd06e3821e26c8ed0df9b46b 100644 (file)
@@ -32,7 +32,7 @@ public class DocumentTypeServiceImpl implements DocumentTypeService {
         */
            public boolean isStudyResult (DocumentType aType) {
        //  -------------------------------
-             List<ProjectSettingsService.Step> step   = getProjectSettingsService().getAllSteps();
+             List<ProjectSettingsService.Step> step   = getProjectSettings().getAllSteps();
              ProjectSettingsService.Step       lastep = step.get( step.size()-1 );
              return    (aType.isResultOf(lastep));
            }
@@ -40,11 +40,11 @@ public class DocumentTypeServiceImpl implements DocumentTypeService {
        /**
         * @return
         */
-       public ProjectSettingsService getProjectSettingsService() {
+       public ProjectSettingsService getProjectSettings() {
                return _projectSettingsService;
        }
 
-       public void setProjectSettingsService(
+       public void setProjectSettings(
                        ProjectSettingsService projectSettingsService) {
                _projectSettingsService = projectSettingsService;
        }
index 8f643874942b491f0040f77cabd633f5165858e5..7fb730ba70bb0d6210f438641b1b4fc7997c9138 100644 (file)
@@ -286,7 +286,7 @@ public class PublicationServiceImpl implements PublicationService {
                        throw new FileNotFoundException();
 
                if (state == ProgressState.inWORK || state == ProgressState.EXTERN) {
-                       Database.getSession().save(this); // Must be done before updating the study in order to fix this final (rid-based) hascode
+                       Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode
                        aPublication.value().updateAs(state);
                } else {
                        DocumentType mytype = aPublication.value().getType();
index 003c4dba159ddb14a57aa585994bc6633dc1f079..8cf54cdfb7b5952547072c1a8f6233b822f4596d 100644 (file)
@@ -176,7 +176,7 @@ public class ScenarioServiceImpl implements ScenarioService {
 
                aScenario.setUser(user);
                aScenario.setLastModificationDate(Calendar.getInstance().getTime());
-               Database.getSession().update(this);
+               Database.getSession().update(aScenario);
                return true;
        }
 
index 9a0457ad71cd79cc9998ce1978b878f623d73dfe..871a0b9aa1d8937b60d1b9e1b702e91ec204bedf 100644 (file)
@@ -9,10 +9,16 @@
 
 package org.splat.service;
 
+import java.io.IOException;
+
+import org.splat.dal.bo.som.Document;
+import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MismatchException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
+import org.splat.kernel.NotApplicableException;
 import org.splat.som.Step;
 
 /**
@@ -21,6 +27,19 @@ import org.splat.som.Step;
  */
 public interface StepService {
 
+       public Publication createDocument(Step aStep, Document.Properties dprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException, IOException;
+
+       public Publication assignDocument(Step aStep, Document.Properties dprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       NotApplicableException;
+
+       public Publication versionDocument(Step aStep, Publication base,
+                       Document.Properties dprop) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException, IOException,
+                       MismatchException;
+
        public SimulationContext addSimulationContext(Step aStep,
                        SimulationContext.Properties dprop) throws MissedPropertyException,
                        InvalidPropertyException, MultiplyDefinedException,
index dda84d66b00fb482af8be20e3e6570853aabce50..353477ebf7f01266720ca822ad8aa8c3c725f166 100644 (file)
@@ -9,19 +9,31 @@
 
 package org.splat.service;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
 
 import org.hibernate.Session;
+import org.splat.dal.bo.kernel.Relation;
+import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
+import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.UsedByRelation;
+import org.splat.dal.bo.som.UsesRelation;
+import org.splat.dal.bo.som.VersionsRelation;
 import org.splat.dal.dao.som.Database;
 import org.splat.kernel.InvalidPropertyException;
+import org.splat.kernel.MismatchException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
+import org.splat.kernel.NotApplicableException;
 import org.splat.service.technical.IndexService;
 import org.splat.service.technical.IndexServiceImpl;
+import org.splat.som.Revision;
 import org.splat.som.Step;
 
 /**
@@ -31,6 +43,7 @@ import org.splat.som.Step;
 public class StepServiceImpl implements StepService {
 
        private IndexService _indexService;
+       private DocumentService _documentService;
 
        public SimulationContext addSimulationContext(Step aStep,
                        SimulationContext.Properties dprop) throws MissedPropertyException,
@@ -112,6 +125,77 @@ public class StepServiceImpl implements StepService {
       return true;
     }
 
+    public Publication createDocument (Step aStep, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException {
+    //  -------------------------------------------------------------
+          Document  newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep()));
+          getDocumentService().generateDocumentId(newdoc, dprop);
+
+//        Creation of the save directory      
+          File wdir = newdoc.getSaveDirectory();
+         if (!wdir.exists()) if (!wdir.mkdirs()) throw new IOException("Cannot create the repository vault directory");
+
+//        Identification and save
+          newdoc.buildReferenceFrom(aStep.getOwnerStudy());
+          Database.getSession().save(newdoc);
+
+          return  new Publication(newdoc, aStep.getOwner());
+        }
+
+        public Publication assignDocument (Step aStep, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, NotApplicableException {
+    //  -------------------------------------------------------------
+          String refid = dprop.getReference();
+          if    (refid == null)    return null;
+
+          Document  slot = Database.selectDocument(refid, new Revision().toString());
+          if ( slot == null )      return null;
+          if (!slot.isUndefined()) return null;     // Should not happen
+
+          getDocumentService().initialize(slot, dprop.setOwner(aStep.getOwnerStudy()));
+          return  new Publication(slot, aStep.getOwner());
+        }
+
+        public Publication versionDocument (Step aStep, Publication base) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
+    //  -----------------------------------------------------
+          return versionDocument(aStep, base, new Document.Properties());
+        }
+
+        public Publication versionDocument (Step aStep, Publication base, String reason) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
+    //  --------------------------------------------------------------------
+          return versionDocument(aStep, base, new Document.Properties().setDescription(reason));
+        }
+
+        public Publication versionDocument (Step aStep, Publication base, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
+    //  --------------------------------------------------------------------------------
+          Document previous = base.value();
+          
+          dprop.setDocument(previous);        // Initializes the Step property
+          if (dprop.getStep().getNumber() != aStep.getNumber()) throw new MismatchException();
+
+          if (dprop.getAuthor() == null) dprop.setAuthor(previous.getAuthor());
+          String    summary = dprop.getDescription();
+
+//        Creation of the document
+          Document  newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep()));
+          getDocumentService().generateDocumentId(newdoc, dprop);
+          newdoc.buildReferenceFrom(aStep.getOwner(), previous);
+          Database.getSession().save(newdoc);
+
+//        Versioning
+          if (summary == null) newdoc.addRelation( new VersionsRelation(newdoc, previous) );
+          else                 newdoc.addRelation( new VersionsRelation(newdoc, previous, summary) );
+
+//        Update of usedby relations, if exist
+          List<Relation> relist = previous.getRelations(UsedByRelation.class);
+          Study          scope  = aStep.getOwnerStudy();
+          for (Iterator<Relation> i=relist.iterator(); i.hasNext();) {
+            UsedByRelation relation  = (UsedByRelation)i.next();
+            Document       relatedoc = relation.getTo();
+            if (scope.shares(relatedoc)) relatedoc.addRelation( new UsesRelation(relatedoc, newdoc) );
+            else                         relation.moveTo(newdoc);
+          }
+          return  new Publication(newdoc, aStep.getOwner());
+        }
+
        /**
         * @return
         */
@@ -122,4 +206,20 @@ public class StepServiceImpl implements StepService {
        public void setIndexService(IndexService indexService) {
                _indexService = indexService;
        }
+
+       /**
+        * 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;
+       }
 }
index a9fe8b47155581055b4a83a0a6264b9c38d4b807..d0b9a56c0f5a9369f9cfeb5f7470544522f4c39d 100644 (file)
@@ -122,17 +122,6 @@ public class StudyServiceImpl implements StudyService {
                return added;
        }
 
-       /**
-        * @return
-        */
-       public StepService getStepService() {
-               return _stepService;
-       }
-
-       public void setStepService(StepService stepService) {
-               _stepService = stepService;
-       }
-
        public SimulationContext addProjectContext(Study aStudy,
                        SimulationContext context) {
                // ----------------------------------------------------------------------
@@ -495,4 +484,20 @@ public class StudyServiceImpl implements StudyService {
                        ProjectElementService projectElementService) {
                _projectElementService = projectElementService;
        }
+
+       /**
+        * 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;
+       }
 }
index d7a8dfb79079bdd6efbd732768980e008f0a4d71..ebac98cabfad70920e8b35b7cf60f34274388c0a 100644 (file)
@@ -30,6 +30,7 @@ import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.UsedByRelation;
 import org.splat.dal.bo.som.UsesRelation;
 import org.splat.dal.bo.som.VersionsRelation;
+import org.splat.dal.bo.som.Document.Properties;
 import org.splat.dal.dao.som.Database;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MismatchException;
@@ -78,75 +79,6 @@ public class Step {
 //  Public member functions
 //  ==============================================================================================================================
 
-    public Publication createDocument (Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException {
-//  -------------------------------------------------------------
-      Document  newdoc = new Document(dprop.setOwner(owner).setStep(step));
-
-//    Creation of the save directory      
-      File wdir = newdoc.getSaveDirectory();
-         if (!wdir.exists()) if (!wdir.mkdirs()) throw new IOException("Cannot create the repository vault directory");
-
-//    Identification and save
-      newdoc.buildReferenceFrom(getOwnerStudy());
-      Database.getSession().save(newdoc);
-
-      return  new Publication(newdoc, owner);
-    }
-
-    public Publication assignDocument (Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, NotApplicableException {
-//  -------------------------------------------------------------
-      String refid = dprop.getReference();
-      if    (refid == null)    return null;
-
-      Document  slot = Database.selectDocument(refid, new Revision().toString());
-      if ( slot == null )      return null;
-      if (!slot.isUndefined()) return null;     // Should not happen
-
-      slot.initialize(dprop.setOwner(getOwnerStudy()));
-      return  new Publication(slot, owner);
-    }
-
-    public Publication versionDocument (Publication base) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
-//  -----------------------------------------------------
-      return versionDocument(base, new Document.Properties());
-    }
-
-    public Publication versionDocument (Publication base, String reason) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
-//  --------------------------------------------------------------------
-      return versionDocument(base, new Document.Properties().setDescription(reason));
-    }
-
-    public Publication versionDocument (Publication base, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
-//  --------------------------------------------------------------------------------
-      Document previous = base.value();
-      
-      dprop.setDocument(previous);        // Initializes the Step property
-      if (dprop.getStep().getNumber() != this.step.getNumber()) throw new MismatchException();
-
-      if (dprop.getAuthor() == null) dprop.setAuthor(previous.getAuthor());
-      String    summary = dprop.getDescription();
-
-//    Creation of the document
-      Document  newdoc = new Document(dprop.setOwner(owner).setStep(step));
-      newdoc.buildReferenceFrom(getOwner(), previous);
-      Database.getSession().save(newdoc);
-
-//    Versioning
-      if (summary == null) newdoc.addRelation( new VersionsRelation(newdoc, previous) );
-      else                 newdoc.addRelation( new VersionsRelation(newdoc, previous, summary) );
-
-//    Update of usedby relations, if exist
-      List<Relation> relist = previous.getRelations(UsedByRelation.class);
-      Study          scope  = getOwnerStudy();
-      for (Iterator<Relation> i=relist.iterator(); i.hasNext();) {
-        UsedByRelation relation  = (UsedByRelation)i.next();
-        Document       relatedoc = relation.getTo();
-        if (scope.shares(relatedoc)) relatedoc.addRelation( new UsesRelation(relatedoc, newdoc) );
-        else                         relation.moveTo(newdoc);
-      }
-      return  new Publication(newdoc, owner);
-    }
-
     public User getActor () {
 //  -----------------------
       return actor;
index 01da7c59a2c6561ec2e3140ffc97d5b2bcbd4401..337c839f4780d7043d032561d1ef55a0823e031f 100644 (file)
@@ -18,8 +18,13 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
        <bean id="documentTypeService"
                class="org.splat.service.DocumentTypeServiceImpl">
-               <property name="projectSettingsService"
-                       ref="projectSettings" />
+               <property name="projectSettings" ref="projectSettings" />
+       </bean>
+
+       <bean id="documentService"
+               class="org.splat.service.DocumentServiceImpl">
+               <property name="projectSettings" ref="projectSettings" />
+               <property name="studyService" ref="studyService" />
        </bean>
 
        <bean id="knowledgeElementService"
@@ -54,6 +59,7 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
        <bean id="stepService" class="org.splat.service.StepServiceImpl">
                <property name="indexService" ref="indexService" />
+               <property name="documentService" ref="documentService" />
        </bean>
 
        <bean id="studyService"
index 4ff25593894746fdfc16784287192c0006e479ee..d9d7bf1e72d810b89b1afe2814b7837089a101c4 100644 (file)
@@ -68,7 +68,7 @@ public class SaveDocumentAction extends Action {
                        connex.flush();
 
                        Document.Properties dprop = new Document.Properties();
-                       Publication credoc = step.createDocument(dprop.setName(docname)
+                       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();
@@ -234,7 +234,7 @@ 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();
index 9c113ca9588df455b49c1c24d6e04d314f78da0f..a51a9d546cda0a649700321a5945ba82421c5fd5 100644 (file)
@@ -1,4 +1,5 @@
 package org.splat.simer;
+
 /**
  * 
  * @author    Daniel Brunier-Coulin
@@ -30,306 +31,368 @@ import org.splat.dal.bo.som.UsesRelation;
 import org.splat.dal.bo.som.VersionsRelation;
 import org.splat.wapp.PopupMenu;
 
-
 public class DocumentFacade implements HistoryFacade {
 
-    private OpenObject           owner;
-    private Publication          me;
-    private Document             my;        // Published document
-    private ProgressState        state;     // Document state
-    private String               version;   // My document version in customized format
-    private State                display;   // Presentation state
-    private String               surl;      // URL of the source file
-    private String               format;    // Extension of the source file
-    private String               icon;      // Corresponding icon
-    private String               sharing;   // Icon qualifying sharing between scenarios of a same study
-    private String               updated;   // Icon qualifying versioning from the previous study version
-    private String               size;
-    private String               date;
-    private String               description;
-    private List<DocumentFacade> uses;
-    private List<FileFacade>     exports;
-    private List<HistoryFacade>  history;
-    private PopupMenu            popup;
+       private OpenObject owner;
+       private Publication me;
+       private Document my; // Published document
+       private ProgressState state; // Document state
+       private String version; // My document version in customized format
+       private State display; // Presentation state
+       private String surl; // URL of the source file
+       private String format; // Extension of the source file
+       private String icon; // Corresponding icon
+       private String sharing; // Icon qualifying sharing between scenarios of a same study
+       private String updated; // Icon qualifying versioning from the previous study version
+       private String size;
+       private String date;
+       private String description;
+       private List<DocumentFacade> uses;
+       private List<FileFacade> exports;
+       private List<HistoryFacade> history;
+       private PopupMenu popup;
        private ProjectSettingsService _projectSettingsService;
        private PublicationService _publicationService;
-    
-    private enum State { closed, open, deepopen }
-
-//  ==============================================================================================================================
-//  Constructors
-//  ==============================================================================================================================
-
-    public DocumentFacade (OpenObject opened, Publication represented) {
-//  ------------------------------------------------------------------
-      owner       = opened;
-      me          = represented;
-      my          = me.value();
-      state       = my.getProgressState();
-      display     = State.closed;
-      description = null;
-      uses        = null;
-      exports     = null;
-      history     = null;
-      popup       = null;
-
-      this.refresh();                       // Initializes the presentation of my document
-    }
-/**
- * Constructs the facade of a document presented in the history folder.
- * 
- * @param represented the represented history document
- */
-    private DocumentFacade (OpenObject opened, Document represented) {
-//  ----------------------------------------------------------------
-      owner       = opened;
-      me          = null;                   // Marks the history context
-      my          = represented;
-      state       = my.getProgressState();  // In reality, HISTORY
-      display     = State.open;             // Because the given document is a history document
-      description = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale()).getString("history.creation") + " " + my.getAuthor().toString();
-      uses        = null;
-      exports     = null;
-      history     = null;
-      popup       = null;
-
-      this.refresh();                       // Initializes the presentation of my document
-    }
-
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
-
-    public void develop () {
-//  -------------------
-      if (display != State.open) {   // Opening the document
-        if (uses == null) {
-          List<Publication> relist = me.getRelations(UsesRelation.class);
-
-          uses = new ArrayList<DocumentFacade>(relist.size());
-          for (Iterator<Publication> i=relist.iterator(); i.hasNext();) {
-               Publication     used   = i.next();
-            Integer         index  = used.getIndex();
-            DocumentFacade  facade = OpenObject.docpres.get(index);
-            if (facade == null) {
-               facade = new DocumentFacade(owner, used);
-              OpenObject.docpres.put(index, facade);
-            }
-            uses.add(facade);
-          }
-        }
-        if (exports == null) {
-                 List<Relation> relation = my.getRelations(ConvertsRelation.class);
-
-          exports = new ArrayList<FileFacade>(relation.size());
-          for (Iterator<Relation> i=relation.iterator(); i.hasNext();) {
-               ConvertsRelation export = (ConvertsRelation)i.next();
-            exports.add( new FileFacade(export) );
-          }
-        }
-        if (history == null) {
-          if (my.getPreviousVersion() != null || state == ProgressState.inCHECK || state == ProgressState.APPROVED) history = new ArrayList<HistoryFacade>();
-        }
-        display = State.open;
-      } else {                     // Opening the history of document, if exist
-       if (history.isEmpty()) collectHistory(my);
-       display = State.deepopen;
-      }
-    }
-
-    public void reduce () {
-//  ---------------------
-      if (display == State.deepopen) display = State.open;
-    }
-
-    public void reduceAll () {
-//  ------------------------
-       display = State.closed;
-    }
-
-//  ==============================================================================================================================
-//  Getters
-//  ==============================================================================================================================
-
-    public List<FileFacade> getAttachments () {
-//  ------------------------------------------
-      return exports;
-    }
-    public String getDate () {
-//  ------------------------
-      return date;
-    }
-    public String getDescription () {
-//  -------------------------------
-      return description;
-    }
-    public String getEditIcon () {
-//  ----------------------------
-      return "icon.ed" + state + ".png";
-    }
-    public String getFileIcon () {
-//  ----------------------------
-      return icon;
-    }
-    public List<HistoryFacade> getHistory () {
-//  ----------------------------------------
-      return history;
-    }
-    public String getIndex () {
-//  -------------------------
-      return String.valueOf(my.getIndex());
-    }
-    public PopupMenu getPopup () {          // Contextualizes the pop-up
-//  ----------------------------
-      popup.setContext("document", new DocumentRights(owner.getUser(), me));
-      return popup;                         // callers must "use" the returned pop-up before getting another pop-up
-    }
-    public String getPresentationState () {
-//  -------------------------------------
-      return display.toString();
-    }
-    public String getProgressState () {
-//  ---------------------------------
-      return state.toString();
-    }
-    public String getSharingIcon () {
-//  -------------------------------
-      return sharing;
-    }
-    public String getSize () {
-//  ------------------------
-      return size;
-    }
-    public String getStateIcon () {
-//  -----------------------------
-      return "icon." + state + ".png";
-    }
-    public String getTitle () {
-//  -------------------------
-      return my.getTitle();
-    }
-    public String getURL () {
-//  -----------------------
-      return surl;
-    }
-    public List<DocumentFacade> getUses () {
-//  ---------------------------------------
-      return uses;
-    }
-    public String getVersion () {
-//  ---------------------------
-      return version;
-    }
-    public String getVersioningIcon () {
-//  ----------------------------------
-      return updated;
-    }
-    public boolean isFacadeOf (Publication represented) {
-//  ---------------------------------------------------
-      return  me.equals(represented);
-    }
-//  ==============================================================================================================================
-//  Protected services
-//  ==============================================================================================================================
-
-    protected void refresh () {
-//  -------------------------
-      ResourceBundle      custom    = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
-         DecimalFormat       sizstring = new DecimalFormat(custom.getString("size.format"));     // Locale size display format
-         SimpleDateFormat    datstring = new SimpleDateFormat(custom.getString("date.format"));  // Locale date display format
-         Revision.Format     verstring = new Revision.Format(getProjectSettings().getRevisionPattern());
-      String              path      = my.getSourceFile().getRelativePath();
-      String[]            mapping   = ApplicationSettings.getViewersMapping();
-
-      for (int i=0; i<mapping.length; i++) {
-        org.splat.dal.bo.som.File  export  = my.getAttachedFile(mapping[i]);
-        if (export == null) continue;
-        path = export.getRelativePath();
-        break;
-      }
-      surl   = ApplicationSettings.getRepositoryURL() + path;
-      surl   = surl.replaceAll("'", "\\\\'");
-      format = my.getFormat();
-      if (format.equals("xml")) format = XMLDocument.getActualFormat(my.getSourceFile().asFile());
-
-//    Document state (overridable by the publication - see below)
-      state   = my.getProgressState();
-      version = my.getVersion();                              // May be null
-
-//    Icons definition
-      icon    = "icon." + format + ".png";
-      sharing = "image.hold.gif";
-      updated = "image.hold.gif";
-      File image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
-      if (!image.exists()) icon = "icon.any.png";
-
-      if (me != null) {
-        if (me.getOwnerStudy().shares(my)) {
-                             sharing = "image.share.png";
-                             updated = "icon.hold.png";
-        }
-        if (me.isOutdated()) state   = ProgressState.inWORK;  // Overrides the document state
-
-      } else {            // Facade in the history folder
-       if (!my.isVersioned()) {                              // History of the last version
-          if (state != ProgressState.inWORK) icon = "icon.inWORK.png";
-          else                               icon = "icon." + state.toString() + ".png";
-       } else
-       if ( my.isPublished()) {
-                                sharing = "image.share.png";     // Not correct if published in a previous version of the study
-                             updated = "icon.hold.png";
-       }
-      }
-//    Document description
-      VersionsRelation  versions = (VersionsRelation)my.getFirstRelation(VersionsRelation.class);
-      if (versions != null) {
-        description = versions.getDescription();
-      }
-//    File details
-      if (state != ProgressState.EXTERN) version = verstring.format(version);
-         size = sizstring.format(my.getSourceFile().asFile().length()/1000);
-         date = datstring.format(my.getLastModificationDate());
-
-//    Refresh of the history in case of promotion
-      if (display == State.deepopen) {
-        history.clear();
-        collectHistory(my);
-      }
-//    Popup menus
-         if (me == null) return;                                 // No pop-up (yet) in the history folder
-         if       (state == ProgressState.EXTERN)   popup = ApplicationSettings.getPopupMenu("extern");
-         else if  (state == ProgressState.inWORK)   popup = ApplicationSettings.getPopupMenu("editable");
-         else if  (state == ProgressState.inDRAFT)  popup = ApplicationSettings.getPopupMenu("reviewable");
-         else if  (state == ProgressState.APPROVED) popup = ApplicationSettings.getPopupMenu("approved");
-         else { //(state == ProgressState.inCHECK)
-        DocumentType mytype = me.value().getType();           // Only result documents need to be approved
-        Step         mystep = getPublicationService().getInvolvedStep(me);
-               if (mytype.isResultOf(mystep.getStep())) popup = ApplicationSettings.getPopupMenu("approvable");
-               else                                     popup = ApplicationSettings.getPopupMenu("notresult");
-         }
-    }
-
-    protected void setVersioned () {
-//  ------------------------------
-      updated = "image.modified.png";
-    }
-
-//  ==============================================================================================================================
-//  Private services
-//  ==============================================================================================================================
-
-    private void collectHistory (Document given) {
-//  --------------------------------------------
-      VersionsRelation  versions = (VersionsRelation)given.getFirstRelation(VersionsRelation.class);
-      Timestamp[]       stamp    = given.getStamps();         // Stamps in ascending order of date
-
-      for  (int i=stamp.length-1; i>-1; i--) history.add( new StampFacade(stamp[i]) );
-      history.add( new DocumentFacade(owner, given) );
-      if (versions != null) collectHistory(versions.getTo());
-    }
-    
-    /**
-     * Get project settings.
+
+       private enum State {
+               closed, open, deepopen
+       }
+
+       // ==============================================================================================================================
+       // Constructors
+       // ==============================================================================================================================
+
+       public DocumentFacade(OpenObject opened, Publication represented,
+                       ProjectSettingsService projectSettings,
+                       PublicationService publicationService) {
+               // ------------------------------------------------------------------
+               setProjectSettings(projectSettings);
+               setPublicationService(publicationService);
+               owner = opened;
+               me = represented;
+               my = me.value();
+               state = my.getProgressState();
+               display = State.closed;
+               description = null;
+               uses = null;
+               exports = null;
+               history = null;
+               popup = null;
+
+               this.refresh(); // Initializes the presentation of my document
+       }
+
+       /**
+        * Constructs the facade of a document presented in the history folder.
+        * 
+        * @param represented
+        *            the represented history document
+        */
+       private DocumentFacade(OpenObject opened, Document represented,
+                       ProjectSettingsService projectSettings,
+                       PublicationService publicationService) {
+               // ----------------------------------------------------------------
+               setProjectSettings(projectSettings);
+               setPublicationService(publicationService);
+               owner = opened;
+               me = null; // Marks the history context
+               my = represented;
+               state = my.getProgressState(); // In reality, HISTORY
+               display = State.open; // Because the given document is a history document
+               description = ResourceBundle.getBundle("som",
+                               ApplicationSettings.getCurrentLocale()).getString(
+                               "history.creation")
+                               + " " + my.getAuthor().toString();
+               uses = null;
+               exports = null;
+               history = null;
+               popup = null;
+
+               this.refresh(); // Initializes the presentation of my document
+       }
+
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+
+       public void develop() {
+               // -------------------
+               if (display != State.open) { // Opening the document
+                       if (uses == null) {
+                               List<Publication> relist = me.getRelations(UsesRelation.class);
+
+                               uses = new ArrayList<DocumentFacade>(relist.size());
+                               for (Iterator<Publication> i = relist.iterator(); i.hasNext();) {
+                                       Publication used = i.next();
+                                       Integer index = used.getIndex();
+                                       DocumentFacade facade = OpenObject.docpres.get(index);
+                                       if (facade == null) {
+                                               facade = new DocumentFacade(owner, used, getProjectSettings(), getPublicationService());
+                                               OpenObject.docpres.put(index, facade);
+                                       }
+                                       uses.add(facade);
+                               }
+                       }
+                       if (exports == null) {
+                               List<Relation> relation = my
+                                               .getRelations(ConvertsRelation.class);
+
+                               exports = new ArrayList<FileFacade>(relation.size());
+                               for (Iterator<Relation> i = relation.iterator(); i.hasNext();) {
+                                       ConvertsRelation export = (ConvertsRelation) i.next();
+                                       exports.add(new FileFacade(export));
+                               }
+                       }
+                       if (history == null) {
+                               if (my.getPreviousVersion() != null
+                                               || state == ProgressState.inCHECK
+                                               || state == ProgressState.APPROVED)
+                                       history = new ArrayList<HistoryFacade>();
+                       }
+                       display = State.open;
+               } else { // Opening the history of document, if exist
+                       if (history.isEmpty())
+                               collectHistory(my);
+                       display = State.deepopen;
+               }
+       }
+
+       public void reduce() {
+               // ---------------------
+               if (display == State.deepopen)
+                       display = State.open;
+       }
+
+       public void reduceAll() {
+               // ------------------------
+               display = State.closed;
+       }
+
+       // ==============================================================================================================================
+       // Getters
+       // ==============================================================================================================================
+
+       public List<FileFacade> getAttachments() {
+               // ------------------------------------------
+               return exports;
+       }
+
+       public String getDate() {
+               // ------------------------
+               return date;
+       }
+
+       public String getDescription() {
+               // -------------------------------
+               return description;
+       }
+
+       public String getEditIcon() {
+               // ----------------------------
+               return "icon.ed" + state + ".png";
+       }
+
+       public String getFileIcon() {
+               // ----------------------------
+               return icon;
+       }
+
+       public List<HistoryFacade> getHistory() {
+               // ----------------------------------------
+               return history;
+       }
+
+       public String getIndex() {
+               // -------------------------
+               return String.valueOf(my.getIndex());
+       }
+
+       public PopupMenu getPopup() { // Contextualizes the pop-up
+       // ----------------------------
+               popup.setContext("document", new DocumentRights(owner.getUser(), me));
+               return popup; // callers must "use" the returned pop-up before getting another pop-up
+       }
+
+       public String getPresentationState() {
+               // -------------------------------------
+               return display.toString();
+       }
+
+       public String getProgressState() {
+               // ---------------------------------
+               return state.toString();
+       }
+
+       public String getSharingIcon() {
+               // -------------------------------
+               return sharing;
+       }
+
+       public String getSize() {
+               // ------------------------
+               return size;
+       }
+
+       public String getStateIcon() {
+               // -----------------------------
+               return "icon." + state + ".png";
+       }
+
+       public String getTitle() {
+               // -------------------------
+               return my.getTitle();
+       }
+
+       public String getURL() {
+               // -----------------------
+               return surl;
+       }
+
+       public List<DocumentFacade> getUses() {
+               // ---------------------------------------
+               return uses;
+       }
+
+       public String getVersion() {
+               // ---------------------------
+               return version;
+       }
+
+       public String getVersioningIcon() {
+               // ----------------------------------
+               return updated;
+       }
+
+       public boolean isFacadeOf(Publication represented) {
+               // ---------------------------------------------------
+               return me.equals(represented);
+       }
+
+       // ==============================================================================================================================
+       // Protected services
+       // ==============================================================================================================================
+
+       protected void refresh() {
+               // -------------------------
+               ResourceBundle custom = ResourceBundle.getBundle("som",
+                               ApplicationSettings.getCurrentLocale());
+               DecimalFormat sizstring = new DecimalFormat(custom
+                               .getString("size.format")); // Locale size display format
+               SimpleDateFormat datstring = new SimpleDateFormat(custom
+                               .getString("date.format")); // Locale date display format
+               Revision.Format verstring = new Revision.Format(getProjectSettings()
+                               .getRevisionPattern());
+               String path = my.getSourceFile().getRelativePath();
+               String[] mapping = ApplicationSettings.getViewersMapping();
+
+               for (int i = 0; i < mapping.length; i++) {
+                       org.splat.dal.bo.som.File export = my.getAttachedFile(mapping[i]);
+                       if (export == null)
+                               continue;
+                       path = export.getRelativePath();
+                       break;
+               }
+               surl = ApplicationSettings.getRepositoryURL() + path;
+               surl = surl.replaceAll("'", "\\\\'");
+               format = my.getFormat();
+               if (format.equals("xml"))
+                       format = XMLDocument.getActualFormat(my.getSourceFile().asFile());
+
+               // Document state (overridable by the publication - see below)
+               state = my.getProgressState();
+               version = my.getVersion(); // May be null
+
+               // Icons definition
+               icon = "icon." + format + ".png";
+               sharing = "image.hold.gif";
+               updated = "image.hold.gif";
+               File image = new File(ApplicationSettings.getApplicationSkinPath()
+                               + icon);
+               if (!image.exists())
+                       icon = "icon.any.png";
+
+               if (me != null) {
+                       if (me.getOwnerStudy().shares(my)) {
+                               sharing = "image.share.png";
+                               updated = "icon.hold.png";
+                       }
+                       if (me.isOutdated())
+                               state = ProgressState.inWORK; // Overrides the document state
+
+               } else { // Facade in the history folder
+                       if (!my.isVersioned()) { // History of the last version
+                               if (state != ProgressState.inWORK)
+                                       icon = "icon.inWORK.png";
+                               else
+                                       icon = "icon." + state.toString() + ".png";
+                       } else if (my.isPublished()) {
+                               sharing = "image.share.png"; // Not correct if published in a previous version of the study
+                               updated = "icon.hold.png";
+                       }
+               }
+               // Document description
+               VersionsRelation versions = (VersionsRelation) my
+                               .getFirstRelation(VersionsRelation.class);
+               if (versions != null) {
+                       description = versions.getDescription();
+               }
+               // File details
+               if (state != ProgressState.EXTERN)
+                       version = verstring.format(version);
+               size = sizstring.format(my.getSourceFile().asFile().length() / 1000);
+               date = datstring.format(my.getLastModificationDate());
+
+               // Refresh of the history in case of promotion
+               if (display == State.deepopen) {
+                       history.clear();
+                       collectHistory(my);
+               }
+               // Popup menus
+               if (me == null)
+                       return; // No pop-up (yet) in the history folder
+               if (state == ProgressState.EXTERN)
+                       popup = ApplicationSettings.getPopupMenu("extern");
+               else if (state == ProgressState.inWORK)
+                       popup = ApplicationSettings.getPopupMenu("editable");
+               else if (state == ProgressState.inDRAFT)
+                       popup = ApplicationSettings.getPopupMenu("reviewable");
+               else if (state == ProgressState.APPROVED)
+                       popup = ApplicationSettings.getPopupMenu("approved");
+               else { // (state == ProgressState.inCHECK)
+                       DocumentType mytype = me.value().getType(); // Only result documents need to be approved
+                       Step mystep = getPublicationService().getInvolvedStep(me);
+                       if (mytype.isResultOf(mystep.getStep()))
+                               popup = ApplicationSettings.getPopupMenu("approvable");
+                       else
+                               popup = ApplicationSettings.getPopupMenu("notresult");
+               }
+       }
+
+       protected void setVersioned() {
+               // ------------------------------
+               updated = "image.modified.png";
+       }
+
+       // ==============================================================================================================================
+       // Private services
+       // ==============================================================================================================================
+
+       private void collectHistory(Document given) {
+               // --------------------------------------------
+               VersionsRelation versions = (VersionsRelation) given
+                               .getFirstRelation(VersionsRelation.class);
+               Timestamp[] stamp = given.getStamps(); // Stamps in ascending order of date
+
+               for (int i = stamp.length - 1; i > -1; i--)
+                       history.add(new StampFacade(stamp[i]));
+               history.add(new DocumentFacade(owner, given, getProjectSettings(), getPublicationService()));
+               if (versions != null)
+                       collectHistory(versions.getTo());
+       }
+
+       /**
+        * Get project settings.
+        * 
         * @return Project settings service
         */
        private ProjectSettingsService getProjectSettings() {
@@ -338,12 +401,14 @@ public class DocumentFacade implements HistoryFacade {
 
        /**
         * Set project settings service.
-        * @param projectSettingsService project settings service
+        * 
+        * @param projectSettingsService
+        *            project settings service
         */
-       public void setProjectSettings(
-                       ProjectSettingsService projectSettingsService) {
+       public void setProjectSettings(ProjectSettingsService projectSettingsService) {
                _projectSettingsService = projectSettingsService;
        }
+
        /**
         * Get the publicationService.
         * 
index 3de836904923375c870fec63544a27f538db2bbf..b565afbd382a845b549d7ece165e16b80291285f 100644 (file)
@@ -20,6 +20,7 @@ import org.splat.dal.dao.som.Database;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.ProgressState;
 import org.splat.service.PublicationService;
+import org.splat.service.StepService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.DocumentType;
@@ -35,6 +36,7 @@ public class ImportDocumentAction extends UploadBaseNextAction {
        private String date = ""; // Date extracted from the imported file, if exist
        private ProjectSettingsService _projectSettingsService;
        private PublicationService _publicationService;
+       private StepService _stepService;
 
        private static final long serialVersionUID = 2587822564883588556L;
 
@@ -163,7 +165,7 @@ public class ImportDocumentAction extends UploadBaseNextAction {
 
                        if (docref.length() == 0) { // Importation of a foreign document
                        // TODO: Extract property of supported documents (DOCX, ODT...)
-                               addoc = step.createDocument(dprop.setName(docname)
+                               addoc = getStepService().createDocument(step, dprop.setName(docname)
                                                .setType(type).setFormat(table[table.length - 1])
                                                .setAuthor(user));
                                updir = addoc.getSourceFile().asFile();
@@ -187,7 +189,7 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                                                        locale.getString("date.format"));
                                        dprop.setDate(get.parse(date));
                                }
-                               addoc = step.assignDocument(dprop.setReference(docref).setName(
+                               addoc = getStepService().assignDocument(step, dprop.setReference(docref).setName(
                                                docname));
                                updir = addoc.getSourceFile().asFile();
                                if (logger.isInfoEnabled())
@@ -357,4 +359,20 @@ public class ImportDocumentAction extends UploadBaseNextAction {
        public void setPublicationService(PublicationService publicationService) {
                _publicationService = publicationService;
        }
+
+       /**
+        * 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
index 86dfc0c1a5adb3a2873df250bb95dc01c6d48c4b..402abfe97e999b678bb32badd31c83a862676106 100644 (file)
@@ -21,7 +21,6 @@ public class OpenKnowledge extends OpenObject {
        private KnowledgeElement myknelm;
        private String credate;
        private ProjectElementService _projectElementService;
-       private ProjectSettingsService _projectSettingsService;
 
        public class Menu extends SimpleMenu {
                // ------------------------------------
@@ -202,20 +201,4 @@ public class OpenKnowledge extends OpenObject {
                _projectElementService = projectElementService;
        }
 
-       /**
-        * Get project settings.
-        * @return Project settings service
-        */
-       private ProjectSettingsService getProjectSettings() {
-               return _projectSettingsService;
-       }
-
-       /**
-        * Set project settings service.
-        * @param projectSettingsService project settings service
-        */
-       public void setProjectSettings(
-                       ProjectSettingsService projectSettingsService) {
-               _projectSettingsService = projectSettingsService;
-       }
 }
\ No newline at end of file
index 92905fd57dbeb2502d8d4de21c8f951835346f3b..b00ad00f71a7e597f2d340ada6d3482521e1bf5b 100644 (file)
@@ -11,7 +11,9 @@ import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.ProgressState;
+import org.splat.service.PublicationService;
 import org.splat.service.dto.Proxy;
+import org.splat.service.technical.ProjectSettingsService;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.som.Step;
@@ -32,6 +34,8 @@ public abstract class OpenObject implements Proxy {
        
        protected  Menu                          menu        = null;   // Left pane menu of this object
        protected  PopupMenu                     popup       = null;   // Pop-up menu of this object, if the user has write access
+       private ProjectSettingsService _projectSettingsService;
+       private PublicationService _publicationService;
 
     protected static HashMap<Integer, DocumentFacade>         docpres  = null;
     protected static HashMap<Integer, KnowledgeElementFacade> knowpres = null;
@@ -253,7 +257,7 @@ public abstract class OpenObject implements Proxy {
           Integer         index   = present.getIndex();
           DocumentFacade  facade  = docpres.get(index);
           if (facade == null) {
-            facade = new DocumentFacade(this, present);
+            facade = new DocumentFacade(this, present, getProjectSettings(), getPublicationService());
             docpres.put(index, facade);
           }
          contents.add(facade);
@@ -262,4 +266,40 @@ public abstract class OpenObject implements Proxy {
         contents = null;
          }
     }
+
+       /**
+        * Get project settings.
+        * @return Project settings service
+        */
+    public ProjectSettingsService getProjectSettings() {
+               return _projectSettingsService;
+       }
+
+       /**
+        * Get the publicationService.
+        * 
+        * @return the publicationService
+        */
+       public PublicationService getPublicationService() {
+               return _publicationService;
+       }
+
+       /**
+        * Set project settings service.
+        * @param projectSettingsService project settings service
+        */
+       public void setProjectSettings(
+                       ProjectSettingsService projectSettingsService) {
+               _projectSettingsService = projectSettingsService;
+       }
+
+       /**
+        * Set the publicationService.
+        * 
+        * @param publicationService
+        *            the publicationService to set
+        */
+       public void setPublicationService(PublicationService publicationService) {
+               _publicationService = publicationService;
+       }
 }
\ No newline at end of file
index 92673d24305853dbdbef61994874d91d2343ffee..8fdc2868f013fc18a878413ae600d5b4bcdad9c2 100644 (file)
@@ -27,7 +27,9 @@ 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.ProjectElementService;
+import org.splat.service.PublicationService;
 import org.splat.service.ScenarioService;
+import org.splat.service.StepService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.dal.bo.som.Publication;
 import org.splat.som.Revision;
@@ -49,11 +51,10 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
     private  String      credate;
     private  String      lasdate;
     private  Publication selecdoc;
-       private ProjectSettingsService _projectSettingsService;
        private ProjectElementService _projectElementService;
        private ScenarioService _scenarioService;
-    
-    protected final static Logger   logger = org.splat.simer.Action.logger;
+       private StepService _stepService;
+       protected final static Logger   logger = org.splat.simer.Action.logger;
     
 //  ==============================================================================================================================
 //  Constructor
@@ -190,7 +191,7 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
         Step                step  = getSelectedStep();   // Should we check if the given document type is compatible ?
            DocumentType        type  = Document.selectType(typename);
         Document.Properties dprop = new Document.Properties();
-        Document            medoc = step.createDocument(dprop.setType(type).setFormat("xml").setAuthor(author)).value();
+        Document            medoc = getStepService().createDocument(step, dprop.setType(type).setFormat("xml").setAuthor(author)).value();
         transax.commit();
 
 //      Instantiation of the template into the user download directory
@@ -279,7 +280,7 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
 
     protected void add (Publication doc) {
 //  ------------------------------------
-         DocumentFacade  facade = new DocumentFacade(this, doc);
+         DocumentFacade  facade = new DocumentFacade(this, doc, getProjectSettings(), getPublicationService());
          boolean         first  = (contents.size() == 0);
 
       docpres.put(doc.getIndex(), facade);
@@ -422,22 +423,6 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
     }
     
     /**
-     * Get project settings.
-        * @return Project settings service
-        */
-       private ProjectSettingsService getProjectSettings() {
-               return _projectSettingsService;
-       }
-
-       /**
-        * Set project settings service.
-        * @param projectSettingsService project settings service
-        */
-       public void setProjectSettings(
-                       ProjectSettingsService projectSettingsService) {
-               _projectSettingsService = projectSettingsService;
-       }
-       /**
         * Get the projectElementService.
         * 
         * @return the projectElementService
@@ -475,4 +460,20 @@ public class OpenStudy extends OpenObject implements OpenStudyServices {
        public void setScenarioService(ScenarioService scenarioService) {
                _scenarioService = scenarioService;
        }
+
+       /**
+        * 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
index c68b0ce61e735027dd20cf7053c2359a25fbc426..a5503b38f32d9ab1745725cb4546fdebc34f8754 100644 (file)
@@ -22,6 +22,7 @@ import org.splat.dal.dao.som.Database;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.ProgressState;
 import org.splat.service.PublicationService;
+import org.splat.service.StepService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.dal.bo.som.Publication;
 import org.splat.som.Revision;
@@ -39,6 +40,7 @@ public class VersionDocumentAction extends UploadBaseNextAction {
        private String date = ""; // Date extracted from the imported file, if exist
        private ProjectSettingsService _projectSettingsService;
        private PublicationService _publicationService;
+       private StepService _stepService;
 
        private static final long serialVersionUID = -5702264003232132168L;
 
@@ -143,7 +145,7 @@ public class VersionDocumentAction extends UploadBaseNextAction {
                        Publication next;
 
                        if (docver.length() == 0) { // Importation of a foreign document
-                               next = step.versionDocument(current, dprop.setAuthor(user)
+                               next = getStepService().versionDocument(step, current, dprop.setAuthor(user)
                                                .setDescription(summary));
                                updir = next.getSourceFile().asFile();
                                if (logger.isInfoEnabled())
@@ -166,7 +168,7 @@ public class VersionDocumentAction extends UploadBaseNextAction {
                                                        locale.getString("date.format"));
                                        dprop.setDate(get.parse(date));
                                }
-                               next = step.versionDocument(current, dprop.setAuthor(user)
+                               next = getStepService().versionDocument(step, current, dprop.setAuthor(user)
                                                .setDescription(summary));
                                updir = next.getSourceFile().asFile();
                                if (logger.isInfoEnabled())
@@ -328,4 +330,20 @@ public class VersionDocumentAction extends UploadBaseNextAction {
        public void setPublicationService(PublicationService publicationService) {
                _publicationService = publicationService;
        }
+
+       /**
+        * 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
index 693609c343b4b204b5db1eddfbfd2849f89c32b1..9d65a2f24ae6c6d255b850f1b84d52b693681402 100644 (file)
@@ -99,7 +99,7 @@ public class SimulationContextAction extends Action {
 
         tocheck = new Vector<SimulationContextFacade>(context.size());
         for (Iterator<SimulationContext> i=context.iterator(); i.hasNext(); ) {
-          tocheck.add( new SimulationContextFacade(i.next()) );
+          tocheck.add( new SimulationContextFacade(i.next(), getProjectSettings().getAllSteps()) );
         }
         selection = 0;
         edition   = null;
@@ -130,7 +130,7 @@ public class SimulationContextAction extends Action {
                edition = next;
                selected.add(edition);
           }
-          tocheck.add( new SimulationContextFacade(next) );
+          tocheck.add( new SimulationContextFacade(next, getProjectSettings().getAllSteps()) );
         }
         KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
         List<Proxy>                 kelm  = getSearchService().selectKnowledgeElementsWhere(kprop.setSimulationContexts(selected).setState(ProgressState.inWORK));
index 49048343ecf9c4f8fbacd4dc0495361528ff949a..d27d373946f6792acd4f42736fc953a7a8e5d5e1 100644 (file)
@@ -17,15 +17,13 @@ public class SimulationContextFacade {
     private String             name;
     private int                at;
     private ProgressState      state;
-       private ProjectSettingsService _projectSettingsService;
 
 //  ==============================================================================================================================
 //  Constructor
 //  ==============================================================================================================================
 
-    public SimulationContextFacade (SimulationContext represented) {
+    public SimulationContextFacade (SimulationContext represented, List<ProjectSettingsService.Step> steps) {
 //  --------------------------------------------------------------
-      List<ProjectSettingsService.Step> steps = getProjectSettings().getAllSteps();
       SimulationContextType      mytype;
 
       my     = represented;
@@ -70,20 +68,4 @@ public class SimulationContextFacade {
 //  -------------------------
       return  my.getValue();
     }
-    /**
-     * Get project settings.
-        * @return Project settings service
-        */
-       private ProjectSettingsService getProjectSettings() {
-               return _projectSettingsService;
-       }
-
-       /**
-        * Set project settings service.
-        * @param projectSettingsService project settings service
-        */
-       public void setProjectSettings(
-                       ProjectSettingsService projectSettingsService) {
-               _projectSettingsService = projectSettingsService;
-       }
 }
\ No newline at end of file
index d915f684acb3872180ae463859ecc1bd37473be5..f8cc9fd168fa3faa791f19826871b65d61c74237 100644 (file)
@@ -17,7 +17,9 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
                <property name="projectElementService"
                        ref="projectElementService" />
                <property name="projectSettings" ref="projectSettings" />
+               <property name="publicationService" ref="publicationService" />
                <property name="scenarioService" ref="scenarioService" />
+               <property name="stepService" ref="stepService" />
        </bean>
 
        <bean id="openKnowledge" class="org.splat.simer.OpenKnowledge"
@@ -119,6 +121,7 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 
        <bean id="importDocumentAction"
                class="org.splat.simer.ImportDocumentAction" scope="prototype">
+               <property name="stepService" ref="stepService" />
                <property name="projectSettings" ref="projectSettings" />
                <property name="publicationService" ref="publicationService" />
        </bean>
@@ -127,6 +130,7 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
                class="org.splat.simer.VersionDocumentAction" scope="prototype">
                <property name="projectSettings" ref="projectSettings" />
                <property name="publicationService" ref="publicationService" />
+               <property name="stepService" ref="stepService" />
        </bean>
 
        <bean id="editDocumentAction"