]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/som/Step.java
Salome HOME
More business logic has been moved from BO to services. ServiceLocator is created...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / som / Step.java
index 46e44661c895d7c27370071565c84ad450462127..385d738a7472a11148151d66452c0596aa3ffe5c 100644 (file)
@@ -1,4 +1,5 @@
 package org.splat.som;
+
 /**
  * 
  * @author    Daniel Brunier-Coulin
@@ -40,231 +41,202 @@ import org.splat.kernel.NotApplicableException;
 import org.splat.service.technical.IndexServiceImpl;
 import org.splat.service.technical.ProjectSettingsService;
 
-
 public class Step {
-       
-       private ProjectSettingsService.Step    step;
-    private ProjectElement          owner;
-    private List<SimulationContext> contex;
-       private List<Publication>       docums;
-    private User                    actor;     // Actor involved in operations on published documents and requiring a time-stamp
-
-//  ==============================================================================================================================
-//  Constructor
-//  ==============================================================================================================================
-
-    public Step (ProjectSettingsService.Step step, ProjectElement owner) {
-//  ----------------------------------------------------------------
-      this.step   = step;
-      this.owner  = owner;
-      this.contex = new Vector<SimulationContext>();
-      this.docums = new Vector<Publication>();
-      this.actor  = null;
-
-//  Filtering of Simulation contexts, if exist
-      for (Iterator<SimulationContext> i=owner.SimulationContextIterator(); i.hasNext();) {
-       SimulationContext adoc = i.next();
-        if (!adoc.isInto(this)) continue;
-        this.contex.add(adoc);
-      }
-//  Filtering of Documents, if exist
-      for (Iterator<Publication> i=owner.PublicationIterator(); i.hasNext();) {
-       Publication mydoc = i.next();
-        if (!mydoc.value().isInto(this)) continue;
-        this.docums.add(mydoc);
-      }
-    }
-
-//  ==============================================================================================================================
-//  Public member functions
-//  ==============================================================================================================================
-
-    public User getActor () {
-//  -----------------------
-      return actor;
-    }
 
-    public List<Publication> getAllDocuments () {
-//  -------------------------------------------
-      return  Collections.unmodifiableList(docums);
-    }
-    
-    public List<SimulationContext> getAllSimulationContexts () {
-//  ----------------------------------------------------------
-      return  Collections.unmodifiableList(contex);
-    }
-
-    public Publication getDocument (long l) {
-//  ------------------------------------------
-      for (Iterator<Publication> i=docums.iterator(); i.hasNext();) {
-       Publication found = i.next();                          // In a given study step,
-       if (found.value().getIndex() == l) return found;   // there is only one publication of a given document
-      }
-      return null;
-    }
-    
-    public int getNumber () {
-//  -----------------------
-      return step.getNumber();
-    }
+       private ProjectSettingsService.Step step;
+       private ProjectElement owner;
+       private List<SimulationContext> contex;
+       private List<Publication> docums;
+       private User actor; // Actor involved in operations on published documents and requiring a time-stamp
+
+       // ==============================================================================================================================
+       // Constructor
+       // ==============================================================================================================================
+
+       public Step(ProjectSettingsService.Step step, ProjectElement owner) {
+               // ----------------------------------------------------------------
+               this.step = step;
+               this.owner = owner;
+               this.contex = new Vector<SimulationContext>();
+               this.docums = new Vector<Publication>();
+               this.actor = null;
+
+               // Filtering of Simulation contexts, if exist
+               for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
+                               .hasNext();) {
+                       SimulationContext adoc = i.next();
+                       if (!adoc.isInto(this))
+                               continue;
+                       this.contex.add(adoc);
+               }
+               // Filtering of Documents, if exist
+               for (Iterator<Publication> i = owner.PublicationIterator(); i.hasNext();) {
+                       Publication mydoc = i.next();
+                       if (!mydoc.value().isInto(this))
+                               continue;
+                       this.docums.add(mydoc);
+               }
+       }
 
-    public ProjectElement getOwner () {
-//  ---------------------------------
-      return owner;   // May be a Study or a Scenario
-    }
+       // ==============================================================================================================================
+       // Public member functions
+       // ==============================================================================================================================
 
-    public Study getOwnerStudy () {
-//  -----------------------------
-      if (owner instanceof Study) return  (Study)owner;
-      else                        return ((Scenario)owner).getOwnerStudy();
-    }
+       public User getActor() {
+               // -----------------------
+               return actor;
+       }
 
-    public String getPath () {
-//  ------------------------
-      return step.getPath();
-    }
+       public List<Publication> getAllDocuments() {
+               // -------------------------------------------
+               return Collections.unmodifiableList(docums);
+       }
 
-    public List<Publication> getResultDocuments () {
-//  ----------------------------------------------
-      List<Publication> result = new Vector<Publication>();
-      
-      if (!docums.isEmpty()) for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
-       Publication  content = i.next();
-        DocumentType type    = content.value().getType();
-        if (!type.isResultOf(this.getStep())) continue;
-        result.add(content);
-         }
-      return result;
-    }
+       /**
+        * Get the persistent collection of step documents.
+        * @return the list of documents
+        */
+       public List<Publication> getDocuments() {
+               return docums;
+       }
 
-    public ProjectSettingsService.Step getStep () {
-//  --------------------------------------
-      return step;
-    }
+       public List<SimulationContext> getAllSimulationContexts() {
+               // ----------------------------------------------------------
+               return Collections.unmodifiableList(contex);
+       }
 
-    public SimulationContext getSimulationContext (long l) {
-//  ---------------------------------------------------------
-      for (Iterator<SimulationContext> i=owner.SimulationContextIterator(); i.hasNext();) {
-        SimulationContext myctex = i.next();
-        if (myctex.getIndex() == l) return myctex;
-      }
-      return null;
-    }
+       public Publication getDocument(long l) {
+               // ------------------------------------------
+               for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
+                       Publication found = i.next(); // In a given study step,
+                       if (found.value().getIndex() == l)
+                               return found; // there is only one publication of a given document
+               }
+               return null;
+       }
 
-    public List<SimulationContext> getSimulationContext (SimulationContextType type) {
-//  --------------------------------------------------------------------------------
-      Vector<SimulationContext> result = new Vector<SimulationContext>();
+       public int getNumber() {
+               // -----------------------
+               return step.getNumber();
+       }
 
-      for (Iterator<SimulationContext> i=owner.SimulationContextIterator(); i.hasNext();) {
-        SimulationContext myctex = i.next();
-        if (myctex.getType().equals(type)) result.add(myctex);
-      }
-      return result;
-    }
+       public ProjectElement getOwner() {
+               // ---------------------------------
+               return owner; // May be a Study or a Scenario
+       }
 
-    public List<DocumentType> getValidDocumentTypes () {
-//  --------------------------------------------------
-      return Document.selectTypesOf(step);
-    }
+       public Study getOwnerStudy() {
+               // -----------------------------
+               if (owner instanceof Study)
+                       return (Study) owner;
+               else
+                       return ((Scenario) owner).getOwnerStudy();
+       }
 
-    public boolean isStarted () {
-//  ---------------------------
-      if (!step.mayContain(KnowledgeElement.class)) return !docums.isEmpty();
+       public String getPath() {
+               // ------------------------
+               return step.getPath();
+       }
 
-      List<KnowledgeElement> kelm = ((Scenario)owner).getAllKnowledgeElements();
-      if (kelm.isEmpty() && docums.isEmpty()) return false;
-      return true;
-    }
+       public List<Publication> getResultDocuments() {
+               // ----------------------------------------------
+               List<Publication> result = new Vector<Publication>();
+
+               if (!docums.isEmpty())
+                       for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
+                               Publication content = i.next();
+                               DocumentType type = content.value().getType();
+                               if (!type.isResultOf(this.getStep()))
+                                       continue;
+                               result.add(content);
+                       }
+               return result;
+       }
 
-    public boolean isFinished () {
-//  ----------------------------
-      if (!step.mayContain(KnowledgeElement.class)) {   // Check if all result documents are approved
-        if (docums.isEmpty()) return false;
-        boolean result = false;
-        for (Iterator<Publication> i=docums.iterator(); i.hasNext(); ) {
-          Document     content = i.next().value();
-          DocumentType type    = content.getType();
-          if (!type.isResultOf(this.getStep())) continue;
-          if (content.getProgressState() == ProgressState.EXTERN) continue;
-          result = true;          // There is at least 1 non external result document
-          if (content.getProgressState() != ProgressState.APPROVED) return false;
-       }
-       return result;
-      }
-      else {                                            // Check if all existing knowledges are approved
-        List<KnowledgeElement> kelm  = ((Scenario)owner).getAllKnowledgeElements();
-        if (kelm.isEmpty()) return false;
-        for (Iterator<KnowledgeElement> i=kelm.iterator(); i.hasNext(); ) {
-                 KnowledgeElement  content = i.next();
-          if (content.getProgressState() != ProgressState.APPROVED) return false;
-               }
-        return true;
-      }
-    }
+       public ProjectSettingsService.Step getStep() {
+               // --------------------------------------
+               return step;
+       }
 
-    public boolean mayContain (@SuppressWarnings("rawtypes") Class type) {
-//  --------------------------------------------------------------------
-      return step.mayContain(type);
-    }
+       public SimulationContext getSimulationContext(long l) {
+               // ---------------------------------------------------------
+               for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
+                               .hasNext();) {
+                       SimulationContext myctex = i.next();
+                       if (myctex.getIndex() == l)
+                               return myctex;
+               }
+               return null;
+       }
 
-    public boolean removeDocument (Publication doctag) {
-//  --------------------------------------------------
-      Document     value   = doctag.value();
-      Publication  torem   = getDocument(value.getIndex());
-      Session      session = Database.getSession();
+       public List<SimulationContext> getSimulationContext(
+                       SimulationContextType type) {
+               // --------------------------------------------------------------------------------
+               Vector<SimulationContext> result = new Vector<SimulationContext>();
+
+               for (Iterator<SimulationContext> i = owner.SimulationContextIterator(); i
+                               .hasNext();) {
+                       SimulationContext myctex = i.next();
+                       if (myctex.getType().equals(type))
+                               result.add(myctex);
+               }
+               return result;
+       }
 
-      if (torem == null)        return false;
+       public boolean isStarted() {
+               // ---------------------------
+               if (!step.mayContain(KnowledgeElement.class))
+                       return !docums.isEmpty();
 
-      this.remove(torem);
-      session.update(owner);
-      if (!value.isPublished() && !value.isVersioned()) {         // The referenced document is no more used
-       Set<Relation>  links = value.getAllRelations();
-       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
-           session.delete(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());
-          }
-        }
-        for (Iterator<Document> i=using.iterator(); i.hasNext(); ) {
-          i.next().removeRelation(UsedByRelation.class, value);
-        }
-       session.delete(value);                              // The corresponding physical file is not removed from the vault
-      }
-      return true;
-    }
+               List<KnowledgeElement> kelm = ((Scenario) owner)
+                               .getAllKnowledgeElements();
+               if (kelm.isEmpty() && docums.isEmpty())
+                       return false;
+               return true;
+       }
 
-    public void setActor (User user) {
-//  --------------------------------
-      actor = user;
-    }
-//  ==============================================================================================================================
-//  Protected member functions
-//  ==============================================================================================================================
+       public boolean isFinished() {
+               // ----------------------------
+               if (!step.mayContain(KnowledgeElement.class)) { // Check if all result documents are approved
+                       if (docums.isEmpty())
+                               return false;
+                       boolean result = false;
+                       for (Iterator<Publication> i = docums.iterator(); i.hasNext();) {
+                               Document content = i.next().value();
+                               DocumentType type = content.getType();
+                               if (!type.isResultOf(this.getStep()))
+                                       continue;
+                               if (content.getProgressState() == ProgressState.EXTERN)
+                                       continue;
+                               result = true; // There is at least 1 non external result document
+                               if (content.getProgressState() != ProgressState.APPROVED)
+                                       return false;
+                       }
+                       return result;
+               } else { // Check if all existing knowledges are approved
+                       List<KnowledgeElement> kelm = ((Scenario) owner)
+                                       .getAllKnowledgeElements();
+                       if (kelm.isEmpty())
+                               return false;
+                       for (Iterator<KnowledgeElement> i = kelm.iterator(); i.hasNext();) {
+                               KnowledgeElement content = i.next();
+                               if (content.getProgressState() != ProgressState.APPROVED)
+                                       return false;
+                       }
+                       return true;
+               }
+       }
 
-    public boolean add (Publication newdoc) {
-//  ------------------------------------------
-      if (!owner.add(newdoc)) return false;   // Updates the study in memory
-      docums.add(0, newdoc);                  // Updates this step
-      newdoc.value().hold();                  // 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;
-    }
+       public boolean mayContain(@SuppressWarnings("rawtypes")
+       Class type) {
+               return step.mayContain(type);
+       }
 
-    public boolean remove (Publication oldoc) {
-//  --------------------------------------------
-      if (!owner.remove(oldoc)) return false; // Updates the study in memory
-      docums.remove(oldoc);                   // Updates this step
-      oldoc.value().release();                // 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;
-    }
+       public void setActor(User user) {
+               actor = user;
+       }
 
-    public List<SimulationContext> getContex() {
+       public List<SimulationContext> getContex() {
                return contex;
        }