Salome HOME
Creation of a new study from an existing one is implemented.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / Document.java
index e39ccba25bb3c850efa6d5c857cc890548c4ffee..79bf7ca212eba6c41e21e56516c7a9305a634287 100644 (file)
@@ -12,6 +12,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
 
+import org.splat.dal.bo.kernel.Entity;
 import org.splat.dal.bo.kernel.Persistent;
 import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.kernel.User;
@@ -20,12 +21,11 @@ import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
 import org.splat.service.technical.ProjectSettingsService;
-import org.splat.service.technical.ProjectSettingsServiceImpl;
 import org.splat.som.Revision;
 import org.splat.som.Step;
 
 /**
- * Document persistent class. 
+ * Document persistent class.
  */
 public class Document extends Entity {
 
@@ -50,10 +50,9 @@ public class Document extends Entity {
        // ==============================================================================================================================
 
        /**
-        * Fields initialization class. 
+        * Fields initialization class.
         */
        public static class Properties extends Persistent.Properties {
-               // ------------------------------------------------------------
                private DocumentType type = null;
                private String did = null; // Only for searching from a given reference
                private ProjectElement owner = null; // Only for constructing a document
@@ -143,6 +142,7 @@ public class Document extends Entity {
 
                /**
                 * Get the date.
+                * 
                 * @return the date
                 */
                public Date getDate() {
@@ -158,7 +158,17 @@ public class Document extends Entity {
                        return this;
                }
 
-               public Properties setDocument(final Document base, final ProjectSettingsService.Step aStep) {
+               /**
+                * Copy base properties from the given original document for versioning.
+                * 
+                * @param base
+                *            the original document
+                * @param aStep
+                *            study step
+                * @return document properties
+                */
+               public Properties setDocument(final Document base,
+                               final ProjectSettingsService.Step aStep) {
                        type = base.type;
                        step = aStep;
                        name = base.name;
@@ -199,14 +209,15 @@ public class Document extends Entity {
                        return this;
                }
 
-               public Properties setName(final String name) throws InvalidPropertyException {
+               public Properties setName(final String name)
+                               throws InvalidPropertyException {
                        if (name.length() == 0) {
                                throw new InvalidPropertyException("name");
                        }
                        this.name = name;
                        return this;
                }
-               
+
                public String getName() {
                        return this.name;
                }
@@ -219,6 +230,7 @@ public class Document extends Entity {
                public ProjectElement getOwner() {
                        return this.owner;
                }
+
                // Required only for passing search arguments
                public Properties setReference(final String did)
                                throws InvalidPropertyException {
@@ -287,18 +299,36 @@ public class Document extends Entity {
                                }
                        }
                }
+
+               /**
+                * Get the format.
+                * 
+                * @return the format
+                */
+               public String getFormat() {
+                       return format;
+               }
        }
 
-       // Database fetch constructor
+       /**
+        * Database fetch constructor.
+        */
        protected Document() {
+               super();
        }
 
-       // Internal constructor
+       /**
+        * Initialization constructor.
+        * 
+        * @param dprop
+        * @throws MissedPropertyException
+        * @throws InvalidPropertyException
+        * @throws MultiplyDefinedException
+        */
        public Document(final Properties dprop) throws MissedPropertyException,
                        InvalidPropertyException, MultiplyDefinedException {
-               // -------------------------------------
                super(dprop); // Throws one of the above exception if not valid
-               myfile = new File(null, dprop.format, dprop.date); // The path is initialized below
+               myfile = new File(dprop.getLocalPath(), dprop.format, dprop.date); // The path is initialized below
                type = dprop.type;
                step = dprop.step.getNumber();
                name = dprop.name;
@@ -323,55 +353,56 @@ public class Document extends Entity {
        // Public member functions
        // ==============================================================================================================================
 
+       /**
+        * Get the attached file of the given format.
+        * 
+        * @param format
+        *            the file format
+        * @return the attached file or null if not found
+        */
        public File getAttachedFile(final String format) {
-               // -------------------------------------------
                List<Relation> exports = getRelations(ConvertsRelation.class);
-
-               for (Iterator<Relation> i = exports.iterator(); i.hasNext();) {
-                       File export = (File) i.next().getTo();
+               File res = null;
+               for (Relation rel : exports) {
+                       File export = (File) rel.getTo();
                        if (export.getFormat().equals(format)) {
-                               return export;
+                               res = export;
+                               break;
                        }
                }
-               return null;
+               return res;
        }
 
        public User getAuthor() {
-               // ------------------------
                return author;
        }
 
        public Date getCreationDate() {
-               // ------------------------------
                return myfile.getDate();
        }
 
        public Date getLastModificationDate() {
-               // --------------------------------------
                return lasdate;
        }
-       
+
        public void setLastModificationDate(final Date aDate) {
                lasdate = aDate;
        }
 
        public String getFormat() {
-               // --------------------------
                return myfile.getFormat();
        }
 
        public Document getPreviousVersion() {
-               // -------------------------------------
                Relation previous = getFirstRelation(VersionsRelation.class);
-               if (previous != null) {
-                       return (Document) previous.getTo();
-               } else {
+               if (previous == null) {
                        return null;
+               } else {
+                       return (Document) previous.getTo();
                }
        }
 
        public ProgressState getProgressState() {
-               // ----------------------------------------
                return state;
        }
 
@@ -382,7 +413,6 @@ public class Document extends Entity {
         * @return the path of the document
         */
        public String getRelativePath() {
-               // --------------------------------
                String[] table = myfile.getRelativePath().split("\\x2E");
                StringBuffer path = new StringBuffer(table[0]);
                for (int i = 1; i < table.length - 1; i++) {
@@ -399,12 +429,10 @@ public class Document extends Entity {
         * @return the document reference
         */
        public String getReference() {
-               // -----------------------------
                return did;
        }
 
        public File getSourceFile() {
-               // ----------------------------
                return myfile;
        }
 
@@ -415,7 +443,6 @@ public class Document extends Entity {
         * @return the stamps of the document in ascending order of dates, or an empty array if no stamp exist.
         */
        public Timestamp[] getStamps() {
-               // -------------------------------
                Vector<Timestamp> stamps = new Vector<Timestamp>();
 
                for (Iterator<Relation> i = this.getAllRelations().iterator(); i
@@ -446,17 +473,18 @@ public class Document extends Entity {
                        return name;
                }
        }
-       
+
        /**
         * Set document title.
-        * @param aTitle document title to set
+        * 
+        * @param aTitle
+        *            document title to set
         */
        public void setTitle(final String aTitle) {
                this.name = aTitle;
        }
 
        public DocumentType getType() {
-               // ------------------------------
                return type;
        }
 
@@ -469,7 +497,6 @@ public class Document extends Entity {
         * @see #isUndefined()
         */
        public String getVersion() {
-               // ---------------------------
                return version;
        }
 
@@ -483,32 +510,28 @@ public class Document extends Entity {
         * @see #initialize(Properties)
         */
        public boolean isUndefined() {
-               // -----------------------------
                return (history == -1);
        }
 
        public boolean isInto(final Step container) {
-               // --------------------------------------
                return (step == container.getNumber());
        }
 
        public boolean isPublished() {
-               // -----------------------------
                return (countag > 0);
        }
 
        public boolean isShared() {
-               // --------------------------
                return (countag + history > 1);
        }
 
        public boolean isVersioned() {
-               // -----------------------------
                return (history > 0);
        }
 
        /**
         * Get the step.
+        * 
         * @return the step
         */
        public int getStep() {
@@ -517,7 +540,9 @@ public class Document extends Entity {
 
        /**
         * Set the step.
-        * @param step the step to set
+        * 
+        * @param step
+        *            the step to set
         */
        public void setStep(final int step) {
                this.step = step;
@@ -525,6 +550,7 @@ public class Document extends Entity {
 
        /**
         * Get the did.
+        * 
         * @return the did
         */
        public String getDid() {
@@ -533,7 +559,9 @@ public class Document extends Entity {
 
        /**
         * Set the did.
-        * @param did the did to set
+        * 
+        * @param did
+        *            the did to set
         */
        public void setDid(final String did) {
                this.did = did;
@@ -541,6 +569,7 @@ public class Document extends Entity {
 
        /**
         * Get the myfile.
+        * 
         * @return the myfile
         */
        public File getFile() {
@@ -549,7 +578,9 @@ public class Document extends Entity {
 
        /**
         * Set the myfile.
-        * @param myfile the myfile to set
+        * 
+        * @param myfile
+        *            the myfile to set
         */
        public void setFile(final File myfile) {
                this.myfile = myfile;
@@ -557,6 +588,7 @@ public class Document extends Entity {
 
        /**
         * Get the history.
+        * 
         * @return the history
         */
        public int getHistory() {
@@ -565,7 +597,9 @@ public class Document extends Entity {
 
        /**
         * Set the history.
-        * @param history the history to set
+        * 
+        * @param history
+        *            the history to set
         */
        public void setHistory(final int history) {
                this.history = history;
@@ -573,7 +607,9 @@ public class Document extends Entity {
 
        /**
         * Set the version.
-        * @param version the version to set
+        * 
+        * @param version
+        *            the version to set
         */
        public void setVersion(final String version) {
                this.version = version;
@@ -581,7 +617,9 @@ public class Document extends Entity {
 
        /**
         * Set the state.
-        * @param state the state to set
+        * 
+        * @param state
+        *            the state to set
         */
        public void setProgressState(final ProgressState state) {
                this.state = state;
@@ -589,6 +627,7 @@ public class Document extends Entity {
 
        /**
         * Get the countag.
+        * 
         * @return the countag
         */
        public int getCountag() {
@@ -597,7 +636,9 @@ public class Document extends Entity {
 
        /**
         * Set the countag.
-        * @param countag the countag to set
+        * 
+        * @param countag
+        *            the countag to set
         */
        public void setCountag(final int countag) {
                this.countag = countag;