]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Fix for removing a document with new attached file: ConvertsRelation was not removed...
authorrkv <rkv@opencascade.com>
Sat, 29 Dec 2012 11:02:16 +0000 (11:02 +0000)
committerrkv <rkv@opencascade.com>
Sat, 29 Dec 2012 11:02:16 +0000 (11:02 +0000)
Fix for attaching a file to a document: the file and ConvertsRelation was not created.
Fix for removing of a document from scenario: new attached file and ConvertsRelation are replicated and not deleted.

16 files changed:
Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Entity.java
Workspace/Siman-Common/src/org/splat/dal/bo/kernel/IdGenerator.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.hbm.xml
Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml
Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman-Common/src/test/splat/service/TestPublicationService.java
Workspace/Siman-Common/src/test/splat/service/TestStepService.java
Workspace/Siman/WebContent/jap/splat-launcher.jar
Workspace/Siman/WebContent/jap/splat-signedlauncher.jar
Workspace/Siman/src/org/splat/module/SaveDocumentAction.java [deleted file]
Workspace/Siman/src/spring/applicationContext.xml
Workspace/Siman/src/struts.xml

index 060f84db6674dd26c99064d109984fc5114dbee2..debc3f65f035398ea672c1a0cf1ec15dbf12b946 100644 (file)
@@ -168,9 +168,28 @@ public abstract class Entity extends Any {
                        }
                }
                if (res != null) {
+                       if (LOG.isDebugEnabled()) {
+                               LOG.debug("Contains: "
+                                               + this.getAllRelations().contains(res));
+                               LOG.debug("Nb relations of this before: "
+                                               + this.getAllRelations().size());
+                       }
+                       res.owner = null;
                        this.getAllRelations().remove(res);
+                       if (LOG.isDebugEnabled()) {
+                               LOG.debug("Nb relations of this after: "
+                                               + this.getAllRelations().size());
+                       }
                        if (res.isBidirectional()) {
+                               if (LOG.isDebugEnabled()) {
+                                       LOG.debug("Nb relations of reverse before: "
+                                                       + ((Entity)res.getTo()).getAllRelations().size());
+                               }
                                ((Entity)res.getTo()).getAllRelations().remove(res.getReverse());
+                               if (LOG.isDebugEnabled()) {
+                                       LOG.debug("Nb relations of reverse after: "
+                                                       + ((Entity)res.getTo()).getAllRelations().size());
+                               }
                        }
                }
                return res;
diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/IdGenerator.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/IdGenerator.java
new file mode 100644 (file)
index 0000000..2a98386
--- /dev/null
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * Company         OPEN CASCADE
+ * Application     SIMAN
+ * File            $Id$ 
+ * Creation date   27.12.2012
+ * @author         $Author$
+ * @version        $Revision$
+ * @copyright      OPEN CASCADE 2012
+ *****************************************************************************/
+
+package org.splat.dal.bo.kernel;
+
+import java.util.UUID;
+
+/**
+ * ID Generator. It is supposed to use UUID for identifying persistent objects<BR>
+ * in the same way before and after saving in the database, i.e. before and<BR>
+ * after persistent id generation. The object UID is used for identification in <BR>
+ * equals() and in hashCode().
+ * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ */
+public class IdGenerator {
+       public static String createId() {
+               UUID uuid = java.util.UUID.randomUUID();
+               return uuid.toString();
+       }
+}
\ No newline at end of file
index bd34d98846fd7b0ea45595e837899d2576f99613..508c1e0c42b497c0a02f5183af0ab593f46964d2 100644 (file)
@@ -1,25 +1,28 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
 <!--
-  - Mapping of the primary key common to all Persistent objects.
-  -
-  -
-  - @author    Daniel Brunier-Coulin
-  - @copyright OPEN CASCADE 2012
-  -->
+       - Mapping of the primary key common to all Persistent objects.
+       -
+       -
+       - @author    Daniel Brunier-Coulin
+       - @copyright OPEN CASCADE 2012
+-->
 
 <hibernate-mapping>
-  <class name="org.splat.dal.bo.kernel.Persistent" abstract="true">
-       <id name="rid" column="rid" access="field" type="long">
-        <generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
-               <param name="sequence_name">persistent_id</param>
-               <param name="initial_value">1000</param>
-        </generator>
-       </id>
-<!--         <set name="references" inverse="true" lazy="false"
-            cascade="all-delete-orphan" access="field">
-            <key column="refer" on-delete="cascade"/>
-            <one-to-many class="org.splat.dal.bo.kernel.Relation" />
-        </set> -->
-  </class>
+       <class name="org.splat.dal.bo.kernel.Persistent" abstract="true">
+               <id name="rid" column="rid" access="field" type="long">
+                       <generator
+                               class="org.hibernate.id.enhanced.SequenceStyleGenerator">
+                               <param name="sequence_name">persistent_id</param>
+                               <param name="initial_value">1000</param>
+                       </generator>
+               </id>
+               <property name="uid" access="property" type="string" length="36"
+                       not-null="true" />
+               <!--         <set name="references" inverse="true" lazy="false"
+                       cascade="all-delete-orphan" access="field">
+                       <key column="refer" on-delete="cascade"/>
+                       <one-to-many class="org.splat.dal.bo.kernel.Relation" />
+                       </set> -->
+       </class>
 </hibernate-mapping>
\ No newline at end of file
index f9f01d6d3725fe9034b59259ceb200d93f67ab99..1f95b0dd4aa0e99914f3b959a4657c4f62c66b27 100644 (file)
@@ -36,7 +36,14 @@ import org.splat.kernel.ObjectProperties;
 
 public abstract class Persistent {
 
-       private long rid; // Primary key of persistent objects
+       /**
+        * Primary key of persistent objects.
+        */
+       private long rid;
+       /**
+        * UUID of the object used for identification in equals() and in hashCode().
+        */
+       private String _uid = IdGenerator.createId();
 
        protected abstract static class Properties implements ObjectProperties {
                private long rid; // Primary key of persistent objects
@@ -70,7 +77,7 @@ public abstract class Persistent {
                 * @param rid
                 *            the rid to set
                 */
-               public void setIndex(long rid) {
+               public void setIndex(final long rid) {
                        this.rid = rid;
                }
        }
@@ -82,7 +89,6 @@ public abstract class Persistent {
         * Database fetch constructor.
         */
        protected Persistent() {
-               // -----------------------
                rid = 0; // Set when loading the object
        }
 
@@ -90,12 +96,12 @@ public abstract class Persistent {
         * Checks the mutual compatibility of arguments previously set in the given properties object, if the validity check is enabled. As this
         * validity depends on concrete classes, the check is delegated to subclasses of the given Persistent.Properties.
         */
-       protected Persistent(ObjectProperties oprop)
+       protected Persistent(final ObjectProperties oprop)
                        throws MissedPropertyException, InvalidPropertyException,
                        MultiplyDefinedException {
-               // ---------------------------------------------
-               if (oprop.mustBeChecked())
+               if (oprop.mustBeChecked()) {
                        oprop.checkValidity(); // Throws one of the above exception if not valid
+               }
                rid = 0; // Set when saving the object
        }
 
@@ -103,20 +109,23 @@ public abstract class Persistent {
        // Public member functions
        // ==============================================================================================================================
 
-       public boolean equals(Object entity) {
-               // ------------------------------------
-               if (entity == null)
-                       return false;
-               if (entity.getClass().equals(this.getClass())) {
-                       Persistent object = (Persistent) entity;
-                       long he = object.getIndex(); // getIndex() is supposed fetching the index if not yet done
-                       long me = this.getIndex(); // getIndex() is supposed fetching the index if not yet done
-                       if (me * he != 0)
-                               return (he == me);
-                       if (me + he == 0)
-                               return (this == object);
+       /**
+        * Persistent objects are equal if their UIDs are equal.<BR>
+        * {@inheritDoc}
+        * 
+        * @see java.lang.Object#equals(java.lang.Object)
+        */
+       @Override
+       public boolean equals(final Object entity) {
+               boolean res = (entity != null);
+               if (res) {
+                       res = Persistent.class.isAssignableFrom(entity.getClass());
+                       if (res) {
+                               Persistent object = (Persistent) entity;
+                               res = getUid().equals(object.getUid());
+                       }
                }
-               return false;
+               return res;
        }
 
        /**
@@ -127,7 +136,6 @@ public abstract class Persistent {
         * @see isSaved()
         */
        public long getIndex() {
-               // ----------------------
                return rid;
        }
 
@@ -137,13 +145,18 @@ public abstract class Persistent {
         * @param anId
         *            id to set
         */
-       public void setIndex(long anId) {
+       public void setIndex(final long anId) {
                rid = anId;
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see java.lang.Object#hashCode()
+        */
+       @Override
        public int hashCode() {
-               // ----------------------
-               return toString().hashCode();
+               return getUid().hashCode();
        }
 
        /**
@@ -153,7 +166,6 @@ public abstract class Persistent {
         * @see getIndex()
         */
        public boolean isSaved() {
-               // -------------------------
                return (getIndex() != 0); // getIndex() is supposed fetching the index if not yet done
        }
 
@@ -162,13 +174,10 @@ public abstract class Persistent {
         * 
         * @return the unique string representation of this object.
         */
+       @Override
        public String toString() {
-               // -------------------------
-               long oid = getIndex(); // getIndex() is supposed fetching the index if not yet done
-               if (oid == 0)
-                       oid = super.hashCode(); // WARNING: Must not call super.toString() as it goes back here (this.toString())
                return new StringBuffer("object ").append(getClass().getName()).append(
-                               "@").append(oid).toString();
+                               "@").append(getUid()).append("@").append(getIndex()).toString();
        }
 
        /**
@@ -186,7 +195,26 @@ public abstract class Persistent {
         * @param rid
         *            the rid to set
         */
-       public void setRid(long rid) {
+       public void setRid(final long rid) {
                this.rid = rid;
        }
+
+       /**
+        * Get the uid.
+        * 
+        * @return the uid
+        */
+       public String getUid() {
+               return _uid;
+       }
+
+       /**
+        * Set the uid.
+        * 
+        * @param uid
+        *            the uid to set
+        */
+       public void setUid(final String uid) {
+               _uid = uid;
+       }
 }
\ No newline at end of file
index c5a26d5868a6d06e4eb5c72c65a6694553da2186..a78f1daf92e68577ec529c56229413134ecda8a4 100644 (file)
@@ -16,7 +16,7 @@
     <many-to-one  name="mydoc" column="doc" cascade="merge"  access="field" not-null="true"/>
     
     <!-- ProjectElement owner -->    
-    <many-to-one  name="owner" column="owner" access="field" not-null="true" />
+    <many-to-one  name="owner" column="owner" cascade="merge" access="field" not-null="true" />
   
     <!-- char isnew -->
     <property     name="isnew" column="isnew" access="field" not-null="true" />    
index e0558ac577d6066e38b80700086267020e5d2835..61cda0b46ee7e5c8ccfa885e202e0548e3f7b13c 100644 (file)
@@ -30,6 +30,7 @@ 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.Document.Properties;
+import org.splat.dal.dao.kernel.RelationDAO;
 import org.splat.dal.dao.som.DocumentDAO;
 import org.splat.dal.dao.som.DocumentTypeDAO;
 import org.splat.dal.dao.som.FileDAO;
@@ -76,6 +77,10 @@ public class DocumentServiceImpl implements DocumentService {
         * Injected document DAO.
         */
        private DocumentDAO _documentDAO;
+       /**
+        * Injected relation DAO.
+        */
+       private RelationDAO _relationDAO;
        /**
         * Injected document type DAO.
         */
@@ -138,7 +143,7 @@ public class DocumentServiceImpl implements DocumentService {
                                .append(aDoc.getFile().getFormat()) // File name and extension
                                .toString();
                aDoc.getFile().changePath(path);
-//             owner = getStudyDAO().merge(owner);
+               owner = getStudyDAO().merge(owner);
 //             getStudyDAO().update(owner);
        }
 
@@ -284,6 +289,7 @@ public class DocumentServiceImpl implements DocumentService {
         *            the format
         * @return the created "Converts" relation
         */
+       @Transactional
        public ConvertsRelation attach(final Document aDoc, final String format) {
                return attach(aDoc, format, null);
        }
@@ -307,14 +313,12 @@ public class DocumentServiceImpl implements DocumentService {
                ConvertsRelation attach = new ConvertsRelation(aDoc, export,
                                description);
 
-               // RKV session.save(export);
-               // RKV session.save(attach);
-
                getFileDAO().create(export);
+               getRelationDAO().create(attach);
 
-               // RKV aDoc.addRelation(attach); // Updates this
-               aDoc.getAllRelations().add(attach); // Updates this //RKV
-
+               aDoc.getAllRelations().add(attach);
+               getDocumentDAO().merge(aDoc);
+               
                return attach;
        }
 
@@ -739,4 +743,20 @@ public class DocumentServiceImpl implements DocumentService {
                _studyDAO = studyDAO;
        }
 
+       /**
+        * Get the relationDAO.
+        * @return the relationDAO
+        */
+       public RelationDAO getRelationDAO() {
+               return _relationDAO;
+       }
+
+       /**
+        * Set the relationDAO.
+        * @param relationDAO the relationDAO to set
+        */
+       public void setRelationDAO(final RelationDAO relationDAO) {
+               _relationDAO = relationDAO;
+       }
+
 }
index c0c408d1f953e0f29f200dfcaa150cb86bd1f9a7..98b0ef7ea6ca3fb36a7119dd7fda7f7d48a7a467 100644 (file)
@@ -691,6 +691,7 @@ public class PublicationServiceImpl implements PublicationService {
         *            the format
         * @return the created "Converts" relation
         */
+       @Transactional
        public ConvertsRelation attach(final Publication aPublication,
                        final String format) {
                return getDocumentService().attach(aPublication.value(), format);
@@ -707,6 +708,7 @@ public class PublicationServiceImpl implements PublicationService {
         *            the description of the relation
         * @return the created "Converts" relation
         */
+       @Transactional
        public ConvertsRelation attach(final Publication aPublication,
                        final String format, final String description) {
                return getDocumentService().attach(aPublication.value(), format,
index 0faf6d8d702592abe6f306bbc49429394b74fed2..6a10e4c9c2d3581d070c81cfc79f524e8aa4e3cb 100644 (file)
@@ -20,7 +20,6 @@ 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;
@@ -258,11 +257,9 @@ public class StepServiceImpl implements StepService {
                }
 
                // Identification and save
-               aStep.getOwnerStudy().setLastLocalIndex(
-                               dprop.getOwner().getOwnerStudy().getLastLocalIndex());
                if (LOG.isDebugEnabled()) {
                        LOG.debug("Local index after: "
-                                       + dprop.getOwner().getOwnerStudy().getLastLocalIndex());
+                                       + aStep.getOwnerStudy().getLastLocalIndex());
                }
                getDocumentService().buildReferenceFrom(newdoc, aStep.getOwnerStudy());
                getDocumentDAO().create(newdoc);
@@ -461,12 +458,8 @@ public class StepServiceImpl implements StepService {
         */
        public boolean remove(final Step aStep, final Publication oldoc) {
                aStep.getDocuments().remove(oldoc); // Updates this step
-               // Synchronize with database
-               ProjectElement owner = getProjectElementDAO().merge(aStep.getOwner());
-               if (owner != null) {
-                       aStep.getOwner().remove(oldoc); // in transient copy
-                       owner.remove(oldoc); // in persistent copy
-               }
+               aStep.getOwner().remove(oldoc); // remove from the parent project element
+               getProjectElementDAO().merge(aStep.getOwner());
                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.
                return true;
@@ -496,15 +489,14 @@ public class StepServiceImpl implements StepService {
                        Document value = torem.value();
                        if (!value.isPublished() && !value.isVersioned()) { // The referenced document is no more used
                                List<Document> using = new ArrayList<Document>();
-                               List<Relation> converts = new ArrayList<Relation>();
+                               List<File> files = new ArrayList<File>();
                                for (Relation link : value.getAllRelations()) {
                                        if (link.getClass().equals(ConvertsRelation.class)) { // File conversion
-                                               converts.add(link);
+                                               files.add((File) link.getTo());
                                        } else if (link.getClass().equals(UsesRelation.class)) { // Document dependency
                                                using.add((Document) link.getTo());
                                        }
                                }
-                               // value.getAllRelations().removeAll(converts);
                                // Remove relations from depending documents
                                if (LOG.isDebugEnabled()) {
                                        LOG.debug("Remove " + using.size() + " UsedByRelation(s).");
@@ -513,20 +505,24 @@ public class StepServiceImpl implements StepService {
                                        if (LOG.isDebugEnabled()) {
                                                LOG.debug("Remove UsedByRelation from "
                                                                + doc.getTitle() + " to " + value.getTitle());
+                                               LOG.debug("Nb relations of doc " + doc.getTitle()
+                                                               + " before: " + doc.getAllRelations().size());
                                        }
                                        doc.removeRelation(UsedByRelation.class, value);
+                                       if (LOG.isDebugEnabled()) {
+                                               LOG.debug("Nb relations of doc " + doc.getTitle()
+                                                               + " after: " + doc.getAllRelations().size());
+                                       }
                                        getDocumentDAO().merge(doc);
                                }
-                               value = getPublicationDAO().merge(torem).value();
                                // Synchronize deleted objects with the database to avoid hibernate exception
-                               // org.hibernate.PropertyValueException: not-null property references a null or transient value:
-                               // org.splat.dal.bo.som.UsedByRelation.refer
-                               getDocumentDAO().flush(); // To show to the database that files from ConvertsRelation(s) are deleted already
-                               getDocumentDAO().delete(value); // The corresponding physical file is not removed from the vault
+                               // org.hibernate.PropertyValueException: not-null property references a null or transient value
+                               getDocumentDAO().flush();
+                               // The corresponding physical file is not removed from the vault
+                               getDocumentDAO().delete(getDocumentDAO().merge(torem.value()));
                                // Delete document's files
-                               for (Relation link : converts) {
-                                       File file = (File) link.getTo();
-                                       getFileDAO().delete(file); // The corresponding physical file is not removed from the vault
+                               for (File file : files) {
+                                       getFileDAO().delete(getFileDAO().merge(file)); // The corresponding physical file is not removed from the vault
                                }
                        }
                }
index e8cbab3bb9dc66cfda96aaa091b6f59d8a15ccc6..ec8070f662602c725595f2e5827302d95cc12088 100644 (file)
@@ -39,7 +39,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="documentDAO" ref="documentDAO" />
                <property name="documentTypeDAO" ref="documentTypeDAO" />
                <property name="repositoryService" ref="repositoryService" />
-               <property name="fileDAO" ref="fileDAO" />
+        <property name="fileDAO" ref="fileDAO" />
+        <property name="relationDAO" ref="relationDAO" />
                <property name="studyDAO" ref="studyDAO" />
        </bean>
 
index ae20269c529c28c3c7faf66e83331ae29cdf57e7..3d4f134855c7e247e8831294a282a4831967d576 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.ConvertsRelation;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.DocumentType;
 import org.splat.dal.bo.som.ProgressState;
@@ -417,11 +418,11 @@ public class TestPublicationService extends BaseTest {
                steps.addAll(Arrays.asList(studySteps));
                steps.addAll(Arrays.asList(scSteps));
                steps.addAll(Arrays.asList(studySteps));
-               for (org.splat.som.Step step: steps) {
+               for (org.splat.som.Step step : steps) {
                        LOG.debug("Create a document for the step " + step.getNumber());
 
-                       List<DocumentType> dtypes = _documentTypeService
-                                       .selectTypesOf(step.getStep());
+                       List<DocumentType> dtypes = _documentTypeService.selectTypesOf(step
+                                       .getStep());
                        if (dtypes.size() > 0) {
                                DocumentType dtype = dtypes.get(0);
                                int oldInd = ht.get(Study.class, aStudyFound.getIndex())
@@ -467,6 +468,121 @@ public class TestPublicationService extends BaseTest {
                LOG.debug(">>>>> END testCreateDoc()");
        }
 
+       /**
+        * Test of file attaching to a study document.<BR>
+        * <B>Description :</B> <BR>
+        * <i>Create a study and try to attach a new file to its each document.</i><BR>
+        * <B>Action : </B><BR>
+        * <i>1. call attach method for each document publication of the study.</i><BR>
+        * <B>Test data : </B><BR>
+        * <i>no input parameters</i><BR>
+        * 
+        * <B>Outcome results:</B><BR>
+        * <i>
+        * <ul>
+        * <li>The new ConvertsRelation and the new File object must be created in the database.<BR>
+        * </li>
+        * </ul>
+        * </i>
+        * 
+        * @throws InvalidPropertyException
+        *             if an invalid property is used when creating objects
+        * @throws MultiplyDefinedException
+        *             when trying to create an object with already existing id
+        * @throws MissedPropertyException
+        *             if a mandatory property is not defined for an object to be created
+        * @throws SQLException
+        *             if test study creation is failed
+        * @throws IOException
+        *             if test study creation is failed
+        * @throws ParseException
+        * @throws InterruptedException
+        * @throws NotApplicableException
+        * 
+        */
+       @Test
+       public void testAttach() throws InvalidPropertyException,
+                       MissedPropertyException, MultiplyDefinedException, IOException,
+                       SQLException, NotApplicableException, InterruptedException,
+                       ParseException {
+               LOG.debug(">>>>> BEGIN testAttach()");
+               startNestedTransaction();
+
+               HibernateTemplate ht = getHibernateTemplate();
+               Study aStudy = createStudy();
+               // Call DAO's create method for a good transient study.
+               Long id = aStudy.getIndex();
+               Assert.assertNotNull(id,
+                               "Create method returns null instead of a new id.");
+               Assert.assertTrue(id > 0, "The new id is not a positive number.");
+
+               // Call DAO's get method for an existing id.
+               _studyDAO.flush();
+               getHibernateTemplate().evict(aStudy);
+               getHibernateTemplate().clear();
+               Study aStudyFound = _studyDAO.get(id);
+               ht.clear();
+               ht.evict(aStudyFound);
+
+               long userId = aStudyFound.getAuthor().getIndex();
+               org.splat.som.Step[] studySteps = _projectElementService
+                               .getSteps(aStudyFound);
+               org.splat.som.Step[] scSteps = _projectElementService
+                               .getSteps(aStudyFound.getScenarii()[0]);
+
+               List<org.splat.som.Step> steps = new ArrayList<org.splat.som.Step>();
+               steps.addAll(Arrays.asList(studySteps));
+               steps.addAll(Arrays.asList(scSteps));
+               steps.addAll(Arrays.asList(studySteps));
+               for (org.splat.som.Step step : steps) {
+                       LOG.debug("Attach a new .py file to documents of the step "
+                                       + step.getNumber() + ": " + step.getStep().getKey() + ": "
+                                       + step.getOwner().getClass().getSimpleName());
+
+                       for (Publication pub : step.getAllDocuments()) {
+
+                               ht.evict(step.getOwner());
+                               ht.evict(pub);
+                               ht.evict(pub.value());
+                               int nbConverts = ht.find("from ConvertsRelation").size();
+                               int nbDocConverts = ht.find("from ConvertsRelation where owner="
+                                                               + pub.value().getIndex()).size();
+                               int nbFiles = ht.find("from File").size();
+                               
+                               ConvertsRelation rel = _publicationService.attach(pub, "py");
+
+                               _studyDAO.flush();
+                               ht.flush();
+                               Assert.assertNotNull(rel,
+                                               "Returned ConvertsRelation must not be null.");
+                               Assert
+                                               .assertTrue(rel.isSaved(),
+                                                               "Returned ConvertsRelation must be saved in the database.");
+                               Assert.assertEquals(ht
+                                               .find("from ConvertsRelation where owner="
+                                                               + pub.value().getIndex()).size(), nbDocConverts + 1,
+                                               "Number of created ConvertsRelations must be 1.");
+                               Assert.assertEquals(ht
+                                               .find("from ConvertsRelation").size(), nbConverts + 1,
+                                               "Number of created ConvertsRelations must be 1.");
+                               Assert.assertNotNull(rel.getTo(),
+                                               "Attached File must not be null.");
+                               Assert.assertTrue(rel.isSaved(),
+                                               "Attached File must be saved in the database.");
+                               Assert.assertEquals(ht
+                                               .find("from File where rid="
+                                                               + rel.getTo().getIndex()).size(), 1,
+                                               "Number of created File must be 1.");
+                               Assert.assertEquals(ht
+                                               .find("from File").size(), nbFiles + 1,
+                                               "Number of created Files must be 1.");
+                       }
+               }
+
+               rollbackNestedTransaction();
+               LOG.debug(">>>>> END testAttach()");
+       }
+
        /**
         * Get path to the user's downloads directory. The directory is created if it is not exist yet.
         * 
index dc3d615f7fdf2d8b090083d9206100b6a2b1111a..7a83e0068ef157c201bac6d83a63a3cffa6a3d82 100644 (file)
@@ -18,8 +18,10 @@ import java.util.List;
 import java.util.Map;
 
 import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.ConvertsRelation;
 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.ProjectElement;
 import org.splat.dal.bo.som.Publication;
 import org.splat.dal.bo.som.Scenario;
@@ -28,6 +30,7 @@ import org.splat.dal.bo.som.UsedByRelation;
 import org.splat.dal.bo.som.UsesRelation;
 import org.splat.dal.bo.som.Document.Properties;
 import org.splat.dal.dao.som.Database;
+import org.splat.dal.dao.som.FileDAO;
 import org.splat.dal.dao.som.ScenarioDAO;
 import org.splat.exception.BusinessException;
 import org.splat.exception.DocumentIsUsedException;
@@ -77,6 +80,13 @@ public class TestStepService extends BaseTest {
        @Qualifier("scenarioDAO")
        private transient ScenarioDAO _scenarioDAO;
 
+       /**
+        * The File DAO. Later injected by Spring.
+        */
+       @Autowired
+       @Qualifier("fileDAO")
+       private transient FileDAO _fileDAO;
+
        /**
         * The PublicationService. Later injected by Spring.
         */
@@ -186,6 +196,7 @@ public class TestStepService extends BaseTest {
                        if (aScStep.getDocuments().size() > 0) {
                                docId = aScStep.getDocuments().get(0).value().getIndex();
                                ht.flush();
+
                                List<UsesRelation> uses = ht
                                                .find("from UsesRelation where owner=" + docId);
                                List<UsedByRelation> usedBy = ht
@@ -313,6 +324,17 @@ public class TestStepService extends BaseTest {
                                Assert.assertEquals(ht.find("from Document where rid=" + docId)
                                                .size(), 1, "Nothing to delete.");
 
+                               
+                               ht.evict(aScStep.getDocuments().get(0).value()
+                                               .getFile());
+                               LOG.debug("Load file#" + aScStep.getDocuments().get(0).value()
+                                               .getRelations(ConvertsRelation.class).get(0).getTo().getIndex());
+
+                               ht.clear();
+                               File f = _fileDAO.get(aScStep.getDocuments().get(0).value()
+                                               .getRelations(ConvertsRelation.class).get(0).getTo().getIndex());
+                               ht.evict(aScStep.getDocuments().get(0).value());
+                               
                                ok = _stepService.removeDocument(aScStep, docId);
 
                                nbRemovedDoc++;
@@ -367,10 +389,9 @@ public class TestStepService extends BaseTest {
                                                - nbRemovedDoc,
                                                "Documents were not removed from the database.");
 
-               Assert
-               .assertEquals(ht.find("from File").size(), 0,
+               Assert.assertEquals(ht.find("from File").size(), 0,
                                "Files were not removed from the database.");
-               
+
                Assert.assertEquals(ht.find(
                                "from Publication where owner=" + aScen.getIndex()).size(), 0,
                                "Publications were not removed from the database.");
index fe41638a56c0218490b740ba26b6902cd83f4352..358d6675f3dbb407c05d346b6f4f188d0a07b549 100644 (file)
Binary files a/Workspace/Siman/WebContent/jap/splat-launcher.jar and b/Workspace/Siman/WebContent/jap/splat-launcher.jar differ
index b35d41ae2f00885db94cc5de0805e2353b39051a..a425f841d7d6e559fcfae47fe6e61bca392f7122 100644 (file)
Binary files a/Workspace/Siman/WebContent/jap/splat-signedlauncher.jar and b/Workspace/Siman/WebContent/jap/splat-signedlauncher.jar differ
diff --git a/Workspace/Siman/src/org/splat/module/SaveDocumentAction.java b/Workspace/Siman/src/org/splat/module/SaveDocumentAction.java
deleted file mode 100644 (file)
index 806dc9b..0000000
+++ /dev/null
@@ -1,444 +0,0 @@
-package org.splat.module;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.splat.dal.bo.kernel.User;
-import org.splat.dal.bo.som.ConvertsRelation;
-import org.splat.dal.bo.som.Document;
-import org.splat.dal.bo.som.DocumentType;
-import org.splat.dal.bo.som.ProgressState;
-import org.splat.dal.bo.som.Publication;
-import org.splat.dal.bo.som.SimulationContext;
-import org.splat.dal.bo.som.SimulationContextType;
-import org.splat.dal.dao.som.Database;
-import org.splat.kernel.Do;
-import org.splat.service.DocumentTypeService;
-import org.splat.service.PublicationService;
-import org.splat.service.ScenarioService;
-import org.splat.service.SimulationContextService;
-import org.splat.service.StepService;
-import org.splat.service.technical.RepositoryService;
-import org.splat.simer.Action;
-import org.splat.simer.OpenStudy;
-import org.splat.som.Step;
-
-public class SaveDocumentAction extends Action {
-
-       /**
-        * Serial version ID.
-        */
-       private static final long serialVersionUID = -3364960833373200115L;
-
-       /**
-        * Current open study.
-        */
-       private transient OpenStudy _mystudy = null;
-       private transient int _doctype = 0;
-       private transient String _filename = null;
-       private transient String _docname = null;
-       private transient ProgressState _state = null;
-       private transient List<Document> _defuses = null;
-       private String _description = null; // Summary of changes in the new version
-       /**
-        * Injected scenario service.
-        */
-       private ScenarioService _scenarioService;
-       /**
-        * Injected publication service.
-        */
-       private PublicationService _publicationService;
-       /**
-        * Injected step service.
-        */
-       private StepService _stepService;
-       /**
-        * Injected document type service.
-        */
-       private DocumentTypeService _documentTypeService;
-       /**
-        * Injected repository service.
-        */
-       private RepositoryService _repositoryService;
-       /**
-        * Injected simulation context service.
-        */
-       private SimulationContextService _simulationContextService;
-
-       // ==============================================================================================================================
-       // Action methods
-       // ==============================================================================================================================
-
-       public String doSave() {
-               // -----------------------
-               Session connex = Database.getCurSession();
-               Transaction transax = connex.beginTransaction();
-               try {
-                       // Getting user inputs
-                       _mystudy = getOpenStudy();
-                       User user = getConnectedUser();
-                       Step step = _mystudy.getSelectedStep();
-                       DocumentType type = getDocumentTypeService().selectType(_doctype);
-                       // File updir = Database.getDownloadDirectory(user);
-                       // File upfile = new File(updir.getPath() + "/" + filename);
-                       String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
-                       // between users
-                       File upfile = new File(upath + _filename);
-                       String[] table = _filename.split("\\x2E");
-                       String format = table[table.length - 1];
-
-                       // Creation of the document
-                       getScenarioService().checkin(step.getOwner().getIndex()); // Modules necessarily save their data in a scenario step
-                       connex.flush();
-
-                       Document.Properties dprop = new Document.Properties();
-                       Publication credoc = getStepService().createDocument(
-                                       step,
-                                       dprop.setName(_docname).setType(type).setFormat(format)
-                                                       .setAuthor(user));
-                       // Writing the uploaded file into the created document
-                       File target = credoc.getSourceFile().asFile();
-                       if (target.exists()) {
-                               target.delete();
-                       }
-                       Do.copy(upfile, target); // Instead of rename for keeping the "uploaded" file for further use
-                       // upfile.renameTo(target);
-
-                       // Saving the document in given state
-                       getPublicationService().saveAs(credoc, _state);
-
-                       // Creation of default uses relations
-                       _defuses = new ArrayList<Document>();
-                       setupDefaultUses(type); // Recursive function
-                       for (Iterator<Document> i = _defuses.iterator(); i.hasNext();) {
-                               credoc.addDependency(i.next());
-                       }
-
-                       // Execution of module specific operations
-
-                       // 1. Conversion of the document to internal format, if required
-                       // TODO: The following code is temporary, waiting for the support of converters
-                       if ("part".equals(format)) {
-                               ConvertsRelation export = getPublicationService().attach(
-                                               credoc, "brep");
-
-                               target = export.getTo().asFile();
-                               if (target.exists()) {
-                                       target.delete();
-                               }
-                               Do.copy(upfile, target); // Instead of rename for keeping the "uploaded" file for further use
-                       }
-                       // 2. Addition of simulation contexts
-                       if ("model".equals(type)) { // Set the characteristics of the mesh
-                               SimulationContext.Properties cprop = new SimulationContext.Properties();
-                               SimulationContextType ctype = getSimulationContextService()
-                                               .selectType("model");
-                               SimulationContext context = getSimulationContextService()
-                                               .selectSimulationContext(ctype, "Éléments finis");
-                               if (context == null) {
-                                       getStepService().addSimulationContext(step,
-                                                       cprop.setType(ctype).setValue("Éléments finis"));
-                               } else {
-                                       getStepService().addSimulationContext(step, context);
-                               }
-                               ctype = getSimulationContextService().selectType("element");
-                               context = getSimulationContextService()
-                                               .selectSimulationContext(ctype, "Surfacique");
-                               if (context == null) {
-                                       getStepService().addSimulationContext(step,
-                                                       cprop.setType(ctype).setValue("Surfacique"));
-                               } else {
-                                       getStepService().addSimulationContext(step, context);
-                               }
-                               ctype = getSimulationContextService().selectType("shape");
-                               context = getSimulationContextService()
-                                               .selectSimulationContext(ctype, "Triangles");
-                               if (context == null) {
-                                       getStepService().addSimulationContext(step,
-                                                       cprop.setType(ctype).setValue("Triangles"));
-                               } else {
-                                       getStepService().addSimulationContext(step, context);
-                               }
-                       }
-                       // Update of the open study
-                       // mystudy.add(credoc); // Useless while the SIMER page need to be refreshed manually
-                       getMenu("study").selects(_mystudy.getSelection()); // Updates the menu icon, in case of first added document
-
-                       transax.commit();
-                       return SUCCESS;
-               } catch (Exception saverror) {
-                       LOG.error("Reason:", saverror);
-                       if (transax != null && transax.isActive()) {
-                               // Second try-catch as the rollback could fail as well
-                               try {
-                                       transax.rollback();
-                               } catch (HibernateException backerror) {
-                                       LOG.debug("Error rolling back transaction", backerror);
-                               }
-                       }
-                       return ERROR;
-               }
-       }
-
-       /**
-        * Get the publicationService.
-        * 
-        * @return publicationService
-        */
-       private PublicationService getPublicationService() {
-               return _publicationService;
-       }
-
-       /**
-        * Set the publicationService.
-        * 
-        * @param publicationService
-        *            the publicationService to set
-        */
-       public void setPublicationService(
-                       final PublicationService publicationService) {
-               _publicationService = publicationService;
-       }
-
-       /**
-        * Get the scenarioService.
-        * 
-        * @return scenarioService
-        */
-       public ScenarioService getScenarioService() {
-               return _scenarioService;
-       }
-
-       /**
-        * Set the scenarioService.
-        * 
-        * @param scenarioService
-        *            the scenarioService to set
-        */
-       public void setScenarioService(final ScenarioService scenarioService) {
-               _scenarioService = scenarioService;
-       }
-
-       /**
-        * Get the stepService.
-        * 
-        * @return the stepService
-        */
-       public StepService getStepService() {
-               return _stepService;
-       }
-
-       /**
-        * Set the stepService.
-        * 
-        * @param stepService
-        *            the stepService to set
-        */
-       public void setStepService(final StepService stepService) {
-               _stepService = stepService;
-       }
-
-       public String doUpdate() {
-               // -------------------------
-               return SUCCESS;
-       }
-
-       public String doVersion() {
-               // --------------------------
-               Session connex = Database.getCurSession();
-               Transaction transax = connex.beginTransaction();
-               try {
-                       // Getting user inputs
-                       _mystudy = getOpenStudy();
-                       User user = getConnectedUser();
-                       Step step = _mystudy.getSelectedStep();
-                       // File updir = Database.getDownloadDirectory(user);
-                       // File upfile = new File(updir.getPath() + "/" + filename);
-                       String upath = getRepositoryService().getTemplatePath(); // Instead of DownloadDirectory for sharing the "uploaded" file
-                       // between users
-                       File upfile = new File(upath + _filename);
-                       String[] table = _filename.split("\\x2E");
-                       String format = table[table.length - 1];
-
-                       // Versioning of the document
-                       Publication current = _mystudy.getSelectedDocument();
-                       Document.Properties dprop = new Document.Properties();
-                       dprop.setAuthor(user);
-                       if (_description.length() > 0) {
-                               dprop.setDescription(_description);
-                       }
-
-                       Publication next = getStepService().versionDocument(step, current,
-                                       dprop);
-
-                       // Writing the uploaded file into the created document
-                       File target = next.getSourceFile().asFile();
-                       if (target.exists()) {
-                               target.delete();
-                       }
-                       Do.copy(upfile, target); // Instead of rename for keeping the "uploaded" file for further use
-                       // upfile.renameTo(target);
-
-                       // Saving the document in given state
-                       getPublicationService().saveAs(next, _state);
-
-                       // Creation of default uses relations
-                       _defuses = new ArrayList<Document>();
-                       setupDefaultUses(next.value().getType()); // Recursive function
-                       for (Iterator<Document> i = _defuses.iterator(); i.hasNext();) {
-                               next.addDependency(i.next());
-                       }
-                       // TODO: Outdating impacted document
-
-                       // Execution of module specific operations
-
-                       // 1. Conversion of the document to internal format, if required
-                       // TODO: The following code is temporary, waiting for the support of converters
-                       if ("part".equals(format)) {
-                               ConvertsRelation export = getPublicationService().attach(next,
-                                               "brep");
-                               String fname = table[0];
-
-                               for (int i = 1; i < table.length - 1; i++) {
-                                       fname = fname + table[i];
-                               }
-                               upfile = new File(upath + fname + ".brep");
-                               upfile.renameTo(export.getTo().asFile());
-                       }
-
-                       // Update of the open study
-                       // mystudy.setSelection(mystudy.getSelection()); // Rebuild the presentation
-
-                       transax.commit();
-                       return SUCCESS;
-               } catch (Exception saverror) {
-                       LOG.error("Reason:", saverror);
-                       if (transax != null && transax.isActive()) {
-                               // Second try-catch as the rollback could fail as well
-                               try {
-                                       transax.rollback();
-                               } catch (HibernateException backerror) {
-                                       LOG.debug("Error rolling back transaction", backerror);
-                               }
-                       }
-                       return ERROR;
-               }
-       }
-
-       // ==============================================================================================================================
-       // Getters and setters
-       // ==============================================================================================================================
-
-       public String getDescription() {
-               // -------------------------------
-               return _description;
-       }
-
-       public void setDescription(final String summary) {
-               // -------------------------------------------
-               this._description = summary;
-       }
-
-       public void setDocumentName(final String name) {
-               // -----------------------------------------
-               this._docname = name;
-       }
-
-       public void setDocumentState(final String state) {
-               // -------------------------------------------
-               this._state = ProgressState.valueOf(state);
-       }
-
-       public void setDocumentType(final String value) {
-               // ------------------------------------------
-               this._doctype = Integer.valueOf(value);
-       }
-
-       public void setFileName(final String name) {
-               // -------------------------------------
-               this._filename = name;
-       }
-
-       // ==============================================================================================================================
-       // Private service
-       // ==============================================================================================================================
-
-       private void setupDefaultUses(final DocumentType type) {
-               Set<DocumentType> uses = type.getDefaultUses();
-
-               for (Iterator<DocumentType> i = uses.iterator(); i.hasNext();) {
-                       DocumentType usetype = i.next();
-                       List<Document> usedoc = _mystudy.collectInvolvedDocuments(usetype);
-                       if (usedoc.isEmpty()) {
-                               setupDefaultUses(usetype);
-                       } else {
-                               _defuses.addAll(usedoc);
-                       }
-               }
-       }
-
-       /**
-        * Get the repositoryService.
-        * 
-        * @return the repositoryService
-        */
-       public RepositoryService getRepositoryService() {
-               return _repositoryService;
-       }
-
-       /**
-        * Set the repositoryService.
-        * 
-        * @param repositoryService
-        *            the repositoryService to set
-        */
-       public void setRepositoryService(final RepositoryService repositoryService) {
-               _repositoryService = repositoryService;
-       }
-
-       /**
-        * Get the simulationContextService.
-        * 
-        * @return the simulationContextService
-        */
-       public SimulationContextService getSimulationContextService() {
-               return _simulationContextService;
-       }
-
-       /**
-        * Set the simulationContextService.
-        * 
-        * @param simulationContextService
-        *            the simulationContextService to set
-        */
-       public void setSimulationContextService(
-                       final SimulationContextService simulationContextService) {
-               _simulationContextService = simulationContextService;
-       }
-
-       /**
-        * Get the documentTypeService.
-        * 
-        * @return the documentTypeService
-        */
-       public DocumentTypeService getDocumentTypeService() {
-               return _documentTypeService;
-       }
-
-       /**
-        * Set the documentTypeService.
-        * 
-        * @param documentTypeService
-        *            the documentTypeService to set
-        */
-       public void setDocumentTypeService(
-                       final DocumentTypeService documentTypeService) {
-               _documentTypeService = documentTypeService;
-       }
-}
\ No newline at end of file
index 1225c736ac3e01e36ed2ba0b6560fe6795f9fa15..a91952736c8766451225a6e6a74212543e20c846 100644 (file)
@@ -296,15 +296,4 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                scope="prototype">
        </bean>
 
-       <bean id="saveDocumentAction"
-               class="org.splat.module.SaveDocumentAction" scope="prototype">
-               <property name="documentTypeService" ref="documentTypeService" />
-               <property name="publicationService" ref="publicationService" />
-               <property name="repositoryService" ref="repositoryService" />
-               <property name="scenarioService" ref="scenarioService" />
-               <property name="stepService" ref="stepService" />
-               <property name="simulationContextService"
-                       ref="simulationContextService" />
-       </bean>
-
 </beans>
index d60b1b9a750324ad5de305bb6a7b9fda956a3d6e..73adc9a324c2cd5a2f6fa4c3811eb7d31a050f63 100644 (file)
                </action>
        </package>
 
-       <package name="sgeom" namespace="/sgeom" extends="simer-default">
-
-               <action name="valid-save" class="saveDocumentAction"
-                       method="save">
-                       <result name="success">/sgeom/index.jsp</result>
-               </action>
-               <action name="valid-update" class="saveDocumentAction"
-                       method="update">
-                       <result name="success">/sgeom/index.jsp</result>
-               </action>
-               <action name="valid-version" class="saveDocumentAction"
-                       method="version">
-                       <result name="success">/sgeom/index.jsp</result>
-               </action>
-
-       </package>
-
-
-       <package name="smesh" namespace="/smesh" extends="simer-default">
-
-               <action name="valid-save" class="saveDocumentAction"
-                       method="save">
-                       <result name="success">/smesh/index.jsp</result>
-               </action>
-               <action name="valid-update" class="saveDocumentAction"
-                       method="update">
-                       <result name="success">/smesh/index.jsp</result>
-               </action>
-               <action name="valid-version" class="saveDocumentAction"
-                       method="version">
-                       <result name="success">/smesh/index.jsp</result>
-               </action>
-
-       </package>
 </struts>
\ No newline at end of file