Use OSWORKFLOW API [original]

xiaoxiao2021-03-06  64

6. Use OsWorkflow's API

Interface selection

OsWorkflow provides multiple implementations of the com.opensymphony.workflow.workflow interface, you can use them directly in your program.

(1) BasicWorkflow

BasicWorkflow does not support transaction processing, but it is possible to support transactions by overcrowding BasicWorkflow, which has been achieved in your persistence. BasicWorkflow is created in the following manner:

Workflow WF = New BasicWorkflow (UserName);

UserName is the username of the current request.

(2) EJBWORKFLOW

EJBWORKFlow uses EJB containers to manage transactions. This is configured in the ejb-jar.xml file. It is built like this:

Workflow wf = new ejbworkflow ();

You don't need to specify the username here because once the user is authorized, it automatically loads the username from the EJB container.

(3) OFBIZWORKFLOW

The only different parts of OFBIZWORKFLOW and BasicWorkflow are to support transaction processing through OFBIZ.

2. Create a new workflow

The following briefly describes how to create a new workflow with an OSWORKFLOW API. First, you should create a file that defines a workflow. Then, your program must know the value of the initialization step to perform the initialization of the process instance. Before you initialize a workflow, you have to create it, this, you can get the reference to this workflow. Below is routine code:

Workflow WF = New BasicWorkflow (UserName);

HashMap INPUTS = New hashMap ();

Inputs.put ("DOCTITLE", Request.getParameter ("Title");

Wf.initialize ("WorkflowName", 1, Inputs);

Note: Under normal circumstances, you should use a reference to a Workflow type, and should not be a reference to BasicWorkflow.

3. Executive action

In OSWORKFLOW, it is very simple to perform an action:

Workflow WF = New BasicWorkflow (UserName);

HashMap INPUTS = New hashMap ();

Inputs.put ("DOCTITLE", Request.getParameter ("Title");

Long id = long.parselong (Request.GetParameter ("WorkflowID"));

Wf.doAction (ID, 1, INPUTS);

4. Query

In OSWORKFLOW 2.6, a new ExpressionQuery API is introduced.

Note: Not all Workflow storage supports query. Currently, all Hibernate, JDBC and memory storage support queries. However, Hibernate stores not supporting the mixed type query (for example: a query of the query information of a history and current step). To perform a query, create a WorkflowExpressionQuery object and call the query method in the WorkflowExpressionQuery object.

Below is an example of a query:

// Get All Workflow Entry ID's for Which the Owner IS 'Testuser'new WorkflowExpressionQuery

New FieldExpression (FieldExpression.Owner, // Check the Owner Field

FieldExpression.current_steps, // Look in The Current Steps Context

FieldExpression.equals, // check equality

"Testuser"); // the equality value is 'testuser'

// Get All Workflow Entry ID's That Have the name 'myworkflow'

New WorkflowExpressionQuery

New FieldExpression (FieldExpression.name, // Check The Name Field

FieldExpression.Entry, // Look in The Entries Context

FieldExpression.equals, // check equality

'myworkflow')) // Equality value is 'myworkflow'

Here is an example of nested query:

// Get All finished Workflow Entries Where The Current Owner IS 'Testuser'

Expression Queryleft = New FieldExpression

FieldExpression.Owner,

FieldExpression.current_steps,

FieldExpression.equals, 'Testuser');

Expression Queryright = New FieldExpression

FieldExpression.status,

FieldExpression.current_steps,

FieldExpression.equals,

"Finished",

True);

WorkflowExpressionQuery Query = New WorkflowExpressionQuery

New NestedExpression (new expression [] {queryft, queryright},

NestedExpression.and));

.

// Get All Workflow Entries That Were finished in the Past

// OR are currently marked finished = new fieldExpression

FieldExpression.finish_date,

FieldExpression.history_steps,

FieldExpression.lt, new date ());

Expression Queryright = New FieldExpression

FieldExpression.status,

FieldExpression.current_steps,

FieldExpression.equals, "finished");

WorkflowExpressionQuery Query = New WorkflowExpressionQuery

New NestedExpression (new expression [] {queryft, queryright},

NestedExpression.or);

转载请注明原文地址:https://www.9cbs.com/read-119538.html

New Post(0)