General tasks

Using the SDK API workflow module

The following code indicates how to use the workflow API. The method initialize() is used to position a certain number of parameters. In most of cases, this method will get the null value as argument, because inside the VDoc system every needed properties are positioned.

public void general_useModule()
{
        // creation of an object of workflow module
        IWorkflowModule workflowModule = new ProcessWorkflowModule();
        try
        {
                // position of certain properties (optional)
                Properties props = new Properties();
                props.setProperty( "language", "fr" );

                // initialization of the module
                workflowModule.initialize( props );
        }
        catch( Exception e )
        {
                // if an error has occurred
                getNavigator().processErrors( e );
        }
        finally
        {
                // do not forget to release the used module
                workflowModule.unInitialize();
        }
}

Recovering a context to use the SDK API

The context notion enables to run processing with a user account. Several cases are displayed. Their using depends on the execution context and the available objects.

public void general_getContext( IWorkflowModule workflowModule ) throws Exception
{
        // 1st case : retrieving the context from a user object
        IUser user = workflowModule.getUserByLogin( "sysadmin" );
        IContext userContext = workflowModule.getContext( user );

        // 2nd case: retrieving the context from an external ID
        IContext extIDCtx = workflowModule.getContext( getNavigator().getLoggedOnUser().getExternId() );

        // 3rd case : retrieving the context from a login
        IContext loginContext = workflowModule.getContextByLogin( "sysadmin" );
}

Recovering an External Reference

This example shows how to recover the Java object corresponding to the external reference defined in the administration.

public void general_getExternalReference( IContext context, IWorkflowModule workflowModule ) throws Exception
{
        // recovering an external reference with its name
        IJdbcReference jdbcReference = workflowModule.getJdbcReference( context, "vdocDatabase" );
        System.out.println( " référence : " + jdbcReference.getName() );
}

Recovering a DataSource

This example shows how to recover a DataSource defined on the JNDI server.

public void general_getDataSource( IWorkflowModule workflowModule ) throws Exception
{
        IDataSourceReference dataSourceReference = workflowModule.getDataSourceReference( "education-ds" );
}

Recovering a connection from an external reference

From an external reference object, you may recover a JDBC connection.

public void general_getConnection( IJdbcReference jdbcReference )
{
        // recovering a connection
        Connection connection = jdbcReference.getConnection();
}

Recovering a connection from a DataSource

From a data source object, you may recover a JDBC connection.

public void general_getConnection( IDataSourceReference dataSourceReference )
{
        // recover a connection from a data source
        Connection connection = dataSourceReference.getConnection();
}

Using the transactions

In numerous cases, we need to gather several processing in a same transaction. Each module has its own transactional mechanism.

The following example shows how to use this transactional mechanism from the workflow module.

public void general_useTransaction( IContext context, IWorkflowModule workflowModule )
{
        try
        {
                // starting a transaction
                workflowModule.beginTransaction( this );

                // doing something
                // ...

                // validating the transaction
                workflowModule.commitTransaction( this );
        }
        catch( Exception e )
        {
                // if an error has occurred, canceling the previous processing
                workflowModule.rollbackTransaction( this );
                getNavigator().processErrors( e );
        }
}