This sample demonstrates how to create and save a workflow definition in a file. Run the sample by entering a command similar to the following:
java WFDefinitionSample username password <server name>:<port
number>/<router instance name> [wfDefinition_filename | wfDefinition_filename
output_filename]
Note For a detailed explanation of the command line, see the Run the sample application section of the Run the Unmodified Samples topic.
The main method uses common techniques for validating and defaulting argument values. The default values for log output file and workflow definition file names are WFDefinitionSample.out and Sample.pep, respectively. The main method sets local variables to point to the VWSession and Logger object arguments and passes them to the sample constructor. Main() handles the login and logoff for the session with the login() and logoff() methods of the sample SessionHelper class. It provides workflow logging with an instance of the sample Logger class. The main method passes the session, the logger, the user name, and the name of the user definition file to the constructor for the class.
The constructor WFDefinitionSample(VWSession, Logger, String, String) performs common exception handling and demonstrates a variety of workflow definition functions. It creates the default workflow definition, sets some the workflow definition general properties, and creates some fields. It sets some properties for the main map, sets the description for the main map and the launch step, and creates some steps in the main map. Finally, it writes the validated workflow definition to a file. The code is organized as follows:
Create the default workflow definition:
workflowDef = new VWWorkflowDefinition();
Set subject, description, and name properties in the workflow definition:
workflowDef.setSubject("\"This is the sample workflow
definition subject\"");
workflowDef.setDescription("This is the sample workflow definition description");
workflowDef.setName("Sample Workflow");
Create an integer and a string field in the workflow definition:
workflowDef.createFieldUsingString("Field1_Integer", "99",
VWFieldType.FIELD_TYPE_INT, false);
workflowDef.createFieldUsingString("Field2_String", "{\"\"}",
VWFieldType.FIELD_TYPE_STRING, true);
Set some properties for the map:
mapDef = workflowDef.getMainMap();
mapDef.setDescription("This is the sample workflow map");
Get the launch step and set its description:
currentStepDef = mapDef.getStartStep();
currentStepDef.setDescription("This is the description for the launch
step.");
precedingStepDef = currentStepDef;
Iteratively create three steps in the "Workflow" (main) map with the local addStep method.
for (int i = 0;
i < 3; i++)
{
currentStepDef = addStep(mapDef, "Step" +
i, userName);
if (currentStepDef != null){
// create a route
precedingStepDef.createRoute(currentStepDef.getStepId());
// reset the preceding step
precedingStepDef
= currentStepDef;
}
}
Write the validated workflow definition to a file:
if (validate(workflowDef, vwSession)){
logger.log("Writing workflow definition to
file: " + wfDefFile);
workflowDef.writeToFile(wfDefFile);
}
Additional code in this method performs common user notification, cleanup, and exception handling.
Creates and initializes a workflow step. The code is organized as follows:
Create a destination step for a new route:
newStepDef = mapDef.createStep(stepName);
nStepId = newStepDef.getStepId();
Create an integer parameter and a string parameter. The last argument for the second VWStepDefinition.createParameter(...) is set to true because the programmer expects the value expression for this parameter to evaluate to an array.
newStepDef.createParameter( "Field1_Integer",
VWModeType.MODE_TYPE_IN, "99", VWFieldType.FIELD_TYPE_INT, false );
newStepDef.createParameter( "Field2_String", VWModeType.MODE_TYPE_OUT,
"Field2_String", VWFieldType.FIELD_TYPE_STRING, true );
Create a named participant and add it to the step
participants = new VWParticipant[1];
participants[0] = new VWParticipant();
participants[0].setParticipantName("\"" + userName
+ "\"");
newStepDef.setParticipants(participants);
Set the queue name, deadline, and reminder times.
The deadline value represents the number of minutes between receipt of the step by an application and expiration of the step's deadline timer at runtime. The reminder value represents the number of minutes prior to expiration of the deadline timer at which the reminder timer expires at runtime:
newStepDef.setQueueName("Inbox");
newStepDef.setDeadline(1000);
newStepDef.setReminder(500);
Set the step description and design display location. The location coordinates in this example are arbitrary.
newStepDef.setDescription("This is the description
for step" + nStepId + ".");
newStepDef.setLocation(new java.awt.Point(nStepId * 100, 150));
Write out the successful step-creation status.
m_logger.log("Creation and initialization of step:
" + nStepId + " is complete.");
}
Additional code in this method handles common cleanup, exception handling, and the return statement for the new VWStepDefinition object.
This method provides common exception and message handling when invoking the VWStepDefinition.validate(...) method. The "false" value of the second parameter of workflowDef.validate() will cause the system to assume that the caller has already set any join step IDs that may exist. Since there are no join step IDs in the example, this enhances performance.
VWValidationError[] validationErrors = null;
validationErrors = workflowDef.validate(vwSession, false);