Class Flow


  • public class Flow
    extends java.lang.Object
    Class that encapsulates the Steps involved in a Knowledge Flow process.
    Version:
    $Revision: $
    Author:
    Mark Hall (mhall{[at]}pentaho{[dot]}com)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.List<javax.swing.filechooser.FileFilter> FLOW_FILE_EXTENSIONS
      Holds available file extensions for flow files handled
    • Constructor Summary

      Constructors 
      Constructor Description
      Flow()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAll​(java.util.List<StepManagerImpl> steps)
      All all steps in the supplied list to this Flow
      void addStep​(StepManagerImpl manager)
      Add the given Step to this flow
      boolean connectSteps​(StepManagerImpl source, StepManagerImpl target, java.lang.String connectionType)
      Connect the supplied source and target steps using the given connectionType.
      boolean connectSteps​(StepManagerImpl source, StepManagerImpl target, java.lang.String connectionType, boolean force)
      Connect the supplied source and target steps using the given connectionType.
      Flow copyFlow()
      Make a copy of this Flow
      java.util.List<StepManagerImpl> findPotentialStartPoints()
      Get a list of potential start points in this Flow.
      StepManagerImpl findStep​(java.lang.String stepName)
      Find a Step by name
      java.lang.String getFlowID()
      Get an ID string for this flow.
      static FlowLoader getFlowLoader​(java.lang.String flowFileExtension, Logger log)
      Utility method to get a FlowLoader implementation suitable for loading a flow with the supplied file extension.
      java.lang.String getFlowName()
      Get the name of this Flow
      java.util.List<StepManagerImpl> getSteps()
      Get a list of the Steps in this Flow
      boolean initFlow​(FlowExecutor executor)
      Initialize the flow by setting the execution environment and calling the init() method of each step
      java.util.Iterator<StepManagerImpl> iterator()
      Get an Iterator over the Steps in this flow
      static Flow JSONToFlow​(java.lang.String flowJSON)
      Parse a Flow from the supplied JSON string
      static Flow JSONToFlow​(java.lang.String flowJSON, boolean dontComplainAboutMissingConnections)
      Parse a Flow from the supplied JSON string
      static Flow loadFlow​(java.io.File flowFile, Logger log)
      Utility method to load a flow from a file
      static Flow loadFlow​(java.io.InputStream is, FlowLoader loader)
      Utility method to load a flow from the supplied input stream using the supplied FlowLoader
      static Flow loadFlow​(java.io.Reader r, FlowLoader loader)
      Utility method to load a flow from the supplied reader using the supplied FlowLoader
      void removeStep​(StepManagerImpl manager)
      Remove the supplied Step from this flow
      void renameStep​(java.lang.String oldName, java.lang.String newName)
      Rename a Step.
      void renameStep​(StepManagerImpl step, java.lang.String newName)
      Rename the supplied step with the supplied name
      void saveFlow​(java.io.File file)
      Save this Flow to the supplied File
      void setFlowName​(java.lang.String name)
      Set the name of this Flow
      int size()
      Get the number of steps in this flow
      java.lang.String toJSON()
      Return the JSON encoded version of this Flow
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FLOW_FILE_EXTENSIONS

        public static final java.util.List<javax.swing.filechooser.FileFilter> FLOW_FILE_EXTENSIONS
        Holds available file extensions for flow files handled
    • Constructor Detail

      • Flow

        public Flow()
    • Method Detail

      • getFlowLoader

        public static FlowLoader getFlowLoader​(java.lang.String flowFileExtension,
                                               Logger log)
                                        throws WekaException
        Utility method to get a FlowLoader implementation suitable for loading a flow with the supplied file extension.
        Parameters:
        flowFileExtension - the file extension to get a FlowLoader for
        log - the log in use
        Returns:
        a FlowLoader
        Throws:
        WekaException - if a problem occurs
      • loadFlow

        public static Flow loadFlow​(java.io.File flowFile,
                                    Logger log)
                             throws WekaException
        Utility method to load a flow from a file
        Parameters:
        flowFile - the file to load from
        log - the log to use
        Returns:
        the loaded Flow
        Throws:
        WekaException - if a problem occurs
      • loadFlow

        public static Flow loadFlow​(java.io.InputStream is,
                                    FlowLoader loader)
                             throws WekaException
        Utility method to load a flow from the supplied input stream using the supplied FlowLoader
        Parameters:
        is - the input stream to load from
        loader - the FlowLoader to use
        Returns:
        the loaded Flow
        Throws:
        WekaException - if a problem occurs
      • loadFlow

        public static Flow loadFlow​(java.io.Reader r,
                                    FlowLoader loader)
                             throws WekaException
        Utility method to load a flow from the supplied reader using the supplied FlowLoader
        Parameters:
        r - the reader to load from
        loader - the FlowLoader to use
        Returns:
        the loaded flow
        Throws:
        WekaException - if a problem occurs
      • JSONToFlow

        public static Flow JSONToFlow​(java.lang.String flowJSON)
                               throws WekaException
        Parse a Flow from the supplied JSON string
        Parameters:
        flowJSON - the JSON string to parse
        Returns:
        the Flow
        Throws:
        WekaException - if a problem occurs
      • JSONToFlow

        public static Flow JSONToFlow​(java.lang.String flowJSON,
                                      boolean dontComplainAboutMissingConnections)
                               throws WekaException
        Parse a Flow from the supplied JSON string
        Parameters:
        flowJSON - the JSON string to parse
        dontComplainAboutMissingConnections - true to not raise an exception if there are connections to non-existent Steps in the JSON flow
        Returns:
        the Flow
        Throws:
        WekaException - if a problem occurs
      • saveFlow

        public void saveFlow​(java.io.File file)
                      throws WekaException
        Save this Flow to the supplied File
        Parameters:
        file - the File to save to
        Throws:
        WekaException - if a problem occurs
      • getFlowName

        public java.lang.String getFlowName()
        Get the name of this Flow
        Returns:
        the name of this flow
      • setFlowName

        public void setFlowName​(java.lang.String name)
        Set the name of this Flow
        Parameters:
        name - the name to set
      • getFlowID

        public java.lang.String getFlowID()
        Get an ID string for this flow. The ID is made up of the FlowName + "_" + the hashcode generated from the JSON representation of the flow.
        Returns:
      • addAll

        public void addAll​(java.util.List<StepManagerImpl> steps)
        All all steps in the supplied list to this Flow
        Parameters:
        steps - a list of StepManagers for the steps to add
      • addStep

        public void addStep​(StepManagerImpl manager)
        Add the given Step to this flow
        Parameters:
        manager - the StepManager containing the Step to add
      • connectSteps

        public boolean connectSteps​(StepManagerImpl source,
                                    StepManagerImpl target,
                                    java.lang.String connectionType)
        Connect the supplied source and target steps using the given connectionType. The connection will be successful only if both source and target are actually part of this Flow, and the target is able to accept the connection at this time.
        Parameters:
        source - the StepManager for the source step
        target - the StepManager for the target step
        connectionType - the connection type to use says it can accept the connection type at this time)
        Returns:
        true if the connection was successful
      • connectSteps

        public boolean connectSteps​(StepManagerImpl source,
                                    StepManagerImpl target,
                                    java.lang.String connectionType,
                                    boolean force)
        Connect the supplied source and target steps using the given connectionType. The connection will be successful only if both source and target are actually part of this Flow, and the target is able to accept the connection at this time.
        Parameters:
        source - the StepManager for the source step
        target - the StepManager for the target step
        connectionType - the connection type to use
        force - true to force the connection (i.e. even if the target step says it can accept the connection type at this time)
        Returns:
        true if the connection was successful
      • renameStep

        public void renameStep​(StepManagerImpl step,
                               java.lang.String newName)
                        throws WekaException
        Rename the supplied step with the supplied name
        Parameters:
        step - the StepManager of the Step to rename
        newName - the new name to give the step
        Throws:
        WekaException - if the Step is not part of this Flow.
      • renameStep

        public void renameStep​(java.lang.String oldName,
                               java.lang.String newName)
                        throws WekaException
        Rename a Step.
        Parameters:
        oldName - the name of the Step to rename
        newName - the new name to use
        Throws:
        WekaException - if the named Step is not part of this flow
      • removeStep

        public void removeStep​(StepManagerImpl manager)
                        throws WekaException
        Remove the supplied Step from this flow
        Parameters:
        manager - the StepManager of the Step to remove
        Throws:
        WekaException - if the step is not part of this flow
      • getSteps

        public java.util.List<StepManagerImpl> getSteps()
        Get a list of the Steps in this Flow
        Returns:
        a list of StepManagers of the steps in this flow
      • iterator

        public java.util.Iterator<StepManagerImpl> iterator()
        Get an Iterator over the Steps in this flow
        Returns:
        an Iterator over the StepManagers of the Steps in this flow
      • size

        public int size()
        Get the number of steps in this flow
        Returns:
        the number of steps in this flow
      • findStep

        public StepManagerImpl findStep​(java.lang.String stepName)
        Find a Step by name
        Parameters:
        stepName - the name of the Step to find
        Returns:
        the StepManager of the named Step, or null if the Step is not part of this flow
      • findPotentialStartPoints

        public java.util.List<StepManagerImpl> findPotentialStartPoints()
        Get a list of potential start points in this Flow. Potential start points are those steps that have no incoming connections.
        Returns:
        a list of potential start points
      • initFlow

        public boolean initFlow​(FlowExecutor executor)
                         throws WekaException
        Initialize the flow by setting the execution environment and calling the init() method of each step
        Parameters:
        executor - the flow executor being used to execute the flow
        Returns:
        false if initialization failed
        Throws:
        WekaException - if a problem occurs during flow initialization
      • toJSON

        public java.lang.String toJSON()
                                throws WekaException
        Return the JSON encoded version of this Flow
        Returns:
        the flow in JSON format
        Throws:
        WekaException - if a problem occurs
      • copyFlow

        public Flow copyFlow()
                      throws WekaException
        Make a copy of this Flow
        Returns:
        a copy of this Flow
        Throws:
        WekaException - if a problem occurs