You can use the GP design time API to set transition targets based on the result states defined for the callable objects of the process.
Transitions provide flexibility of process logic and allow you to guide process flow based on runtime decisions.
● You have instantiated the IGPDesigntimeUpdateManager.
See Instantiating the Design Time Manager.
● You have familiarized yourself with the creation of development objects with GP design time API.
See Creating GP Development Objects.
1. Create a block structure and add activities to it.
Create a block containing two actions (a_2, a_3).
For more information, see Creating Blocks.
2. Assign a callable object with result states to an action and add the action to the block.
We assign a callable object with two result states (X and Y) to action a_1 and add it to the block structure.
Wrapping a Callable Object with Result States into an Action |
import java.util.Locale; import com.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager; import com.sap.caf.eu.gp.co.api.IGPCallableObject; import com.sap.caf.eu.gp.co.api.IGPPhysicalCallableObject; import com.sap.caf.eu.gp.process.api.IGPModifiableAction; import com.sap.caf.eu.gp.process.api.IGPModifiableBlock;
// create a callable object co_1 IGPCallableObject co_1 = manager.createCallableObject( coType, locale, coTitle, coDescription, cat.getID() );
// define two result states: x and y IGPPhysicalCallableObject pco = co_1.resolvePhysicalCallableObject(); pco.addResultState("x", "X"); pco.addResultState("y", "Y");
// save and activate the object manager.save(co_1); manager.activate(co_1);
// create action a_1 IGPModifiableAction a_1 = manager.createAction( locale, aName, aDescription, cat.getID() );
// set execute callable object co_1 a_1.setExecuteCallableObject(co_1); manager.save(a_1);
// add a_1 to the block structure b.getModifiableStructure().addItem(a_1);
|
For more information on how to create a callable object with result states and assign it to an action, see:
3. Retrieve the items from the block structure.
All activities added to a block structure are represented by block structure items (IGPModifiableBlockStructureItem). Items hold information about result state transitions, exception handling, parameter mapping and roles.
To define transitions between the actions, we need to access the corresponding block structure items.
The block structure contains three items, ia_1, ia_2, ia_3, one for each of the three actions.
Retrieving Block Structure Items |
import com.sap.caf.eu.gp.process.api.IGPModifiableBlockStructureItem;
//retrieve block structure items IGPModifiableBlockStructureItem ia_1 = b.getModifiableStructure().getModifiableItem(0); IGPModifiableBlockStructureItem ia_2 = b.getModifiableStructure().getModifiableItem(1); IGPModifiableBlockStructureItem ia_3 = b.getModifiableStructure().getModifiableItem(2);
|
4. Define transitions between the actions.
We set transition target ia_2for result state X, and transition target ia_3 for result state Y. Thus, depending on the user’s runtime decision, the process flow is directed either to action a_2 or action a_3.
Defining Transitions |
// define transitions ia_1.setTransitionTarget("x", ia_2); ia_1.setTransitionTarget("y", ia_3);
|
You can also set a terminal transition, that is, a transition that directs the workflow to the end of the parent activity (block b).
Defining Terminal Transitions |
// define terminal transitions ia_1. setTerminalTransition("x");
|