]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java
Salome HOME
Beans initialization is fixed. Document can be added to study now.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / Document.java
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