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;
@Autowired
@Qualifier("projectSettings")
private transient ProjectSettingsService _projectSettings;
-
+
/**
* The injected by Spring StepCommentAttributeDAO.
*/
@Qualifier("userDAO")
private transient UserDAO _userDAO;
-
/**
* The injected by Spring StudyDAO.
*/
@Qualifier("documentTypeService")
private transient DocumentTypeService _documentTypeService;
+ /**
+ * The ProjectElementService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("projectElementService")
+ private transient ProjectElementService _projectElementService;
+
/**
* Test removeDocument method.<BR>
* <B>Description :</B> <BR>
.getRelations(UsedByRelation.class)) {
LOG.debug(rel.value().getTitle());
}
+ ht.flush();
+ ht.clear();
try {
ok = _stepService.removeDocument(aScStep, docId);
Assert.fail("DocumentIsUsedException must be thrown.");
// ////////////////////////////////////////////////////////
// Call removeDocument method for each document
// starting from the last activity.
+ Study aStudy = _studyService.selectStudy(aScen.getOwnerStudy()
+ .getIndex());
+ aScen = aStudy.getScenarii()[0];
+ Map<Integer, org.splat.som.Step> stSteps = _projectElementService.getStepsMap(aStudy);
+ Map<Integer, org.splat.som.Step> 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 + " "
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++;
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());
/**
* 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 {
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<StepCommentDTO> 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");
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());
}
}