]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
The checkin from SALOME operation is updated (ScenarioService.checkin()). Versioning...
authorrkv <rkv@opencascade.com>
Fri, 23 Nov 2012 06:27:17 +0000 (06:27 +0000)
committerrkv <rkv@opencascade.com>
Fri, 23 Nov 2012 06:27:17 +0000 (06:27 +0000)
16 files changed:
Workspace/Siman-Common/proj_settings_testng.xml [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/DocumentType.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml
Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java
Workspace/Siman-Common/src/org/splat/kernel/InvalidPropertyException.java
Workspace/Siman-Common/src/org/splat/kernel/MismatchException.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/StepServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/technical/ProjectSettingsServiceImpl.java
Workspace/Siman-Common/src/test/splat/service/TestProjectSettingsService.java
Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java

diff --git a/Workspace/Siman-Common/proj_settings_testng.xml b/Workspace/Siman-Common/proj_settings_testng.xml
new file mode 100644 (file)
index 0000000..e8f7046
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+
+<suite name="SimanCommonTests" verbose="1">
+       <test name="all">
+               <method-selectors>
+                       <method-selector>
+                               <script language="beanshell">
+                                       <![CDATA[
+                (groups.containsKey("business") || groups.containsKey("functional") || groups.containsKey("service") ) && method.getName().toUpperCase().startsWith("TEST")             
+              ]]>
+                               </script>
+                       </method-selector>
+               </method-selectors>
+        <groups>
+            <!-- 
+                <define name="all">
+                <include name="business"/>
+                <include name="functional"/>
+                <include name="service"/>
+                </define>
+                <define name="new">
+                <include name="newservice"/>
+                </define>
+                <run>
+                <include name="all"/>
+                <exclude name="old"/>
+                </run>
+            -->
+
+        </groups>
+               <classes>
+                 <class name="test.splat.service.TestProjectSettingsService"></class>
+               </classes>
+       </test>
+</suite>
index bb5d140241fc3b18fbfd838159b63c6fdb3fc772..1713dc2e8bf7c96498433b64f1596d2af1ac7df8 100644 (file)
@@ -25,7 +25,7 @@ import org.splat.som.Revision;
 import org.splat.som.Step;
 
 /**
- * Document persistent class. 
+ * Document persistent class.
  */
 public class Document extends Entity {
 
@@ -50,7 +50,7 @@ public class Document extends Entity {
        // ==============================================================================================================================
 
        /**
-        * Fields initialization class. 
+        * Fields initialization class.
         */
        public static class Properties extends Persistent.Properties {
                // ------------------------------------------------------------
@@ -143,6 +143,7 @@ public class Document extends Entity {
 
                /**
                 * Get the date.
+                * 
                 * @return the date
                 */
                public Date getDate() {
@@ -158,7 +159,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 +210,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 +231,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 {
@@ -289,14 +302,22 @@ public class Document extends Entity {
                }
        }
 
+       /**
+        * Database fetch constructor.
+        */
        protected Document() {
-               // Database fetch constructor
+               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
                type = dprop.type;
@@ -324,7 +345,6 @@ public class Document extends Entity {
        // ==============================================================================================================================
 
        public File getAttachedFile(final String format) {
-               // -------------------------------------------
                List<Relation> exports = getRelations(ConvertsRelation.class);
 
                for (Iterator<Relation> i = exports.iterator(); i.hasNext();) {
@@ -337,31 +357,26 @@ public class Document extends Entity {
        }
 
        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 null;
@@ -371,7 +386,6 @@ public class Document extends Entity {
        }
 
        public ProgressState getProgressState() {
-               // ----------------------------------------
                return state;
        }
 
@@ -382,7 +396,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 +412,10 @@ public class Document extends Entity {
         * @return the document reference
         */
        public String getReference() {
-               // -----------------------------
                return did;
        }
 
        public File getSourceFile() {
-               // ----------------------------
                return myfile;
        }
 
@@ -415,7 +426,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 +456,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 +480,6 @@ public class Document extends Entity {
         * @see #isUndefined()
         */
        public String getVersion() {
-               // ---------------------------
                return version;
        }
 
@@ -483,32 +493,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 +523,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 +533,7 @@ public class Document extends Entity {
 
        /**
         * Get the did.
+        * 
         * @return the did
         */
        public String getDid() {
@@ -533,7 +542,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 +552,7 @@ public class Document extends Entity {
 
        /**
         * Get the myfile.
+        * 
         * @return the myfile
         */
        public File getFile() {
@@ -549,7 +561,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 +571,7 @@ public class Document extends Entity {
 
        /**
         * Get the history.
+        * 
         * @return the history
         */
        public int getHistory() {
@@ -565,7 +580,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 +590,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 +600,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 +610,7 @@ public class Document extends Entity {
 
        /**
         * Get the countag.
+        * 
         * @return the countag
         */
        public int getCountag() {
@@ -597,7 +619,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;
index 707ae66421d964c2ac0d10c98a55438786399449..4e285ecc6953d6b85465f63dadab82d4715cc0c0 100644 (file)
@@ -1,10 +1,12 @@
 package org.splat.dal.bo.som;
+
 /**
  * 
  * @author    Daniel Brunier-Coulin
  * @copyright OPEN CASCADE 2012
  */
 
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -14,208 +16,292 @@ import org.splat.kernel.MissedPropertyException;
 import org.splat.kernel.MultiplyDefinedException;
 import org.splat.service.technical.ProjectSettingsService;
 
-
+/**
+ * Persistent document type.
+ */
 public class DocumentType extends Persistent {
-       
-//  Persistent fields
-    private String            name;
-    private ProgressState     state;
-       private String            step;     // List of (dash separated) steps (numbers) containing this type
-    private String            result;   // Step (number ) having this type as result
-    private final Set<DocumentType> uses = new HashSet<DocumentType>();
-
-//  ==============================================================================================================================
-//  Construction
-//  ==============================================================================================================================
-
-//  Fields initialization class
-    public static class Properties extends Persistent.Properties {
-//  ------------------------------------------------------------
-      private String         name   = null;
-      private String         step   = null;
-      private String         result = null;
-      private DocumentType[] uses   = null;
-
-//  - Public services
-
-      @Override
-       public void clear () {
-        super.clear();
-        name    = null;
-        step    = null;
-        result  = null;
-        uses    = null;
-      }
-//  - Setters of DocumentType properties
-      
-      public Properties setName (final String name) throws InvalidPropertyException
-      {
-        if (name.length() == 0) {
-                       throw new InvalidPropertyException("name");
+
+       // Persistent fields
+       /**
+        * Type name.
+        */
+       private String name;
+       /**
+        * Type progress state.
+        */
+       private ProgressState state;
+       /**
+        * List of (dash separated) steps (numbers) containing this type.
+        */
+       private String step;
+       /**
+        * Step (number) having this type as result.
+        */
+       private String result;
+       /**
+        * Set of "parent" document types, which are used by this type.
+        */
+       private final Set<DocumentType> uses = new HashSet<DocumentType>();
+
+       // ==============================================================================================================================
+       // Construction
+       // ==============================================================================================================================
+
+       /**
+        * Fields initialization class.
+        */
+       public static class Properties extends Persistent.Properties {
+               /**
+                * {@inheritDoc}
+                * 
+                * @see DocumentType#name
+                */
+               private String name = null;
+               /**
+                * {@inheritDoc}
+                * 
+                * @see DocumentType#step
+                */
+               private String step = null;
+               /**
+                * {@inheritDoc}
+                * 
+                * @see DocumentType#result
+                */
+               private String result = null;
+               /**
+                * {@inheritDoc}
+                * 
+                * @see DocumentType#uses
+                */
+               private DocumentType[] uses = null;
+
+               // - Public services
+
+               /**
+                * {@inheritDoc}
+                * 
+                * @see org.splat.dal.bo.kernel.Persistent.Properties#clear()
+                */
+               @Override
+               public void clear() {
+                       super.clear();
+                       name = null;
+                       step = null;
+                       result = null;
+                       uses = null;
+               }
+
+               // - Setters of DocumentType properties
+
+               public Properties setName(final String name)
+                               throws InvalidPropertyException {
+                       if (name.length() == 0) {
+                               throw new InvalidPropertyException("name");
+                       }
+                       this.name = name;
+                       return this;
                }
-        this.name = name;
-        return this;
-      }
-      public Properties setResult (final ProjectSettingsService.Step step)
-      {
-        this.result = String.valueOf(step.getNumber());
-        return this;
-      }
-      public Properties setStep (final ProjectSettingsService.Step... step)
-      {
-        this.step = "-";
-       for (int i=0; i<step.length; i++) {
-                       this.step = this.step + String.valueOf(step[i].getNumber()) + "-";
+
+               public Properties setResult(final ProjectSettingsService.Step step) {
+                       this.result = String.valueOf(step.getNumber());
+                       return this;
                }
-        return this;
-      }
-      public Properties setUses (final DocumentType... type)
-      {
-        this.uses = type;
-        return this;
-      }
-//  - Global validity check
-        
-      public void checkValidity() throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException
-      {
-        if (name == null) {
-                       throw new MissedPropertyException("name");
+
+               public Properties setStep(final ProjectSettingsService.Step... step) {
+                       this.step = "-";
+                       for (int i = 0; i < step.length; i++) {
+                               this.step = this.step + String.valueOf(step[i].getNumber())
+                                               + "-";
+                       }
+                       return this;
                }
-        if (step == null) {
-                       throw new MissedPropertyException("path");
+
+               public Properties setUses(final DocumentType... type) {
+                       this.uses = type;
+                       return this;
                }
-      }
-    }
-//  Database fetch constructor
-    protected DocumentType () {
-//  -------------------------
-    }
-//  Initialization constructor
-    public DocumentType (final Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
-//  -----------------------------------------
-      super(dprop);              // Throws one of the above exception if not valid
-      name   = dprop.name;
-      state  = ProgressState.inCHECK;
-      step   = dprop.step;
-      result = dprop.result;     // May be null
-      if (dprop.uses != null) {
-               for (int i=0; i<dprop.uses.length; i++) {
-                       getUses().add(dprop.uses[i]);
+
+               // - Global validity check
+
+               public void checkValidity() throws MissedPropertyException,
+                               InvalidPropertyException, MultiplyDefinedException {
+                       if (name == null) {
+                               throw new MissedPropertyException("name");
+                       }
+                       if (step == null) {
+                               throw new MissedPropertyException("path");
+                       }
+               }
+
+               /**
+                * Get the name.
+                * 
+                * @return the name
+                */
+               public String getName() {
+                       return name;
                }
        }
-    }
 
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
+       /**
+        * Database fetch constructor.
+        */
+       protected DocumentType() {
+               super();
+       }
 
-    @Override
-       public boolean equals(final Object entity) {
-//  ------------------------------------
-      if (entity == null) {
-               return false;
+       /**
+        * Initialization constructor.
+        * 
+        * @param dprop
+        *            type properties
+        * @throws MissedPropertyException
+        *             if some mandatory property is missed
+        * @throws InvalidPropertyException
+        *             if some property has invalid value
+        * @throws MultiplyDefinedException
+        *             if some property is defined several times
+        */
+       public DocumentType(final Properties dprop) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException {
+               super(dprop); // Throws one of the above exception if not valid
+               name = dprop.name;
+               state = ProgressState.inCHECK;
+               step = dprop.step;
+               result = dprop.result; // May be null
+               if (dprop.uses != null) {
+                       for (int i = 0; i < dprop.uses.length; i++) {
+                               getUses().add(dprop.uses[i]);
+                       }
+               }
        }
-      if (entity instanceof String) {
-        return this.name.equals(entity);   // Names are unique
-      } else if (entity instanceof DocumentType) {
-        DocumentType object = (DocumentType)entity;
-        long   he = object.getIndex();
-        long   me = this.getIndex();
-        if (me*he != 0) {
-               return (he == me);
-        } else {
-               return this.getName().equals(object.getName());
-        }
-      } else {
-        return false;
-      }
-    }
-
-    public String getName () {
-//  ------------------------
-      return name;
-    }
-
-    public Set<DocumentType> getDefaultUses () {
-//  -------------------------------------------
-      return getUses();
-    }
-
-    public boolean isApproved () {
-//  ----------------------------
-      return (state == ProgressState.APPROVED);
-    }
 
-/**
- * Checks if documents of this type are attached to the given study step, either as result or content.
- * 
- * @param  step the involved study step
- * @return true if documents of this type are attached to the given step.
- * @see    #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
- */
-    public boolean isContentInto (final ProjectSettingsService.Step step) {
-//  --------------------------------------------------------
-      String[] path = this.step.split("-");
-      for (int i=0; i<path.length; i++) {
-       String value = path[i];
-       if (value.length() == 0) {
-                       continue;
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
+
+       @Override
+       public boolean equals(final Object entity) {
+               if (entity == null) {
+                       return false;
                }
-       if (Integer.valueOf(value) == step.getNumber()) {
-                       return true;
+               if (entity instanceof String) {
+                       return this.name.equals(entity); // Names are unique
+               } else if (entity instanceof DocumentType) {
+                       DocumentType object = (DocumentType) entity;
+                       long he = object.getIndex();
+                       long me = this.getIndex();
+                       if (me * he == 0) {
+                               return this.getName().equals(object.getName());
+                       } else {
+                               return (he == me);
+                       }
+               } else {
+                       return false;
                }
-      }
-      return false;
-    }
+       }
 
-/**
- * Checks if documents of this type are result of any study step.
- * 
- * @return true if documents of this type are result of a step.
- * @see    #isStudyResult()
- * @see    #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
- */
-    public boolean isStepResult () {
-//  ------------------------------
-      return (result != null);
-    }
+       public String getName() {
+               return name;
+       }
 
-/**
- * Checks if documents of this type are result of the given study step.
- * 
- * @param  step the involved study step
- * @return true if documents of this type are result of the given step.
- * @see    #isContentInto(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
- * @see    #isStepResult()
- * @see    #isStudyResult()
- */
-    public boolean isResultOf (final ProjectSettingsService.Step step) {
-//  -----------------------------------------------------
-      if (result == null) {
+       public Set<DocumentType> getDefaultUses() {
+               return getUses();
+       }
+
+       public boolean isApproved() {
+               return (state == ProgressState.APPROVED);
+       }
+
+       /**
+        * Checks if documents of this type are attached to the given study step, either as result or content.
+        * 
+        * @param step
+        *            the involved study step
+        * @return true if documents of this type are attached to the given step.
+        * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+        */
+       public boolean isContentInto(final ProjectSettingsService.Step step) {
+               String[] path = this.step.split("-");
+               for (int i = 0; i < path.length; i++) {
+                       String value = path[i];
+                       if (value.length() == 0) {
+                               continue;
+                       }
+                       if (Integer.valueOf(value) == step.getNumber()) {
+                               return true;
+                       }
+               }
                return false;
        }
-      return (Integer.valueOf(result) == step.getNumber());
-    }
-    
-    /**
+
+       /**
+        * Checks if documents of this type are result of any study step.
+        * 
+        * @return true if documents of this type are result of a step.
+        * @see #isStudyResult()
+        * @see #isResultOf(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+        */
+       public boolean isStepResult() {
+               return (result != null);
+       }
+
+       /**
+        * Checks if documents of this type are result of the given study step.
+        * 
+        * @param step
+        *            the involved study step
+        * @return true if documents of this type are result of the given step.
+        * @see #isContentInto(org.splat.service.technical.ProjectSettingsServiceImpl.Step)
+        * @see #isStepResult()
+        * @see #isStudyResult()
+        */
+       public boolean isResultOf(final ProjectSettingsService.Step step) {
+               if (result == null) {
+                       return false;
+               }
+               return (Integer.valueOf(result) == step.getNumber());
+       }
+
+       /**
         * Get the state.
+        * 
         * @return the state
         */
        public ProgressState getState() {
                return state;
        }
+
        /**
         * Set the state.
-        * @param state the state to set
+        * 
+        * @param state
+        *            the state to set
         */
        public void setState(final ProgressState state) {
                this.state = state;
        }
+
        /**
         * Get the uses.
+        * 
         * @return the uses
         */
        protected Set<DocumentType> getUses() {
                return uses;
        }
+
+       /**
+        * Set properties of document type except persistent id and name.
+        * 
+        * @param tprop
+        *            type properties
+        */
+       public void setProperties(final Properties tprop) {
+               this.step = tprop.step;
+               this.result = tprop.result;
+               this.uses.clear();
+               this.uses.addAll(Arrays.asList(tprop.uses));
+       }
 }
\ No newline at end of file
index cae063c741d049d7be7c0fc6981953ae8627dc11..71c5402513278b0396731c0751b356ba451aa09f 100644 (file)
@@ -56,14 +56,21 @@ public abstract class ProjectElement extends Entity {
 //  Constructors
 //  ==============================================================================================================================
 
-//  Database fetch constructor
+    /**
+     * Database fetch constructor.
+     */
     protected ProjectElement () {
-//  ---------------------------
-      folders  = null;
+       super();
+       folders  = null;
     }
-//  Initialization constructor
+    /**
+     * Initialization constructor.
+     * @param oprop
+     * @throws MissedPropertyException
+     * @throws InvalidPropertyException
+     * @throws MultiplyDefinedException
+     */
     protected ProjectElement (final ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
-//  -------------------------------------------------          
       super(oprop);       // Throws one of the above exception if not valid
       title    = null;     // Initialized by subclasses
       credate  = null;     // Initialized by subclasses
@@ -79,7 +86,6 @@ public abstract class ProjectElement extends Entity {
 //  ==============================================================================================================================
 
     public User getAuthor () {
-//  ------------------------
       return manager;
     }
 
@@ -87,12 +93,10 @@ public abstract class ProjectElement extends Entity {
  * Returns the creation date of this Project Element.
  */
     public Date getDate () {
-//  ----------------------
       return credate;
     }
 
     public String getDescription () {
-//  -------------------------------
       String               summary = null;
       DescriptionAttribute field   = (DescriptionAttribute)this.getAttribute(DescriptionAttribute.class);
       if (field != null) {
@@ -117,7 +121,6 @@ public abstract class ProjectElement extends Entity {
  * @return the publication of the document version, or null if the given document version is not published into this Project Element
  */
     public Publication getPublication (final Document doc) {
-//  ------------------------------------------------
       long  index = doc.getIndex();
       for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
        Publication  found = i.next();
@@ -129,7 +132,6 @@ public abstract class ProjectElement extends Entity {
     }
 
     public String getTitle () {
-//  -------------------------
       return title;
     }
 
@@ -138,7 +140,6 @@ public abstract class ProjectElement extends Entity {
     }
 
     public boolean publishes (final Document doc) {
-//  ---------------------------------------
       long  index = doc.getIndex();
       for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
        Document  found = i.next().value();
@@ -150,12 +151,10 @@ public abstract class ProjectElement extends Entity {
     }
 
     public Iterator<Publication> PublicationIterator () {
-//  ---------------------------------------------------
       return  Collections.unmodifiableSet(docums).iterator();
     }
 
     public Iterator<SimulationContext> SimulationContextIterator () {
-//  ---------------------------------------------------------------
       return  Collections.unmodifiableList(contex).iterator();
     }
 
@@ -164,22 +163,18 @@ public abstract class ProjectElement extends Entity {
 //  ==============================================================================================================================
 
     public boolean add (final Publication newdoc) {
-//  ------------------------------------------
       return  docums.add(newdoc);
     }
 
     public boolean add (final SimulationContext newdoc) {
-//  ------------------------------------------------
       return  contex.add(newdoc);
     }
 
     public boolean remove (final Publication oldoc) {
-//  --------------------------------------------
       return  docums.remove(oldoc);   // The removed tag becoming orphan, it is supposed automatically deleted from the data store
     }
 
     public boolean remove (final SimulationContext oldoc) {
-//  --------------------------------------------------
       return  contex.remove(oldoc);
     }
        /**
index 997ffc7173dac10bb3b7711c2f9e448e51d5fca7..d5e6f08d04de5d574d9d4a8b95914d2b6f42d99c 100644 (file)
@@ -13,7 +13,7 @@
 <!-- Publication properties
   -->
     <!-- Document       mydoc -->    
-    <many-to-one  name="mydoc" column="doc"   access="field" not-null="true" cascade="delete"/>
+    <many-to-one  name="mydoc" column="doc"   access="field" not-null="true"/>
     
     <!-- ProjectElement owner -->    
     <many-to-one  name="owner" column="owner" access="field" not-null="true" />
index 91f4ce1820394de19d1250f7705cc91ed634b790..4b782cacbf9ad00c61ab99b89e6b5963527d1956 100644 (file)
@@ -126,6 +126,10 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
                return (_uplevel >= 0);
        }
 
+       public void reset() {
+               _uplevel = -1;
+       }
+       
        public void initialize() throws IOException, SQLException {
                LOG.info("Creation of the database.");
 
index 68b60be4f07925269c099cc14316181d7a774194..a22d58ee8291642249f37ca1f41e6e76ef8a2777 100644 (file)
@@ -37,7 +37,6 @@ public class InvalidPropertyException extends BusinessException {
        public InvalidPropertyException(final String messageKey,
                        final Object... context) {
                super(messageKey, context);
-               // TODO auto-generated constructor
        }
 
        /**
index 956932f4656fba49a6b85a7616e59e54c8c032de..aa6b8ca4d4f21b0bc4cb70d2fce23b34cd123183 100644 (file)
@@ -22,6 +22,18 @@ public class MismatchException extends BusinessException {
                super();
        }
 
+       /**
+        * Create a MismatchException.
+        * 
+        * @param messageKey
+        *            error message key
+        * @param context
+        *            parameters
+        */
+       public MismatchException(final String messageKey, final Object... context) {
+               super(messageKey, context);
+       }
+
        /**
         * Create a MismatchException. 
         * @param message the error message. 
index cfa49834adb4b1804f9d6a430c2c856924e4ce91..ff9d5e1009aa3a46706e7a949a4a2fc7ae50d740 100644 (file)
@@ -29,7 +29,6 @@ import org.splat.dal.bo.som.StampRelation;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.Timestamp;
 import org.splat.dal.bo.som.ValidationStep;
-import org.splat.dal.bo.som.VersionsRelation;
 import org.splat.dal.bo.som.Document.Properties;
 import org.splat.dal.dao.som.DocumentDAO;
 import org.splat.dal.dao.som.DocumentTypeDAO;
@@ -539,27 +538,20 @@ public class DocumentServiceImpl implements DocumentService {
                } else {
                        Revision myvers = new Revision(aDoc.getVersion());
                        if (!myvers.isNull()) { // Versionning context
-                               for (Iterator<Relation> i = aDoc.getAllRelations().iterator(); i
-                                               .hasNext();) {
-                                       Relation link = i.next();
-                                       if (link.getClass().equals(VersionsRelation.class)) {
-                                               previous = (Document) link.getTo(); // Versioned document
-                                               break;
-                                       }
-                               }
+                               previous = aDoc.getPreviousVersion();
                        }
                        if (aDoc.getProgressState() != null) {
                                myvers.incrementAs(state); // Incrementation if the reversion number is not imposed
                        }
                        aDoc.setVersion(myvers.toString());
                }
-               // Update this document and the previous version, if exit
+               // Update this document and the previous version, if exist
                if (previous != null) {
                        previous.setHistory(previous.getHistory() + 1);
                        getDocumentDAO().merge(previous);
                }
                aDoc.setProgressState(state);
-               getDocumentDAO().update(aDoc);
+               //RKV: getDocumentDAO().update(aDoc);
        }
 
        // protected void upgrade () {
index 5fa287eb675225d1aa52edb17d34e25d77136346..63f511f2da5d3e0e95f04b636b6528b44285a1c0 100644 (file)
@@ -26,7 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 /**
  * Document type service implementation.
- *
+ * 
  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  */
 public class DocumentTypeServiceImpl implements DocumentTypeService {
@@ -41,7 +41,7 @@ public class DocumentTypeServiceImpl implements DocumentTypeService {
         * 
         * @return the list of all document types
         */
-//     @Transactional(readOnly = true)
+       // @Transactional(readOnly = true)
        @Transactional
        public List<DocumentType> selectAllTypes() {
                List<DocumentType> types = getDocumentTypeDAO().getAll();
@@ -104,9 +104,14 @@ public class DocumentTypeServiceImpl implements DocumentTypeService {
        public DocumentType createType(final DocumentType.Properties tprop)
                        throws MissedPropertyException, InvalidPropertyException,
                        MultiplyDefinedException {
-               // TODO: Check for duplicate definition
-               DocumentType type = new DocumentType(tprop);
-               getDocumentTypeDAO().create(type);
+               DocumentType type = getDocumentTypeDAO().findByCriteria(
+                               Restrictions.eq("name", tprop.getName()));
+               if (type == null) {
+                       type = new DocumentType(tprop);
+                       getDocumentTypeDAO().create(type);
+               } else {
+                       type.setProperties(tprop); // Update properties of persistent type
+               }
                return type;
        }
 
@@ -118,7 +123,8 @@ public class DocumentTypeServiceImpl implements DocumentTypeService {
         * @return the list of found document types
         */
        @Transactional(readOnly = true)
-       public List<DocumentType> selectTypesOf(final ProjectSettingsService.Step step) {
+       public List<DocumentType> selectTypesOf(
+                       final ProjectSettingsService.Step step) {
                Integer number = step.getNumber();
                String sampleStr = new StringBuffer("%-").append(number).append("-%")
                                .toString();
@@ -132,11 +138,13 @@ public class DocumentTypeServiceImpl implements DocumentTypeService {
 
        /**
         * Approve the document type.
-        * @param aType the document type to approve
+        * 
+        * @param aType
+        *            the document type to approve
         * @return true if approval succeeded
         */
        @Transactional
-    public boolean approve(final DocumentType aType) {
+       public boolean approve(final DocumentType aType) {
                boolean res = (aType.getState() == ProgressState.inCHECK);
                if (res) {
                        aType.setState(ProgressState.APPROVED); // The type name is supposed being localized
index 9e3a570afcbc01de09d022814d8408df5e009a1d..a47e1dc7ed43d554a45a61d0538399dbd81e8974 100644 (file)
@@ -450,11 +450,12 @@ public class PublicationServiceImpl implements PublicationService {
                if (previous != null) {
                        Publication oldoc = step.getDocument(previous.getIndex());
                        boolean done = getStepService().remove(step, oldoc); // Decrements the configuration tag count of document
-                       if (done) {
+/*                     if (done) {
                                oldoc = getPublicationDAO().merge(oldoc); //RKV: to avoid: NonUniqueObjectException: a different object with the same identifier value was already associated with the session
-                               getPublicationDAO().delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object
+                               //RKV: use delete-orphan by removing from project element, see StepService.remove
+                               //RKV: getPublicationDAO().delete(oldoc); // WARNING: Potential problem because it's not automatically done as orphan object
                        }
-               }
+*/             }
                getStepService().add(step, aPublication); // Increments the configuration tag count of document
 
                // Import the document properties and update of the study
index 4dc064893d08da5f68ac4c445de8e7c894372a9d..03372095f9e647b0884b15b234e6630b8efa8d7e 100644 (file)
@@ -395,8 +395,6 @@ public class ScenarioServiceImpl implements ScenarioService {
 
                // For each processed existing document keep its new version
                Map<Document, Document> newVersion = new HashMap<Document, Document>();
-               // For each processed existing document keep its previous version
-               Map<Publication, Document> prevVersion = new HashMap<Publication, Document>();
                // Keep newly created documents to create uses relations to results of a previous step.
                List<Publication> newVers = new ArrayList<Publication>();
                List<Publication> newDocs = new ArrayList<Publication>();
@@ -406,6 +404,9 @@ public class ScenarioServiceImpl implements ScenarioService {
                Document.Properties dprop = new Document.Properties();
                Date aDate = new Date();
                for (StepDTO stepDTO : scInfo) {
+                       if (LOG.isDebugEnabled()) {
+                               LOG.debug("Checkin the step:\n" + stepDTO);
+                       }
                        // Find a result document type of the step
                        int i = 0;
                        resType = null;
@@ -447,14 +448,17 @@ public class ScenarioServiceImpl implements ScenarioService {
                                                                        MessageKeyEnum.SCN_000002.toString(), doc
                                                                                        .getId());
                                                }
+                                               if (pub.value() == null) {
+                                                       throw new MismatchException(
+                                                                       MessageKeyEnum.SCN_000002.toString(), doc
+                                                                                       .getId());
+                                               }
                                                newPub = getStepService().versionDocument(step, pub,
                                                                dprop);
                                                // Remeber the link from the old document to the new document version
                                                newVersion.put(pub.value(), newPub.value());
                                                // Remember the new version publication
                                                newVers.add(newPub);
-                                               // Remember the previouse document version for the new publication
-                                               prevVersion.put(newPub, pub.value());
                                        } else {
 
                                                // Otherwise create a new document of the result type
@@ -495,8 +499,14 @@ public class ScenarioServiceImpl implements ScenarioService {
                // For each new version copy uses relations from the previous version.
                for (Publication newVer : newVers) {
                        // For each Uses relation of the previous version
-                       for (Relation rel : prevVersion.get(newVer).getRelations(
-                                       UsesRelation.class)) {
+                       Document prevDoc = newVer.value().getPreviousVersion();//prevVersion.get(newVer);
+                       if (LOG.isDebugEnabled()) {
+                               LOG.debug("Previous version for publication #"
+                                               + newVer.getIndex() + " is found: " + prevDoc);
+                       }
+                       List<Relation> usesRelations = prevDoc
+                                       .getRelations(UsesRelation.class);
+                       for (Relation rel : usesRelations) {
                                // If used document has been also versioned then refer to its new version.
                                Document usedDoc = ((UsesRelation) rel).getTo();
                                if (newVersion.containsKey(usedDoc)) {
@@ -514,10 +524,10 @@ public class ScenarioServiceImpl implements ScenarioService {
                for (Publication newDoc : newDocs) {
                        // Find used document type according to the configuration.
                        // Find documents of used type in the previous study step.
-                       
-                       // Create uses relation from the new document 
+
+                       // Create uses relation from the new document
                        // to the found document in the previous step.
-                       //newDoc.addDependency(to);
+                       // newDoc.addDependency(to);
                }
 
                // Mark the scenario as checked in
index 281d57c341852330b919b6402c32cbeb2208f630..934b29682797e9ec6cd932545dbef15426eeca77 100644 (file)
@@ -21,6 +21,7 @@ import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.File;
 import org.splat.dal.bo.som.KnowledgeElement;
+import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
@@ -438,6 +439,10 @@ public class StepServiceImpl implements StepService {
                boolean res = aStep.getOwner().remove(oldoc); // Updates the study in memory
                if (res) {
                        aStep.getDocuments().remove(oldoc); // Updates this step
+                       ProjectElement owner = aStep.getOwner();
+                       if (owner != null) {
+                               owner.remove(oldoc);
+                       }
                        getDocumentService().release(oldoc.value()); // Decrements the configuration tag count of document
                        // The publication becoming orphan, it should automatically be removed from the database when updating of owner scenario.
                }
index c9498f5135faf538d6b0270257892a4a192cda01..6830946e56aed99223542cea343f079c3310e779 100644 (file)
@@ -87,8 +87,18 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * Document type mappings to file formats which should be imported into SALOME during check-out.
         */
        private transient final Map<String, List<String>> _mapimport = new HashMap<String, List<String>>();
+       /**
+        * Default document types structured by step.formats.
+        */
+       private transient final Map<String, DocumentType> _defdoctype = new LinkedHashMap<String, DocumentType>();
 
        // Temporary attributes initialized from the configuration file for populating the database with object types
+       /**
+        * Step.format keys structured by Default document types names. This map is used for loading config before document types are created in
+        * the database. When document types are created then _defdoctype is filled.
+        */
+       private transient final Map<String, List<String>> _defdoctypeKeys = new HashMap<String, List<String>>();
+
        /**
         * Document type names and uses mapping.
         */
@@ -128,11 +138,6 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         */
        private DocumentTypeService _documentTypeService;
 
-       /**
-        * Default document types structured by step.formats.
-        */
-       private transient final Map<String, DocumentType> _defdoctype = new LinkedHashMap<String, DocumentType>();
-
        /**
         * File naming strategy enumeration.
         */
@@ -354,6 +359,10 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
        public DocumentType getDefaultDocumentType(final Step step,
                        final String format) {
                String[] table = format.split("\\x2E");
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("Trying to get default type: " + step.getNumber() + "."
+                                       + table[table.length - 1]);
+               }
                return _defdoctype
                                .get(step.getNumber() + "." + table[table.length - 1]); // May be null
        }
@@ -543,33 +552,53 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         */
        private void loadDefaultDocTypes(final Map<String, Node> children) {
                _defdoctype.clear();
+               _defdoctypeKeys.clear();
                Node child = children.get("default-doctypes");
-               NodeList nlist = child.getChildNodes();
+               if (child != null) {
+                       NodeList nlist = child.getChildNodes();
 
-               List<DocumentType> listype = getDocumentTypeService().selectAllTypes();
-               Map<String, DocumentType> maptype = new HashMap<String, DocumentType>();
-               for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
-                       DocumentType type = i.next();
-                       maptype.put(type.getName(), type);
-               }
-               for (int i = 0; i < nlist.getLength(); i++) {
-                       child = nlist.item(i);
-                       if (!child.getNodeName().equals("step")) {
-                               continue;
+                       List<DocumentType> listype = getDocumentTypeService()
+                                       .selectAllTypes();
+                       Map<String, DocumentType> maptype = new HashMap<String, DocumentType>();
+                       for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
+                               DocumentType type = i.next();
+                               maptype.put(type.getName(), type);
                        }
-
-                       String nstep = child.getAttributes().getNamedItem("number")
-                                       .getNodeValue();
-                       NodeList map = child.getChildNodes();
-                       for (int j = 0; j < map.getLength(); j++) {
-                               child = map.item(j);
-                               if (!child.getNodeName().equals("mapping")) {
+                       for (int i = 0; i < nlist.getLength(); i++) {
+                               child = nlist.item(i);
+                               if (!child.getNodeName().equals("step")) {
                                        continue;
                                }
-                               NamedNodeMap natr = child.getAttributes();
-                               String dext = natr.getNamedItem("extension").getNodeValue();
-                               String type = natr.getNamedItem(TYPE_ATTR).getNodeValue();
-                               _defdoctype.put(nstep + "." + dext, maptype.get(type));
+
+                               String nstep = child.getAttributes().getNamedItem("number")
+                                               .getNodeValue();
+                               NodeList map = child.getChildNodes();
+                               for (int j = 0; j < map.getLength(); j++) {
+                                       child = map.item(j);
+                                       if (!child.getNodeName().equals("mapping")) {
+                                               continue;
+                                       }
+                                       NamedNodeMap natr = child.getAttributes();
+                                       String dext = natr.getNamedItem("extension").getNodeValue();
+                                       String type = natr.getNamedItem(TYPE_ATTR).getNodeValue();
+                                       if (LOG.isDebugEnabled()) {
+                                               LOG.debug("Map default type: " + nstep + "." + dext
+                                                               + ": (type name = " + type + ")"
+                                                               + maptype.get(type));
+                                       }
+                                       _defdoctype.put(nstep + "." + dext, maptype.get(type));
+                                       // Remember the key if type is not created yet
+                                       if (maptype.get(type) == null) {
+                                               List<String> keys;
+                                               if (_defdoctypeKeys.containsKey(type)) {
+                                                       keys = _defdoctypeKeys.get(type);
+                                               } else {
+                                                       keys = new ArrayList<String>();
+                                                       _defdoctypeKeys.put(type, keys);
+                                               }
+                                               keys.add(nstep + "." + dext);
+                                       }
+                               }
                        }
                }
        }
@@ -777,6 +806,16 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                        tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types
                                        getDocumentTypeService().approve(tdoc);
                                        maptype.put(type, tdoc);
+                                       // Remember default type if it is
+                                       if (_defdoctypeKeys.containsKey(type)) {
+                                               for (String key : _defdoctypeKeys.get(type)) {
+                                                       if (LOG.isDebugEnabled()) {
+                                                               LOG.debug("Put mapping for default type: "
+                                                                               + key + ": " + tdoc);
+                                                       }
+                                                       _defdoctype.put(key, tdoc);
+                                               }
+                                       }
                                }
                        }
                } catch (Exception error) {
index da005b31909a577e1a3231c89480ad41fa3c584e..cfc6fe25d0f7fb3fa98b4e82acf22b1b777cab4f 100644 (file)
@@ -14,6 +14,7 @@ import java.sql.SQLException;
 import java.util.List;
 
 import org.splat.dal.bo.som.Scenario;
+import org.splat.dal.dao.som.Database;
 import org.splat.log.AppLogger;
 import org.splat.service.DocumentTypeService;
 import org.splat.service.technical.ProjectSettingsService;
@@ -216,6 +217,7 @@ public class TestProjectSettingsService extends BaseTest {
                /*
                 * geometry: brep model: med loads: c3m results: med
                 */
+               Database.getInstance().reset();
                _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
                try {
                        _projectSettings.configure(ClassLoader.getSystemResource(
@@ -223,6 +225,8 @@ public class TestProjectSettingsService extends BaseTest {
                } catch (FileNotFoundException e) {
                        Assert.fail("Can't find configuration file: ", e);
                }
+               Assert.assertTrue(_documentTypeService.selectAllTypes().size() > 0,
+                               "No document types are created.");
                List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
                Assert.assertTrue(steps.size() > 0, "No steps are created.");
 
@@ -258,11 +262,6 @@ public class TestProjectSettingsService extends BaseTest {
                                        Assert.assertEquals(defTypes.size(), 3);
                                        Assert.assertNull(_projectSettings.getDefaultDocumentType(
                                                        step, "pdf"));
-                                       Assert.assertNotNull(_projectSettings
-                                                       .getDefaultDocumentType(step, "xml"));
-                                       Assert.assertEquals(_projectSettings
-                                                       .getDefaultDocumentType(step, "xml").getName(),
-                                                       "design");
                                        Assert.assertNotNull(_projectSettings
                                                        .getDefaultDocumentType(step, "doc"));
                                        Assert.assertEquals(_projectSettings
@@ -273,6 +272,11 @@ public class TestProjectSettingsService extends BaseTest {
                                        Assert.assertEquals(_projectSettings
                                                        .getDefaultDocumentType(step, "docx").getName(),
                                                        "design");
+                                       Assert.assertNotNull(_projectSettings
+                                                       .getDefaultDocumentType(step, "xml"));
+                                       Assert.assertEquals(_projectSettings
+                                                       .getDefaultDocumentType(step, "xml").getName(),
+                                                       "design");
                                        break;
                                case 3:
                                        Assert.assertEquals(defTypes.size(), 7);
index cb12d2b3e767e901b0906bf25956368af8a803c2..6b8d6c7ffcc3b8571ee1a43aefcfffd7b6542daf 100644 (file)
@@ -8,7 +8,9 @@
  *****************************************************************************/
 package test.splat.service;
 
+import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -21,6 +23,7 @@ import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.Study;
+import org.splat.dal.dao.som.Database;
 import org.splat.dal.dao.som.ScenarioDAO;
 import org.splat.kernel.InvalidPropertyException;
 import org.splat.kernel.MismatchException;
@@ -36,6 +39,7 @@ import org.splat.service.dto.DocumentDTO;
 import org.splat.service.dto.FileDTO;
 import org.splat.service.dto.StepDTO;
 import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.RepositoryService;
 import org.splat.service.technical.ProjectSettingsService.Step;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -66,6 +70,13 @@ public class TestScenarioService extends BaseTest {
        @Qualifier("scenarioService")
        private transient ScenarioService _scenarioService;
 
+       /**
+        * The RepositoryService. Later injected by Spring.
+        */
+       @Autowired
+       @Qualifier("repositoryService")
+       private transient RepositoryService _repositoryService;
+
        /**
         * The Scenario DAO. Later injected by Spring.
         */
@@ -284,20 +295,42 @@ public class TestScenarioService extends BaseTest {
                        MissedPropertyException, MultiplyDefinedException, IOException,
                        SQLException, MismatchException, NotApplicableException {
                LOG.debug(">>>>> BEGIN testCheckin()");
+               _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
                _projectSettings.configure(ClassLoader
                                .getSystemResource("test/som.xml").getPath());
                long scenarioId = createScenario();
                Scenario aScen = _scenarioDAO.get(scenarioId);
                User user = aScen.getAuthor();
-               long userId = user.getIndex(); // TODO: get id of a test user
+               long userId = user.getIndex();
+
+               // Prepare download directory
+               File tmpDir = _repositoryService.getDownloadDirectory(userId);
+               if (!tmpDir.exists()) {
+                       Assert.assertTrue(tmpDir.mkdir(),
+                                       "Can't create temporary directory: "
+                                                       + tmpDir.getAbsolutePath());
+               }
+
                // Call DAO's create method for a good transient knowledge element.
-               List<StepDTO> steps = new ArrayList<StepDTO>();
 
-               _scenarioService.checkin(scenarioId, userId, steps);
+               // Simulate checkout
+               List<StepDTO> steps = _scenarioService.getScenarioInfo(scenarioId);
+               _scenarioService.checkout(aScen, user);
+
+               // Prepare test data for checkin
+               // Checkin only two first steps (geom and mesh)
+               List<StepDTO> stepsToCheckin = new ArrayList<StepDTO>();
+               for (StepDTO step : steps) {
+                       // Prepare GEOM: checkin actual brep
+                       createDocForModule("GEOM", "brep", tmpDir, step, stepsToCheckin);
+                       createDocForModule("SMESH", "med", tmpDir, step, stepsToCheckin);
+               }
+               // Do test checkin
+               _scenarioService.checkin(scenarioId, userId, stepsToCheckin);
 
                // Call DAO's get method for a not existing id.
                try {
-                       _scenarioService.checkin(-1, userId, steps);
+                       _scenarioService.checkin(-1, userId, stepsToCheckin);
                        Assert
                                        .fail("Check in for scenario with not existing id must be failed.");
                } catch (Exception e) {
@@ -307,6 +340,50 @@ public class TestScenarioService extends BaseTest {
                LOG.debug(">>>>> END testCheckin()");
        }
 
+       /**
+        * Prepare a document with a file for check-in.
+        * 
+        * @param module
+        *            SALOME module name
+        * @param format
+        *            file extension
+        * @param tmpDir
+        *            download directory
+        * @param step
+        *            checked out stepDTO
+        * @param stepsToCheckin
+        *            DTO for check-in
+        * @throws IOException
+        *             if file creation failed
+        */
+       private void createDocForModule(final String module, final String format,
+                       final File tmpDir, final StepDTO step,
+                       final List<StepDTO> stepsToCheckin) throws IOException {
+               if (module.equals(step.getModule())) {
+                       StepDTO stepToCheckin = new StepDTO();
+                       stepsToCheckin.add(stepToCheckin);
+                       stepToCheckin.setNumber(step.getNumber());
+                       for (DocumentDTO doc : step.getDocs()) {
+                               if (doc.getFiles().get(0).getState() != 'O') {
+                                       DocumentDTO docToCheckin = stepToCheckin.addDoc(
+                                                       doc.getId(), doc.getTitle());
+                                       for (FileDTO file : doc.getFiles()) {
+                                               if (file.getPath().endsWith(format)) {
+                                                       // Create a file in the download directory
+                                                       String filePath = tmpDir.getAbsolutePath()
+                                                                       + "/" + doc.getTitle() + "_result." + format;
+                                                       FileWriter fw = new FileWriter(filePath);
+                                                       fw.write("Simulation of " + format + " file for checkin at " + new Date());
+                                                       fw.close();
+                                                       FileDTO fileToCheckin = new FileDTO(filePath);
+                                                       docToCheckin.addFile(fileToCheckin);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
        /**
         * Create a persistent scenario for tests.
         * 
@@ -328,6 +405,8 @@ public class TestScenarioService extends BaseTest {
                // Create a scenario for tests
                HibernateTemplate ht = getHibernateTemplate();
 
+               Database.getInstance().reset();
+               _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
                // Load workflow customization
                try {
                        _projectSettings.configure(ClassLoader.getSystemResource(
@@ -356,7 +435,7 @@ public class TestScenarioService extends BaseTest {
 
                // Create a test scenario
                Scenario.Properties sprops = new Scenario.Properties().setTitle(
-                               "TST_Study").setManager(anAuthor).setOwnerStudy(aStudy);
+                               "TST_Scenario").setManager(anAuthor).setOwnerStudy(aStudy);
                Scenario aScenario = new Scenario(sprops);
                aStudy.getScenariiList().add(aScenario);
                ht.saveOrUpdate(anAuthor);
@@ -374,8 +453,12 @@ public class TestScenarioService extends BaseTest {
                        List<DocumentType> dtypes = _documentTypeService
                                        .selectTypesOf(step);
                        for (DocumentType dtype : dtypes) {
-                               dprop.setName("document" + i++).setType(dtype)
-                                               .setFormat("brep");
+                               dprop.setName("document" + i++).setType(dtype);
+                               if (step.getNumber() > 3) {
+                                       dprop.setFormat("med");
+                               } else {
+                                       dprop.setFormat("brep");
+                               }
                                // Create a document published in the scenario
                                // document<i>: document type[0] - first type used on the step
                                // <source-file>.brep
@@ -391,7 +474,7 @@ public class TestScenarioService extends BaseTest {
                                ht.saveOrUpdate(pub);
 
                                // Attach a file
-                               ht.saveOrUpdate(pub.value());
+                               ht.save(pub.value());
                                ht.saveOrUpdate(_publicationService.attach(pub, "med"));
 
                                // Create a document with outdated publication
@@ -413,7 +496,7 @@ public class TestScenarioService extends BaseTest {
                                ht.saveOrUpdate(pub);
 
                                // Attach a file
-                               ht.saveOrUpdate(pub.value());
+                               ht.save(pub.value());
                                ht.saveOrUpdate(_publicationService.attach(pub, "med"));
 
                        }