SystemStepSample

This stand-alone sample demonstrates how to create a workflow, set some properties, add a system step, and launch the workflow. Run the sample by entering a command similar to the following:

java SystemStepSample username password <server name>:<port number>/<router instance name> [queue_name] [output_file]

If no queue name is specified, the program does not associate a queue with the workflow. A workflow without a queue cannot include a Step Processor. If no output file is specified, the name SystemStepSample.out is used.

Note For a detailed explanation of the command line, see the Run the sample application section of the Run the Unmodified Samples topic.

Methods

The SystemStepSample class contains two methods: the main(String args[]) method and the SystemStepSample(VWSession vwSession, Logger logger, String queueName) method, which is the constructor.

main(String args[])

The SystemStepSample main method code creates an instance of the SessionHelper class (sessionHelper) and the Logger class (logger). The sessionHelper.logon() method logs on to a workflow session and returns a VWSession object, vwSession. The main method then passes the vwSession object, the logger object, and the queue name to the sample constructor.

SystemStepSample(VWSession vwSession, Logger logger, String queueName)

The SystemStepSample constructor method shows how to create a workflow with a system step. The sample performs these operations in the general order shown below.

Instantiate a SystemStepHelper object with the vwSession and logger object arguments. This SystemStepHelper object will later assist the current object with its addStep, addCompoundStep, and validate methods.

SystemStepHelper systemStepHelper = new SystemStepHelper(vwSession, logger);

Create the VWWorkflowDefinition object, workflowDef.

VWWorkflowDefinition workflowDef = null;
// ( additional declaration code . . . )
workflowDef = new VWWorkflowDefinition();

Set some workflow definition properties.

workflowDef.setSubject("\"This is the System Step sample workflow\"");
workflowDef.setDescription("This is a workflow generated by the System Step Sample");
workflowDef.setName("System Step Workflow");

Define some workflow definition fields with VWWorkflowDefinition.createFieldUsingString().

workflowDef.createFieldUsingString("Field1_Integer", "99", VWFieldType.FIELD_TYPE_INT, false);
workflowDef.createFieldUsingString("Field2_String", "{\"\"}", VWFieldType.FIELD_TYPE_STRING, true);

Get a VWMapDefinition object as the default map with VWWorkflowDefinition.getMainMap(), and set the map description property.

mapDef = workflowDef.getMainMap();
mapDef.setDescription("This is the sample workflow map");

Get a VWMapNode object as the launch step with VWWorkflowDefinition.getStartStep(), and set the launch step description map property.

currentStepDef = mapDef.getStartStep();
currentStepDef.setDescription("This is the description for the launch step.");

Define the first step after the launch as a system step. The program must first set another VWMapNode object to hold the new launch step.

precedingStepDef = currentStepDef;

Construct, then set a compound step ("Step 1") with the sample helper class method SystemStepHelper.addCompoundStep ().

VWCompoundStepDefinition sysStepDef = null;
sysStepDef = systemStepHelper.addCompoundStep(mapDef, "Step 1");

Create an assignment instruction which initializes system step field "Field1_Integer" to 42.

sysStepDef.createAssignInstruction(new String[][] {{"Field1_Integer","42"}} );

Create a BeginTimer instruction with the VWCompoundStepDefinition.createBeginTimerInstruction() method. The arguments name the Begintimer "Timer 1", set it to expire 15 minutes after reaching this step, and set its expiration to branch to the system workflow instruction "Terminate". This timer is "non-preemptive", which means it will wait until the current step completes before it terminates.

sysStepDef.createBeginTimerInstruction("\"Timer 1\"", "addminutes(systemtime(),15)", "Terminate", null);

Reset the value of the current step definition object variable to the compound system step the program just defined. This step remains defined in the "precedingStepDef" object.

currentStepDef = sysStepDef;

Use the"precedingStepDef" object to create a route from the preceeding (launch) step to the new step (step 1). Note that the createRoute() argument specifies the new step ID by invoking VWNode.getStepId().

precedingStepDef.createRoute(currentStepDef.getStepId());

Create three more (non-compound) steps in the workflow (main) map with the sample class method systemStepHelper.addStep(). If there is no associated queue name, a null value for queueName is valid. VWNode.createRoute() establishes the route from step to step.

for (int i = 0; i < 3; i++){

currentStepDef = systemStepHelper.addStep(mapDef, "Step" + i, queueName);
if (currentStepDef != null){

precedingStepDef.createRoute(currentStepDef.getStepId());

// Reset the preceeding step lag variable.

precedingStepDef = currentStepDef;

}

}

Create a fifth step that terminates "Timer 1", initiated by "Step 1", above. The procedure is much the same as the one that created BeginTimer "Step 1", the previous compound step. The method uses VWNode.createEndTimerInstruction() in place of VWNode.createBeginTimerInstruction(), as follows:

sysStepDef = null;
sysStepDef = systemStepHelper.addCompoundStep(mapDef, "Step 5")
sysStepDef.createEndTimerInstruction("\"Timer 1\"");
currentStepDef = sysStepDef;

// Create a route from the preceeding step to the new one.

precedingStepDef.createRoute(currentStepDef.getStepId());

The program validates the new workflow definition with the sample method systemStepHelper.validate().

if (systemStepHelper.validate(workflowDef, vwSession)){ // ( . . . continue processing)}

Write the local workflow definition file, which contains an XML representation of the workflow definition. (To see a graphical representation of the workflow, use Designer to open this file.)

workflowDef.writeToFile("SystemStepSample.pep");

Transfer the workflow definition with VWSession.transfer().

VWTransferResult transferResult = vwSession.transfer(workflowDef, "uniqueid", false, true);

Use the resulting VWTransferResult object to show whether the transfer was successful or not with the following code:

if (transferResult.success()){

vwVersion = transferResult.getVersion();
logger.log("The transfer was successful.");

}else { ( . . . Display the transfer errors ) }

Launch the workflow: create a step Element with vwSession.createWorkflow(vwVersion), optionally set a comment with VWStepElement.setComment(), and dispatch the workflow with VWStepElement.doDispatch().

VWStepElement launchStep = vwSession.createWorkflow(vwVersion);
launchStep.setComment("This is the System Step sample launch step comment");
launchStep.doDispatch();

Additional code in SystemStepSample manages common messages and errors.