]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java
Salome HOME
Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / PublicationServiceImpl.java
index 7fb730ba70bb0d6210f438641b1b4fc7997c9138..e2e530214d12c71196bf1c657701e1edeff93e41 100644 (file)
@@ -32,23 +32,43 @@ import org.splat.dal.dao.som.Database;
 import org.splat.kernel.NotApplicableException;
 import org.splat.manox.Reader;
 import org.splat.manox.Toolbox;
-import org.splat.som.DocumentRights;
 import org.splat.som.Revision;
 import org.splat.som.Step;
 
 /**
- * @author RKV
+ * Publication service implementation.
  * 
+ * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  */
 public class PublicationServiceImpl implements PublicationService {
 
+       /**
+        * Injected study service.
+        */
        private StudyService _studyService;
+       /**
+        * Injected study service.
+        */
        private StepService _stepService;
+       /**
+        * Injected study service.
+        */
        private DocumentTypeService _documentTypeService;
+       /**
+        * Injected study service.
+        */
        private ProjectElementService _projectElementService;
+       /**
+        * Injected simulation context service.
+        */
+       private SimulationContextService _simulationContextService;
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.PublicationService#copy(org.splat.dal.bo.som.Publication, org.splat.dal.bo.som.ProjectElement)
+        */
        public Publication copy(Publication aPublication, ProjectElement publisher) {
-               // -----------------------------------------------------
                Publication copy = new Publication();
                copy.setValue(aPublication.value());
                copy.setStep(aPublication.getStep()); // May not be initialized yet
@@ -61,18 +81,9 @@ public class PublicationServiceImpl implements PublicationService {
        }
 
        /**
-        * Promotes the document referenced by this publication from In-Check to Approved state, if not out-dated, and attaches the
-        * corresponding time-stamp to the document.</br> If the promoted document is the final result of the owner study, the study is itself
-        * is promoted as well.</br> </br> Limitation: the way this promotion is propagated to the study supposes that the study has only ONE
-        * final result document.
+        * {@inheritDoc}
         * 
-        * @param adate
-        *            the date of approval
-        * @return true if the approval succeeded
-        * @see #getProgressState()
-        * @see DocumentRights#canApprove()
-        * @see DocumentType#isStudyResult()
-        * @see Study#getApproverOf(Publication)
+        * @see org.splat.service.PublicationService#approve(org.splat.dal.bo.som.Publication, java.util.Date)
         */
        public Timestamp approve(Publication aPublication, Date adate) {
                // -------------------------------------
@@ -85,8 +96,8 @@ public class PublicationServiceImpl implements PublicationService {
                Study owner = aPublication.getOwnerStudy();
                ValidationCycle cycle = owner.getValidationCycleOf(type);
                User approver = cycle.getActor(ValidationStep.APPROVAL);
-               Timestamp stamp = new Timestamp(ValidationStep.APPROVAL,
-                               aPublication.value(), approver, adate);
+               Timestamp stamp = new Timestamp(ValidationStep.APPROVAL, aPublication
+                               .value(), approver, adate);
                if (!aPublication.value().promote(stamp))
                        return null;
                if (getDocumentTypeService().isStudyResult(type)
@@ -96,15 +107,9 @@ public class PublicationServiceImpl implements PublicationService {
        }
 
        /**
-        * Demotes the document referenced by this publication to In-Work state, and removes the Promoter of the document, if exist.</br> The
-        * In-Draft state is skipped (direct demotion to In-Work) if the validation cycle of the document does not include the review step.</br>
-        * If the demoted document is the final result of the owner study, the study is itself is demoted as well.</br> </br> Limitation: the
-        * way this demotion is propagated to the study supposes that the study has only ONE final result document.
+        * {@inheritDoc}
         * 
-        * @return true if the demotion succeeded
-        * @see #getProgressState()
-        * @see DocumentRights#canDemote()
-        * @see DocumentType#isStudyResult()
+        * @see org.splat.service.PublicationService#demote(org.splat.dal.bo.som.Publication)
         */
        public boolean demote(Publication aPublication) {
                // ------------------------
@@ -134,15 +139,9 @@ public class PublicationServiceImpl implements PublicationService {
        }
 
        /**
-        * Undo the review operation by demoting the document referenced by this publication from In-Check to In-Draft state and removing the
-        * Reviewer.</br> If the demoted document is the final result of the owner study, the study is itself is demoted as well.</br> </br>
-        * Limitation: the way this demotion is propagated to the study supposes that the study has only ONE final result document.
+        * {@inheritDoc}
         * 
-        * @return true if the demotion succeeded
-        * @see #getProgressState()
-        * @see #review()
-        * @see DocumentRights#canInvalidate()
-        * @see DocumentType#isStudyResult()
+        * @see org.splat.service.PublicationService#invalidate(org.splat.dal.bo.som.Publication)
         */
        public boolean invalidate(Publication aPublication) {
                // ----------------------------
@@ -159,17 +158,9 @@ public class PublicationServiceImpl implements PublicationService {
        }
 
        /**
-        * Promotes the document referenced by this publication from In-Work to In-Draft or In-Check state, if not out-dated, and attaches the
-        * corresponding time-stamp to the document.</br> The In-Draft state is skipped (direct promotion to In-Check) if the validation cycle
-        * of the document does not include the review step.</br> Also, if the promoted document is the final result of the owner study, the
-        * study is itself promoted as well.</br> This operation can be undo-ed by demote().</br> </br> Limitation: the way this promotion is
-        * propagated to the study supposes that the study has only ONE final result document.
+        * {@inheritDoc}
         * 
-        * @return true if the promotion succeeded
-        * @see #getProgressState()
-        * @see #demote()
-        * @see DocumentRights#canPromote()
-        * @see DocumentType#isStudyResult()
+        * @see org.splat.service.PublicationService#promote(org.splat.dal.bo.som.Publication, java.util.Date)
         */
        public Timestamp promote(Publication aPublication, Date pdate) {
                if (aPublication.isOutdated())
@@ -201,19 +192,9 @@ public class PublicationServiceImpl implements PublicationService {
        }
 
        /**
-        * Promotes the document referenced by this publication from In-Draft to In-Check state, if not out-dated, and attaches the
-        * corresponding time-stamp to the document.</br> If the promoted document is the final result of the owner study, the study is itself
-        * is promoted as well.</br> This operation can be undo-ed by invalidate().</br> </br> Limitation: the way this promotion is propagated
-        * to the study supposes that the study has only ONE final result document.
+        * {@inheritDoc}
         * 
-        * @param rdate
-        *            the date of review
-        * @return true if the review succeeded
-        * @see #getProgressState()
-        * @see #invalidate()
-        * @see DocumentRights#canReview()
-        * @see DocumentType#isStudyResult()
-        * @see Study#getReviewerOf(Publication)
+        * @see org.splat.service.PublicationService#review(org.splat.dal.bo.som.Publication, java.util.Date)
         */
        public Timestamp review(Publication aPublication, Date rdate) {
                if (aPublication.isOutdated())
@@ -225,8 +206,8 @@ public class PublicationServiceImpl implements PublicationService {
                Study owner = aPublication.getOwnerStudy();
                ValidationCycle cycle = owner.getValidationCycleOf(type);
                User reviewer = cycle.getActor(ValidationStep.REVIEW);
-               Timestamp stamp = new Timestamp(ValidationStep.REVIEW,
-                               aPublication.value(), reviewer, rdate);
+               Timestamp stamp = new Timestamp(ValidationStep.REVIEW, aPublication
+                               .value(), reviewer, rdate);
                if (!aPublication.value().promote(stamp))
                        return null;
                if (getDocumentTypeService().isStudyResult(type)
@@ -236,18 +217,9 @@ public class PublicationServiceImpl implements PublicationService {
        }
 
        /**
-        * Publishes the document referenced by this publication into the owner Project Element under the given revision number.<br/>
-        * The state of the referenced document is supposed being automatically set according to the given revision number, but, due to the
-        * versioning scheme, as it is not possible to differentiate In-Work and In-Draft states, this function has been deprecated (it is
-        * currently used only for the need of integration of Microsoft Office which anyway has to be redesigned). <br/>
-        * Note: in the context of branch versioning, the given revision may be modified by an update of the branch name.
+        * {@inheritDoc}
         * 
-        * @param newvers
-        *            the required revision number
-        * @throws FileNotFoundException
-        *             If the referenced document is empty
-        * @throws NotApplicableException
-        *             If the referenced document is undefined
+        * @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.som.Revision)
         * @deprecated
         */
        public void saveAs(Publication aPublication, Revision newvers)
@@ -265,16 +237,9 @@ public class PublicationServiceImpl implements PublicationService {
        }
 
        /**
-        * Publishes the document referenced by this publication into the owner Project Element under the given state, the revision number of
-        * the document being automatically set accordingly. If the given state is In-Draft and the document is final result of the owner study,
-        * this automatically promotes the study to In-Draft.
+        * {@inheritDoc}
         * 
-        * @param state
-        *            the required progress state
-        * @throws FileNotFoundException
-        *             If the referenced document is empty
-        * @throws NotApplicableException
-        *             If the referenced document is undefined
+        * @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.dal.bo.som.ProgressState)
         */
        public void saveAs(Publication aPublication, ProgressState state)
                        throws FileNotFoundException, NotApplicableException {
@@ -286,7 +251,8 @@ public class PublicationServiceImpl implements PublicationService {
                        throw new FileNotFoundException();
 
                if (state == ProgressState.inWORK || state == ProgressState.EXTERN) {
-                       Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode
+                       Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
+                       // hascode
                        aPublication.value().updateAs(state);
                } else {
                        DocumentType mytype = aPublication.value().getType();
@@ -300,7 +266,7 @@ public class PublicationServiceImpl implements PublicationService {
                                                                + " state");
                        }
                        Database.getSession().save(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
-                                                                                                               // hascode
+                       // hascode
                        aPublication.value().updateAs(ProgressState.inWORK);
 
                        promote(aPublication, aPublication.value()
@@ -309,8 +275,13 @@ public class PublicationServiceImpl implements PublicationService {
                updateOwner(aPublication);
        }
 
-       public void updateOwner(Publication aPublication) {
-               // ---------------------------
+       /**
+        * Update an owner of the publication.
+        * 
+        * @param aPublication
+        *            the document publication
+        */
+       private void updateOwner(Publication aPublication) {
                Session session = Database.getSession();
                Step step = getInvolvedStep(aPublication);
 
@@ -330,6 +301,16 @@ public class PublicationServiceImpl implements PublicationService {
                session.update(aPublication.getOwner());
        }
 
+       /**
+        * Propagate simulation contexts from the given config file to the publication's owner (study or step).
+        * 
+        * @param aPublication
+        *            the document publication
+        * @param from
+        *            the config file
+        * @param to
+        *            the study step
+        */
        private void forwardProperties(Publication aPublication, java.io.File from,
                        Step to) {
                // -----------------------------------------------------------
@@ -339,7 +320,7 @@ public class PublicationServiceImpl implements PublicationService {
 
                SimulationContextType.Properties sprop = new SimulationContextType.Properties()
                                .setStep(to.getStep()).setState(ProgressState.APPROVED);
-               List<SimulationContextType> contype = SimulationContext
+               List<SimulationContextType> contype = getSimulationContextService()
                                .selectTypesWhere(sprop);
                if (contype.isEmpty())
                        return; // No approved property type configured at this step
@@ -381,10 +362,15 @@ public class PublicationServiceImpl implements PublicationService {
 
        /**
         * Returns the study Step into which the document version referenced by this publication has been published.
+        * 
+        * @param aPublication
+        *            the document publication
+        * @return the study step where the document is published
         */
        public Step getInvolvedStep(Publication aPublication) {
                if (aPublication.getStep() == null) {
-                       Step[] step = getProjectElementService().getSteps(aPublication.getOwner());
+                       Step[] step = getProjectElementService().getSteps(
+                                       aPublication.getOwner());
                        for (int i = 0; i < step.length; i++) {
                                aPublication.setStep(step[i]); // The involved step necessarily exists
                                if (aPublication.value().isInto(aPublication.getStep()))
@@ -395,51 +381,90 @@ public class PublicationServiceImpl implements PublicationService {
        }
 
        /**
-        * @return
+        * Get the projectElementService.
+        * 
+        * @return the projectElementService
         */
-       private StepService getStepService() {
-               return _stepService;
+       public ProjectElementService getProjectElementService() {
+               return _projectElementService;
        }
 
-       public void setStepService(StepService stepService) {
-               _stepService = stepService;
+       /**
+        * Set the projectElementService.
+        * 
+        * @param projectElementService
+        *            the projectElementService to set
+        */
+       public void setProjectElementService(
+                       ProjectElementService projectElementService) {
+               _projectElementService = projectElementService;
+       }
+
+       /**
+        * Get the simulationContextService.
+        * 
+        * @return the simulationContextService
+        */
+       public SimulationContextService getSimulationContextService() {
+               return _simulationContextService;
+       }
+
+       /**
+        * Set the simulationContextService.
+        * 
+        * @param simulationContextService
+        *            the simulationContextService to set
+        */
+       public void setSimulationContextService(
+                       SimulationContextService simulationContextService) {
+               _simulationContextService = simulationContextService;
        }
 
        /**
-        * @return
+        * Get the studyService.
+        * @return the studyService
         */
        public StudyService getStudyService() {
                return _studyService;
        }
 
+       /**
+        * Set the studyService.
+        * @param studyService the studyService to set
+        */
        public void setStudyService(StudyService studyService) {
                _studyService = studyService;
        }
 
        /**
-        * @return
+        * Get the stepService.
+        * @return the stepService
         */
-       public DocumentTypeService getDocumentTypeService() {
-               return _documentTypeService;
+       public StepService getStepService() {
+               return _stepService;
        }
 
-       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
-               _documentTypeService = documentTypeService;
+       /**
+        * Set the stepService.
+        * @param stepService the stepService to set
+        */
+       public void setStepService(StepService stepService) {
+               _stepService = stepService;
        }
 
        /**
-        * Get the projectElementService.
-        * @return the projectElementService
+        * Get the documentTypeService.
+        * @return the documentTypeService
         */
-       public ProjectElementService getProjectElementService() {
-               return _projectElementService;
+       public DocumentTypeService getDocumentTypeService() {
+               return _documentTypeService;
        }
 
        /**
-        * Set the projectElementService.
-        * @param projectElementService the projectElementService to set
+        * Set the documentTypeService.
+        * @param documentTypeService the documentTypeService to set
         */
-       public void setProjectElementService(ProjectElementService projectElementService) {
-               _projectElementService = projectElementService;
+       public void setDocumentTypeService(DocumentTypeService documentTypeService) {
+               _documentTypeService = documentTypeService;
        }
 }