From: rkv Date: Tue, 26 Mar 2013 12:59:07 +0000 (+0000) Subject: Fix of checkin and removeDocument. X-Git-Tag: Root_Delivery2_2013_04_22~80 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=65d011aed9130a3f3dc200db63b1b45f54e3614f;p=tools%2Fsiman.git Fix of checkin and removeDocument. --- 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 d915972..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 @@ -13,7 +13,7 @@ - + diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AbstractGenericDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AbstractGenericDAOImpl.java index 296df73..778ac11 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AbstractGenericDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AbstractGenericDAOImpl.java @@ -262,24 +262,36 @@ public abstract class AbstractGenericDAOImpl } /** - * Save changes made to a persistent object. + * Update the persistent instance with the identifier of the given detached
+ * instance. If there is a persistent instance with the same identifier, an
+ * exception is thrown. This operation cascades to associated instances if
+ * the association is mapped with cascade="save-update". * - * @param transientObject + * @param detachedObject * transient instance of the object to update + * @see Session#update(Object) */ - public void update(final T transientObject) { - getSession().update(transientObject); + public void update(final T detachedObject) { + getSession().update(detachedObject); } /** - * Refresh a persistent object. + * Re-read the state of the given instance from the underlying database.
+ * It is inadvisable to use this to implement long-running sessions that
+ * span many business tasks. This method is, however, useful in certain
+ * special circumstances. For example + *
    + *
  • where a database trigger alters the object state upon insert or update
  • + *
  • after executing direct SQL (eg. a mass update) in the same session
  • + *
  • after inserting a Blob or Clob
  • + *
* - * @param transientObject - * transient instance of the object to refresh + * @param anObject + * a persistent or detached instance to refresh * @see Session#refresh(Object) */ - public void refresh(final T transientObject) { - getSession().refresh(transientObject); + public void refresh(final T anObject) { + getSession().refresh(anObject); } /** 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 09ea36e..477ab48 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 @@ -61,12 +61,16 @@ public interface GenericDAO { T get(PK id); /** - * Save changes made to a persistent object. + * Update the persistent instance with the identifier of the given detached
+ * instance. If there is a persistent instance with the same identifier, an
+ * exception is thrown. This operation cascades to associated instances if
+ * the association is mapped with cascade="save-update". * - * @param transientObject + * @param detachedObject * transient instance of the object to update + * @see Session#update(Object) */ - void update(T transientObject); + public void update(final T detachedObject); /** * Refresh a persistent object. diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 9d933d2..4884096 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -469,7 +469,7 @@ public class StepServiceImpl implements StepService { public boolean remove(final Step aStep, final Publication oldoc) { aStep.getDocuments().remove(oldoc); // Updates this step aStep.getOwner().remove(oldoc); // remove from the parent project element - getProjectElementDAO().merge(aStep.getOwner()); + getProjectElementDAO().merge(aStep.getOwner().getOwnerStudy()); 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; @@ -532,9 +532,10 @@ public class StepServiceImpl implements StepService { // The corresponding physical file is not removed from the vault getDocumentDAO().delete(getDocumentDAO().merge(torem.value())); // Delete document's files - for (File file : files) { - getFileDAO().delete(getFileDAO().merge(file)); // The corresponding physical file is not removed from the vault - } + //TODO: delete files from file system +// for (File file : files) { +// getFileDAO().delete(getFileDAO().merge(file)); // The corresponding physical file is not removed from the vault +// } } } return res; diff --git a/Workspace/Siman-Common/src/test/splat/service/TestStepService.java b/Workspace/Siman-Common/src/test/splat/service/TestStepService.java index 0003b00..c81589f 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestStepService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestStepService.java @@ -44,6 +44,7 @@ import org.splat.kernel.MissedPropertyException; import org.splat.kernel.MultiplyDefinedException; import org.splat.log.AppLogger; import org.splat.service.DocumentTypeService; +import org.splat.service.ProjectElementService; import org.splat.service.PublicationService; import org.splat.service.StepService; import org.splat.service.StudyService; @@ -114,7 +115,7 @@ public class TestStepService extends BaseTest { @Autowired @Qualifier("projectSettings") private transient ProjectSettingsService _projectSettings; - + /** * The injected by Spring StepCommentAttributeDAO. */ @@ -129,7 +130,6 @@ public class TestStepService extends BaseTest { @Qualifier("userDAO") private transient UserDAO _userDAO; - /** * The injected by Spring StudyDAO. */ @@ -144,6 +144,13 @@ public class TestStepService extends BaseTest { @Qualifier("documentTypeService") private transient DocumentTypeService _documentTypeService; + /** + * The ProjectElementService. Later injected by Spring. + */ + @Autowired + @Qualifier("projectElementService") + private transient ProjectElementService _projectElementService; + /** * Test removeDocument method.
* Description :
@@ -266,6 +273,8 @@ public class TestStepService extends BaseTest { .getRelations(UsedByRelation.class)) { LOG.debug(rel.value().getTitle()); } + ht.flush(); + ht.clear(); try { ok = _stepService.removeDocument(aScStep, docId); Assert.fail("DocumentIsUsedException must be thrown."); @@ -304,18 +313,23 @@ public class TestStepService extends BaseTest { // //////////////////////////////////////////////////////// // Call removeDocument method for each document // starting from the last activity. + Study aStudy = _studyService.selectStudy(aScen.getOwnerStudy() + .getIndex()); + aScen = aStudy.getScenarii()[0]; + Map stSteps = _projectElementService.getStepsMap(aStudy); + Map scSteps = _projectElementService.getStepsMap(aScen); + org.splat.som.Step aScStep; for (int i = _projectSettings.getAllSteps().size(); i > 0; i--) { LOG.debug("Remove documents from the step " + i); step = _projectSettings.getStep(i); if (step.appliesTo(Study.class)) { - projElem = _studyService.selectStudy(aScen.getOwnerStudy() - .getIndex()); + projElem = aStudy; + aScStep = stSteps.get(step.getNumber()); } else { projElem = aScen; + aScStep = scSteps.get(step.getNumber()); } - org.splat.som.Step aScStep = new org.splat.som.Step(step, projElem); - if (aScStep.getDocuments().size() > 0) { docId = aScStep.getDocuments().get(0).value().getIndex(); LOG.debug("Remove document#" + docId + " " @@ -352,17 +366,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.evict(aScStep.getDocuments().get(0).value() - .getFile()); - LOG.debug("Load file#" + aScStep.getDocuments().get(0).value() - .getRelations(ConvertsRelation.class).get(0).getTo().getIndex()); - + ht.flush(); 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()); - + 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++; @@ -661,71 +675,74 @@ public class TestStepService extends BaseTest { return pub; } - + /** * Test of addition of a new step comment. - * - * @throws BusinessException if there is something wrong likely unrelated to the tested method + * + * @throws BusinessException + * if there is something wrong likely unrelated to the tested method */ @Test - public void testAddStepComment() throws BusinessException{ + public void testAddStepComment() throws BusinessException { User goodUser = TestEntitiesGenerator.getTestUser("goodUser"); _userDAO.create(goodUser); Study goodStudy = TestEntitiesGenerator.getTestStudy(goodUser); _studyDAO.create(goodStudy); getHibernateTemplate().flush(); - StepCommentDTO goodStepCommentDTO = createStepCommentDTO(goodUser, goodStudy); + StepCommentDTO goodStepCommentDTO = createStepCommentDTO(goodUser, + goodStudy); - //valid DTO, existing params + // valid DTO, existing params _stepService.addStepComment(goodStepCommentDTO); Long id = goodStepCommentDTO.getId(); - Assert.assertNotNull(id, "Add method returns null instead of a new id."); + Assert + .assertNotNull(id, + "Add method returns null instead of a new id."); Assert.assertTrue(id > 0, "The new id is not a positive number."); - StepCommentDTO retrievedComment = getDTOfromStepCommentAttribute( - _stepCommentAttributeDAO.get(id)); - Assert.assertTrue(compareStepCommentDTO(goodStepCommentDTO, retrievedComment), + StepCommentDTO retrievedComment = getDTOfromStepCommentAttribute(_stepCommentAttributeDAO + .get(id)); + Assert.assertTrue(compareStepCommentDTO(goodStepCommentDTO, + retrievedComment), "The comment created in database has wrong data"); - //valid DTO, non-existing user + // valid DTO, non-existing user { - //get a non-existing id + // get a non-existing id User badUser = TestEntitiesGenerator.getTestUser("badUser"); _userDAO.create(badUser); - getHibernateTemplate().evict(badUser);//so createStepCommentDTO will invoke an - //actual query to the base, not cache, in order to check if the user already exists + getHibernateTemplate().evict(badUser);// so createStepCommentDTO will invoke an + // actual query to the base, not cache, in order to check if the user already exists StepCommentDTO aBadDTO = createStepCommentDTO(badUser, goodStudy); - try{ + try { _stepService.addStepComment(aBadDTO); getHibernateTemplate().flush(); Assert.fail("Creation with non-existing user must be failed."); - } - catch(InvalidParameterException e){ + } catch (InvalidParameterException e) { LOG.debug("Expected exception is thrown: " - + e.getClass().getSimpleName() + ": " + e.getMessage()); + + e.getClass().getSimpleName() + ": " + e.getMessage()); } } - //valid DTO, non-existing project element + // valid DTO, non-existing project element { Study badStudy = TestEntitiesGenerator.getTestStudy(goodUser); _studyDAO.create(badStudy); - getHibernateTemplate().evict(badStudy);//so createStepCommentDTO will invoke an - //actual query to the base, not cache in order to check if the study already exists + getHibernateTemplate().evict(badStudy);// so createStepCommentDTO will invoke an + // actual query to the base, not cache in order to check if the study already exists StepCommentDTO aBadDTO = createStepCommentDTO(goodUser, badStudy); - try{ + try { _stepService.addStepComment(aBadDTO); Assert.fail("Creation with non-existing user must be failed."); - } - catch(InvalidParameterException e){ + } catch (InvalidParameterException e) { LOG.debug("Expected exception is thrown: " - + e.getClass().getSimpleName() + ": " + e.getMessage()); + + e.getClass().getSimpleName() + ": " + e.getMessage()); } } - //not valid DTO (id filled in) + // not valid DTO (id filled in) { StepCommentDTO aBadDTO = createStepCommentDTO(goodUser, goodStudy); aBadDTO.setId(goodStepCommentDTO.getId()); @@ -742,8 +759,9 @@ public class TestStepService extends BaseTest { /** * Test of retrieval of all comments corresponding to a step. - * - * @throws BusinessException if there is something wrong likely unrelated to the tested method + * + * @throws BusinessException + * if there is something wrong likely unrelated to the tested method */ @Test public void testGetStepComments() throws BusinessException { @@ -751,83 +769,96 @@ public class TestStepService extends BaseTest { User user = TestEntitiesGenerator.getTestUser("goodUser"); _userDAO.create(user); Study study = TestEntitiesGenerator.getTestStudy(user); - - //Before we create the study in the database: - org.splat.som.Step step = new org.splat.som.Step(_projectSettings.getStep(1), study); - try{ + + // Before we create the study in the database: + org.splat.som.Step step = new org.splat.som.Step(_projectSettings + .getStep(1), study); + try { _stepService.getStepComments(step); - Assert.fail("Retrieval by step with non-existing owner project element must be failed."); - } - catch(InvalidParameterException e){ + Assert + .fail("Retrieval by step with non-existing owner project element must be failed."); + } catch (InvalidParameterException e) { LOG.debug("Expected exception is thrown: " - + e.getClass().getSimpleName() + ": " + e.getMessage()); + + e.getClass().getSimpleName() + ": " + e.getMessage()); } - + _studyDAO.create(study); - + StepCommentAttribute matchingStepComment = new StepCommentAttribute( - study, "matching test comment", new Date(), step.getNumber(), user, "matching test comment title"); + study, "matching test comment", new Date(), step.getNumber(), + user, "matching test comment title"); StepCommentAttribute notMatchingStepComment = new StepCommentAttribute( - study, "not matching test comment", new Date(), 2, user, "not matching test comment title"); + study, "not matching test comment", new Date(), 2, user, + "not matching test comment title"); _stepCommentAttributeDAO.create(matchingStepComment); _stepCommentAttributeDAO.create(notMatchingStepComment); getHibernateTemplate().flush(); - + List stepComments = _stepService.getStepComments(step); - Assert.assertTrue(stepComments.size() == 1, "Wrong number of retrieved comments"); + Assert.assertTrue(stepComments.size() == 1, + "Wrong number of retrieved comments"); StepCommentDTO stepCommentDTO = stepComments.get(0); - Assert.assertTrue(stepCommentDTO.getId().equals(matchingStepComment.getRid()) - && stepCommentDTO.getDate().equals(matchingStepComment.getDate()) - && stepCommentDTO.getText().equals(matchingStepComment.getValue()) - && stepCommentDTO.getUser().getIndex() == matchingStepComment.getUser().getRid() - && stepCommentDTO.getTitle().equals(matchingStepComment.getTitle()), - "some of the needed fields of the retrieved comment doesn't match with original."); + Assert + .assertTrue( + stepCommentDTO.getId().equals( + matchingStepComment.getRid()) + && stepCommentDTO.getDate().equals( + matchingStepComment.getDate()) + && stepCommentDTO.getText().equals( + matchingStepComment.getValue()) + && stepCommentDTO.getUser().getIndex() == matchingStepComment + .getUser().getRid() + && stepCommentDTO.getTitle().equals( + matchingStepComment.getTitle()), + "some of the needed fields of the retrieved comment doesn't match with original."); } - + /** * Test of retrieval of all comments corresponding to a step. - * - * @throws BusinessException if there is something wrong likely unrelated to the tested method + * + * @throws BusinessException + * if there is something wrong likely unrelated to the tested method */ @Test public void testEditStepComments() throws BusinessException { LOG.debug(">>>>> BEGIN testEditStepComments()"); startNestedTransaction(); - + User goodUser = TestEntitiesGenerator.getTestUser("goodUser"); _userDAO.create(goodUser); Study goodStudy = TestEntitiesGenerator.getTestStudy(goodUser); _studyDAO.create(goodStudy); getHibernateTemplate().flush(); - org.splat.som.Step step = new org.splat.som.Step(_projectSettings.getStep(1), goodStudy); - - StepCommentAttribute comment = new StepCommentAttribute(goodStudy, "commentValue", - new Date(), Integer.valueOf(step.getNumber()), goodUser, "commentTitle"); + org.splat.som.Step step = new org.splat.som.Step(_projectSettings + .getStep(1), goodStudy); + + StepCommentAttribute comment = new StepCommentAttribute(goodStudy, + "commentValue", new Date(), Integer.valueOf(step.getNumber()), + goodUser, "commentTitle"); _stepCommentAttributeDAO.saveOrUpdate(comment); getHibernateTemplate().flush(); - - //non-existing id - StepCommentAttribute tmpComment = new StepCommentAttribute(goodStudy,"tmpCommentValue", - new Date(), Integer.valueOf(step.getNumber()), goodUser, "tmpCommentTitle"); + + // non-existing id + StepCommentAttribute tmpComment = new StepCommentAttribute(goodStudy, + "tmpCommentValue", new Date(), Integer + .valueOf(step.getNumber()), goodUser, "tmpCommentTitle"); _stepCommentAttributeDAO.create(tmpComment); long nonExistingId = tmpComment.getIndex(); _stepCommentAttributeDAO.delete(tmpComment); - //getHibernateTemplate().evict(goodUser); - + // getHibernateTemplate().evict(goodUser); - try{ + try { _stepService.editStepComment(nonExistingId, "newValue", "newTitle"); getHibernateTemplate().flush(); Assert.fail("Creation with non-existing user must be failed."); - } - catch(InvalidParameterException e){ + } catch (InvalidParameterException e) { LOG.debug("Expected exception is thrown: " - + e.getClass().getSimpleName() + ": " + e.getMessage()); + + e.getClass().getSimpleName() + ": " + e.getMessage()); } - //different configurations with valid comment id + // different configurations with valid comment id testEdit(comment, "newValue", null); testEdit(comment, null, "newTitle"); testEdit(comment, "veryNewValue", "veryNewTitle"); @@ -835,84 +866,95 @@ public class TestStepService extends BaseTest { rollbackNestedTransaction(); LOG.debug(">>>>> END testEditStepComments()"); } - + /** * Test of comment editing. - * @param comment the comment - * @param value the value - * @param title the title - * @throws InvalidParameterException if there is something wrong likely unrelated to the tested method + * + * @param comment + * the comment + * @param value + * the value + * @param title + * the title + * @throws InvalidParameterException + * if there is something wrong likely unrelated to the tested method */ - private void testEdit(final StepCommentAttribute comment, final String value, final String title) + private void testEdit(final StepCommentAttribute comment, + final String value, final String title) throws InvalidParameterException { String oldValue = comment.getValue(); String oldTitle = comment.getTitle(); - + _stepService.editStepComment(comment.getIndex(), value, title); _stepCommentAttributeDAO.flush(); getHibernateTemplate().evict(comment); _stepCommentAttributeDAO.refresh(comment); - if(value == null) { + if (value == null) { Assert.assertEquals(comment.getValue(), oldValue); } else { Assert.assertEquals(comment.getValue(), value); } - if(title == null) { + if (title == null) { Assert.assertEquals(comment.getTitle(), oldTitle); } else { Assert.assertEquals(comment.getTitle(), title); } } - - + /** * Create a transient StepCommentDTO. - * - * @param study must be already persisted into the database - * @param user must be already persisted into the database + * + * @param study + * must be already persisted into the database + * @param user + * must be already persisted into the database * @return a transient StepCommentDTO - * @throws BusinessException if something's wrong + * @throws BusinessException + * if something's wrong */ - private StepCommentDTO createStepCommentDTO(final User user, final Study study) throws BusinessException { + private StepCommentDTO createStepCommentDTO(final User user, + final Study study) throws BusinessException { return new StepCommentDTO(null, "A good comment", study.getRid(), - new Integer(0), new Date(), user.getRid(), user.getName(), "Good comment title"); + new Integer(0), new Date(), user.getRid(), user.getName(), + "Good comment title"); } /** * Create StepCommentDTO with all the fields filled in from StepCommentAttribute. - * @param comment the comment + * + * @param comment + * the comment * @return Step Comment DTO */ - private StepCommentDTO getDTOfromStepCommentAttribute(final StepCommentAttribute comment) { - - StepCommentDTO stepCommentDTO = new StepCommentDTO( - comment.getRid(), - comment.getValue(), - comment.getFrom().getRid(), - comment.getStep(), - comment.getDate(), - comment.getUser().getRid(), - comment.getUser().getName(), - comment.getTitle() - ); + private StepCommentDTO getDTOfromStepCommentAttribute( + final StepCommentAttribute comment) { + + StepCommentDTO stepCommentDTO = new StepCommentDTO(comment.getRid(), + comment.getValue(), comment.getFrom().getRid(), comment + .getStep(), comment.getDate(), comment.getUser() + .getRid(), comment.getUser().getName(), comment + .getTitle()); return stepCommentDTO; } /** * Compare StepCommentDTO. - * @param a the first DTO to compare - * @param b the second DTO to compare + * + * @param a + * the first DTO to compare + * @param b + * the second DTO to compare * @return true if comments are equal */ - private Boolean compareStepCommentDTO(final StepCommentDTO a, final StepCommentDTO b){ - return a.getId().equals(b.getId()) - && a.getId().equals(b.getId()) + private Boolean compareStepCommentDTO(final StepCommentDTO a, + final StepCommentDTO b) { + return a.getId().equals(b.getId()) && a.getId().equals(b.getId()) && a.getDate().equals(b.getDate()) && a.getStep().equals(b.getStep()) && a.getText().equals(b.getText()) && a.getUserId().equals(b.getUserId()) - && a.getProjectElementId().equals(b.getProjectElementId()) + && a.getProjectElementId().equals(b.getProjectElementId()) && a.getTitle().equals(b.getTitle()); } }