Salome HOME
StepServiceImpl doesn't use Database class anymore.
authorrkv <rkv@opencascade.com>
Wed, 17 Oct 2012 12:48:40 +0000 (12:48 +0000)
committerrkv <rkv@opencascade.com>
Wed, 17 Oct 2012 12:48:40 +0000 (12:48 +0000)
Workspace/Siman-Common/src/org/splat/dal/bo/som/Scenario.java
Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java
Workspace/Siman-Common/src/spring/businessServiceContext.xml
Workspace/Siman-Common/src/spring/daoContext.xml

index 54a119f4170df4a40645c1b6f606ff0f073bb28a..f4458be27273f8ded91f0b01a4f9200d54edb2a7 100644 (file)
@@ -254,23 +254,6 @@ public class Scenario extends ProjectElement {
       return (cuser != null);
     }
 
-    
-
-//  ==============================================================================================================================
-//  Protected member function
-//  ==============================================================================================================================
-
-    public void updateMyIndex (IndexService lucin) throws IOException {
-//  ------------------------------------------
-      if (ucase == null) for (Iterator<KnowledgeElement> i=kelms.iterator(); i.hasNext(); ) {
-        KnowledgeElement  kelm = i.next();
-        if (!kelm.getType().equals("usecase")) continue;
-        ucase = kelm;
-        break;
-      }
-      lucin.update(ucase);
-    }
-
 //  ==============================================================================================================================
 //  Private services
 //  ==============================================================================================================================
@@ -292,4 +275,11 @@ public class Scenario extends ProjectElement {
        public List<KnowledgeElement> getKnowledgeElementsList() {
                return knowl;
        }
+       /**
+        * Get the ucase.
+        * @return the ucase
+        */
+       public KnowledgeElement getUcase() {
+               return ucase;
+       }
 }
\ No newline at end of file
index 9df836e407d486653ed191c8fb10ad4cbc4083ad..ccb0faca57e227217ef0ecfd7a7a1756fee87623 100644 (file)
@@ -14,7 +14,6 @@ import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
 
-import org.hibernate.Session;
 import org.splat.dal.bo.kernel.Relation;
 import org.splat.dal.bo.som.Document;
 import org.splat.dal.bo.som.KnowledgeElement;
@@ -25,13 +24,15 @@ 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.VersionsRelation;
-import org.splat.dal.dao.som.Database;
 import org.splat.dal.dao.som.DocumentDAO;
+import org.splat.dal.dao.som.ProjectElementDAO;
+import org.splat.dal.dao.som.SimulationContextDAO;
 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.technical.IndexService;
 import org.splat.som.Revision;
 import org.splat.som.Step;
@@ -39,10 +40,16 @@ 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 {
 
+       /**
+        * logger for the service.
+        */
+       public final static AppLogger logger = AppLogger
+                       .getLogger(StepServiceImpl.class);
        /**
         * Injected index service.
         */
@@ -59,7 +66,20 @@ public class StepServiceImpl implements StepService {
         * Injected simulation context service.
         */
        private SimulationContextService _simulationContextService;
+       /**
+        * Injected simulation context DAO.
+        */
+       private SimulationContextDAO _simulationContextDAO;
+       /**
+        * Injected project element DAO.
+        */
+       private ProjectElementDAO _projectElementDAO;
 
+       /**
+        * {@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,
@@ -69,20 +89,23 @@ public class StepServiceImpl implements StepService {
                return addSimulationContext(aStep, context);
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.StepService#addSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext)
+        */
+       @Transactional
        public SimulationContext addSimulationContext(Step aStep,
                        SimulationContext context) {
                getSimulationContextService().hold(context); // Increments the reference count of simulation context
                if (aStep.getOwner().isSaved())
                        try {
-                               Session session = Database.getSession();
-                               IndexService lucin = getIndexService();
-
                                if (!context.isSaved())
-                                       session.save(context);
+                                       getSimulationContextDAO().create(context);
                                aStep.getOwner().add(context);
                                aStep.getContex().add(context); // The context is also referenced from this (transient) Step
-                               session.update(aStep.getOwner());
-                               updateKnowledgeElementsIndex(aStep, lucin);
+                               getProjectElementDAO().update(aStep.getOwner());
+                               updateKnowledgeElementsIndex(aStep);
                        } catch (Exception error) {
                                return null;
                        }
@@ -94,8 +117,13 @@ public class StepServiceImpl implements StepService {
                return context;
        }
 
-       private void updateKnowledgeElementsIndex(Step aStep, IndexService lucin) {
-               // ------------------------------------------------------
+       /**
+        * Update lucene index of knowledge elements of a scenario or a study which the given step is related to.
+        * 
+        * @param aStep
+        *            the step (activity)
+        */
+       private void updateKnowledgeElementsIndex(Step aStep) {
                Scenario[] scenarii;
                if (aStep.getOwner() instanceof Scenario) {
                        scenarii = new Scenario[1];
@@ -110,118 +138,200 @@ public class StepServiceImpl implements StepService {
                                for (Iterator<KnowledgeElement> j = knelm.iterator(); j
                                                .hasNext();) {
                                        KnowledgeElement kelm = j.next();
-                                       lucin.update(kelm);
+                                       getIndexService().update(kelm);
                                }
-                               scene.updateMyIndex(lucin);
+                               updateScenarioIndex(scene);
                        }
                } catch (Exception error) {
-                       // logger.error("Unable to re-index Knowledge Elements, reason:", error);
+                       logger.error("Unable to re-index Knowledge Elements, reason:", error);
+               }
+       }
+
+       /**
+        * Update lucene index for knowledge elements of the scenario.
+        * 
+        * @param scene
+        *            the scenario
+        * @throws IOException
+        *             if can't update lucene index
+        */
+       private void updateScenarioIndex(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"))
+                                       continue;
+                               scene.setUcase(kelm);
+                               break;
+                       }
                }
+               getIndexService().update(scene.getUcase());
+       }
+
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.StepService#removeSimulationContext(org.splat.som.Step, org.splat.dal.bo.som.SimulationContext)
+        */
+       @Transactional
+       public boolean removeSimulationContext(Step aStep, SimulationContext context) {
+               boolean isOk = false;
+               SimulationContext torem = aStep
+                               .getSimulationContext(context.getIndex());
+
+               if ((torem != null) && (aStep.getOwner().remove(torem))) {
+
+                       aStep.getContex().remove(torem);
+                       getProjectElementDAO().update(aStep.getOwner());
+                       if (torem.isShared()) {
+                               getSimulationContextService().release(torem);
+                               getSimulationContextDAO().update(torem);
+                       } else {
+                               getSimulationContextDAO().delete(torem);
+                       }
+                       isOk = true;
+               }
+               return isOk;
+       }
+
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.StepService#createDocument(org.splat.som.Step, org.splat.dal.bo.som.Document.Properties)
+        */
+       @Transactional
+       public Publication createDocument(Step aStep, Document.Properties dprop)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException, IOException {
+               Document newdoc = new Document(dprop.setOwner(aStep.getOwner())
+                               .setStep(aStep.getStep()));
+               getDocumentService().generateDocumentId(newdoc, dprop);
+
+               // Creation of the save directory
+               File wdir = getDocumentService().getSaveDirectory(newdoc);
+               if (!wdir.exists())
+                       if (!wdir.mkdirs())
+                               throw new IOException(
+                                               "Cannot create the repository vault directory");
+
+               // Identification and save
+               newdoc.buildReferenceFrom(aStep.getOwnerStudy());
+               getDocumentDAO().create(newdoc);
+
+               return new Publication(newdoc, aStep.getOwner());
        }
 
-    public boolean removeSimulationContext (Step aStep, SimulationContext context) {
-//  ------------------------------------------------------------------
-      SimulationContext  torem   = aStep.getSimulationContext(context.getIndex());
-      Session            session = Database.getSession();
-
-      if (torem == null)        return false;
-      if (!aStep.getOwner().remove(torem)) return false;
-
-      aStep.getContex().remove(torem);
-      session.update(aStep.getOwner());
-      if (torem.isShared()) {
-        getSimulationContextService().release(torem);
-        session.update(torem);
-      } else {
-       session.delete(torem);
-      }
-      return true;
-    }
-
-    @Transactional
-    public Publication createDocument (Step aStep, Document.Properties dprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException {
-          Document  newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep()));
-          getDocumentService().generateDocumentId(newdoc, dprop);
-
-//        Creation of the save directory      
-          File wdir = getDocumentService().getSaveDirectory(newdoc);
-         if (!wdir.exists()) if (!wdir.mkdirs()) throw new IOException("Cannot create the repository vault directory");
-
-//        Identification and save
-          newdoc.buildReferenceFrom(aStep.getOwnerStudy());
-          getDocumentDAO().create(newdoc);
-
-          return  new Publication(newdoc, aStep.getOwner());
-        }
-
-        public Publication assignDocument (Step aStep, 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());
-        }
-
-        public Publication versionDocument (Step aStep, Publication base) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
-    //  -----------------------------------------------------
-          return versionDocument(aStep, base, new Document.Properties());
-        }
-
-        public Publication versionDocument (Step aStep, Publication base, String reason) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException, IOException, MismatchException {
-    //  --------------------------------------------------------------------
-          return versionDocument(aStep, base, new Document.Properties().setDescription(reason));
-        }
-
-        @Transactional
-        public Publication versionDocument (Step aStep, Publication base, 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()) throw new MismatchException();
-
-          if (dprop.getAuthor() == null) dprop.setAuthor(previous.getAuthor());
-          String    summary = dprop.getDescription();
-
-//        Creation of the document
-          Document  newdoc = new Document(dprop.setOwner(aStep.getOwner()).setStep(aStep.getStep()));
-          getDocumentService().generateDocumentId(newdoc, dprop);
-          newdoc.buildReferenceFrom(aStep.getOwner(), previous);
-          getDocumentDAO().create(newdoc);
-
-//        Versioning
-          if (summary == null) newdoc.addRelation( new VersionsRelation(newdoc, previous) );
-          else                 newdoc.addRelation( new VersionsRelation(newdoc, previous, summary) );
-
-//        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);
-          }
-          return  new Publication(newdoc, aStep.getOwner());
-        }
+       /**
+        * {@inheritDoc}
+        * 
+        * @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 {
+               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());
+       }
 
        /**
+        * @param aStep
+        * @param base
         * @return
+        * @throws MissedPropertyException
+        * @throws InvalidPropertyException
+        * @throws MultiplyDefinedException
+        * @throws IOException
+        * @throws MismatchException
         */
-       public IndexService getIndexService() {
-               return _indexService;
+       public Publication versionDocument(Step aStep, Publication base)
+                       throws MissedPropertyException, InvalidPropertyException,
+                       MultiplyDefinedException, IOException, MismatchException {
+               return versionDocument(aStep, base, new Document.Properties());
        }
 
-       public void setIndexService(IndexService indexService) {
-               _indexService = indexService;
+       /**
+        * @param aStep
+        * @param base
+        * @param reason
+        * @return
+        * @throws MissedPropertyException
+        * @throws InvalidPropertyException
+        * @throws MultiplyDefinedException
+        * @throws IOException
+        * @throws MismatchException
+        */
+       public Publication versionDocument(Step aStep, Publication base,
+                       String reason) throws MissedPropertyException,
+                       InvalidPropertyException, MultiplyDefinedException, IOException,
+                       MismatchException {
+               return versionDocument(aStep, base, new Document.Properties()
+                               .setDescription(reason));
+       }
+
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.service.StepService#versionDocument(org.splat.som.Step, org.splat.dal.bo.som.Publication,
+        *      org.splat.dal.bo.som.Document.Properties)
+        */
+       @Transactional
+       public Publication versionDocument(Step aStep, Publication base,
+                       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())
+                       throw new MismatchException();
+
+               if (dprop.getAuthor() == null)
+                       dprop.setAuthor(previous.getAuthor());
+               String summary = dprop.getDescription();
+
+               // Creation of the document
+               Document newdoc = new Document(dprop.setOwner(aStep.getOwner())
+                               .setStep(aStep.getStep()));
+               getDocumentService().generateDocumentId(newdoc, dprop);
+               newdoc.buildReferenceFrom(aStep.getOwner(), previous);
+               getDocumentDAO().create(newdoc);
+
+               // Versioning
+               if (summary == null)
+                       newdoc.addRelation(new VersionsRelation(newdoc, previous));
+               else
+                       newdoc.addRelation(new VersionsRelation(newdoc, previous, summary));
+
+               // 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);
+               }
+               return new Publication(newdoc, aStep.getOwner());
        }
 
        /**
         * Get the documentService.
+        * 
         * @return the documentService
         */
        public DocumentService getDocumentService() {
@@ -230,7 +340,9 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the documentService.
-        * @param documentService the documentService to set
+        * 
+        * @param documentService
+        *            the documentService to set
         */
        public void setDocumentService(DocumentService documentService) {
                _documentService = documentService;
@@ -238,6 +350,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the simulationContextService.
+        * 
         * @return the simulationContextService
         */
        public SimulationContextService getSimulationContextService() {
@@ -246,7 +359,9 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the simulationContextService.
-        * @param simulationContextService the simulationContextService to set
+        * 
+        * @param simulationContextService
+        *            the simulationContextService to set
         */
        public void setSimulationContextService(
                        SimulationContextService simulationContextService) {
@@ -255,6 +370,7 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Get the documentDAO.
+        * 
         * @return the documentDAO
         */
        public DocumentDAO getDocumentDAO() {
@@ -263,9 +379,69 @@ public class StepServiceImpl implements StepService {
 
        /**
         * Set the documentDAO.
-        * @param documentDAO the documentDAO to set
+        * 
+        * @param documentDAO
+        *            the documentDAO to set
         */
        public void setDocumentDAO(DocumentDAO documentDAO) {
                _documentDAO = documentDAO;
        }
+
+       /**
+        * Get the simulationContextDAO.
+        * 
+        * @return the simulationContextDAO
+        */
+       public SimulationContextDAO getSimulationContextDAO() {
+               return _simulationContextDAO;
+       }
+
+       /**
+        * Set the simulationContextDAO.
+        * 
+        * @param simulationContextDAO
+        *            the simulationContextDAO to set
+        */
+       public void setSimulationContextDAO(
+                       SimulationContextDAO simulationContextDAO) {
+               _simulationContextDAO = simulationContextDAO;
+       }
+
+       /**
+        * Get the projectElementDAO.
+        * 
+        * @return the projectElementDAO
+        */
+       public ProjectElementDAO getProjectElementDAO() {
+               return _projectElementDAO;
+       }
+
+       /**
+        * Set the projectElementDAO.
+        * 
+        * @param projectElementDAO
+        *            the projectElementDAO to set
+        */
+       public void setProjectElementDAO(ProjectElementDAO projectElementDAO) {
+               _projectElementDAO = projectElementDAO;
+       }
+
+       /**
+        * Get the indexService.
+        * 
+        * @return the indexService
+        */
+       public IndexService getIndexService() {
+               return _indexService;
+       }
+
+       /**
+        * Set the indexService.
+        * 
+        * @param indexService
+        *            the indexService to set
+        */
+       public void setIndexService(IndexService indexService) {
+               _indexService = indexService;
+       }
 }
index 5505908e969bd85a72515f668ac35b0fe49d3087..4592bf74c535b64e99c6da30dd1754f0ddb10c10 100644 (file)
@@ -65,8 +65,12 @@ http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                <property name="indexService" ref="indexService" />
         <property name="documentDAO" ref="documentDAO" />
         <property name="documentService" ref="documentService" />
-               <property name="simulationContextService"
-                       ref="simulationContextService" />
+        <property name="simulationContextService"
+            ref="simulationContextService" />
+        <property name="simulationContextDAO"
+            ref="simulationContextDAO" />
+        <property name="projectElementDAO"
+            ref="projectElementDAO" />
        </bean>
 
        <bean id="simulationContextService"
index fb558d89c05e9c57abe935a565fbe676bcadc259..3fd1378b2de110f7fcd5204c0af44e351798dabb 100644 (file)
@@ -4,8 +4,28 @@
        xsi:schemaLocation="
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
-<!-- Generated by Siman Generator on Tue Oct 16 14:37:09 MSD 2012 -->
+<!-- Generated by Siman Generator on Wed Oct 17 14:28:24 MSD 2012 -->
 
+    <bean id="persistentDAO" parent="genericDAO"
+        class="org.splat.dal.dao.kernel.PersistentDAOImpl">
+    </bean>
+    
+    <bean id="anyDAO" parent="genericDAO"
+        class="org.splat.dal.dao.kernel.AnyDAOImpl">
+    </bean>
+    
+    <bean id="entityDAO" parent="genericDAO"
+        class="org.splat.dal.dao.kernel.EntityDAOImpl">
+    </bean>
+    
+    <bean id="attributeDAO" parent="genericDAO"
+        class="org.splat.dal.dao.kernel.AttributeDAOImpl">
+    </bean>
+    
+    <bean id="relationDAO" parent="genericDAO"
+        class="org.splat.dal.dao.kernel.RelationDAOImpl">
+    </bean>
+    
     <bean id="textAttributeDAO" parent="genericDAO"
         class="org.splat.dal.dao.kernel.TextAttributeDAOImpl">
     </bean>
@@ -18,6 +38,10 @@ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
         class="org.splat.dal.dao.kernel.UserDAOImpl">
     </bean>
     
+    <bean id="projectElementDAO" parent="genericDAO"
+        class="org.splat.dal.dao.som.ProjectElementDAOImpl">
+    </bean>
+    
     <bean id="studyDAO" parent="genericDAO"
         class="org.splat.dal.dao.som.StudyDAOImpl">
     </bean>