From a4ac35ce8653ea88a4b81a445c5de72411f10c85 Mon Sep 17 00:00:00 2001 From: rkv Date: Mon, 29 Oct 2012 11:37:36 +0000 Subject: [PATCH] Mapping is fixed. Relation in the mapping is inherited from Persistent now. Versioning a document is working. --- .../src/org/splat/dal/bo/kernel/Any.hbm.xml | 41 ++--- .../src/org/splat/dal/bo/kernel/Any.java | 25 ++-- .../org/splat/dal/bo/kernel/Attribute.hbm.xml | 31 ++-- .../org/splat/dal/bo/kernel/Attribute.java | 2 +- .../org/splat/dal/bo/kernel/Entity.hbm.xml | 43 ++---- .../src/org/splat/dal/bo/kernel/Entity.java | 3 +- .../splat/dal/bo/kernel/Persistent.hbm.xml | 8 - .../org/splat/dal/bo/kernel/Relation.hbm.xml | 44 ++---- .../src/org/splat/dal/bo/kernel/Relation.java | 3 +- .../splat/dal/bo/kernel/TextAttribute.hbm.xml | 19 ++- .../splat/dal/bo/kernel/TextAttribute.java | 4 +- .../src/org/splat/dal/bo/kernel/User.hbm.xml | 69 +++++---- .../org/splat/dal/bo/som/Attributes.hbm.xml | 28 ++-- .../dal/bo/som/DescriptionAttribute.java | 2 +- .../src/org/splat/dal/bo/som/Document.hbm.xml | 14 -- .../org/splat/dal/bo/som/DocumentType.java | 14 +- .../src/org/splat/dal/bo/som/File.hbm.xml | 6 - .../splat/dal/bo/som/KnowledgeElement.hbm.xml | 9 -- .../splat/dal/bo/som/ProjectElement.hbm.xml | 14 -- .../org/splat/dal/bo/som/ProjectElement.java | 8 +- .../org/splat/dal/bo/som/Publication.hbm.xml | 6 - .../src/org/splat/dal/bo/som/Scenario.java | 3 +- .../src/org/splat/dal/bo/som/Study.java | 4 +- .../org/splat/dal/bo/som/Timestamp.hbm.xml | 10 -- .../splat/dal/bo/som/ValidationCycle.hbm.xml | 6 - .../org/splat/dal/dao/kernel/GenericDAO.java | 5 + .../splat/dal/dao/kernel/GenericDAOImpl.java | 7 + .../splat/service/DocumentServiceImpl.java | 28 +++- .../org/splat/service/PublicationService.java | 62 ++++---- .../splat/service/PublicationServiceImpl.java | 141 +++++++++++++++++- .../org/splat/service/StepServiceImpl.java | 31 +++- .../src/spring/businessServiceContext.xml | 7 +- .../splat/simer/VersionDocumentAction.java | 35 +++-- 33 files changed, 418 insertions(+), 314 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.hbm.xml index 5bc0fd6..0a391d3 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.hbm.xml @@ -1,32 +1,23 @@ + - Mapping of the root abstract class supporting dynamic attributes. + - All objects instance of a subclass of Any are uniquely identified by the rid primary key through the IDGenerator identifier generator class. + - + - @author Daniel Brunier-Coulin + - @copyright OPEN CASCADE 2012 +--> + - - - - - - - - - - - - - - - + + + + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java index b047d8f..5366bc7 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java @@ -21,7 +21,7 @@ import org.splat.kernel.ObjectProperties; public abstract class Any extends Persistent { - private Set attributes; + private Set attributes = new HashSet(); // ============================================================================================================================== // Constructors @@ -34,14 +34,12 @@ public abstract class Any extends Persistent { protected Any (ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException { // -------------------------------------- super(oprop); - attributes = new HashSet(); } protected Any (Attribute... field) { // ---------------------------------- - attributes = new HashSet(); for (int i=0; i type) { // --------------------------------------------------------------- - for (Iterator i=attributes.iterator(); i.hasNext(); ) { + for (Iterator i=getAttributes().iterator(); i.hasNext(); ) { Attribute field = i.next(); if (field.getClass().equals(type)) return field; } @@ -64,7 +62,7 @@ public abstract class Any extends Persistent { protected boolean removeAttribute (Attribute field) { // --------------------------------------------------- - for (Iterator i=attributes.iterator(); i.hasNext(); ) { + for (Iterator i=getAttributes().iterator(); i.hasNext(); ) { if (!i.next().equals(field)) continue; i.remove(); //RKV if (this.isSaved()) Database.getCurSession().update(this); @@ -79,16 +77,23 @@ public abstract class Any extends Persistent { //RKV Session session = Database.getCurSession(); if (!field.getFrom().equals(this)) return false; - for (Iterator i=attributes.iterator(); i.hasNext(); ) { + for (Iterator i=getAttributes().iterator(); i.hasNext(); ) { if (!i.next().getClass().equals(type)) continue; i.remove(); break; } - attributes.add(field); - if (this.isSaved()) { + getAttributes().add(field); + //RKVif (this.isSaved()) { //RKV if (!field.isSaved()) session.save(field); //RKV session.update(this); - } // Else, when saving this, Hibernate will propagate the operation + //RKV} // Else, when saving this, Hibernate will propagate the operation return true; } + /** + * Get the attributes. + * @return the attributes + */ + protected Set getAttributes() { + return attributes; + } } \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Attribute.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Attribute.hbm.xml index 79c5a85..12f0c0a 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Attribute.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Attribute.hbm.xml @@ -1,26 +1,21 @@ + - Mapping of the Attribute class hierarchy. + - The attribute hierarchy is mapped to a single table using a String discriminator. + - + - @author Daniel Brunier-Coulin + - @copyright OPEN CASCADE 2012 +--> + - - - - - - - - - - - - + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Attribute.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Attribute.java index c3096c7..50f94c2 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Attribute.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Attribute.java @@ -16,7 +16,7 @@ public abstract class Attribute extends Persistent { // ============================================================================================================================== // Database fetch constructor. - protected Attribute () { + public Attribute () { } // Initialization constructor protected Attribute (Any from) { diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Entity.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Entity.hbm.xml index e024f44..0992d7d 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Entity.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Entity.hbm.xml @@ -1,35 +1,24 @@ + - Mapping of the root abstract class supporting relations. + - + - + - @author Daniel Brunier-Coulin + - @copyright OPEN CASCADE 2012 +--> + - - - - - - - - - - - - - - - - + + + + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Entity.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Entity.java index d423d25..ebe0874 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Entity.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Entity.java @@ -24,7 +24,7 @@ import org.splat.kernel.ObjectProperties; public abstract class Entity extends Any { - private Set relations; + private Set relations = new HashSet(); // ============================================================================================================================== // Constructors @@ -37,7 +37,6 @@ public abstract class Entity extends Any { protected Entity (ObjectProperties prop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException { // ---------------------------------------- super(prop); - relations = new HashSet(); } // ============================================================================================================================== diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.hbm.xml index 132e51a..a4a9ef9 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.hbm.xml @@ -9,20 +9,12 @@ --> - - - - persistent_id 1000 - - \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.hbm.xml index 47b7ab8..2ffa7f5 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.hbm.xml @@ -1,39 +1,19 @@ + - Mapping of the Relation class hierarchy. + - The entire hierarchy is mapped to one single table using a String discriminator. + - + - @author Daniel Brunier-Coulin + - @copyright OPEN CASCADE 2012 +--> + - - - - - - - - relation_id - - - - - - - - - - - - - - - - + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.java index 9f8964f..b176ad0 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Relation.java @@ -38,7 +38,6 @@ public abstract class Relation extends Any { // Initialization constructor protected Relation (Entity from) { // -------------------------------- - super((Attribute)null); // For building the collection of attributes this.owner = from; this.reverse = null; // Initialized by subclasses } @@ -88,8 +87,10 @@ public abstract class Relation extends Any { public void moveTo (Entity nowner) { //RKV Session session = Database.getCurSession(); + Entity oldOwner = this.owner; this.owner = nowner; nowner.getAllRelations().add(this); + oldOwner.getAllRelations().remove(this); // myold.getAllRelations().remove(this); Harmful as it leads to remove this relation from the database (!?) //RKV session.update(this); //RKV session.update(nowner); diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/TextAttribute.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/TextAttribute.hbm.xml index 7b5fe9b..6f7fd24 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/TextAttribute.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/TextAttribute.hbm.xml @@ -1,14 +1,17 @@ + - + - @author Daniel Brunier-Coulin + - @copyright OPEN CASCADE 2012 +--> - - - - + + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/TextAttribute.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/TextAttribute.java index 36c6fa0..1ebf2e4 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/TextAttribute.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/TextAttribute.java @@ -17,7 +17,7 @@ public abstract class TextAttribute extends Attribute { // ============================================================================================================================== // Database fetch constructor. - protected TextAttribute () { + public TextAttribute () { } // Initialization constructor @@ -40,7 +40,7 @@ public abstract class TextAttribute extends Attribute { // Protected services // ============================================================================================================================== - protected void setValue (String value) { + public void setValue (String value) { // -------------------------------------- mytext = value; //RKV if (this.isSaved()) Database.getCurSession().update(this); diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.hbm.xml index 50479c7..ffa5d73 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/User.hbm.xml @@ -1,37 +1,46 @@ + - Mapping of the User class and its corresponding Role definition. + - User and Role are associated by a one-to-one association on the username User foreign key. + - + - @author Daniel Brunier-Coulin + - @copyright OPEN CASCADE 2012 +--> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml index 7aefad5..cda4ad8 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml @@ -1,22 +1,24 @@ + - Mapping of the Attribute concrete subclasses. + - + - @author Daniel Brunier-Coulin + - @copyright OPEN CASCADE 2012 +--> - - - + + + - - - + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/DescriptionAttribute.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/DescriptionAttribute.java index 4213156..c6ce6a8 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/DescriptionAttribute.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/DescriptionAttribute.java @@ -17,7 +17,7 @@ public class DescriptionAttribute extends TextAttribute { // ============================================================================================================================== // Database fetch constructor. - protected DescriptionAttribute () { + public DescriptionAttribute () { } /** * Constructs the description of a study or a scenario. diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.hbm.xml index ca6e184..2207b7a 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Document.hbm.xml @@ -11,20 +11,6 @@ - - - - diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElement.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElement.hbm.xml index d471b0f..5ca1351 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElement.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/KnowledgeElement.hbm.xml @@ -10,12 +10,6 @@ - - - @@ -44,9 +38,6 @@ - diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.hbm.xml index d98a3cc..0a13cf3 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.hbm.xml @@ -12,20 +12,6 @@ - - - diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java index 9e8655d..fd8d747 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ProjectElement.java @@ -30,8 +30,8 @@ public abstract class ProjectElement extends Entity { protected User manager; protected Date credate; // Object creation date protected Date lasdate; // Object Last modification date - private List contex; // Structured by the Step transient class - private Set docums; // Structured by the Step transient class + private List contex = new Vector(); // Structured by the Step transient class + private Set docums = new LinkedHashSet(); // Structured by the Step transient class // Transient field private Step[] folders; @@ -69,8 +69,8 @@ public abstract class ProjectElement extends Entity { title = null; // Initialized by subclasses credate = null; // Initialized by subclasses lasdate = null; // Initialized by subclasses - docums = new LinkedHashSet(); - contex = new Vector(); +//RKV docums = new LinkedHashSet(); +//RKV contex = new Vector(); folders = null; } diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml index 827b912..c4f261e 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.hbm.xml @@ -10,12 +10,6 @@ - - - diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java index f473093..b2e154b 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java @@ -44,7 +44,7 @@ public class Scenario extends ProjectElement { /** * The persistent set of scenario knowledge elements. */ - private Set kelms; + private Set kelms = new HashSet(); // Transient fields /** @@ -178,7 +178,6 @@ public class Scenario extends ProjectElement { known = null; knowl = null; // Initialized when getting all Knowledge Elements ucase = null; - kelms = new HashSet(); manager = sprop.manager; // RKV: The business logic is moved to business services: if (!owner.isStaffedBy(manager)) throw new diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Study.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Study.java index 1fd88f4..3af40f5 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Study.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Study.java @@ -52,7 +52,7 @@ public class Study extends ProjectElement { /** * Persistent list of study scenarii. */ - private List scenarii; + private List scenarii = new LinkedList(); private String version; /** * Persistent history property. It is a number of studies versioning this one, if any. @@ -242,7 +242,7 @@ public class Study extends ProjectElement { manager = sprop.manager; docount = 0; history = 0; - scenarii = new LinkedList(); +//RKV scenarii = new LinkedList(); visibility = Visibility.PRIVATE; state = ProgressState.inWORK; diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Timestamp.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Timestamp.hbm.xml index 8a8f537..e162fde 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Timestamp.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Timestamp.hbm.xml @@ -15,16 +15,6 @@ - - - diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/ValidationCycle.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ValidationCycle.hbm.xml index 0a60a67..29793e6 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/ValidationCycle.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ValidationCycle.hbm.xml @@ -10,12 +10,6 @@ - - - diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java index bfed9c5..415ec25 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java @@ -152,4 +152,9 @@ public interface GenericDAO { * @return merged persistent object */ public T merge(T transientObject); + + /** + * Synchronize the session data with the database. + */ + public void flush(); } diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java index 88420ad..55ed8bb 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAOImpl.java @@ -214,6 +214,13 @@ public abstract class GenericDAOImpl extends return (T) getSession().merge(transientObject); } + /** + * Synchronize the session data with the database. + */ + public void flush() { + getSession().flush(); + } + /** * Get persistent object type. * diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java index 325bfd1..f7e811c 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java @@ -34,6 +34,7 @@ import org.splat.dal.bo.som.Document.Properties; import org.splat.dal.dao.som.DocumentDAO; import org.splat.dal.dao.som.DocumentTypeDAO; import org.splat.dal.dao.som.FileDAO; +import org.splat.dal.dao.som.StudyDAO; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MissedPropertyException; import org.splat.kernel.NotApplicableException; @@ -78,6 +79,10 @@ public class DocumentServiceImpl implements DocumentService { * Injected file DAO. */ private FileDAO _fileDAO; + /** + * Injected study DAO. + */ + private StudyDAO _studyDAO; /** * {@inheritDoc} @@ -114,6 +119,9 @@ public class DocumentServiceImpl implements DocumentService { else owner = ((Scenario) dprop.getOwner()).getOwnerStudy(); + // Synchronize the object with the current Hibernate session. + owner = getStudyDAO().get(owner.getIndex()); + SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); String year = tostring.format(owner.getDate()); String filename = generateEncodedName(aDoc, owner); @@ -449,7 +457,7 @@ public class DocumentServiceImpl implements DocumentService { public void release(Document aDoc) { aDoc.setCountag(aDoc.getCountag() - 1); if (aDoc.isSaved()) { - getDocumentDAO().update(aDoc); + getDocumentDAO().merge(aDoc); } } @@ -527,7 +535,7 @@ public class DocumentServiceImpl implements DocumentService { // Update this document and the previous version, if exit if (previous != null) { previous.setHistory(previous.getHistory() + 1); - getDocumentDAO().update(previous); + getDocumentDAO().merge(previous); } aDoc.setProgressState(state); getDocumentDAO().update(aDoc); @@ -702,4 +710,20 @@ public class DocumentServiceImpl implements DocumentService { _fileDAO = fileDAO; } + /** + * Get the studyDAO. + * @return the studyDAO + */ + public StudyDAO getStudyDAO() { + return _studyDAO; + } + + /** + * Set the studyDAO. + * @param studyDAO the studyDAO to set + */ + public void setStudyDAO(StudyDAO studyDAO) { + _studyDAO = studyDAO; + } + } diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java index 192dc66..2a3051c 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationService.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationService.java @@ -10,8 +10,11 @@ package org.splat.service; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Date; +import java.util.List; +import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.ConvertsRelation; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.ProgressState; @@ -20,6 +23,9 @@ import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.Study; import org.splat.dal.bo.som.Timestamp; import org.splat.kernel.InvalidPropertyException; +import org.splat.kernel.MismatchException; +import org.splat.kernel.MissedPropertyException; +import org.splat.kernel.MultiplyDefinedException; import org.splat.kernel.NotApplicableException; import org.splat.som.DocumentRights; import org.splat.som.Revision; @@ -43,6 +49,13 @@ public interface PublicationService { */ public Publication copy(Publication aPublication, ProjectElement publisher); + public void versionDocument(Step step, User user, String filename, + long docIndex, String docver, String summary, ProgressState state, + Date date, String[] docuses, long[] docusedby/*, List steps*/) + throws MissedPropertyException, InvalidPropertyException, + MultiplyDefinedException, IOException, MismatchException, + NotApplicableException, InterruptedException; + /** * Returns the study Step into which the document version referenced by this publication has been published. * @@ -54,10 +67,9 @@ public interface PublicationService { /** * Promotes the document referenced by this publication from In-Check to Approved state, if not out-dated, and attaches the - * corresponding time-stamp to the document.
- * If the promoted document is the final result of the owner study, the study is itself is promoted as well.
- *
- * Limitation: the way this promotion is propagated to the study supposes that the study has only ONE final result document. + * corresponding time-stamp to the document.
If the promoted document is the final result of the owner study, the study is itself + * is promoted as well.

Limitation: the way this promotion is propagated to the study supposes that the study has only ONE + * final result document. * * @param aPublication * the document publication @@ -72,11 +84,10 @@ public interface PublicationService { public Timestamp approve(Publication aPublication, Date adate); /** - * Demotes the document referenced by this publication to In-Work state, and removes the Promoter of the document, if exist.
- * The In-Draft state is skipped (direct demotion to In-Work) if the validation cycle of the document does not include the review step.
- * If the demoted document is the final result of the owner study, the study is itself is demoted as well.
- *
- * Limitation: the way this demotion is propagated to the study supposes that the study has only ONE final result document. + * Demotes the document referenced by this publication to In-Work state, and removes the Promoter of the document, if exist.
The + * In-Draft state is skipped (direct demotion to In-Work) if the validation cycle of the document does not include the review step.
+ * If the demoted document is the final result of the owner study, the study is itself is demoted as well.

Limitation: the + * way this demotion is propagated to the study supposes that the study has only ONE final result document. * * @param aPublication * the document publication @@ -89,9 +100,7 @@ public interface PublicationService { /** * Undo the review operation by demoting the document referenced by this publication from In-Check to In-Draft state and removing the - * Reviewer.
- * If the demoted document is the final result of the owner study, the study is itself is demoted as well.
- *
+ * Reviewer.
If the demoted document is the final result of the owner study, the study is itself is demoted as well.

* Limitation: the way this demotion is propagated to the study supposes that the study has only ONE final result document. * * @param aPublication @@ -106,13 +115,10 @@ public interface PublicationService { /** * Promotes the document referenced by this publication from In-Work to In-Draft or In-Check state, if not out-dated, and attaches the - * corresponding time-stamp to the document.
- * The In-Draft state is skipped (direct promotion to In-Check) if the validation cycle of the document does not include the review - * step.
- * Also, if the promoted document is the final result of the owner study, the study is itself promoted as well.
- * This operation can be undo-ed by demote().
- *
- * Limitation: the way this promotion is propagated to the study supposes that the study has only ONE final result document. + * corresponding time-stamp to the document.
The In-Draft state is skipped (direct promotion to In-Check) if the validation cycle + * of the document does not include the review step.
Also, if the promoted document is the final result of the owner study, the + * study is itself promoted as well.
This operation can be undo-ed by demote().

Limitation: the way this promotion is + * propagated to the study supposes that the study has only ONE final result document. * * @param aPublication * the document publication @@ -128,11 +134,9 @@ public interface PublicationService { /** * Promotes the document referenced by this publication from In-Draft to In-Check state, if not out-dated, and attaches the - * corresponding time-stamp to the document.
- * If the promoted document is the final result of the owner study, the study is itself is promoted as well.
- * This operation can be undo-ed by invalidate().
- *
- * Limitation: the way this promotion is propagated to the study supposes that the study has only ONE final result document. + * corresponding time-stamp to the document.
If the promoted document is the final result of the owner study, the study is itself + * is promoted as well.
This operation can be undo-ed by invalidate().

Limitation: the way this promotion is + * propagated to the study supposes that the study has only ONE final result document. * * @param aPublication * the document publication @@ -165,11 +169,11 @@ public interface PublicationService { throws FileNotFoundException, NotApplicableException; /** - * Publishes the document referenced by this publication into the owner Project Element under the given revision number.
- * The state of the referenced document is supposed being automatically set according to the given revision number, but, due to the - * versioning scheme, as it is not possible to differentiate In-Work and In-Draft states, this function has been deprecated (it is - * currently used only for the need of integration of Microsoft Office which anyway has to be redesigned).
- * Note: in the context of branch versioning, the given revision may be modified by an update of the branch name. + * Publishes the document referenced by this publication into the owner Project Element under the given revision number.
The state + * of the referenced document is supposed being automatically set according to the given revision number, but, due to the versioning + * scheme, as it is not possible to differentiate In-Work and In-Draft states, this function has been deprecated (it is currently used + * only for the need of integration of Microsoft Office which anyway has to be redesigned).
Note: in the context of branch + * versioning, the given revision may be modified by an update of the branch name. * * @param aPublication * the document publication diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index e5a6634..b77bf91 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -9,12 +9,16 @@ package org.splat.service; +import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import org.apache.log4j.Logger; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.ConvertsRelation; import org.splat.dal.bo.som.Document; @@ -29,13 +33,16 @@ import org.splat.dal.bo.som.Timestamp; import org.splat.dal.bo.som.UsedByRelation; import org.splat.dal.bo.som.ValidationCycle; import org.splat.dal.bo.som.ValidationStep; -import org.splat.dal.dao.som.Database; import org.splat.dal.dao.som.ProjectElementDAO; import org.splat.dal.dao.som.PublicationDAO; import org.splat.kernel.InvalidPropertyException; +import org.splat.kernel.MismatchException; +import org.splat.kernel.MissedPropertyException; +import org.splat.kernel.MultiplyDefinedException; import org.splat.kernel.NotApplicableException; import org.splat.manox.Reader; import org.splat.manox.Toolbox; +import org.splat.service.technical.RepositoryService; import org.splat.som.DocumentRights; import org.splat.som.Revision; import org.splat.som.Step; @@ -48,6 +55,12 @@ import org.springframework.transaction.annotation.Transactional; */ public class PublicationServiceImpl implements PublicationService { + /** + * Logger for this class. + */ + protected final static Logger logger = Logger + .getLogger(PublicationServiceImpl.class); + /** * Injected study service. */ @@ -76,6 +89,10 @@ public class PublicationServiceImpl implements PublicationService { * Injected project element DAO. */ private ProjectElementDAO _projectElementDAO; + /** + * Injected repository service. + */ + private RepositoryService _repositoryService; /** * {@inheritDoc} @@ -94,6 +111,95 @@ public class PublicationServiceImpl implements PublicationService { return copy; } + @Transactional + public void versionDocument(Step step, User user, String filename, + long docIndex, String docver, String summary, ProgressState state, + Date date, String[] docuses, long[] docusedby/*, List steps*/) + throws MissedPropertyException, InvalidPropertyException, + MultiplyDefinedException, IOException, MismatchException, + NotApplicableException, InterruptedException { + File updir = getRepositoryService().getDownloadDirectory(user); + File upfile = new File(updir.getPath() + "/" + filename); + + // Versioning of the document + Document.Properties dprop = new Document.Properties(); + Publication current = step.getDocument(docIndex); + Publication next; + + if (docver.length() == 0) { // Importation of a foreign document + next = getStepService().versionDocument(step, current, + dprop.setAuthor(user).setDescription(summary)); + updir = next.getSourceFile().asFile(); + if (logger.isInfoEnabled()) + logger.info("Moving \"" + upfile.getName() + "\" to \"" + + updir.getPath() + "\"."); + upfile.renameTo(updir); + try { + saveAs(next, state); // May throw FileNotFound if rename was not done + } catch (FileNotFoundException saverror) { + Thread.sleep(1000); + logger.info("Waiting for the file."); + upfile.renameTo(updir); + saveAs(next, state); // Forget it if throw again FileNotFound + } + } else { + if (date != null) { + dprop.setDate(date); + } + next = getStepService().versionDocument(step, current, + dprop.setAuthor(user).setDescription(summary)); + updir = next.getSourceFile().asFile(); + if (logger.isInfoEnabled()) + logger.info("Moving \"" + upfile.getName() + "\" to \"" + + updir.getPath() + "\"."); + upfile.renameTo(updir); + try { + saveAs(next, new Revision(docver)); + } catch (FileNotFoundException saverror) { + Thread.sleep(1000); + logger.info("Waiting for the file."); + upfile.renameTo(updir); + saveAs(next, state); + } + } + // TODO: Remove current document details from the contents of open study + + // Creation of uses relations + if (docuses != null) { + for (int i = 0; i < docuses.length; i++) { + Long index = Long.valueOf(docuses[i].trim()); + Publication used = getPublicationDAO().get(index);//RKV: getPublication(index, steps); + next.addDependency(used); + } + } + // Outdating impacted document + HashSet compatible = new HashSet(); + if (docusedby != null) { + for (int i = 0; i < docusedby.length; i++) { + compatible.add(docusedby[i]); + } + } + List relist = current.getRelations(UsedByRelation.class); + for (Iterator i = relist.iterator(); i.hasNext();) { + Publication using = i.next(); + if (!compatible.contains(using.getIndex())) + outdate(using); + } + + } + +/* protected Publication getPublication(int index, List steps) { + for (Iterator i = steps.iterator(); i.hasNext();) { + List published = i.next().getAllDocuments(); + for (Iterator j = published.iterator(); j.hasNext();) { + Publication found = j.next(); // In a given study step, + if (found.value().getIndex() == index) + return found; // there is only one publication of a given document + } + } + return null; + } +*/ /** * {@inheritDoc} * @@ -110,8 +216,8 @@ public class PublicationServiceImpl implements PublicationService { ValidationCycle cycle = getStudyService().getValidationCycleOf(owner, type); User approver = cycle.getActor(ValidationStep.APPROVAL); - Timestamp stamp = new Timestamp(ValidationStep.APPROVAL, - aPublication.value(), approver, adate); + Timestamp stamp = new Timestamp(ValidationStep.APPROVAL, aPublication + .value(), approver, adate); if (!getDocumentService().promote(aPublication.value(), stamp)) return null; if (getDocumentService().isStudyResult(type) @@ -221,8 +327,8 @@ public class PublicationServiceImpl implements PublicationService { ValidationCycle cycle = getStudyService().getValidationCycleOf(owner, type); User reviewer = cycle.getActor(ValidationStep.REVIEW); - Timestamp stamp = new Timestamp(ValidationStep.REVIEW, - aPublication.value(), reviewer, rdate); + Timestamp stamp = new Timestamp(ValidationStep.REVIEW, aPublication + .value(), reviewer, rdate); if (!getDocumentService().promote(aPublication.value(), stamp)) return null; if (getDocumentService().isStudyResult(type) @@ -307,15 +413,17 @@ 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 + } } getStepService().add(step, aPublication); // Increments the configuration tag count of document // Import the document properties and update of the study forwardProperties(aPublication, aPublication.value().getSourceFile() .asFile(), step); - getProjectElementDAO().update(aPublication.getOwner()); + getProjectElementDAO().merge(aPublication.getOwner()); } /** @@ -615,4 +723,23 @@ public class PublicationServiceImpl implements PublicationService { public void setProjectElementDAO(ProjectElementDAO projectElementDAO) { _projectElementDAO = projectElementDAO; } + + /** + * Get the repositoryService. + * + * @return the repositoryService + */ + public RepositoryService getRepositoryService() { + return _repositoryService; + } + + /** + * Set the repositoryService. + * + * @param repositoryService + * the repositoryService to set + */ + public void setRepositoryService(RepositoryService repositoryService) { + _repositoryService = repositoryService; + } } diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index d40b87a..5472c81 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -32,6 +32,7 @@ import org.splat.dal.dao.som.DocumentDAO; import org.splat.dal.dao.som.FileDAO; import org.splat.dal.dao.som.ProjectElementDAO; import org.splat.dal.dao.som.SimulationContextDAO; +import org.splat.dal.dao.som.VersionsRelationDAO; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MismatchException; import org.splat.kernel.MissedPropertyException; @@ -87,6 +88,10 @@ public class StepServiceImpl implements StepService { * Injected project element DAO. */ private ProjectElementDAO _projectElementDAO; + /** + * Injected versions relation DAO. + */ + private VersionsRelationDAO _versionsRelationDAO; /** * {@inheritDoc} @@ -358,11 +363,11 @@ public class StepServiceImpl implements StepService { getDocumentDAO().create(newdoc); // Versioning - if (summary == null) - newdoc.addRelation(new VersionsRelation(newdoc, previous)); - else - newdoc.addRelation(new VersionsRelation(newdoc, previous, summary)); - + VersionsRelation aRel; + aRel = new VersionsRelation(newdoc, previous, summary); +// getVersionsRelationDAO().create(aRel); + newdoc.addRelation(aRel); + // Update of usedby relations, if exist List relist = previous.getRelations(UsedByRelation.class); Study scope = aStep.getOwnerStudy(); @@ -615,4 +620,20 @@ public class StepServiceImpl implements StepService { public void setDocumentTypeService(DocumentTypeService documentTypeService) { _documentTypeService = documentTypeService; } + + /** + * Get the versionsRelationDAO. + * @return the versionsRelationDAO + */ + public VersionsRelationDAO getVersionsRelationDAO() { + return _versionsRelationDAO; + } + + /** + * Set the versionsRelationDAO. + * @param versionsRelationDAO the versionsRelationDAO to set + */ + public void setVersionsRelationDAO(VersionsRelationDAO versionsRelationDAO) { + _versionsRelationDAO = versionsRelationDAO; + } } diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index 2bb17ee..f4389b2 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -40,6 +40,7 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> + + - + + usedby = null; - private String docusedby = null; + private long[] docusedby = null; private String summary = null; // Summary of changes in the new version private String docver = ""; // Version number extracted from the imported file, if exist private String date = ""; // Date extracted from the imported file, if exist @@ -166,14 +167,28 @@ public class VersionDocumentAction extends UploadBaseNextAction { if (action == ToDo.cancel) return "cancel"; - Session connex = Database.getCurSession(); - Transaction transax = connex.beginTransaction(); try { // Getting user inputs mystudy = getOpenStudy(); User user = getConnectedUser(); Step step = mystudy.getSelectedStep(); - File updir = getRepositoryService().getDownloadDirectory(user); +// List steps = mystudy.getInvolvedSteps(); + Date aDate = null; + if (date.length() > 0) { + ResourceBundle locale = ResourceBundle.getBundle("som", + ApplicationSettings.getCurrentLocale()); + SimpleDateFormat get = new SimpleDateFormat( + locale.getString("date.format")); + aDate = get.parse(date); + } + + String[] listDocuses = null; + if (docuses != null) { + listDocuses = docuses.split(","); + } + getPublicationService().versionDocument(step, user, filename, Integer.valueOf(index), docver, + summary, state, aDate, listDocuses, docusedby/*, steps*/); + /* File updir = getRepositoryService().getDownloadDirectory(user); File upfile = new File(updir.getPath() + "/" + filename); // Versioning of the document @@ -246,11 +261,11 @@ public class VersionDocumentAction extends UploadBaseNextAction { if (!compatible.contains(using.getIndex())) getPublicationService().outdate(using); } +*/ // Update of the open study mystudy.setSelection(mystudy.getSelection()); // Rebuilds the presentation // TODO: Look is an optimization is possible (for example by updating the presentation of versioned document) - transax.commit(); return SUCCESS; } catch (FileNotFoundException error) { logger.error("Reason:", error); @@ -259,14 +274,6 @@ public class VersionDocumentAction extends UploadBaseNextAction { logger.error("Reason:", error); setErrorCode("internal"); } - if (transax != null && transax.isActive()) { - // Second try-catch as the rollback could fail as well - try { - transax.rollback(); - } catch (HibernateException backerror) { - logger.debug("Error rolling back transaction", backerror); - } - } return ERROR; } @@ -320,7 +327,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { this.index = index; } - public void setUsedBy(String list) { + public void setUsedBy(long[] list) { // ----------------------------------- this.docusedby = list; } -- 2.30.2