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}
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}
/**
* 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) {
<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
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+}
--- /dev/null
+/*****************************************************************************
+ * 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> {
+}
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+
+}
--- /dev/null
+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();
+ }
+}
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;
/**
* @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;
}
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.
*
*/
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,
*
* @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) {
*
* @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) {
*
* @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,
*
* @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 {
* @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)
* the study step
* @return the list of document types
*/
+ @Override
public List<DocumentType> getValidDocumentTypes(final Step aStep) {
return getDocumentTypeService().selectTypesOf(aStep.getStep());
}
* 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) {
* 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
* @throws DocumentIsUsedException
* if the document is used by other documents
*/
+ @Override
@Transactional
public boolean removeDocument(final Step aStep, final long docId)
throws DocumentIsUsedException {
}
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.
private ProjectSettingsService getProjectSettings() {
return _projectSettings;
}
-
+
/**
* Set project settings service.
*
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.
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+}
<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"
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>
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;
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;
@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.
*/
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());
+ }
}
<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
--- /dev/null
+<%@ 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> </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
%>
<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> </p>', 450, 150);");
%> </script>
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> </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>
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) {
<%@ 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
=============================================================================================================================
-->
<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>
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;
* Injected study service.
*/
private StudyService _studyService;
+
+ /**
+ * Step comments.
+ */
+ private List<StepCommentDTO> _comments = null;
+
+ /**
+ * Injected Step Service.
+ */
+ private StepService _stepService;
// ==============================================================================================================================
// Action methods
setMenu();
}
+ loadComments();
return res;
}
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
// ==============================================================================================================================
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
--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+}
class="org.splat.simer.DisplayStudyStepAction" parent="baseAction"
scope="prototype">
<property name="studyService" ref="studyService" />
+ <property name="stepService" ref="stepService" />
</bean>
<!--========= Inherited from displayStudyStepAction ========= -->
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 -->
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>