Creating a Workflow Instance

Creating a workflow instance is a required operation in order for a Launch Step Processor to launch a workflow. Creating a workflow instance involves creating a workflow definition object from a workflow definition file (from an Object store, File store, Content Services library, etc.), transferring it to the Process database (if needed), creating and setting the parameter values for the Launch step.

Once a workflow instance has been created, you can launch the workflow using the VWStepElement.doDispatch() method.

To create a workflow instance, create a class to do the following:

Tip To facilitate development, you may wish to adapt the API sample constructor LaunchSample(VWSession vwSession, Logger, String wfDefFile).

Create the Workflow Definition Object

Create a workflow definition object from an Object store, File store, or Content Services library file using the VWWorkflowDefinition.readFromFile() method. For example:

wflDef = VWWorkflowDefinition.readFromFile(wfDefFile);

Note This presumes that local workflow definition (Sample.pep, for example) was created previously; for example, by the constructor for the API sample class WFDefinitionSample.

Transfer the Workflow Definition Object

If the workflow has already been transferred to the Process database and has not been changed, transfer is not necessary. However, if the workflow has not yet been transferred or if there has been a change in the workflow, transfer is required.

Transfer the workflow definition object to the Process database using the VWSession.transfer(...) method. Specify the Content Engine (or Content Services) docid as a parameter to identify the workflow definition. For example:

// Transfer the workflow definition object. The second parameter is a unique id.
// A unique Content Engine ID from the lib/docid /version "uniqueid" is
// used for this value.

VWTransferResult transferResult = m_vwSession.transfer(wflDef, "uniqueid", false, true);

Validate That The Transfer Was Successful 

If you transferred the workflow definition object to the Process database, validate and log whether the transfer was successful and display the transfer errors.

    if (transferResult.success()){

m_logger.log("The transfer was successful.");

// ( less significant code . . . )

    }
    else
    {

           // Display the transfer errors.

        String[] errorArray = transferResult.getErrors();
        if (errorArray != null)
            m_logger.log("\tThe following transfer errors occurred: ", errorArray);
        else
            m_logger.log("\t\tError messages were not available.");
    }

Retrieve the Transfer Result Version

Prepare to create the Launch step by retrieving the version from the VWTransferResult object. For example:

vwVersion = transferResult.getVersion();

Use the version string (see "launchStep" below) as the argument to instantiate a VWStepElement object when you create the workflow instance with the API method VWSession.createWorkflow(string).

Create the Workflow Instance

Create an instance of the workflow using the API VWSession.createWorkflow(string) method. You can use the API VWStepElement.setComment(string) method to label this Launch step. For example:

launchStep = m_vwSession.createWorkflow(vwVersion);
launchStep.setComment("This is a sample workflow Launch step comment");

The createWorkflow(string) method returns a VWStepElement object that represents the Launch step for the workflow. Once you have created the workflow instance, you can either update the workflow data and then launch the workflow, or just launch the workflow., which is launched when the Launch step is dispatched with the API VWStepElement.doDispatch() method.