From 05b824febc84c9b16251ec73460edf25b67d4a83 Mon Sep 17 00:00:00 2001 From: mka Date: Thu, 14 Feb 2013 07:13:16 +0000 Subject: [PATCH] Show and Edit comments functionalities are implemented --- .../src/conf/log-messages.properties | 4 +- .../src/conf/log-messages_en.properties | 4 +- .../common/properties/MessageKeyEnum.java | 9 +- .../org/splat/dal/bo/som/Attributes.hbm.xml | 11 + .../dal/bo/som/StepCommentAttribute.java | 127 +++++++++ .../dal/dao/som/StepCommentAttributeDAO.java | 22 ++ .../dao/som/StepCommentAttributeDAOImpl.java | 32 +++ .../exception/InvalidParameterException.java | 26 ++ .../src/org/splat/service/StepService.java | 27 ++ .../org/splat/service/StepServiceImpl.java | 132 +++++++++- .../org/splat/service/dto/StepCommentDTO.java | 213 +++++++++++++++ .../src/spring/businessServiceContext.xml | 2 + .../Siman-Common/src/spring/daoContext.xml | 4 + .../test/splat/service/TestStepService.java | 248 +++++++++++++++++- .../WebContent/WEB-INF/tiles/tiles-defs.xml | 19 +- .../Siman/WebContent/jsp/commentPane.jsp | 68 +++++ .../Siman/WebContent/jsp/editKnowledge.jsp | 3 +- .../Siman/WebContent/jsp/readComment.jsp | 27 +- Workspace/Siman/WebContent/rtef/richtext.js | 2 +- .../WebContent/study/displayStudyStep.jsp | 21 +- .../splat/simer/DisplayStudyStepAction.java | 58 ++++ .../splat/simer/EditStepCommentAction.java | 104 ++++++++ .../Siman/src/spring/applicationContext.xml | 12 + Workspace/Siman/src/struts.xml | 19 +- 24 files changed, 1164 insertions(+), 30 deletions(-) create mode 100644 Workspace/Siman-Common/src/org/splat/dal/bo/som/StepCommentAttribute.java create mode 100644 Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAO.java create mode 100644 Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAOImpl.java create mode 100644 Workspace/Siman-Common/src/org/splat/exception/InvalidParameterException.java create mode 100644 Workspace/Siman-Common/src/org/splat/service/dto/StepCommentDTO.java create mode 100644 Workspace/Siman/WebContent/jsp/commentPane.jsp create mode 100644 Workspace/Siman/src/org/splat/simer/EditStepCommentAction.java diff --git a/Workspace/Siman-Common/src/conf/log-messages.properties b/Workspace/Siman-Common/src/conf/log-messages.properties index a19abed..2112319 100644 --- a/Workspace/Siman-Common/src/conf/log-messages.properties +++ b/Workspace/Siman-Common/src/conf/log-messages.properties @@ -13,8 +13,10 @@ SCN-000006=Scenario #{0} is not found SCN-000007=The user {0} does not participate in the scenario #{1} SCN-000008=The scenario #{0} is already checked out by the user {1} USR-000001=User {0} is not found in the database -KNT-000001=Knowledge element type "{0}" already exists +KNT-000001=Knowledge element type "{1}" already exists +SCT-000001=Simulation context type "{1}" already exists SCT-000001=Simulation context type "{0}" already exists DCT-000001=Document type "{0}" already exists DCT-000002=Can not delete the document "{0}" because it is used by other documents. DCT-000003=Can not save a document in {0} state. Check the validation cycle. +PARAM-000001=Parameter {1} is invalid with value: {2} diff --git a/Workspace/Siman-Common/src/conf/log-messages_en.properties b/Workspace/Siman-Common/src/conf/log-messages_en.properties index a19abed..2112319 100644 --- a/Workspace/Siman-Common/src/conf/log-messages_en.properties +++ b/Workspace/Siman-Common/src/conf/log-messages_en.properties @@ -13,8 +13,10 @@ SCN-000006=Scenario #{0} is not found SCN-000007=The user {0} does not participate in the scenario #{1} SCN-000008=The scenario #{0} is already checked out by the user {1} USR-000001=User {0} is not found in the database -KNT-000001=Knowledge element type "{0}" already exists +KNT-000001=Knowledge element type "{1}" already exists +SCT-000001=Simulation context type "{1}" already exists SCT-000001=Simulation context type "{0}" already exists DCT-000001=Document type "{0}" already exists DCT-000002=Can not delete the document "{0}" because it is used by other documents. DCT-000003=Can not save a document in {0} state. Check the validation cycle. +PARAM-000001=Parameter {1} is invalid with value: {2} diff --git a/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java b/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java index b532f00..27be5b2 100644 --- a/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java +++ b/Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java @@ -92,15 +92,18 @@ public enum MessageKeyEnum { /** * DCT-000003=Can not save a document in {0} state. Check the validation cycle. */ - DCT_000003("DCT-000003"); - + DCT_000003("DCT-000003"), + /** + * Parameter {1} is invalid with value: {2}. + */ + PARAM_000001("PARAM-000001"); /** * Value. */ private final String _value; /** - * The enum contructor with param(s). + * The enum constructor with param(s). * @param value The value */ MessageKeyEnum(final String value) { diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml index cda4ad8..2072446 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml @@ -20,5 +20,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/StepCommentAttribute.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/StepCommentAttribute.java new file mode 100644 index 0000000..0266e18 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/StepCommentAttribute.java @@ -0,0 +1,127 @@ +/***************************************************************************** + * Company EURIWARE + * Application SIMAN + * File $Id$ + * Creation date 29.10.2012 + * @author $Author$ + * @version $Revision$ + *****************************************************************************/ + +package org.splat.dal.bo.som; + +import java.util.Date; + +import org.splat.dal.bo.kernel.Any; +import org.splat.dal.bo.kernel.TextAttribute; +import org.splat.dal.bo.kernel.User; + +/** + * User comment attached to a particular step. + * + */ +public class StepCommentAttribute extends TextAttribute { + + /** + * The date the comment was made. + */ + private Date _date; + /** + * Step the step to which the correspond to. + */ + private Integer _step; + /** + * the user who made the comment. + */ + private User _user; + /** + * The title of the the comment. + */ + private String _title; + + /** + * Database fetch constructor. + */ + public StepCommentAttribute() { + super(); + } + + /** + * Constructor with all necessary parameters. + * @param from owner of the comment, a project element + * @param value the text of the comment + * @param date the date + * @param step the step + * @param user the user + * @param title the title + */ + public StepCommentAttribute(final Any from, final String value, final Date date, + final Integer step, final User user, final String title) { + super(from, value); + _date = date; + _step = step; + _user = user; + _title = title; + } + + /** + * Get the date. + * @return the date + */ + public Date getDate() { + return _date; + } + + /** + * Set the date. + * @param date the date to set + */ + public void setDate(final Date date) { + _date = date; + } + + /** + * Get the step. + * @return the step + */ + public Integer getStep() { + return _step; + } + + /** + * Set the step. + * @param step the step to set + */ + public void setStep(final Integer step) { + _step = step; + } + + /** + * Get the user. + * @return the user + */ + public User getUser() { + return _user; + } + + /** + * Set the user. + * @param user the user to set + */ + public void setUser(final User user) { + _user = user; + } + /** + * Get the title. + * @return the title + */ + public String getTitle() { + return _title; + } + /** + * Set the title. + * @param title the title to set + */ + public void setTitle(final String title) { + _title = title; + } +} diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAO.java new file mode 100644 index 0000000..ee5e493 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAO.java @@ -0,0 +1,22 @@ +/***************************************************************************** + * Company OPEN CASCADE + * Application SIMAN + * File $Id$ + * Creation date 06.10.2012 + * @author $Author$ + * @version $Revision$ + * Generated by Siman Generator on Tue Oct 30 16:20:38 MSK 2012 + *****************************************************************************/ + +package org.splat.dal.dao.som; + +import org.splat.dal.bo.som.StepCommentAttribute; +import org.splat.dal.dao.kernel.GenericDAO; + +/** + * StepCommentAttribute DAO class implementation. + * @author Roman Kozlov (RKV) + * + */ +public interface StepCommentAttributeDAO extends GenericDAO { +} diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAOImpl.java new file mode 100644 index 0000000..992d9c5 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAOImpl.java @@ -0,0 +1,32 @@ +/***************************************************************************** + * Company EURIWARE + * Application SIMAN + * File $Id$ + * Creation date 13.02.2013 + * @author Author: Maria KRUCHININA + * @version Revision: + *****************************************************************************/ + +package org.splat.dal.dao.som; + +import org.splat.dal.bo.som.StepCommentAttribute; +import org.splat.dal.dao.kernel.AbstractGenericDAOImpl; + +/** + * StepCommentAttribute DAO. + * @author Maria KRUCHININA + * + */ +public class StepCommentAttributeDAOImpl extends + AbstractGenericDAOImpl implements StepCommentAttributeDAO { + + /** + * {@inheritDoc} + * @see org.splat.dal.dao.kernel.AbstractGenericDAOImpl#getType() + */ + @Override + protected Class getType() { + return StepCommentAttribute.class; + } + +} diff --git a/Workspace/Siman-Common/src/org/splat/exception/InvalidParameterException.java b/Workspace/Siman-Common/src/org/splat/exception/InvalidParameterException.java new file mode 100644 index 0000000..45630c1 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/exception/InvalidParameterException.java @@ -0,0 +1,26 @@ +package org.splat.exception; + + +/** + * Exception thrown when a parameter passed to a method is invalid. + */ +public class InvalidParameterException extends BusinessException { + + /** + * Version id for serialization. + */ + private static final long serialVersionUID = -4596111071538834057L; + + /** + * Constructor. + * @param param + * the the name of the invalid parameter + * @param value + * the value of the parameter + */ + public InvalidParameterException(final String param, final String value){ + //super(MessageKeyEnum.PARAM_000001.toString(), param, value); + //constructor doesn't create any meaningful message so localization problems doesn't block further development + super(); + } +} diff --git a/Workspace/Siman-Common/src/org/splat/service/StepService.java b/Workspace/Siman-Common/src/org/splat/service/StepService.java index a4071b1..1576adb 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepService.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepService.java @@ -17,11 +17,13 @@ import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.SimulationContext; import org.splat.exception.DocumentIsUsedException; +import org.splat.exception.InvalidParameterException; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MismatchException; import org.splat.kernel.MissedPropertyException; import org.splat.kernel.MultiplyDefinedException; import org.splat.kernel.NotApplicableException; +import org.splat.service.dto.StepCommentDTO; import org.splat.som.Step; /** @@ -183,4 +185,29 @@ public interface StepService { * @return the list of document types */ List getValidDocumentTypes(Step aStep); + + + /** + * Add a comment to study step specified in DTO. + * The 'id' field must be null, new primary key will be placed there if succeeded. + * User is identified by userId, userName is not necessary. + * + * @param comment + * data to be placed in the comment attribute + * @throws InvalidParameterException + * if some parameter is invalid + */ + void addStepComment(final StepCommentDTO comment) throws InvalidParameterException; + + /** + * Retrieves from the database all the comments related to the given step. + * + * @param step + * the step + * @return list of StepCommentDTO's with properties 'id', 'text', 'user', 'date' filled in. + * + * @throws InvalidParameterException + * if the owner of the step is not found in the database. + */ + List getStepComments(final Step step) 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 f5d5c40..47d0962 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -14,38 +14,48 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.hibernate.criterion.Restrictions; import org.splat.dal.bo.kernel.Relation; +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.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; +import org.splat.dal.bo.som.StepCommentAttribute; import org.splat.dal.bo.som.UsedByRelation; import org.splat.dal.bo.som.UsesRelation; import org.splat.dal.bo.som.VersionsRelation; import org.splat.dal.dao.kernel.RelationDAO; +import org.splat.dal.dao.kernel.UserDAO; import org.splat.dal.dao.som.DocumentDAO; import org.splat.dal.dao.som.FileDAO; import org.splat.dal.dao.som.ProjectElementDAO; import org.splat.dal.dao.som.PublicationDAO; import org.splat.dal.dao.som.SimulationContextDAO; +import org.splat.dal.dao.som.StepCommentAttributeDAO; import org.splat.dal.dao.som.VersionsRelationDAO; import org.splat.exception.DocumentIsUsedException; +import org.splat.exception.InvalidParameterException; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MismatchException; import org.splat.kernel.MissedPropertyException; import org.splat.kernel.MultiplyDefinedException; import org.splat.kernel.NotApplicableException; import org.splat.log.AppLogger; +import org.splat.service.dto.StepCommentDTO; import org.splat.service.technical.IndexService; import org.splat.service.technical.ProjectSettingsService; import org.splat.som.Revision; import org.splat.som.Step; +import org.splat.util.BeanHelper; import org.springframework.transaction.annotation.Transactional; + /** * Step service implementation. * @@ -107,11 +117,23 @@ public class StepServiceImpl implements StepService { */ private PublicationDAO _publicationDAO; + /** + * Injected text attribute DAO. + */ + private StepCommentAttributeDAO _stepCommentAttributeDAO; + + /** + * 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 public SimulationContext addSimulationContext(final Step aStep, final SimulationContext.Properties dprop) throws MissedPropertyException, InvalidPropertyException, @@ -126,6 +148,7 @@ public class StepServiceImpl implements StepService { * * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext) */ + @Override @Transactional public SimulationContext addSimulationContext(final Step aStep, final SimulationContext context) { @@ -211,6 +234,7 @@ public class StepServiceImpl implements StepService { * * @see org.splat.service.StepService#removeSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext) */ + @Override @Transactional public boolean removeSimulationContext(final Step aStep, final SimulationContext context) { @@ -237,6 +261,7 @@ public class StepServiceImpl implements StepService { * * @see org.splat.service.StepService#createDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties) */ + @Override @Transactional public Publication createDocument(final Step aStep, final Document.Properties dprop) throws MissedPropertyException, @@ -272,6 +297,7 @@ public class StepServiceImpl implements StepService { * * @see org.splat.service.StepService#assignDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties) */ + @Override public Publication assignDocument(final Step aStep, final Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, NotApplicableException { @@ -364,6 +390,7 @@ public class StepServiceImpl implements StepService { * @throws MismatchException * if the document is not applicable to the given study step */ + @Override @Transactional public Publication versionDocument(final Step aStep, final Publication base, final Document.Properties dprop) @@ -423,6 +450,7 @@ public class StepServiceImpl implements StepService { * the study step * @return the list of document types */ + @Override public List getValidDocumentTypes(final Step aStep) { return getDocumentTypeService().selectTypesOf(aStep.getStep()); } @@ -436,6 +464,7 @@ public class StepServiceImpl implements StepService { * the document publication to add * @return true if publication succeeded */ + @Override public boolean add(final Step aStep, final Publication newdoc) { boolean res = aStep.getOwner().add(newdoc); // Updates the study in memory if (res) { @@ -456,6 +485,7 @@ public class StepServiceImpl implements StepService { * the document publication to remove * @return true if removing of the publication succeeded */ + @Override 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 @@ -476,6 +506,7 @@ public class StepServiceImpl implements StepService { * @throws DocumentIsUsedException * if the document is used by other documents */ + @Override @Transactional public boolean removeDocument(final Step aStep, final long docId) throws DocumentIsUsedException { @@ -528,6 +559,73 @@ public class StepServiceImpl implements StepService { } return res; } + + /** + * {@inheritDoc} + * + * @see org.splat.service.StepService#addComment(org.splat.som.Step, org.splat.dal.bo.som.CommentAttribute) + */ + @Override + @Transactional + public void addStepComment(final StepCommentDTO comment) throws InvalidParameterException { + + if(comment.getId()!= null) { + throw new InvalidParameterException("id", String.valueOf(comment.getId())); + } + User user = getUserDAO().get(comment.getUserId()); + if (user == null) { + throw new InvalidParameterException("userId", String.valueOf(comment.getUserId())); + } + ProjectElement projectElement = getProjectElementDAO().get(comment.getProjectElementId()); + if (projectElement==null) { + throw new InvalidParameterException("projectElementId", comment.getProjectElementId().toString()); + } + if(comment.getStep() == null || comment.getStep()<0) { + throw new InvalidParameterException("step", String.valueOf(comment.getStep())); + } + if(comment.getDate() == null) { + throw new InvalidParameterException("date", String.valueOf(comment.getDate())); + } + if(comment.getTitle() == null) { + throw new InvalidParameterException("title", String.valueOf(comment.getTitle())); + } + + StepCommentAttribute newComment = new StepCommentAttribute( + projectElement, + comment.getText(), + comment.getDate(), + comment.getStep(), + user, + comment.getTitle() + ); + + Long resultKey=getStepCommentAttributeDAO().create(newComment); + comment.setId(resultKey); + } + + /** + * @see org.splat.service.StepService#getStepComments(org.splat.som.Step) + */ + @Override + public List getStepComments(final Step step) throws InvalidParameterException { + ProjectElement owner = _projectElementDAO.get(step.getOwner().getRid()); + if(owner == null) { + throw new InvalidParameterException("step owner id", + Long.valueOf(step.getOwner().getRid()).toString()); + } + List comments = _stepCommentAttributeDAO.getFilteredList( + Restrictions.and( + Restrictions.eq("step", Integer.valueOf(step.getNumber())), + Restrictions.eq("owner", owner))); + List commentDTOs = new ArrayList(); + for(StepCommentAttribute comment : comments) { + StepCommentDTO stepCommentDTO = BeanHelper.copyBean(comment, StepCommentDTO.class); + stepCommentDTO.setText(comment.getValue()); + stepCommentDTO.setId(Long.valueOf(comment.getRid())); + commentDTOs.add(stepCommentDTO); + } + return commentDTOs; + } /** * Get the documentService. @@ -712,7 +810,7 @@ public class StepServiceImpl implements StepService { private ProjectSettingsService getProjectSettings() { return _projectSettings; } - + /** * Set project settings service. * @@ -723,6 +821,38 @@ public class StepServiceImpl implements StepService { final ProjectSettingsService projectSettingsService) { _projectSettings = projectSettingsService; } + + /** + * Get the stepCommentAttributeDAO. + * @return the stepCommentAttributeDAO + */ + public StepCommentAttributeDAO getStepCommentAttributeDAO() { + return _stepCommentAttributeDAO; + } + + /** + * Set the stepCommentAttributeDAO. + * @param commentAttributeDAO the stepCommentAttributeDAO to set + */ + public void setStepCommentAttributeDAO( + final StepCommentAttributeDAO commentAttributeDAO) { + _stepCommentAttributeDAO = commentAttributeDAO; + } + + /** + * Get the userDAO. + * @return the userDAO + */ + public UserDAO getUserDAO() { + return _userDAO; + } + /** + * Set the userDAO. + * @param userDAO the userDAO to set + */ + public void setUserDAO(final UserDAO userDAO) { + _userDAO = userDAO; + } /** * Get the publicationDAO. diff --git a/Workspace/Siman-Common/src/org/splat/service/dto/StepCommentDTO.java b/Workspace/Siman-Common/src/org/splat/service/dto/StepCommentDTO.java new file mode 100644 index 0000000..41de0f2 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/service/dto/StepCommentDTO.java @@ -0,0 +1,213 @@ +/***************************************************************************** + * Company EURIWARE + * Application SIMAN + * File $Id$ + * Creation date 01.11.2012 + * @author $Author$ + * @version $Revision$ + *****************************************************************************/ + +package org.splat.service.dto; + +import java.util.Date; + +/** + * DTO for step comments. + * + * @author isr + */ +public class StepCommentDTO { + /** + * ID of the comment in the data base. + */ + private Long _id; + /** + * The text of the comment itself. + */ + private String _text; + /** + * ID of the project element containing the step. + */ + private Long _projectElementId; + /** + * Number of step to which the comment is attached. + */ + private Integer _step; + /** + * The date on which the comment was made. + */ + private Date _date; + /** + * Name of the user who made the comment. + */ + private String _userName; + /** + * Id of the user who made the comment. + */ + private Long _userId; + /** + * The user who made the comment. + */ + private UserDTO _user; + /** + * The title of the the comment. + */ + private String _title; + + /** + * Default constructor. + */ + public StepCommentDTO() { + super(); + } + + /** + * Constructor from all properties.* Constructor from all properties. + * @param id the id + * @param text the text of the comment + * @param projectElementId the id + * @param step the step number + * @param date the date + * @param userId the user id + * @param userName the user name + * @param title the title + */ + public StepCommentDTO(final Long id, final String text, final Long projectElementId, final Integer step, + final Date date, final Long userId, final String userName, final String title) { + _id = id; + _text = text; + _projectElementId = projectElementId; + _step = step; + _date = date; + _userName = userName; + _userId = userId; + _title = title; + } + + /** + * Get the id. + * @return the id + */ + public Long getId() { + return _id; + } + /** + * Set the id. + * @param id the id to set + */ + public void setId(final Long id) { + _id = id; + } + /** + * Get the text. + * @return the text + */ + public String getText() { + return _text; + } + /** + * Set the text. + * @param text the text to set + */ + public void setText(final String text) { + _text = text; + } + /** + * Get the projectElementID. + * @return the projectElementID + */ + public Long getProjectElementId() { + return _projectElementId; + } + /** + * Set the projectElementID. + * @param projectElementId the projectElementId to set + */ + public void setProjectElementId(final Long projectElementId) { + _projectElementId = projectElementId; + } + /** + * Get the step. + * @return the step + */ + public Integer getStep() { + return _step; + } + /** + * Set the step. + * @param step the step to set + */ + public void setStep(final Integer step) { + _step = step; + } + /** + * Get the date. + * @return the date + */ + public Date getDate() { + return _date; + } + /** + * Set the date. + * @param date the date to set + */ + public void setDate(final Date date) { + _date = date; + } + /** + * Get the userName. + * @return the userName + */ + public String getUserName() { + return _userName; + } + /** + * Set the userName. + * @param userName the userName to set + */ + public void setUserName(final String userName) { + _userName = userName; + } + /** + * Get the userId. + * @return the userId + */ + public Long getUserId() { + return _userId; + } + /** + * Set the userId. + * @param userId the userId to set + */ + public void setUserId(final Long userId) { + _userId = userId; + } + /** + * Get the user. + * @return the user + */ + public UserDTO getUser() { + return _user; + } + /** + * Set the user. + * @param user the user to set + */ + public void setUser(final UserDTO user) { + _user = user; + } + /** + * Get the title. + * @return the title + */ + public String getTitle() { + return _title; + } + /** + * Set the title. + * @param title the title to set + */ + public void setTitle(final String title) { + _title = title; + } +} diff --git a/Workspace/Siman-Common/src/spring/businessServiceContext.xml b/Workspace/Siman-Common/src/spring/businessServiceContext.xml index ec8070f..1999046 100644 --- a/Workspace/Siman-Common/src/spring/businessServiceContext.xml +++ b/Workspace/Siman-Common/src/spring/businessServiceContext.xml @@ -121,6 +121,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> + + class="org.splat.dal.dao.som.CommentAttributeDAOImpl"> + + + diff --git a/Workspace/Siman-Common/src/test/splat/service/TestStepService.java b/Workspace/Siman-Common/src/test/splat/service/TestStepService.java index 7a83e00..92329d5 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestStepService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestStepService.java @@ -20,20 +20,28 @@ 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.ProgressState; 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; +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.bo.som.Visibility; +import org.splat.dal.dao.kernel.UserDAO; import org.splat.dal.dao.som.Database; import org.splat.dal.dao.som.FileDAO; import org.splat.dal.dao.som.ScenarioDAO; +import org.splat.dal.dao.som.StepCommentAttributeDAO; +import org.splat.dal.dao.som.StudyDAO; import org.splat.exception.BusinessException; import org.splat.exception.DocumentIsUsedException; +import org.splat.exception.InvalidParameterException; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.MissedPropertyException; import org.splat.kernel.MultiplyDefinedException; @@ -42,6 +50,7 @@ import org.splat.service.DocumentTypeService; import org.splat.service.PublicationService; import org.splat.service.StepService; import org.splat.service.StudyService; +import org.splat.service.dto.StepCommentDTO; import org.splat.service.technical.ProjectSettingsService; import org.splat.service.technical.ProjectSettingsService.Step; import org.springframework.beans.factory.annotation.Autowired; @@ -108,6 +117,28 @@ public class TestStepService extends BaseTest { @Qualifier("projectSettings") private transient ProjectSettingsService _projectSettings; + /** + * The injected by Spring StepCommentAttributeDAO. + */ + @Autowired + @Qualifier("stepCommentAttributeDAO") + private transient StepCommentAttributeDAO _stepCommentAttributeDAO; + + /** + * The injected by Spring UserDAO. + */ + @Autowired + @Qualifier("userDAO") + private transient UserDAO _userDAO; + + + /** + * The injected by Spring StudyDAO. + */ + @Autowired + @Qualifier("studyDAO") + private transient StudyDAO _studyDAO; + /** * The DocumentTypeService. Later injected by Spring. */ @@ -634,4 +665,219 @@ 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 + */ + @Test + public void testAddStepComment() throws BusinessException{ + + User goodUser = getTestUser("goodUser"); + _userDAO.create(goodUser); + Study goodStudy = getTestStudy(goodUser); + _studyDAO.create(goodStudy); + getHibernateTemplate().flush(); + StepCommentDTO goodStepCommentDTO = createStepCommentDTO(goodUser, goodStudy); + + //valid DTO, existing params + _stepService.addStepComment(goodStepCommentDTO); + Long id = goodStepCommentDTO.getId(); + 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), + "The comment created in database has wrong data"); + + //valid DTO, non-existing user + { + //get a non-existing id + User badUser = 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 + StepCommentDTO aBadDTO = createStepCommentDTO(badUser, goodStudy); + + try{ + _stepService.addStepComment(aBadDTO); + 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()); + } + } + + //valid DTO, non-existing project element + { + Study badStudy = 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 + StepCommentDTO aBadDTO = createStepCommentDTO(goodUser, badStudy); + + try{ + _stepService.addStepComment(aBadDTO); + Assert.fail("Creation with non-existing user must be failed."); + } + catch(InvalidParameterException e){ + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + } + + //not valid DTO (id filled in) + { + StepCommentDTO aBadDTO = createStepCommentDTO(goodUser, goodStudy); + aBadDTO.setId(goodStepCommentDTO.getId()); + + try { + _stepService.addStepComment(aBadDTO); + Assert.fail("Creation with filled in id must be failed."); + } catch (InvalidParameterException e) { + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + } + } + + /** + * 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 testGetStepComments() throws BusinessException { + + User user = getTestUser("goodUser"); + _userDAO.create(user); + Study study = 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{ + _stepService.getStepComments(step); + 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()); + } + + _studyDAO.create(study); + + StepCommentAttribute matchingStepComment = new StepCommentAttribute( + 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"); + _stepCommentAttributeDAO.create(matchingStepComment); + _stepCommentAttributeDAO.create(notMatchingStepComment); + getHibernateTemplate().flush(); + + List stepComments = _stepService.getStepComments(step); + 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."); + } + + /** + * Create a transient StepCommentDTO. + * + * @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 + */ + 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"); + } + + /** + * Create a transient user. + * + * @param userName the userName + * @return a transient StepCommentDTO + * @throws BusinessException if something's wrong + */ + private User getTestUser(final String userName) throws BusinessException { + + User.Properties uprop = new User.Properties(); + uprop.setUsername(userName) + .setName("TST_Username") + .setFirstName("TST_FirstName") + .setDisplayName("TST_test.user") + .setMailAddress("noreply@salome-platform.org") + .addRole("TST-User"); + uprop.disableCheck(); + User user = new User(uprop); + return user; + } + + /** + * Create a transient study. + * + * @param user the user that will be placed in 'manager' and 'actor' properties + * @return the test study + * @throws BusinessException if something's wrong + */ + private Study getTestStudy(final User user) throws BusinessException{ + Study.Properties studyProps = new Study.Properties(); + studyProps.setActor(user) + .setManager(user) + .setTitle("a test study") + .setDescription("description") + .setDate(new Date()) + .setReference("test reference") + .setSimulationContexts(new ArrayList()) + .setState(ProgressState.inWORK) + .setVisibility(Visibility.PUBLIC); + Study study = new Study(studyProps); + return study; + } + + /** + * Create StepCommentDTO with all the fields filled in from StepCommentAttribute. + * @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() + ); + return stepCommentDTO; + } + + /** + * Compare StepCommentDTO. + * @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()) + && 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.getTitle().equals(b.getTitle()); + } } diff --git a/Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml b/Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml index 897ce9b..319ce10 100644 --- a/Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml +++ b/Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml @@ -62,8 +62,19 @@ + + + + + + + + + + + - + @@ -127,4 +138,10 @@ + + + + + + \ No newline at end of file diff --git a/Workspace/Siman/WebContent/jsp/commentPane.jsp b/Workspace/Siman/WebContent/jsp/commentPane.jsp new file mode 100644 index 0000000..2f16c62 --- /dev/null +++ b/Workspace/Siman/WebContent/jsp/commentPane.jsp @@ -0,0 +1,68 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="s" uri="/struts-tags"%> +<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> + +
+ +
+ + + + +
+ + + + + +
+ " onMouseOver=this.src="" + onMouseOut=this.src="" title=""/> +  
+
+ + +
\ No newline at end of file diff --git a/Workspace/Siman/WebContent/jsp/editKnowledge.jsp b/Workspace/Siman/WebContent/jsp/editKnowledge.jsp index 745e5df..f47f9d9 100644 --- a/Workspace/Siman/WebContent/jsp/editKnowledge.jsp +++ b/Workspace/Siman/WebContent/jsp/editKnowledge.jsp @@ -21,8 +21,8 @@ %> - + <% for (Iterator knowtypes = knowlist.iterator(); knowtypes.hasNext(); ) { AbstractOpenObject.KnowledgeIterator type = knowtypes.next(); @@ -114,6 +114,7 @@
+ diff --git a/Workspace/Siman/WebContent/jsp/readComment.jsp b/Workspace/Siman/WebContent/jsp/readComment.jsp index 69345cd..fe5b445 100644 --- a/Workspace/Siman/WebContent/jsp/readComment.jsp +++ b/Workspace/Siman/WebContent/jsp/readComment.jsp @@ -2,13 +2,20 @@ pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags" %> - - - - - - - -
- " border="none" title="" /> -  
\ No newline at end of file + + + + + + + + + + +
+ + , +
+
+
+
diff --git a/Workspace/Siman/WebContent/rtef/richtext.js b/Workspace/Siman/WebContent/rtef/richtext.js index 3dada53..3f5671c 100644 --- a/Workspace/Siman/WebContent/rtef/richtext.js +++ b/Workspace/Siman/WebContent/rtef/richtext.js @@ -269,7 +269,7 @@ function writeRichText(rte, html, css, width, height, buttons, readOnly, fullscr document.writeln(''); insertBar(); if(fullscreen || activeCommand.get("save") != null){ - document.writeln(''); + document.writeln(''); nbcommand += 1; } if(!isSafari && !isKonqueror) { diff --git a/Workspace/Siman/WebContent/study/displayStudyStep.jsp b/Workspace/Siman/WebContent/study/displayStudyStep.jsp index 95b721d..7803b46 100644 --- a/Workspace/Siman/WebContent/study/displayStudyStep.jsp +++ b/Workspace/Siman/WebContent/study/displayStudyStep.jsp @@ -1,6 +1,7 @@ <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> +<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> @@ -17,6 +18,7 @@ +