Salome HOME
Compare method signature and DocToCompareDTO are added.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / StepServiceImpl.java
index f5d5c401d67ac03fb25c3ce73abfa054dd209f59..9e94849f9ffb93169ff9266b9c90f2a3a089075c 100644 (file)
@@ -14,41 +14,51 @@ 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.
- * 
+ *
  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  */
 public class StepServiceImpl implements StepService {
@@ -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,
@@ -123,9 +145,10 @@ public class StepServiceImpl implements StepService {
 
        /**
         * {@inheritDoc}
-        * 
+        *
         * @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) {
@@ -155,7 +178,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Update lucene index of knowledge elements of a scenario or a study which the given step is related to.
-        * 
+        *
         * @param aStep
         *            the step (activity)
         */
@@ -185,7 +208,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Update lucene index for knowledge elements of the scenario.
-        * 
+        *
         * @param scene
         *            the scenario
         * @throws IOException
@@ -208,9 +231,10 @@ public class StepServiceImpl implements StepService {
 
        /**
         * {@inheritDoc}
-        * 
+        *
         * @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) {
@@ -234,9 +258,10 @@ public class StepServiceImpl implements StepService {
 
        /**
         * {@inheritDoc}
-        * 
+        *
         * @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,
@@ -269,9 +294,10 @@ public class StepServiceImpl implements StepService {
 
        /**
         * {@inheritDoc}
-        * 
+        *
         * @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 {
@@ -291,7 +317,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Create a new version of a document in the given study step.
-        * 
+        *
         * @param aStep
         *            the study step
         * @param base
@@ -316,7 +342,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Create a new version of a document in the given study step.
-        * 
+        *
         * @param aStep
         *            the study step
         * @param base
@@ -345,7 +371,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Create a new version of a document in the given study step.
-        * 
+        *
         * @param aStep
         *            the study step
         * @param base
@@ -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)
@@ -418,24 +445,26 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get document types which are applicable for the given study step (activity).
-        * 
+        *
         * @param aStep
         *            the study step
         * @return the list of document types
         */
+       @Override
        public List<DocumentType> getValidDocumentTypes(final Step aStep) {
                return getDocumentTypeService().selectTypesOf(aStep.getStep());
        }
 
        /**
         * Add a document publication to the given step.
-        * 
+        *
         * @param aStep
         *            the target study step
         * @param newdoc
         *            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) {
@@ -449,13 +478,14 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Remove a document publication from the given step.
-        * 
+        *
         * @param aStep
         *            the study step
         * @param oldoc
         *            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 {
@@ -527,11 +558,132 @@ 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);
+       }
+
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.service.StepService#getStepComments(org.splat.som.Step)
+        */
+       @Override
+       @Transactional(readOnly = true)
+       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;
+       }
+       
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.service.StepService#removeStepComment(long)
+        */
+       @Override
+       @Transactional
+       public void removeStepComment(final long commentId) throws InvalidParameterException {
+               StepCommentAttribute stepComment = _stepCommentAttributeDAO.get(Long.valueOf(commentId));
+               if(stepComment == null) {
+                       throw new InvalidParameterException("commentId",String.valueOf(commentId));
+               }
+               _stepCommentAttributeDAO.delete(stepComment);
+       }
+
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.service.StepService#editStepComment(long, java.lang.String, java.lang.String)
+        */
+       @Override
+       @Transactional
+       public void editStepComment(final long commentId, final String newValue, final String newTitle)
+                       throws InvalidParameterException {
+               StepCommentAttribute comment = _stepCommentAttributeDAO.get(Long.valueOf(commentId));
+               if(comment == null) {
+                       throw new InvalidParameterException("commentId",String.valueOf(commentId));
+               }
+               if(newTitle != null) {
+                       comment.setTitle(newTitle);
+               }
+               if(newValue != null) {
+                       comment.setValue(newValue);
+               }
+               _stepCommentAttributeDAO.update(comment);
+       }
+
+       /** 
+        * {@inheritDoc}
+        * @see org.splat.service.StepService#isCommentMadeByUser(long, long)
+        */
+       @Override
+       @Transactional(readOnly = true)
+       public boolean isCommentMadeByUser(final long commentId, final long userId)
+                       throws InvalidParameterException {
+               StepCommentAttribute comment = _stepCommentAttributeDAO.get(Long.valueOf(commentId));
+               if(comment == null) {
+                       throw new InvalidParameterException("commentId", String.valueOf(commentId));
+               }
+               return comment.getUser().getIndex() == userId;
+       }
+       
        /**
         * Get the documentService.
-        * 
+        *
         * @return the documentService
         */
        public DocumentService getDocumentService() {
@@ -540,7 +692,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the documentService.
-        * 
+        *
         * @param documentService
         *            the documentService to set
         */
@@ -550,7 +702,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the simulationContextService.
-        * 
+        *
         * @return the simulationContextService
         */
        public SimulationContextService getSimulationContextService() {
@@ -559,7 +711,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the simulationContextService.
-        * 
+        *
         * @param simulationContextService
         *            the simulationContextService to set
         */
@@ -570,7 +722,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the documentDAO.
-        * 
+        *
         * @return the documentDAO
         */
        public DocumentDAO getDocumentDAO() {
@@ -579,7 +731,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the documentDAO.
-        * 
+        *
         * @param documentDAO
         *            the documentDAO to set
         */
@@ -589,7 +741,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the simulationContextDAO.
-        * 
+        *
         * @return the simulationContextDAO
         */
        public SimulationContextDAO getSimulationContextDAO() {
@@ -598,7 +750,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the simulationContextDAO.
-        * 
+        *
         * @param simulationContextDAO
         *            the simulationContextDAO to set
         */
@@ -609,7 +761,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the projectElementDAO.
-        * 
+        *
         * @return the projectElementDAO
         */
        public ProjectElementDAO getProjectElementDAO() {
@@ -618,7 +770,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the projectElementDAO.
-        * 
+        *
         * @param projectElementDAO
         *            the projectElementDAO to set
         */
@@ -628,7 +780,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the indexService.
-        * 
+        *
         * @return the indexService
         */
        public IndexService getIndexService() {
@@ -637,7 +789,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the indexService.
-        * 
+        *
         * @param indexService
         *            the indexService to set
         */
@@ -647,7 +799,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the fileDAO.
-        * 
+        *
         * @return the fileDAO
         */
        public FileDAO getFileDAO() {
@@ -656,7 +808,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the fileDAO.
-        * 
+        *
         * @param fileDAO
         *            the fileDAO to set
         */
@@ -666,7 +818,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the documentTypeService.
-        * 
+        *
         * @return the documentTypeService
         */
        public DocumentTypeService getDocumentTypeService() {
@@ -675,7 +827,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the documentTypeService.
-        * 
+        *
         * @param documentTypeService
         *            the documentTypeService to set
         */
@@ -686,7 +838,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the versionsRelationDAO.
-        * 
+        *
         * @return the versionsRelationDAO
         */
        public VersionsRelationDAO getVersionsRelationDAO() {
@@ -695,7 +847,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the versionsRelationDAO.
-        * 
+        *
         * @param versionsRelationDAO
         *            the versionsRelationDAO to set
         */
@@ -706,7 +858,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get project settings.
-        * 
+        *
         * @return Project settings service
         */
        private ProjectSettingsService getProjectSettings() {
@@ -715,7 +867,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set project settings service.
-        * 
+        *
         * @param projectSettingsService
         *            project settings service
         */
@@ -724,6 +876,38 @@ public class StepServiceImpl implements StepService {
                _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.
         *