LaunchSample

This sample demonstrates how to create a workflow definition object from the workflow definition file and transfer it to the database. Run the sample by entering a command similar to the following:

java LaunchSample 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.

Methods

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

main(String args[])

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 LaunchSample.out and Sample.pep, respectively. The main method constructs and passes vwSession and Logger objects 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 sample's class constructor.

LaunchSample(VWSession vwSession, Logger, String wfDefFile)

The sample constructor LaunchSample(VWSession vwSession, Logger, String wfDefFile) defines a workflow, transfers the definition to the system database, creates and comments the launch step, and dispatches the workflow as follows:

Create a workflow definition object from a file with VWWorkflowDefinition.readFromFile(). This presumes that local workflow definition (Sample.pep, for example) was created previously (for example, by the constructor for the sample class WFDefinitionSample).

wflDef = VWWorkflowDefinition.readFromFile(wfDefFile);

Transfer the definition with VWSession.transfer(...) and validate that the transfer was successful:

// Transfer the workflow definition.  The second parameter is a unique id.

// Transfer the workflow definition.  The second parameter is a unique id.
// We use a unique Content Services ID for this value,
// from the lib/docid /version.

VWTransferResult transferResult = m_vwSession.transfer(wflDef, "uniqueid", false, true);
    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.");
    }

Prepare to create a launch step by getting the version from the VWTransferResult object. Use the version string as the argument to instantiate a VWStepElement object ("launchStep") with the API method VWSession.createWorkflow(string). VWStepElement.setComment(string) to label this launch step as follows:

vwVersion = transferResult.getVersion();

// ( less significant code . . . )

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

Use the Logger object to log the launch step properties, which include the names and values of the parameters that were assigned to this step in a previous invocation of SysConfigSample.

m_logger.log("\nLaunch Step information:\n");
m_logger.log("\tWorkflow Name:  " + launchStep.getWorkflowName());
m_logger.log("\tSubject:  " + launchStep.getSubject());
m_logger.log("\tComment:  " + launchStep.getComment());
m_logger.log("\tStep Description:  " + launchStep.getStepDescription());

m_logger.log("\nParameters:\n");

paramNames = launchStep.getParameterNames();
if (paramNames == null)

m_logger.log("\t\t no parameters!");

}
else { // ( less significant code . . . )

// Display the parameter names and their values.

for (int i = 0; i < paramNames.length; i++){

if (paramNames[i] != null){

  // Retrieve the parameter value.

value = launchStep.getParameterValue(paramNames[i]);

  // Write the information to the log.

m_logger.log("\t" + paramNames[i] + " = ", value);

}

}

Complete, or dispatch,  the launch step with VWStepElement.doDispatch(). The dispatch saves the changes made to the step (comment properties, in this case) to the workflow database.

launchStep.doDispatch();

This sample, and all of the non-helper class samples, use the Logger and SessionHelper classes in the main method to log events and initialize the workflow session when it is run as a standalone application.