Class WorkflowMethods


  • public final class WorkflowMethods
    extends Object
    • Constructor Detail

      • WorkflowMethods

        public WorkflowMethods​(Supplier<com.torocloud.workflow.WorkflowLoader> defaultWorkflowLoader,
                               com.torocloud.workflow.InvocableChainFactory invocableChainFactory,
                               com.torocloud.workflow.WorkflowEventManager workflowEventManager,
                               MartiniPackageProvider packageProvider)
    • Method Detail

      • invokeWorkflow

        public static GloopModel invokeWorkflow​(@GloopParameter(allowNull=false)
                                                String workflowName,
                                                GloopModel input)
        Execute a Workflow service belonging to a certain package.

        Example scenarios: - When the Workflow service has multiple input properties, you can put the expected properties in gloop model.

         Example 1: Creating and passing a GloopModel directly
         GloopModel input = new GloopModel();
         input.setProperty("message", "Hello");
         input.setProperty("person", new GloopModel()
             .setProperty("firstname", "John")
             .setProperty("lastname", "Doe"));
        
         GloopModel result = WorkflowMethods.invokeWorkflow("WorkflowWithMultipleInputs", input);
        
         Example 2:
         - When the Workflow service has a single input property, you can pass the input directly
         GloopModel input = new GloopModel()
         input.setProperty("firstname", "John");
         input.setProperty("lastname", "Doe");
        
         GloopModel result = WorkflowMethods.invokeWorkflow("WorkflowWithSingleInput", input);
         
        Parameters:
        workflowName - The name of the Workflow file (with or without the file extension) to execute. If nested within a directory, parent directories must be prefixed while using . as a separator (e.g path.to.WorkflowService.
        input - object containing the inputs for the Workflow service
        Returns:
        the GloopModel of the Context
        See Also:
        invokeWorkflow(String, GloopModel)
      • invokeWorkflow

        public static GloopModel invokeWorkflow​(@GloopParameter(allowNull=false)
                                                String workflowName,
                                                Map<String,​Object> input)
        Execute a Workflow service belonging to a certain package.

        Example scenarios: - When the Workflow service has multiple input properties, you can pass them as a map.

         Example 1: Passing a map with multiple properties and declared like json style
         userInput = [
            "message":"Hello",
            "person": [
                "firstname":"John",
                "lastname":"Doe"
            ]
         ] - which is equivalent to GloopModel with two properties "message" and "person"
         GloopModel result = WorkflowMethods.invokeWorkflow("userWorkflow", userInput);
        
         Example 2: Passing the model directly to map
         GloopModel input = new GloopModel();
         input.setProperty("message", "Hello");
         input.setProperty("person", new GloopModel()
            .setProperty("firstname", "John")
             setProperty("lastname", "Doe"));
        
         userInput = [input:input] - which is equivalent to GloopModel with a single property "input"
         GloopModel result = WorkflowMethods.invokeWorkflow("customerWorkflow", userInput);
         
        Parameters:
        workflowName - The name of the Workflow file (with or without the file extension) to execute. If nested within a directory, parent directories must be prefixed while using . as a separator (e.g path.to.WorkflowService.
        input - map containing the inputs for the Workflow service
        Returns:
        the GloopModel of the Context
        See Also:
        invokeWorkflow(String, Map)
      • invokeWorkflow

        public static GloopModel invokeWorkflow​(@GloopParameter(allowNull=false)
                                                String workflowName)
        Execute a Workflow service belonging to a certain package.
        Parameters:
        workflowName - The name of the Workflow file (with or without the file extension) to execute. If nested within a directory, parent directories must be prefixed while using . as a separator (e.g path.to.WorkflowService.
        Returns:
        the GloopModel of the Context
        See Also:
        invokeWorkflow(String)
      • sendEvent

        public static List<com.torocloud.workflow.PostEventWorkflow> sendEvent​(com.torocloud.workflow.WorkflowEvent workflowEvent)
        Send event to all running workflow.
        Parameters:
        workflowEvent - The name of the event to send.
        Returns:
        the list of post event process result of each workflow
      • sendEvent

        public static com.torocloud.workflow.PostEventWorkflow sendEvent​(com.torocloud.workflow.WorkflowEvent workflowEvent,
                                                                         String contextId)
        Sent event to a specific workflow by contextId
        Parameters:
        workflowEvent - The name of the event to send.
        contextId - The contextId of the workflow where the event will be sent.
        Returns:
        the post event process result of the workflow
      • resolve

        public static com.torocloud.workflow.Workflow resolve​(@GloopParameter(allowNull=false)
                                                              String namespace)
        Resolve the workflow object based on the provided namespace.
        Parameters:
        namespace - the name of the workflow file
        Returns:
        the workflow object
        Throws:
        com.torocloud.workflow.exception.WorkflowNotFoundException - the workflow not found
      • resolve

        public static com.torocloud.workflow.Workflow resolve​(@GloopParameter(allowNull=false)
                                                              String packageName,
                                                              @GloopParameter(allowNull=false)
                                                              String namespace)
        Resolve the workflow object from other package packageName based on the provided namespace.
        Parameters:
        namespace - the name of the workflow file
        packageName - the name of the package
        Returns:
        the workflow object
        Throws:
        com.torocloud.workflow.exception.WorkflowNotFoundException - the workflow not found
        io.toro.martini.ipackage.exception.PackageNotFoundException - the package not found