01.08.2012 Views

Using Osworkflow in your Application

Using Osworkflow in your Application

Using Osworkflow in your Application

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Us<strong>in</strong>g</strong> OSWorkfl ow <strong>in</strong> <strong>your</strong> <strong>Application</strong><br />

Execut<strong>in</strong>g Actions<br />

We now have a newly created <strong>in</strong>stance; let's execute some actions. We need to <strong>in</strong>voke<br />

the doAction method of the Workflow <strong>in</strong>terface. The code is as follows:<br />

Wf.doAction(id, 1, null);<br />

The parameters are the workfl ow identifi er number, the action number ID (now you<br />

can see why actions must be uniquely numbered with<strong>in</strong> a defi nition), and a map<br />

with <strong>in</strong>puts for the workfl ow. We send null as the third parameter <strong>in</strong>dicat<strong>in</strong>g that<br />

there is no need of external <strong>in</strong>puts for this workfl ow type and action.<br />

Every call to the <strong>in</strong>itialize() and doAction() methods takes a map as an <strong>in</strong>put<br />

parameter. The transient variables map is merged with this <strong>in</strong>put map, so you can<br />

also fi nd the <strong>in</strong>put content. This is the ma<strong>in</strong> mechanism to send <strong>in</strong>formation to the<br />

Workflow <strong>in</strong>stance from the caller. The <strong>in</strong>put map key name is preserved <strong>in</strong> the<br />

transient variables map.<br />

What's the Status?<br />

To get the current steps of the workfl ow, you must call the getCurrentSteps()<br />

method of the Workflow <strong>in</strong>terface. The code snippet is as follows:<br />

List steps = wf.getCurrentSteps(id);<br />

This method returns a list of StepDescriptor, one for each current step<br />

of the Workflow <strong>in</strong>stance. To see the step <strong>in</strong>formation, we must call the<br />

WorkflowDescriptor. The follow<strong>in</strong>g code snippet shows you how to do that:<br />

for (Iterator iterator = steps.iterator(); iterator.hasNext();)<br />

{<br />

Step step = (Step) iterator.next();<br />

StepDescriptor sd = wd.getStep(step.getStepId());<br />

}<br />

By iterat<strong>in</strong>g the current step list and look<strong>in</strong>g up a StepDescriptor from the<br />

WorkflowDescriptor, we can get detailed step <strong>in</strong>formation, such as the ID, start<br />

date, fi nish date, and name of the step. If you want to see the history steps, call the<br />

getHistorySteps() method. The code is as follows:<br />

List steps = wf.getHistorySteps(id);<br />

Similarly to its current steps counterpart, getHistorySteps returns a list of<br />

StepDescriptor, this time with the completed steps of the Workflow <strong>in</strong>stance. To<br />

describe the history steps, you can use the code snippet mentioned earlier to describe<br />

the current steps.<br />

[ 72 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!