Salome HOME
Show and Edit comments functionalities are implemented
authormka <mka@opencascade.com>
Thu, 14 Feb 2013 07:13:16 +0000 (07:13 +0000)
committermka <mka@opencascade.com>
Thu, 14 Feb 2013 07:13:16 +0000 (07:13 +0000)
24 files changed:
Workspace/Siman-Common/src/conf/log-messages.properties
Workspace/Siman-Common/src/conf/log-messages_en.properties
Workspace/Siman-Common/src/org/splat/common/properties/MessageKeyEnum.java
Workspace/Siman-Common/src/org/splat/dal/bo/som/Attributes.hbm.xml
Workspace/Siman-Common/src/org/splat/dal/bo/som/StepCommentAttribute.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAO.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/dal/dao/som/StepCommentAttributeDAOImpl.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/exception/InvalidParameterException.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/service/StepService.java
Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/dto/StepCommentDTO.java [new file with mode: 0644]
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman-Common/src/spring/daoContext.xml
Workspace/Siman-Common/src/test/splat/service/TestStepService.java
Workspace/Siman/WebContent/WEB-INF/tiles/tiles-defs.xml
Workspace/Siman/WebContent/jsp/commentPane.jsp [new file with mode: 0644]
Workspace/Siman/WebContent/jsp/editKnowledge.jsp
Workspace/Siman/WebContent/jsp/readComment.jsp
Workspace/Siman/WebContent/rtef/richtext.js
Workspace/Siman/WebContent/study/displayStudyStep.jsp
Workspace/Siman/src/org/splat/simer/DisplayStudyStepAction.java
Workspace/Siman/src/org/splat/simer/EditStepCommentAction.java [new file with mode: 0644]
Workspace/Siman/src/spring/applicationContext.xml
Workspace/Siman/src/struts.xml

index a19abedba2b3cfdaab7a2af35fd162a2b058cee6..21123199d593b0d441ed5395e6259a1c4eabd7d2 100644 (file)
@@ -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}
index a19abedba2b3cfdaab7a2af35fd162a2b058cee6..21123199d593b0d441ed5395e6259a1c4eabd7d2 100644 (file)
@@ -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}
index b532f006d2bee8f5f2ea2831a2f412b5c543f6e4..27be5b2fbd0931724e3cf40eae73b4d911cfe675 100644 (file)
@@ -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) {
index cda4ad8e98e10e0ee92a66c3e7480492d6bb517f..2072446520dc057ceaeae3b76902491aef5da8fe 100644 (file)
        <union-subclass name="org.splat.dal.bo.som.CommentAttribute"
                extends="org.splat.dal.bo.kernel.TextAttribute" table="comment_attr">
        </union-subclass>
+       
+       <!-- Step Comment attribute
+       -->
+       <union-subclass name="org.splat.dal.bo.som.StepCommentAttribute"
+               extends="org.splat.dal.bo.kernel.TextAttribute" table="step_comment">
+               
+               <many-to-one name="user" column="user" not-null="true" />       
+           <property name="date" column="date" not-null="true" />
+           <property name="step" column="step" not-null="true" />
+        <property name="title" column="title" not-null="true" type="text"/>
+       </union-subclass>       
 
 </hibernate-mapping>
\ 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 (file)
index 0000000..0266e18
--- /dev/null
@@ -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 (file)
index 0000000..ee5e493
--- /dev/null
@@ -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 <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
+ *
+ */
+public interface StepCommentAttributeDAO extends GenericDAO<StepCommentAttribute, Long> {
+}
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 (file)
index 0000000..992d9c5
--- /dev/null
@@ -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<StepCommentAttribute, Long> implements StepCommentAttributeDAO {
+
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.dal.dao.kernel.AbstractGenericDAOImpl#getType()
+        */
+       @Override
+       protected Class<StepCommentAttribute> 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 (file)
index 0000000..45630c1
--- /dev/null
@@ -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();
+       }
+}
index a4071b12dda117775b3674fea6d429dcf7287783..1576adb3a82dde7ab577c74acdf3022e5891d89c 100644 (file)
@@ -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<DocumentType> 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<StepCommentDTO> getStepComments(final Step step) throws InvalidParameterException;
 }
index f5d5c401d67ac03fb25c3ce73abfa054dd209f59..47d096253daee1715ae9d9f0569a6616c5527634 100644 (file)
@@ -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<DocumentType> 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<StepCommentDTO> 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<StepCommentAttribute> comments = _stepCommentAttributeDAO.getFilteredList(
+                               Restrictions.and(
+                                               Restrictions.eq("step", Integer.valueOf(step.getNumber())),
+                                               Restrictions.eq("owner", owner)));
+               List<StepCommentDTO> commentDTOs = new ArrayList<StepCommentDTO>();
+               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 (file)
index 0000000..41de0f2
--- /dev/null
@@ -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;
+       }
+}
index ec8070f662602c725595f2e5827302d95cc12088..199904679f1133c903cba8925bf05cfe0cb99581 100644 (file)
@@ -121,6 +121,8 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="projectElementDAO" ref="projectElementDAO" />
                <property name="projectSettings" ref="projectSettings" />
                <property name="versionsRelationDAO" ref="versionsRelationDAO" />
+               <property name="stepCommentAttributeDAO" ref="stepCommentAttributeDAO" />
+               <property name="userDAO" ref="userDAO" />
        </bean>
 
        <bean id="simulationContextService"
index 168201b6d4c3a85e765814219ce46c53ed74cd55..eac924fab9d16da5dad8dc0b792dc5cc33557f47 100644 (file)
@@ -58,6 +58,10 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
         class="org.splat.dal.dao.som.CommentAttributeDAOImpl">
     </bean>
     
+    <bean id="stepCommentAttributeDAO" parent="genericDAO"
+        class="org.splat.dal.dao.som.StepCommentAttributeDAOImpl">
+    </bean>
+    
     <bean id="usesRelationDAO" parent="genericDAO"
         class="org.splat.dal.dao.som.UsesRelationDAOImpl">
     </bean>
index 7a83e0068ef157c201bac6d83a63a3cffa6a3d82..92329d53107573a10bd9b2240b55b6beaab533c0 100644 (file)
@@ -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<StepCommentDTO> 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<SimulationContext>())
+                               .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());
+       }
 }
index 897ce9b48ab747526169c48f539d4a10d0817547..319ce104b4b26eab13ea71c7865a8bd896e7eaf5 100644 (file)
        <put-attribute name="presentation_pane"   value="/study/searchKnowledge.jsp"/>
 </definition>
 
+<!-- BEGIN: Display Study -->
+<definition name="zone.stepcomments"  template="/jsp/readComment.jsp"/>
+
+<definition name="page.stepcomments" template="/jsp/commentPane.jsp">
+    <put-attribute name="display_comments_pane"   value="zone.stepcomments"/>
+</definition>
+
+<definition name="zone.displaystudy" template="/study/displayStudyStep.jsp">
+    <put-attribute name="step_comments_pane" value="page.stepcomments" />
+</definition>
+
 <definition name="page.displaystudy" extends="baseLayout">
-    <put-attribute name="presentation_pane"   value="/study/displayStudyStep.jsp"/>
+        <put-attribute name="presentation_pane" value="zone.displaystudy"/>
 </definition>
 <!-- RKV: BEGIN: Simulation contexts -->
 <definition name="page.newcontext" extends="baseLayout">
 <definition name="page.importerror" extends="baseLayout">
        <put-attribute name="presentation_pane"   value="/study/importError.jsp"/>
 </definition>
+
+<definition name="page.comparestudy" extends="baseLayout">
+    <put-attribute name="left_menus"   value="/jsp/comparisonResult.jsp"/>
+    <put-attribute name="presentation_pane"   value="/study/comparison.jsp"/>
+</definition>
+
 </tiles-definitions>
\ 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 (file)
index 0000000..2f16c62
--- /dev/null
@@ -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"%>
+
+<div id="display_comments_div">
+  <tiles:insertAttribute name="display_comments_pane" ignore="true" />
+</div>
+
+<s:if test="%{writeAccess == 'true' && stepEnabled == 'true'}">
+       <script type="text/javascript">
+           $(document).ready(function(){
+               $("#comments_form").ajaxForm({
+                   target: '#display_comments_div'
+               });
+           
+               // Bind the add button
+                   $("#add_button").click(function() {
+                     document.getElementById("add_button_div").style.display = 'none';
+                     document.getElementById("add_comments_div").style.display = 'block';
+                   });
+                   
+                   function hideEditor() {
+                 document.getElementById("add_button_div").style.display = 'block';
+                 document.getElementById("add_comments_div").style.display = 'none';
+                 document.getElementById(currentRTE).contentDocument.body.innerHTML='';    //clean input area
+                 document.getElementById("commentTitle").value='';
+               }
+                   
+                   // Bind the cancel button
+                   $("#cancel_button").click(hideEditor);
+                   
+                   // Bind the submit button
+               $('#comments_form').on('submit', hideEditor);
+           });
+       </script>
+       
+       <div id="add_button_div">
+         <table width="100%" cellpadding="0" cellspacing="0" border="0" class="attribute">
+           <tr>
+             <td width="20" height="20" align="center">
+               <img id="add_button" src="<s:url value="/skin/icon.add.png"/>" onMouseOver=this.src="<s:url value="/skin/icon.addhot.png"/>"
+                   onMouseOut=this.src="<s:url value="/skin/icon.add.png"/>" title="<s:text name="tooltip.addcomment"/>"/>
+              </td>
+             <td>&nbsp;</td>
+           </tr>
+         </table>  
+       </div>
+       
+       <div id="add_comments_div" style="display: none;">
+       <form name="comments_form" id="comments_form" action="create-stepComment" method="post">
+         <table width="100%" cellpadding="0" cellspacing="0" border="0" class="attribute">
+           <tr valign="top">
+             <td width="20" height="20" align="center">
+               <img id="cancel_button" src="<s:url value="/skin/icon.undo.png"/>"
+                   title="<s:text name="tooltip.cancel"/>" />
+             </td>
+             <td>
+            <input type="text" name="commentTitle" id="commentTitle">
+               <script language='JavaScript'>
+                   displayTextEditor('commentValue', '', 650, 150);
+               </script>   
+             </td>
+           </tr>
+         </table> 
+       </form>
+       </div>
+</s:if>
\ No newline at end of file
index 745e5df750050bce8045962344161b5ad64eaee1..f47f9d9331c3946347b399ee58630699718fb755 100644 (file)
@@ -21,8 +21,8 @@
 %>
 <s:url id="undo" namespace="/study" action="step-study"></s:url>
 
-<input type=hidden name=knowledgeType value="<%=typenumber%>"/>
 <table width=100% cellpadding=0 cellspacing=0 border=0 class=text>
+<input type=hidden name=knowledgeType value="<%=typenumber%>"/>
 <%
     for (Iterator<AbstractOpenObject.KnowledgeIterator> knowtypes = knowlist.iterator(); knowtypes.hasNext(); ) {
        AbstractOpenObject.KnowledgeIterator type = knowtypes.next();
         </table>
       </td>
       <td>
+        <input type=hidden name=text>
         <script language='JavaScript' type='text/javascript'>
 <%        out.print("displayTextEditor('knowledgeValue', '<p>&nbsp;</p>', 450, 150);");
 %>      </script>
index 69345cd8fcddeb59c2eb4bd467d7b6165428528d..fe5b44573e0e8ffc367b5260a4a17f0310275e91 100644 (file)
@@ -2,13 +2,20 @@
     pageEncoding="ISO-8859-1"%>
 <%@ taglib prefix="s" uri="/struts-tags"
 %>
-<table width=100% cellpadding=0 cellspacing=0 border=0 class=attribute>
-  <tr height=22 valign=bottom>
-    <s:if test="%{writeAccess == 'true' && stepEnabled == 'true' && userRights.canAddComment()}">
-      <td width=20 align=center>
-        <img src="<s:url value="/skin/icon.add.png"/>" border="none" title="<s:text name="tooltip.addcomment"/>" />
-      </td>
-      <td>&nbsp;</td>
-    </s:if>
-  </tr>
-</table>
\ No newline at end of file
+<s:if test="%{comments != null && !comments.isEmpty()}">
+  <table width="100%" cellpadding="0" cellspacing="5" border="0" class="attribute">
+    <s:iterator var="current" value="comments">
+      <tr>
+        <td width="20" height="20" align="center">
+        </td>
+        <td>
+          <s:date name="#current.date" format="dd.MM.yyyy" />, <s:property value="#current.title"/>
+          <br><s:property value="#current.text" escapeHtml="false"/>
+          <br><s:property value="#current.user.displayName"/>
+        </td> 
+      </tr>
+      <tr height="1" bgcolor="#AAAAAA"><td colspan="2"></td></tr>
+    </s:iterator>
+  </table>
+</s:if>
index 3dada53abc36cea1123b0866b021f3c833006638..3f5671c3a7dfe3c50155fac833001fbc9136a7bd 100644 (file)
@@ -269,7 +269,7 @@ function writeRichText(rte, html, css, width, height, buttons, readOnly, fullscr
                  document.writeln('<tbody><tr>');
                  insertBar();
                  if(fullscreen || activeCommand.get("save") != null){
-                         document.writeln('<td><input type="image" class="rteImg" src="'+imagesPath+'save.gif" alt="'+lblSave+'" title="'+lblSave+'" onmouseover="this.className=\'rteImgUp\'" onmouseout="this.className=\'rteImg\'" onmousedown="this.className=\'rteImgDn\'" onmouseup="this.className=\'rteImgUp\'" onClick="submitEdit()"></td>');
+                         document.writeln('<td><input type="image" class="rteImg" src="'+imagesPath+'save.gif" alt="'+lblSave+'" title="'+lblSave+'" onmouseover="this.className=\'rteImgUp\'" onmouseout="this.className=\'rteImg\'" onmousedown="this.className=\'rteImgDn\'" onmouseup="this.className=\'rteImgUp\'" onClick="prepareSubmitEdit(currentRTE)"></td>');
                          nbcommand += 1;
                  }
                  if(!isSafari && !isKonqueror) {
index 95b721d50d3b94b3bf2ade3be5d292b1e094dc97..7803b465857912eddf7867019ec56edba2606b69 100644 (file)
@@ -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"%>
 <!-- Initialization of the edit action, if any
      =============================================================================================================================
   -->
@@ -17,6 +18,7 @@
     <script language="JavaScript" type="text/javascript" src="<s:url value="/rtef/xhtml.js"/>"></script>
     <script language="JavaScript" type="text/javascript" src="<s:url value="/js/popup.js"/>"></script>
     <script language="JavaScript" type="text/javascript" src="<s:url value="/js/action.js"/>"></script>
+    <script language="JavaScript" type="text/javascript" src="<s:url value="/js/jquery.form.js"/>"></script>       
 
     <script language="JavaScript">
     
       }
       return html;
     }
-    function submitEdit () {
+    
+    function prepareSubmitEdit (currentRTE) { //invoked         for all editors,with ajax and regular submit functionality
 //  ----------------------     
-      updateRTEs();   // Sets the value of knowledgeValue input    
-      edit.knowledgeValue.value = clean(edit.knowledgeValue.value);
-      edit.submit();
+      updateRTEs();   // Sets the value of the input    
+      var currentInput = document.getElementsByName(currentRTE)[0];
+      currentInput.value = clean(currentInput.value);
+      return false;
     }
+    
     $(document).ready(function (){
         initialize('<%=action%>');
     });
           </s:else>
         </div>
       </div>
+      </s:if> 
 
 <!-- Comment section
      =============================================================================================================================
   -->
-      <s:if test="%{writeAccess == 'true' && stepEnabled == 'true'}">
-      <div id=article-box>
+            <div id=article-box>
         <div id=section><s:text name="title.comment"/></div>
         <div id=article-body class=text>
-          <jsp:include page="/jsp/readComment.jsp"/>
+            <tiles:insertAttribute name="step_comments_pane" ignore="true" />
         </div>
       </div>
-      </s:if>
-      </s:if>
index 82dca6d924169e80c05f68f8b9a5488da61c51e6..f8523e137db8092e6a34c1d151f2caecf356ff73 100644 (file)
@@ -4,7 +4,10 @@ import java.util.List;
 
 import org.splat.dal.bo.som.ProjectElement;
 import org.splat.dal.bo.som.Scenario;
+import org.splat.exception.InvalidParameterException;
+import org.splat.service.StepService;
 import org.splat.service.StudyService;
+import org.splat.service.dto.StepCommentDTO;
 import org.splat.som.StepRights;
 import org.splat.wapp.Constants;
 import org.splat.wapp.PopupMenu;
@@ -32,6 +35,16 @@ public class DisplayStudyStepAction extends AbstractDisplayAction {
         * Injected study service.
         */
        private StudyService _studyService;
+       
+       /**
+        * Step comments.
+        */
+       private List<StepCommentDTO> _comments = null;
+
+       /**
+        * Injected Step Service.
+        */
+       private StepService _stepService;
 
        // ==============================================================================================================================
        // Action methods
@@ -88,6 +101,7 @@ public class DisplayStudyStepAction extends AbstractDisplayAction {
 
                        setMenu();
                }
+               loadComments();
                return res;
        }
 
@@ -172,6 +186,18 @@ public class DisplayStudyStepAction extends AbstractDisplayAction {
                return SUCCESS;
        }
 
+       /**
+        * Loads step comments (if already loaded - reloads).
+        */
+       public void loadComments() {
+               try {
+                       _comments = _stepService.getStepComments(_openStudy.getSelectedStep());
+               } catch(InvalidParameterException exception) {
+                       _comments = null;
+                       LOG.debug("Error while trying to add comment: " + exception.getMessage());
+               }
+       }
+       
        // ==============================================================================================================================
        // Getters
        // ==============================================================================================================================
@@ -242,4 +268,36 @@ public class DisplayStudyStepAction extends AbstractDisplayAction {
                super.setOpenStudy(study);
                _openStudy = study;
        }
+       
+       /**
+        * Get the comments.
+        * @return the comments
+        */
+       public List<StepCommentDTO> getComments() {
+               return _comments;
+       }
+
+       /**
+        * Set the comments.
+        * @param comments the comments to set
+        */
+       public void setComments(final List<StepCommentDTO> comments) {
+               _comments = comments;
+       }
+
+       /**
+        * Get the stepService.
+        * @return the stepService
+        */
+       public StepService getStepService() {
+               return _stepService;
+       }
+
+       /**
+        * Set the stepService.
+        * @param stepService the stepService to set
+        */
+       public void setStepService(final StepService stepService) {
+               _stepService = stepService;
+       }
 }
\ No newline at end of file
diff --git a/Workspace/Siman/src/org/splat/simer/EditStepCommentAction.java b/Workspace/Siman/src/org/splat/simer/EditStepCommentAction.java
new file mode 100644 (file)
index 0000000..ea857b0
--- /dev/null
@@ -0,0 +1,104 @@
+/*****************************************************************************
+ * Company         EURIWARE
+ * Application     SIMAN
+ * File            $Id$
+ * Creation date   Nov 21, 2012
+ * @author         $Author$
+ * @version        $Revision$
+ *****************************************************************************/
+
+package org.splat.simer;
+
+import java.util.Date;
+
+import org.splat.exception.InvalidParameterException;
+import org.splat.service.dto.StepCommentDTO;
+/**
+ * Step comment creation/modification action.
+ *
+ */
+public class EditStepCommentAction extends DisplayStudyStepAction {
+
+       /**
+        * Serial version ID.
+        */
+       private static final long serialVersionUID = 6467920934724352021L;
+
+       /**
+        * The value of the comment.
+        */
+       private String _commentValue;
+
+       /**
+        * The title of the comment.
+        */
+       private String _commentTitle;
+
+       // ==============================================================================================================================
+       // Action methods
+       // ==============================================================================================================================
+
+       /**
+        * Creation of a new comment.
+        * @return SUCCESS if operation succeeded, ERROR if Runtime exception, otherwise INPUT
+        */
+       public String doCreate() {
+               String res = INPUT;
+               if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()
+                               && _commentValue!=null  && _commentValue.length()>0
+                               && _commentTitle!=null  && _commentTitle.length()>0) {
+
+                       StepCommentDTO stepCommentDTO = new StepCommentDTO(
+                                       null,   //id must be null
+                                       _commentValue,
+                                       getOpenStudy().getSelectedStep().getOwner().getIndex(),
+                                       getOpenStudy().getSelectedStep().getNumber(),
+                                       new Date(),     //current date and time
+                                       getConnectedUser().getRid(),
+                                       null,   //userName is unnecessary
+                                       _commentTitle
+                               );
+                       try {
+                               getStepService().addStepComment(stepCommentDTO);
+                               res = SUCCESS;
+                       } catch (InvalidParameterException error) {
+                               LOG.debug("Error while trying to add comment: " + error.getMessage());
+                               res = INPUT;
+                       }
+               }
+               loadComments();
+               return res;
+       }
+
+       /**
+        * Get the commentValue.
+        * @return the commentValue
+        */
+       public String getCommentValue() {
+               return _commentValue;
+       }
+
+       /**
+        * Set the commentValue.
+        * @param commentValue the commentValue to set
+        */
+       public void setCommentValue(final String commentValue) {
+               _commentValue = commentValue;
+       }
+
+       /**
+        * Get the commentTitle.
+        * @return the commentTitle
+        */
+       public String getCommentTitle() {
+               return _commentTitle;
+       }
+
+       /**
+        * Set the commentTitle.
+        * @param commentTitle the commentTitle to set
+        */
+       public void setCommentTitle(final String commentTitle) {
+               _commentTitle = commentTitle;
+       }
+}
index d3dfbf17ccc7db52a18ce54176323db1cbde0a37..47ee0e96011b05cc77df5c03d95f058366ef3245 100644 (file)
@@ -152,6 +152,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                class="org.splat.simer.DisplayStudyStepAction" parent="baseAction"
                scope="prototype">
                <property name="studyService" ref="studyService" />
+               <property name="stepService" ref="stepService" />
        </bean>
 
        <!--========= Inherited from displayStudyStepAction ========= -->
@@ -203,6 +204,17 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
                        ref="knowledgeElementTypeService" />
                <property name="scenarioService" ref="scenarioService" />
        </bean>
+       
+       <bean id="editStepCommentAction"
+        class="org.splat.simer.EditStepCommentAction" scope="prototype"
+        parent="displayStudyStepAction">
+    </bean>
+    
+    <!-- bean id="CompareStudyAction"
+        class="org.splat.simer.CompareStudyAction" scope="prototype"
+        parent="displayStudyStepAction">
+        <property name="studyService" ref="studyService" />
+    </bean-->
 
        <!-- End of Inherited from displayStudyStepAction -->
 
index 051dd994b0c49f2f1bfdfb2e38af3ef3dd11b556..4dadb4c340a31bac0183411ffa434c72065593a9 100644 (file)
                                page.displaystudy
                        </result>
                </action>
-
+               
+               <!-- Edition of step
+          -->
+        <action name="create-stepComment" class="editStepCommentAction" method="create">
+            <result name="success" type="tiles">zone.stepcomments</result>
+            <result name="input" type="tiles">zone.stepcomments</result>
+        </action>
+        
+        <!-- Comparison of studies
+          -->     
+        <action name="init-study-comparison" class="CompareStudyAction" method="initComparison">
+            <result name="success" type="tiles">page.comparestudy</result>
+            <result name="error" type="tiles">page.comparestudy</result>
+        </action>
+        <action name="compare-studies" class="CompareStudyAction" method="compare">
+            <result name="success" type="tiles">page.comparestudy</result>
+            <result name="error" type="tiles">page.comparestudy</result>
+        </action>
        </package>