From: mka Date: Tue, 5 Mar 2013 13:21:25 +0000 (+0000) Subject: Edit/Delete of the description/comments functionalities are implemented X-Git-Tag: Root_Delivery2_2013_04_22~122 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b6343a018a953ae4bf5b843ae62aa0a30e2abb22;p=tools%2Fsiman.git Edit/Delete of the description/comments functionalities are implemented --- 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 faba859..c84935c 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 @@ -58,7 +58,7 @@ public abstract class Any extends Persistent { // Protected services // ============================================================================================================================== - protected boolean removeAttribute (Attribute field) { + public boolean removeAttribute (Attribute field) { for (Iterator i=getAttributes().iterator(); i.hasNext(); ) { if (!i.next().equals(field)) continue; i.remove(); diff --git a/Workspace/Siman-Common/src/org/splat/log/AppLogger.java b/Workspace/Siman-Common/src/org/splat/log/AppLogger.java index 7349f4a..ec9bbd3 100644 --- a/Workspace/Siman-Common/src/org/splat/log/AppLogger.java +++ b/Workspace/Siman-Common/src/org/splat/log/AppLogger.java @@ -225,7 +225,7 @@ public class AppLogger { * @param exception the exception which originated the message * @param message the message */ - public void debug(final String message, final Exception exception) { + public void debug(final String message, final Throwable exception) { _logger.debug(message, exception); } diff --git a/Workspace/Siman-Common/src/org/splat/service/StepService.java b/Workspace/Siman-Common/src/org/splat/service/StepService.java index 1576adb..c196d3d 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepService.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepService.java @@ -28,14 +28,14 @@ import org.splat.som.Step; /** * Step service interface. - * + * * @author Roman Kozlov (RKV) */ public interface StepService { /** * Create a new document published in the given study step. - * + * * @param aStep * the target study step * @param dprop @@ -56,7 +56,7 @@ public interface StepService { /** * Publish an existing document in the given study step. - * + * * @param aStep * the target study step * @param dprop @@ -75,7 +75,7 @@ public interface StepService { /** * Create a new version of a document in the given study step. - * + * * @param aStep * the study step * @param base @@ -101,7 +101,7 @@ public interface StepService { /** * Add simulation context to the study step. - * + * * @param aStep * the study step * @param dprop @@ -120,7 +120,7 @@ public interface StepService { /** * Add simulation context to the study step. - * + * * @param firstStep * the study step * @param context @@ -132,7 +132,7 @@ public interface StepService { /** * Remove a simulation context from the study step. - * + * * @param aStep * the study step * @param context @@ -143,7 +143,7 @@ public interface StepService { /** * Add a document publication to the given step. - * + * * @param aStep * the target study step * @param newdoc @@ -154,7 +154,7 @@ public interface StepService { /** * Remove a document publication from the given step. - * + * * @param aStep * the study step * @param oldoc @@ -179,7 +179,7 @@ public interface StepService { /** * Get document types which are applicable for the given study step (activity). - * + * * @param aStep * the study step * @return the list of document types @@ -210,4 +210,36 @@ public interface StepService { * if the owner of the step is not found in the database. */ List getStepComments(final Step step) throws InvalidParameterException; + + /** + * Removes the comment with given id from the database. + * + * @param commentId + * the comment id + * @throws InvalidParameterException + * if the comment is not found in the database. + */ + void removeStepComment(final long commentId) throws InvalidParameterException; + + + /** + * Checks if a given comment was made by a given user. + * @param commentId the comment id + * @param userId the user id + * @return if the comment was made by the user + * @throws InvalidParameterException if the comment with such id does not exist. + */ + boolean isCommentMadeByUser(final long commentId, final long userId) throws InvalidParameterException; + + + /** + * Edit value and title of a comment. + * If value or title is null - no changes will be applied to this field. + * @param commentId the comment id + * @param newValue the new comment value + * @param newTitle the new comment title + * @throws InvalidParameterException if the comment with such id does not exist. + */ + void editStepComment(final long commentId, final String newValue, final String newTitle) + throws InvalidParameterException; } diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index af8ffcb..9e94849 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -58,7 +58,7 @@ import org.springframework.transaction.annotation.Transactional; /** * Step service implementation. - * + * * @author Roman Kozlov (RKV) */ public class StepServiceImpl implements StepService { @@ -126,11 +126,11 @@ public class StepServiceImpl implements StepService { * Injected user DAO. */ private UserDAO _userDAO; - - + + /** * {@inheritDoc} - * + * * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext.Properties) */ @Override @@ -145,7 +145,7 @@ public class StepServiceImpl implements StepService { /** * {@inheritDoc} - * + * * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext) */ @Override @@ -178,7 +178,7 @@ public class StepServiceImpl implements StepService { /** * Update lucene index of knowledge elements of a scenario or a study which the given step is related to. - * + * * @param aStep * the step (activity) */ @@ -208,7 +208,7 @@ public class StepServiceImpl implements StepService { /** * Update lucene index for knowledge elements of the scenario. - * + * * @param scene * the scenario * @throws IOException @@ -231,7 +231,7 @@ public class StepServiceImpl implements StepService { /** * {@inheritDoc} - * + * * @see org.splat.service.StepService#removeSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext) */ @Override @@ -258,7 +258,7 @@ public class StepServiceImpl implements StepService { /** * {@inheritDoc} - * + * * @see org.splat.service.StepService#createDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties) */ @Override @@ -294,7 +294,7 @@ public class StepServiceImpl implements StepService { /** * {@inheritDoc} - * + * * @see org.splat.service.StepService#assignDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties) */ @Override @@ -317,7 +317,7 @@ public class StepServiceImpl implements StepService { /** * Create a new version of a document in the given study step. - * + * * @param aStep * the study step * @param base @@ -342,7 +342,7 @@ public class StepServiceImpl implements StepService { /** * Create a new version of a document in the given study step. - * + * * @param aStep * the study step * @param base @@ -371,7 +371,7 @@ public class StepServiceImpl implements StepService { /** * Create a new version of a document in the given study step. - * + * * @param aStep * the study step * @param base @@ -445,7 +445,7 @@ public class StepServiceImpl implements StepService { /** * Get document types which are applicable for the given study step (activity). - * + * * @param aStep * the study step * @return the list of document types @@ -457,7 +457,7 @@ public class StepServiceImpl implements StepService { /** * Add a document publication to the given step. - * + * * @param aStep * the target study step * @param newdoc @@ -478,7 +478,7 @@ public class StepServiceImpl implements StepService { /** * Remove a document publication from the given step. - * + * * @param aStep * the study step * @param oldoc @@ -558,8 +558,10 @@ public class StepServiceImpl implements StepService { } } return res; + + } - + /** * {@inheritDoc} * @@ -603,7 +605,7 @@ public class StepServiceImpl implements StepService { comment.setId(resultKey); } - /** + /** * {@inheritDoc} * @see org.splat.service.StepService#getStepComments(org.splat.som.Step) */ @@ -628,10 +630,60 @@ public class StepServiceImpl implements StepService { } return commentDTOs; } + + /** + * {@inheritDoc} + * @see org.splat.service.StepService#removeStepComment(long) + */ + @Override + @Transactional + public void removeStepComment(final long commentId) throws InvalidParameterException { + StepCommentAttribute stepComment = _stepCommentAttributeDAO.get(Long.valueOf(commentId)); + if(stepComment == null) { + throw new InvalidParameterException("commentId",String.valueOf(commentId)); + } + _stepCommentAttributeDAO.delete(stepComment); + } + /** + * {@inheritDoc} + * @see org.splat.service.StepService#editStepComment(long, java.lang.String, java.lang.String) + */ + @Override + @Transactional + public void editStepComment(final long commentId, final String newValue, final String newTitle) + throws InvalidParameterException { + StepCommentAttribute comment = _stepCommentAttributeDAO.get(Long.valueOf(commentId)); + if(comment == null) { + throw new InvalidParameterException("commentId",String.valueOf(commentId)); + } + if(newTitle != null) { + comment.setTitle(newTitle); + } + if(newValue != null) { + comment.setValue(newValue); + } + _stepCommentAttributeDAO.update(comment); + } + + /** + * {@inheritDoc} + * @see org.splat.service.StepService#isCommentMadeByUser(long, long) + */ + @Override + @Transactional(readOnly = true) + public boolean isCommentMadeByUser(final long commentId, final long userId) + throws InvalidParameterException { + StepCommentAttribute comment = _stepCommentAttributeDAO.get(Long.valueOf(commentId)); + if(comment == null) { + throw new InvalidParameterException("commentId", String.valueOf(commentId)); + } + return comment.getUser().getIndex() == userId; + } + /** * Get the documentService. - * + * * @return the documentService */ public DocumentService getDocumentService() { @@ -640,7 +692,7 @@ public class StepServiceImpl implements StepService { /** * Set the documentService. - * + * * @param documentService * the documentService to set */ @@ -650,7 +702,7 @@ public class StepServiceImpl implements StepService { /** * Get the simulationContextService. - * + * * @return the simulationContextService */ public SimulationContextService getSimulationContextService() { @@ -659,7 +711,7 @@ public class StepServiceImpl implements StepService { /** * Set the simulationContextService. - * + * * @param simulationContextService * the simulationContextService to set */ @@ -670,7 +722,7 @@ public class StepServiceImpl implements StepService { /** * Get the documentDAO. - * + * * @return the documentDAO */ public DocumentDAO getDocumentDAO() { @@ -679,7 +731,7 @@ public class StepServiceImpl implements StepService { /** * Set the documentDAO. - * + * * @param documentDAO * the documentDAO to set */ @@ -689,7 +741,7 @@ public class StepServiceImpl implements StepService { /** * Get the simulationContextDAO. - * + * * @return the simulationContextDAO */ public SimulationContextDAO getSimulationContextDAO() { @@ -698,7 +750,7 @@ public class StepServiceImpl implements StepService { /** * Set the simulationContextDAO. - * + * * @param simulationContextDAO * the simulationContextDAO to set */ @@ -709,7 +761,7 @@ public class StepServiceImpl implements StepService { /** * Get the projectElementDAO. - * + * * @return the projectElementDAO */ public ProjectElementDAO getProjectElementDAO() { @@ -718,7 +770,7 @@ public class StepServiceImpl implements StepService { /** * Set the projectElementDAO. - * + * * @param projectElementDAO * the projectElementDAO to set */ @@ -728,7 +780,7 @@ public class StepServiceImpl implements StepService { /** * Get the indexService. - * + * * @return the indexService */ public IndexService getIndexService() { @@ -737,7 +789,7 @@ public class StepServiceImpl implements StepService { /** * Set the indexService. - * + * * @param indexService * the indexService to set */ @@ -747,7 +799,7 @@ public class StepServiceImpl implements StepService { /** * Get the fileDAO. - * + * * @return the fileDAO */ public FileDAO getFileDAO() { @@ -756,7 +808,7 @@ public class StepServiceImpl implements StepService { /** * Set the fileDAO. - * + * * @param fileDAO * the fileDAO to set */ @@ -766,7 +818,7 @@ public class StepServiceImpl implements StepService { /** * Get the documentTypeService. - * + * * @return the documentTypeService */ public DocumentTypeService getDocumentTypeService() { @@ -775,7 +827,7 @@ public class StepServiceImpl implements StepService { /** * Set the documentTypeService. - * + * * @param documentTypeService * the documentTypeService to set */ @@ -786,7 +838,7 @@ public class StepServiceImpl implements StepService { /** * Get the versionsRelationDAO. - * + * * @return the versionsRelationDAO */ public VersionsRelationDAO getVersionsRelationDAO() { @@ -795,7 +847,7 @@ public class StepServiceImpl implements StepService { /** * Set the versionsRelationDAO. - * + * * @param versionsRelationDAO * the versionsRelationDAO to set */ @@ -806,16 +858,16 @@ public class StepServiceImpl implements StepService { /** * Get project settings. - * + * * @return Project settings service */ private ProjectSettingsService getProjectSettings() { return _projectSettings; } - + /** * Set project settings service. - * + * * @param projectSettingsService * project settings service */ @@ -823,7 +875,7 @@ public class StepServiceImpl implements StepService { final ProjectSettingsService projectSettingsService) { _projectSettings = projectSettingsService; } - + /** * Get the stepCommentAttributeDAO. * @return the stepCommentAttributeDAO @@ -855,7 +907,7 @@ public class StepServiceImpl implements StepService { public void setUserDAO(final UserDAO userDAO) { _userDAO = userDAO; } - + /** * Get the publicationDAO. * diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyService.java b/Workspace/Siman-Common/src/org/splat/service/StudyService.java index 19fa71f..a7353d6 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyService.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyService.java @@ -9,6 +9,7 @@ package org.splat.service; +import java.util.Date; import java.util.List; import org.splat.dal.bo.kernel.User; @@ -293,4 +294,13 @@ public interface StudyService { */ void setDescription(Long studyId, String descriptionText) throws InvalidParameterException; + /** + * Remove a description attached to a study. + * + * @param studyId the study id + * @throws InvalidParameterException + * if no study with such Id has been found in the database. + * @return true if succeeded, false if study doesn't have a description. + */ + boolean removeDescription(final Long studyId) throws InvalidParameterException; } diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java index b1f0305..1826adb 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java @@ -59,6 +59,7 @@ import org.splat.service.technical.RepositoryService; import org.splat.som.Revision; import org.springframework.transaction.annotation.Transactional; + /** * This class defines all methods for creation, modification the study. * @@ -122,7 +123,7 @@ public class StudyServiceImpl implements StudyService { * Injected user service. */ private UserService _userService; - + /** * Injected publication DAO. */ @@ -148,6 +149,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#selectStudy(long) */ + @Override @Transactional public Study selectStudy(final long index) { Study result = getStudyDAO().get(index); @@ -175,6 +177,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#createStudy(org.splat.dal.bo.som.Study.Properties) */ + @Override @Transactional public Study createStudy(final Study.Properties sprop) throws MissedPropertyException, InvalidPropertyException, @@ -200,6 +203,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext.Properties) */ + @Override @Transactional public SimulationContext addProjectContext(final Study aStudy, final SimulationContext.Properties cprop) @@ -216,6 +220,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext) */ + @Override @Transactional public SimulationContext addProjectContext(final Study aStudy, final SimulationContext context) { @@ -230,6 +235,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#addContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User) */ + @Override public boolean addContributor(final Study aStudy, final User user) { List contributor = getModifiableContributors(aStudy); // Initializes contributor for (Iterator i = contributor.iterator(); i.hasNext();) { @@ -259,6 +265,7 @@ public class StudyServiceImpl implements StudyService { * @see #isPublic() * @see Publication#approve(Date) */ + @Override public boolean moveToReference(final Study aStudy) { if (aStudy.getProgressState() != ProgressState.APPROVED) { return false; @@ -279,6 +286,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#update(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Study.Properties) */ + @Override public boolean update(final Study aStudy, final Properties sprop) throws InvalidPropertyException { if (sprop.getTitle() != null) { @@ -318,6 +326,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#removeContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User[]) */ + @Override public boolean removeContributor(final Study aStudy, final User... users) { List contributor = getModifiableContributors(aStudy); // Initializes contributor Boolean done = false; @@ -346,6 +355,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#removeProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext) */ + @Override public boolean removeProjectContext(final Study aStudy, final SimulationContext context) { boolean done = getStepService().removeSimulationContext( @@ -360,6 +370,7 @@ public class StudyServiceImpl implements StudyService { * @see org.splat.service.StudyService#setValidationCycle(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.DocumentType, * org.splat.dal.bo.som.ValidationCycle.Properties) */ + @Override @Transactional public void setValidationCycle(final Study aStudyDTO, final DocumentType type, final ValidationCycle.Properties vprop) { @@ -404,6 +415,7 @@ public class StudyServiceImpl implements StudyService { * a study to demote * @return true if the demotion succeeded. */ + @Override public boolean demote(final Study aStudy) { if (aStudy.getProgressState() == ProgressState.inCHECK) { aStudy.setProgressState(ProgressState.inDRAFT); @@ -420,6 +432,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#generateLocalIndex(org.splat.dal.bo.som.Study) */ + @Override @Transactional public int generateLocalIndex(final Study aStudy) { aStudy.setLastLocalIndex(aStudy.getLastLocalIndex() + 1); @@ -434,6 +447,7 @@ public class StudyServiceImpl implements StudyService { * a study to promote * @return true if the demotion succeeded. */ + @Override @Transactional public boolean promote(final Study aStudy) { if (aStudy.getProgressState() == ProgressState.inWORK) { @@ -462,6 +476,7 @@ public class StudyServiceImpl implements StudyService { * @return true if the move succeeded. * @see #isPublic() */ + @Override @Transactional public boolean moveToPublic(final Study aStudy) { boolean isOk = false; @@ -481,6 +496,7 @@ public class StudyServiceImpl implements StudyService { * a study to move * @return true if the move succeeded. */ + @Override @Transactional public boolean moveToPrivate(final Study aStudy) { boolean isOk = false; @@ -856,6 +872,7 @@ public class StudyServiceImpl implements StudyService { * the study * @return the unmodifiable not null transient list of contributors of this study */ + @Override public List getContributors(final Study aStudy) { if (aStudy.getContributor() == null) { setShortCuts(aStudy); @@ -886,6 +903,7 @@ public class StudyServiceImpl implements StudyService { * the document type being subject of validation * @return the validation cycle of the document, or null if not defined. */ + @Override public ValidationCycle getValidationCycleOf(final Study aStudy, final DocumentType type) { if (aStudy.getValidationCycles() == null || aStudy.getValidationCycles().isEmpty()) { @@ -914,6 +932,7 @@ public class StudyServiceImpl implements StudyService { * @return true if the given user is actor of this study. * @see #getActors() */ + @Override public boolean hasActor(final Study aStudy, final User user) { if (user == null) { return false; @@ -937,6 +956,7 @@ public class StudyServiceImpl implements StudyService { * @return true if the given user is actor of this study. * @see #getContributors() */ + @Override public boolean isStaffedBy(final Study aStudy, final User user) { if (user == null) { return false; @@ -964,6 +984,7 @@ public class StudyServiceImpl implements StudyService { * @param aStudy * the study */ + @Override public void loadWorkflow(final Study aStudy) { setShortCuts(aStudy); } @@ -1053,6 +1074,7 @@ public class StudyServiceImpl implements StudyService { getStudyDAO().merge(aStudy); } + /** * {@inheritDoc} * @see org.splat.service.StudyService#getDescription(java.lang.Long) @@ -1088,6 +1110,23 @@ public class StudyServiceImpl implements StudyService { } study.setAttribute(new DescriptionAttribute(study, descriptionText)); } + + /** + * {@inheritDoc} + * @see org.splat.service.StudyService#removeStudyDescription(java.lang.Long) + */ + @Override + @Transactional + public boolean removeDescription(final Long studyId) throws InvalidParameterException { + if(studyId == null) { + throw new InvalidParameterException("studyId", String.valueOf(studyId)); + } + Study study = _studyDAO.get(studyId); + if(study == null) { + throw new InvalidParameterException("studyId", String.valueOf(studyId)); + } + return study.removeAttribute(study.getAttribute(DescriptionAttribute.class)); + } /** * Get project settings. @@ -1282,7 +1321,7 @@ public class StudyServiceImpl implements StudyService { public void setUserService(final UserService userService) { _userService = userService; } - + /** * Get the publicationDAO. * @return the publicationDAO @@ -1347,5 +1386,4 @@ public class StudyServiceImpl implements StudyService { final DescriptionAttributeDAO descriptionAttributeDAO) { _descriptionAttributeDAO = descriptionAttributeDAO; } - } diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/StepCommentDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/StepCommentDTO.java index 41de0f2..c9edebe 100644 --- a/Workspace/Siman-Common/src/org/splat/service/dto/StepCommentDTO.java +++ b/Workspace/Siman-Common/src/org/splat/service/dto/StepCommentDTO.java @@ -210,4 +210,12 @@ public class StepCommentDTO { public void setTitle(final String title) { _title = title; } + + /** + * Get the id. Used with this name in menupopup.jsp. + * @return the id + */ + public Long getIndex() { + return _id; + } } diff --git a/Workspace/Siman-Common/src/test/splat/service/TestStepService.java b/Workspace/Siman-Common/src/test/splat/service/TestStepService.java index f0e0bf8..9ead134 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestStepService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestStepService.java @@ -20,7 +20,6 @@ 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.Document.Properties; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.File; import org.splat.dal.bo.som.ProjectElement; @@ -30,6 +29,7 @@ import org.splat.dal.bo.som.StepCommentAttribute; import org.splat.dal.bo.som.Study; 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.kernel.UserDAO; import org.splat.dal.dao.som.Database; import org.splat.dal.dao.som.FileDAO; @@ -114,7 +114,7 @@ public class TestStepService extends BaseTest { @Autowired @Qualifier("projectSettings") private transient ProjectSettingsService _projectSettings; - + /** * The injected by Spring StepCommentAttributeDAO. */ @@ -695,7 +695,7 @@ public class TestStepService extends BaseTest { 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 + //actual query to the base, not cache, in order to check if the user already exists StepCommentDTO aBadDTO = createStepCommentDTO(badUser, goodStudy); try{ @@ -786,6 +786,87 @@ public class TestStepService extends BaseTest { "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 + */ + @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"); + _stepCommentAttributeDAO.saveOrUpdate(comment); + + getHibernateTemplate().flush(); + + //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); + + + try{ + _stepService.editStepComment(nonExistingId, "newValue", "newTitle"); + getHibernateTemplate().flush(); + Assert.fail("Creation with non-existing user must be failed."); + } + catch(InvalidParameterException e){ + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + + //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 + */ + private void testEdit(StepCommentAttribute comment, String value, 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) { + Assert.assertEquals(comment.getValue(), oldValue); + } else { + Assert.assertEquals(comment.getValue(), value); + } + if(title == null) { + Assert.assertEquals(comment.getTitle(), oldTitle); + } else { + Assert.assertEquals(comment.getTitle(), title); + } + } + + /** * Create a transient StepCommentDTO. * diff --git a/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java b/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java index 565cfea..d3a704b 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java @@ -512,4 +512,60 @@ public class TestStudyService extends BaseTest { rollbackNestedTransaction(); LOG.debug(">>>>> END testSetDescription()"); } + + /** + * Test of removal of a study description. + * + * @throws BusinessException if there is something wrong likely unrelated to the tested method + */ + @Test + public void testRemoveDescription() throws BusinessException { + LOG.debug(">>>>> BEGIN testRemoveDescription()"); + startNestedTransaction(); + + User user = TestEntitiesGenerator.getTestUser("GoodUser"); + _userDAO.create(user); + Study study = TestEntitiesGenerator.getTestStudy(user); + _studyDAO.create(study); + _studyDAO.flush(); + Long studyId = Long.valueOf(study.getIndex()); + + //Empty description: + Assert.assertFalse(_studyService.removeDescription(studyId), + "returned value for study without description must be null"); + + //Not empty description: + study.setAttribute(new DescriptionAttribute(study, "description")); + _studyDAO.update(study); + _studyDAO.flush(); + Assert.assertTrue(_studyService.removeDescription(studyId), "existing description removal must return true"); + + + Assert.assertNull(_studyService.getDescription(studyId), "description hasn't been successfully removed"); + + //null id + try { + _studyService.removeDescription(null); + Assert.fail("removal with null study id must fail"); + } catch(InvalidParameterException e){ + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + + //Non-existing id + Study tmpStudy = TestEntitiesGenerator.getTestStudy(user); + _studyDAO.create(tmpStudy); + Long nonExistingId = tmpStudy.getIndex(); + _studyDAO.delete(tmpStudy); + try { + _studyService.removeDescription(nonExistingId); + Assert.fail("removal with non-existing study id must fail"); + } catch(InvalidParameterException e){ + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + + rollbackNestedTransaction(); + LOG.debug(">>>>> END testGetDescription()"); + } } diff --git a/Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml b/Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml index 435051c..9d13842 100644 --- a/Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml +++ b/Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml @@ -71,9 +71,7 @@ - - - + diff --git a/Workspace/Siman/WebContent/js/action.js b/Workspace/Siman/WebContent/js/action.js index 9c55f43..98e5b42 100644 --- a/Workspace/Siman/WebContent/js/action.js +++ b/Workspace/Siman/WebContent/js/action.js @@ -22,6 +22,8 @@ // alert("Executing " + args[0] + " with " + args[1]); document.perform.launch(args[0], args[1]); } + } else { //javascript function call + eval(action); } } else { // Server side execution via a Struts action diff --git a/Workspace/Siman/WebContent/jsp/commentPane.jsp b/Workspace/Siman/WebContent/jsp/commentPane.jsp index 2f16c62..63a0634 100644 --- a/Workspace/Siman/WebContent/jsp/commentPane.jsp +++ b/Workspace/Siman/WebContent/jsp/commentPane.jsp @@ -4,55 +4,132 @@ <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
- +
+ + + + + + + +
+ "/> +
+ + + + -
+
-
- " onMouseOver=this.src="" + " onMouseOver=this.src="" onMouseOut=this.src="" title=""/>  
+
-