Salome HOME
Show and Edit description functionalities are implemented
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / StepServiceImpl.java
index d40b87a50d22c329a76ec721b96721a337ea5b29..af8ffcb90112268733c14743203b04d3f23f9c81 100644 (file)
 package org.splat.service;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
-import java.util.Vector;
 
+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.Study;
+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.
  * 
@@ -53,7 +66,7 @@ public class StepServiceImpl implements StepService {
        /**
         * logger for the service.
         */
-       public final static AppLogger logger = AppLogger
+       public final static AppLogger LOG = AppLogger
                        .getLogger(StepServiceImpl.class);
        /**
         * Injected index service.
@@ -71,6 +84,10 @@ public class StepServiceImpl implements StepService {
         * Injected document DAO.
         */
        private DocumentDAO _documentDAO;
+       /**
+        * Injected relation DAO.
+        */
+       private RelationDAO _relationDAO;
        /**
         * Injected file DAO.
         */
@@ -87,15 +104,40 @@ public class StepServiceImpl implements StepService {
         * Injected project element DAO.
         */
        private ProjectElementDAO _projectElementDAO;
+       /**
+        * Injected versions relation DAO.
+        */
+       private VersionsRelationDAO _versionsRelationDAO;
+       /**
+        * Injected project service.
+        */
+       private ProjectSettingsService _projectSettings;
+       /**
+        * Injected publication DAO.
+        */
+       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)
         */
-       public SimulationContext addSimulationContext(Step aStep,
-                       SimulationContext.Properties dprop) throws MissedPropertyException,
-                       InvalidPropertyException, MultiplyDefinedException {
+       @Override
+       public SimulationContext addSimulationContext(final Step aStep,
+                       final SimulationContext.Properties dprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException {
                SimulationContext context = new SimulationContext(dprop.setStep(aStep
                                .getStep()));
                return addSimulationContext(aStep, context);
@@ -106,27 +148,32 @@ 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(Step aStep,
-                       SimulationContext context) {
+       public SimulationContext addSimulationContext(final Step aStep,
+                       final SimulationContext context) {
+               SimulationContext res = null;
                getSimulationContextService().hold(context); // Increments the reference count of simulation context
-               if (aStep.getOwner().isSaved())
+               if (aStep.getOwner().isSaved()) {
                        try {
-                               if (!context.isSaved())
+                               if (!context.isSaved()) {
                                        getSimulationContextDAO().create(context);
+                               }
                                aStep.getOwner().add(context);
                                aStep.getContex().add(context); // The context is also referenced from this (transient) Step
                                getProjectElementDAO().update(aStep.getOwner());
                                updateKnowledgeElementsIndex(aStep);
+                               res = context;
                        } catch (Exception error) {
-                               return null;
+                               LOG.debug(error.getMessage(), error);
                        }
-               else { // Happens when copying a scenario
+               else { // Happens when copying a scenario
                        aStep.getOwner().add(context);
                        aStep.getContex().add(context); // The context is also referenced from this (transient) Step
                        // In case of owner scenario, the Knowledge Element index will be updated later, when saving the scenario
+                       res = context;
                }
-               return context;
+               return res;
        }
 
        /**
@@ -135,7 +182,7 @@ public class StepServiceImpl implements StepService {
         * @param aStep
         *            the step (activity)
         */
-       private void updateKnowledgeElementsIndex(Step aStep) {
+       private void updateKnowledgeElementsIndex(final Step aStep) {
                Scenario[] scenarii;
                if (aStep.getOwner() instanceof Scenario) {
                        scenarii = new Scenario[1];
@@ -155,8 +202,7 @@ public class StepServiceImpl implements StepService {
                                updateScenarioIndex(scene);
                        }
                } catch (Exception error) {
-                       logger.error("Unable to re-index Knowledge Elements, reason:",
-                                       error);
+                       LOG.error("Unable to re-index Knowledge Elements, reason:", error);
                }
        }
 
@@ -168,13 +214,14 @@ public class StepServiceImpl implements StepService {
         * @throws IOException
         *             if can't update lucene index
         */
-       private void updateScenarioIndex(Scenario scene) throws IOException {
+       private void updateScenarioIndex(final Scenario scene) throws IOException {
                if (scene.getUcase() == null) {
                        for (Iterator<KnowledgeElement> i = scene.getKnowledgeElements()
                                        .iterator(); i.hasNext();) {
                                KnowledgeElement kelm = i.next();
-                               if (!kelm.getType().equals("usecase"))
+                               if (!kelm.getType().equals("usecase")) {
                                        continue;
+                               }
                                scene.setUcase(kelm);
                                break;
                        }
@@ -187,13 +234,15 @@ 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(Step aStep, SimulationContext context) {
-               boolean isOk = false;
+       public boolean removeSimulationContext(final Step aStep,
+                       final SimulationContext context) {
                SimulationContext torem = aStep
                                .getSimulationContext(context.getIndex());
 
-               if ((torem != null) && (aStep.getOwner().remove(torem))) {
+               boolean isOk = (torem != null) && (aStep.getOwner().remove(torem));
+               if (isOk) {
 
                        aStep.getContex().remove(torem);
                        getProjectElementDAO().update(aStep.getOwner());
@@ -203,7 +252,6 @@ public class StepServiceImpl implements StepService {
                        } else {
                                getSimulationContextDAO().delete(torem);
                        }
-                       isOk = true;
                }
                return isOk;
        }
@@ -213,22 +261,31 @@ 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(Step aStep, Document.Properties dprop)
-                       throws MissedPropertyException, InvalidPropertyException,
-                       MultiplyDefinedException, IOException {
+       public Publication createDocument(final Step aStep,
+                       final Document.Properties dprop) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException, IOException {
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("Local index before: "
+                                       + aStep.getOwnerStudy().getLastLocalIndex());
+               }
                Document newdoc = new Document(dprop.setOwner(aStep.getOwner())
                                .setStep(aStep.getStep()));
                getDocumentService().generateDocumentId(newdoc, dprop);
 
                // Creation of the save directory
                java.io.File wdir = getDocumentService().getSaveDirectory(newdoc);
-               if (!wdir.exists())
-                       if (!wdir.mkdirs())
-                               throw new IOException(
-                                               "Cannot create the repository vault directory");
+               if ((!wdir.exists()) && (!wdir.mkdirs())) {
+                       throw new IOException(
+                                       "Cannot create the repository vault directory");
+               }
 
                // Identification and save
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("Local index after: "
+                                       + aStep.getOwnerStudy().getLastLocalIndex());
+               }
                getDocumentService().buildReferenceFrom(newdoc, aStep.getOwnerStudy());
                getDocumentDAO().create(newdoc);
 
@@ -240,23 +297,22 @@ public class StepServiceImpl implements StepService {
         * 
         * @see org.splat.service.StepService#assignDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties)
         */
-       public Publication assignDocument(Step aStep, Document.Properties dprop)
-                       throws MissedPropertyException, InvalidPropertyException,
-                       NotApplicableException {
+       @Override
+       public Publication assignDocument(final Step aStep,
+                       final Document.Properties dprop) throws MissedPropertyException,
+                       InvalidPropertyException, NotApplicableException {
                String refid = dprop.getReference();
-               if (refid == null)
-                       return null;
-
-               Document slot = getDocumentService().selectDocument(refid,
-                               new Revision().toString());
-               if (slot == null)
-                       return null;
-               if (!slot.isUndefined())
-                       return null; // Should not happen
-
-               getDocumentService().initialize(slot,
-                               dprop.setOwner(aStep.getOwnerStudy()));
-               return new Publication(slot, aStep.getOwner());
+               Publication res = null;
+               if (refid != null) {
+                       Document slot = getDocumentService().selectDocument(refid,
+                                       new Revision().toString());
+                       if ((slot != null) && (slot.isUndefined())) {
+                               getDocumentService().initialize(slot,
+                                               dprop.setOwner(aStep.getOwnerStudy()));
+                               res = new Publication(slot, aStep.getOwner());
+                       }
+               }
+               return res;
        }
 
        /**
@@ -278,7 +334,7 @@ public class StepServiceImpl implements StepService {
         * @throws MismatchException
         *             if the document is not applicable to the given study step
         */
-       public Publication versionDocument(Step aStep, Publication base)
+       public Publication versionDocument(final Step aStep, final Publication base)
                        throws MissedPropertyException, InvalidPropertyException,
                        MultiplyDefinedException, IOException, MismatchException {
                return versionDocument(aStep, base, new Document.Properties());
@@ -305,10 +361,10 @@ public class StepServiceImpl implements StepService {
         * @throws MismatchException
         *             if the document is not applicable to the given study step
         */
-       public Publication versionDocument(Step aStep, Publication base,
-                       String reason) throws MissedPropertyException,
-                       InvalidPropertyException, MultiplyDefinedException, IOException,
-                       MismatchException {
+       public Publication versionDocument(final Step aStep,
+                       final Publication base, final String reason)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException, IOException, MismatchException {
                return versionDocument(aStep, base, new Document.Properties()
                                .setDescription(reason));
        }
@@ -334,19 +390,33 @@ public class StepServiceImpl implements StepService {
         * @throws MismatchException
         *             if the document is not applicable to the given study step
         */
+       @Override
        @Transactional
-       public Publication versionDocument(Step aStep, Publication base,
-                       Document.Properties dprop) throws MissedPropertyException,
-                       InvalidPropertyException, MultiplyDefinedException, IOException,
-                       MismatchException {
+       public Publication versionDocument(final Step aStep,
+                       final Publication base, final Document.Properties dprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException, IOException, MismatchException {
                Document previous = base.value();
 
-               dprop.setDocument(previous); // Initializes the Step property
-               if (dprop.getStep().getNumber() != aStep.getNumber())
+               // RKV: Keep the new file format if it is related to the same document type on this step.
+               String newFormat = dprop.getFormat();
+
+               dprop.setDocument(previous, getProjectSettings().getStep(
+                               base.getStep().getNumber())); // Initializes the Step property
+               if (dprop.getStep().getNumber() != aStep.getNumber()) {
                        throw new MismatchException();
+               }
+
+               if (newFormat != null
+                               /*&& previous.getType().equals(
+                                               getProjectSettings().getDefaultDocumentType(
+                                                               aStep.getStep(), newFormat))*/) {
+                       dprop.setFormat(newFormat);
+               }
 
-               if (dprop.getAuthor() == null)
+               if (dprop.getAuthor() == null) {
                        dprop.setAuthor(previous.getAuthor());
+               }
                String summary = dprop.getDescription();
 
                // Creation of the document
@@ -358,22 +428,18 @@ public class StepServiceImpl implements StepService {
                getDocumentDAO().create(newdoc);
 
                // Versioning
-               if (summary == null)
-                       newdoc.addRelation(new VersionsRelation(newdoc, previous));
-               else
-                       newdoc.addRelation(new VersionsRelation(newdoc, previous, summary));
+               VersionsRelation aRel;
+               aRel = new VersionsRelation(newdoc, previous, summary);
+               // getVersionsRelationDAO().create(aRel);
+               newdoc.addRelation(aRel);
 
                // Update of usedby relations, if exist
-               List<Relation> relist = previous.getRelations(UsedByRelation.class);
-               Study scope = aStep.getOwnerStudy();
-               for (Iterator<Relation> i = relist.iterator(); i.hasNext();) {
-                       UsedByRelation relation = (UsedByRelation) i.next();
-                       Document relatedoc = relation.getTo();
-                       if (scope.shares(relatedoc))
-                               relatedoc.addRelation(new UsesRelation(relatedoc, newdoc));
-                       else
-                               relation.moveTo(newdoc);
-               }
+               /*
+                * RKV: Consider the new version as not used by old dependent documents. So these documents must be marked as outdated then. List<Relation>
+                * relist = previous.getRelations(UsedByRelation.class); Study scope = aStep.getOwnerStudy(); for (Iterator<Relation> i =
+                * relist.iterator(); i.hasNext();) { UsedByRelation relation = (UsedByRelation) i.next(); Document relatedoc = relation.getTo(); if
+                * (scope.shares(relatedoc)) { relatedoc.addRelation(new UsesRelation(relatedoc, newdoc)); } else { relation.moveTo(newdoc); } }
+                */
                return new Publication(newdoc, aStep.getOwner());
        }
 
@@ -384,7 +450,8 @@ public class StepServiceImpl implements StepService {
         *            the study step
         * @return the list of document types
         */
-       public List<DocumentType> getValidDocumentTypes(Step aStep) {
+       @Override
+       public List<DocumentType> getValidDocumentTypes(final Step aStep) {
                return getDocumentTypeService().selectTypesOf(aStep.getStep());
        }
 
@@ -397,14 +464,16 @@ public class StepServiceImpl implements StepService {
         *            the document publication to add
         * @return true if publication succeeded
         */
-       public boolean add(Step aStep, Publication newdoc) {
-               if (!aStep.getOwner().add(newdoc))
-                       return false; // Updates the study in memory
-               aStep.getDocuments().add(0, newdoc); // Updates this step
-               getDocumentService().hold(newdoc.value()); // Increments the configuration tag count of document
-               // If not yet saved, the Publication MUST NOT be saved here, although this creates a temporary inconsistent state into the
-               // database (it will be saved later by cascading the update of owner scenario).
-               return true;
+       @Override
+       public boolean add(final Step aStep, final Publication newdoc) {
+               boolean res = aStep.getOwner().add(newdoc); // Updates the study in memory
+               if (res) {
+                       aStep.getDocuments().add(0, newdoc); // Updates this step
+                       getDocumentService().hold(newdoc.value()); // Increments the configuration tag count of document
+                       // If not yet saved, the Publication MUST NOT be saved here, although this creates a temporary inconsistent state into the
+                       // database (it will be saved later by cascading the update of owner scenario).
+               }
+               return res;
        }
 
        /**
@@ -416,50 +485,148 @@ public class StepServiceImpl implements StepService {
         *            the document publication to remove
         * @return true if removing of the publication succeeded
         */
-       public boolean remove(Step aStep, Publication oldoc) {
-               if (!aStep.getOwner().remove(oldoc))
-                       return false; // Updates the study in memory
+       @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
+               getProjectElementDAO().merge(aStep.getOwner());
                getDocumentService().release(oldoc.value()); // Decrements the configuration tag count of document
                // The publication becoming orphan, it should automatically be removed from the database when updating of owner scenario.
                return true;
        }
 
        /**
-        * Remove a document from the given step.
+        * Remove a document from the given step and from the database if it is no more used.
         * 
         * @param aStep
         *            the study step
-        * @param doctag
-        *            the document publication
+        * @param docId
+        *            the document id
         * @return true if removing of the document succeeded
+        * @throws DocumentIsUsedException
+        *             if the document is used by other documents
         */
-       public boolean removeDocument(Step aStep, Publication doctag) {
-               Document value = doctag.value();
-               Publication torem = aStep.getDocument(value.getIndex());
-
-               if (torem == null)
-                       return false;
-
-               remove(aStep, torem);
-               getProjectElementDAO().update(aStep.getOwner());
-               if (!value.isPublished() && !value.isVersioned()) { // The referenced document is no more used
-                       Set<Relation> links = value.getAllRelations(); // Get all relation of the document to remove them
-                       List<Document> using = new Vector<Document>();
-                       for (Iterator<Relation> i = links.iterator(); i.hasNext();) {
-                               Relation link = i.next();
-                               if (link.getClass().equals(ConvertsRelation.class)) { // File conversion
-                                       getFileDAO().delete((File) link.getTo()); // The corresponding physical file is not removed from the vault
-                               } else if (link.getClass().equals(UsesRelation.class)) { // Document dependency
-                                       using.add((Document) link.getTo());
-                               }
+       @Override
+       @Transactional
+       public boolean removeDocument(final Step aStep, final long docId)
+                       throws DocumentIsUsedException {
+               Publication torem = aStep.getDocument(docId);
+               boolean res = (torem != null);
+               if (res) {
+                       if (!torem.value().getRelations(UsedByRelation.class).isEmpty()) {
+                               throw new DocumentIsUsedException(torem.value().getTitle());
                        }
-                       for (Iterator<Document> i = using.iterator(); i.hasNext();) {
-                               i.next().removeRelation(UsedByRelation.class, value); // TODO: RKV: don't use Database.getSession in removeRelation
+                       remove(aStep, torem);
+                       Document value = torem.value();
+                       if (!value.isPublished() && !value.isVersioned()) { // The referenced document is no more used
+                               List<Document> using = new ArrayList<Document>();
+                               List<File> files = new ArrayList<File>();
+                               for (Relation link : value.getAllRelations()) {
+                                       if (link.getClass().equals(ConvertsRelation.class)) { // File conversion
+                                               files.add((File) link.getTo());
+                                       } else if (link.getClass().equals(UsesRelation.class)) { // Document dependency
+                                               using.add((Document) link.getTo());
+                                       }
+                               }
+                               // Remove relations from depending documents
+                               if (LOG.isDebugEnabled()) {
+                                       LOG.debug("Remove " + using.size() + " UsedByRelation(s).");
+                               }
+                               for (Document doc : using) {
+                                       if (LOG.isDebugEnabled()) {
+                                               LOG.debug("Remove UsedByRelation from "
+                                                               + doc.getTitle() + " to " + value.getTitle());
+                                               LOG.debug("Nb relations of doc " + doc.getTitle()
+                                                               + " before: " + doc.getAllRelations().size());
+                                       }
+                                       doc.removeRelation(UsedByRelation.class, value);
+                                       if (LOG.isDebugEnabled()) {
+                                               LOG.debug("Nb relations of doc " + doc.getTitle()
+                                                               + " after: " + doc.getAllRelations().size());
+                                       }
+                                       getDocumentDAO().merge(doc);
+                               }
+                               // Synchronize deleted objects with the database to avoid hibernate exception
+                               // org.hibernate.PropertyValueException: not-null property references a null or transient value
+                               getDocumentDAO().flush();
+                               // The corresponding physical file is not removed from the vault
+                               getDocumentDAO().delete(getDocumentDAO().merge(torem.value()));
+                               // Delete document's files
+                               for (File file : files) {
+                                       getFileDAO().delete(getFileDAO().merge(file)); // The corresponding physical file is not removed from the vault
+                               }
                        }
-                       getDocumentDAO().delete(value); // The corresponding physical file is not removed from the vault
                }
-               return true;
+               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;
        }
 
        /**
@@ -477,7 +644,7 @@ public class StepServiceImpl implements StepService {
         * @param documentService
         *            the documentService to set
         */
-       public void setDocumentService(DocumentService documentService) {
+       public void setDocumentService(final DocumentService documentService) {
                _documentService = documentService;
        }
 
@@ -497,7 +664,7 @@ public class StepServiceImpl implements StepService {
         *            the simulationContextService to set
         */
        public void setSimulationContextService(
-                       SimulationContextService simulationContextService) {
+                       final SimulationContextService simulationContextService) {
                _simulationContextService = simulationContextService;
        }
 
@@ -516,7 +683,7 @@ public class StepServiceImpl implements StepService {
         * @param documentDAO
         *            the documentDAO to set
         */
-       public void setDocumentDAO(DocumentDAO documentDAO) {
+       public void setDocumentDAO(final DocumentDAO documentDAO) {
                _documentDAO = documentDAO;
        }
 
@@ -536,7 +703,7 @@ public class StepServiceImpl implements StepService {
         *            the simulationContextDAO to set
         */
        public void setSimulationContextDAO(
-                       SimulationContextDAO simulationContextDAO) {
+                       final SimulationContextDAO simulationContextDAO) {
                _simulationContextDAO = simulationContextDAO;
        }
 
@@ -555,7 +722,7 @@ public class StepServiceImpl implements StepService {
         * @param projectElementDAO
         *            the projectElementDAO to set
         */
-       public void setProjectElementDAO(ProjectElementDAO projectElementDAO) {
+       public void setProjectElementDAO(final ProjectElementDAO projectElementDAO) {
                _projectElementDAO = projectElementDAO;
        }
 
@@ -574,7 +741,7 @@ public class StepServiceImpl implements StepService {
         * @param indexService
         *            the indexService to set
         */
-       public void setIndexService(IndexService indexService) {
+       public void setIndexService(final IndexService indexService) {
                _indexService = indexService;
        }
 
@@ -593,7 +760,7 @@ public class StepServiceImpl implements StepService {
         * @param fileDAO
         *            the fileDAO to set
         */
-       public void setFileDAO(FileDAO fileDAO) {
+       public void setFileDAO(final FileDAO fileDAO) {
                _fileDAO = fileDAO;
        }
 
@@ -612,7 +779,118 @@ public class StepServiceImpl implements StepService {
         * @param documentTypeService
         *            the documentTypeService to set
         */
-       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+       public void setDocumentTypeService(
+                       final DocumentTypeService documentTypeService) {
                _documentTypeService = documentTypeService;
        }
+
+       /**
+        * Get the versionsRelationDAO.
+        * 
+        * @return the versionsRelationDAO
+        */
+       public VersionsRelationDAO getVersionsRelationDAO() {
+               return _versionsRelationDAO;
+       }
+
+       /**
+        * Set the versionsRelationDAO.
+        * 
+        * @param versionsRelationDAO
+        *            the versionsRelationDAO to set
+        */
+       public void setVersionsRelationDAO(
+                       final VersionsRelationDAO versionsRelationDAO) {
+               _versionsRelationDAO = versionsRelationDAO;
+       }
+
+       /**
+        * Get project settings.
+        * 
+        * @return Project settings service
+        */
+       private ProjectSettingsService getProjectSettings() {
+               return _projectSettings;
+       }
+       
+       /**
+        * Set project settings service.
+        * 
+        * @param projectSettingsService
+        *            project settings service
+        */
+       public void setProjectSettings(
+                       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.
+        * 
+        * @return the publicationDAO
+        */
+       public PublicationDAO getPublicationDAO() {
+               return _publicationDAO;
+       }
+
+       /**
+        * Set the publicationDAO.
+        * 
+        * @param publicationDAO
+        *            the publicationDAO to set
+        */
+       public void setPublicationDAO(final PublicationDAO publicationDAO) {
+               this._publicationDAO = publicationDAO;
+       }
+
+       /**
+        * Get the relationDAO.
+        * 
+        * @return the relationDAO
+        */
+       public RelationDAO getRelationDAO() {
+               return _relationDAO;
+       }
+
+       /**
+        * Set the relationDAO.
+        * 
+        * @param relationDAO
+        *            the relationDAO to set
+        */
+       public void setRelationDAO(final RelationDAO relationDAO) {
+               _relationDAO = relationDAO;
+       }
 }