From e239e95ec3924d357bcc03d234c73c7d8534461c Mon Sep 17 00:00:00 2001 From: rkv Date: Sat, 29 Dec 2012 11:02:16 +0000 Subject: [PATCH] Fix for removing a document with new attached file: ConvertsRelation was not removed from the set of relations because of hashCode() changing due to persistent id generation. Now UID is used in equals() and hashCode(). 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. --- .../src/org/splat/dal/bo/kernel/Entity.java | 19 + .../org/splat/dal/bo/kernel/IdGenerator.java | 28 ++ .../splat/dal/bo/kernel/Persistent.hbm.xml | 41 +- .../org/splat/dal/bo/kernel/Persistent.java | 88 ++-- .../org/splat/dal/bo/som/Publication.hbm.xml | 2 +- .../splat/service/DocumentServiceImpl.java | 34 +- .../splat/service/PublicationServiceImpl.java | 2 + .../org/splat/service/StepServiceImpl.java | 38 +- .../src/spring/businessServiceContext.xml | 3 +- .../splat/service/TestPublicationService.java | 122 ++++- .../test/splat/service/TestStepService.java | 27 +- .../Siman/WebContent/jap/splat-launcher.jar | Bin 10714 -> 10714 bytes .../WebContent/jap/splat-signedlauncher.jar | Bin 12436 -> 12437 bytes .../org/splat/module/SaveDocumentAction.java | 444 ------------------ .../Siman/src/spring/applicationContext.xml | 11 - Workspace/Siman/src/struts.xml | 34 -- 16 files changed, 319 insertions(+), 574 deletions(-) create mode 100644 Workspace/Siman-Common/src/org/splat/dal/bo/kernel/IdGenerator.java delete mode 100644 Workspace/Siman/src/org/splat/module/SaveDocumentAction.java 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 060f84d..debc3f6 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 @@ -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 index 0000000..2a98386 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/IdGenerator.java @@ -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
+ * in the same way before and after saving in the database, i.e. before and
+ * after persistent id generation. The object UID is used for identification in
+ * equals() and in hashCode(). + * + * @author Roman Kozlov (RKV) + */ +public class IdGenerator { + public static String createId() { + UUID uuid = java.util.UUID.randomUUID(); + return uuid.toString(); + } +} \ No newline at end of file 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 bd34d98..508c1e0 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 @@ -1,25 +1,28 @@ + - Mapping of the primary key common to all Persistent objects. + - + - + - @author Daniel Brunier-Coulin + - @copyright OPEN CASCADE 2012 +--> - - - - persistent_id - 1000 - - - - + + + + persistent_id + 1000 + + + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java index f9f01d6..1f95b0d 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Persistent.java @@ -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.
+ * {@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 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 c5a26d5..a78f1da 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 @@ -16,7 +16,7 @@ - + diff --git a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java index e0558ac..61cda0b 100644 --- a/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/DocumentServiceImpl.java @@ -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; + } + } diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index c0c408d..98b0ef7 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -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, diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 0faf6d8..6a10e4c 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -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 using = new ArrayList(); - List converts = new ArrayList(); + List files = new ArrayList(); 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 } } } diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index e8cbab3..ec8070f 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -39,7 +39,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> - + + diff --git a/Workspace/Siman-Common/src/test/splat/service/TestPublicationService.java b/Workspace/Siman-Common/src/test/splat/service/TestPublicationService.java index ae20269..3d4f134 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestPublicationService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestPublicationService.java @@ -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 dtypes = _documentTypeService - .selectTypesOf(step.getStep()); + List 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.
+ * Description :
+ * Create a study and try to attach a new file to its each document.
+ * Action :
+ * 1. call attach method for each document publication of the study.
+ * Test data :
+ * no input parameters
+ * + * Outcome results:
+ * + *
    + *
  • The new ConvertsRelation and the new File object must be created in the database.
    + *
  • + *
+ *
+ * + * @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 steps = new ArrayList(); + 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. * diff --git a/Workspace/Siman-Common/src/test/splat/service/TestStepService.java b/Workspace/Siman-Common/src/test/splat/service/TestStepService.java index dc3d615..7a83e00 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestStepService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestStepService.java @@ -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 uses = ht .find("from UsesRelation where owner=" + docId); List 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."); diff --git a/Workspace/Siman/WebContent/jap/splat-launcher.jar b/Workspace/Siman/WebContent/jap/splat-launcher.jar index fe41638a56c0218490b740ba26b6902cd83f4352..358d6675f3dbb407c05d346b6f4f188d0a07b549 100644 GIT binary patch delta 254 zcmcZ=d@GnYz?+$civa{Q;^$7})!3bggDA0PgHb9smFU delta 254 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 _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(); - setupDefaultUses(type); // Recursive function - for (Iterator 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(); - setupDefaultUses(next.value().getType()); // Recursive function - for (Iterator 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 uses = type.getDefaultUses(); - - for (Iterator i = uses.iterator(); i.hasNext();) { - DocumentType usetype = i.next(); - List 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 diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index 1225c73..a919527 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -296,15 +296,4 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> scope="prototype"> - - - - - - - - - diff --git a/Workspace/Siman/src/struts.xml b/Workspace/Siman/src/struts.xml index d60b1b9..73adc9a 100644 --- a/Workspace/Siman/src/struts.xml +++ b/Workspace/Siman/src/struts.xml @@ -577,38 +577,4 @@ - - - - /sgeom/index.jsp - - - /sgeom/index.jsp - - - /sgeom/index.jsp - - - - - - - - - /smesh/index.jsp - - - /smesh/index.jsp - - - /smesh/index.jsp - - - \ No newline at end of file -- 2.39.2