You can create blocks using the GP design time API. The interface allows you to manipulate with block types and structure.
You have instantiated the IGPDesigntimeUpdateManager. For more information, see Instantiating the Design Time Manager.
...
1. Create a block by providing its basic data:
You need to specify a category for the newly-created block. For this purpose, you can create a new category or provide the Id of an existing one.
Creating a Block |
import java.util.Locale; import com.sap.caf.eu.gp.context.api.IGPUserContext; import com.sap.caf.eu.gp.process.api.IGPCategory; import com.sap.caf.eu.gp.process.api.IGPModifiableBlock; import com.sap.caf.eu.gp.process.api.GPProcessFactory; import com.sap.caf.eu.gp.process.dt.api.IGPDesigntimeManager; import com.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager; import com.sap.caf.eu.gp.process.api.GPBlockType;
// instantiate the design time manager to get the root category IGPDesigntimeManager dtManager = GPProcessFactory.getDesigntimeManager(); IGPCategory root = dtManager.getRootCategory(userContext);
// create a new category “test” in the root category IGPCategory cat = manager.createCategory("test", "A test category", root);
// create a block in the cat category String bName = "Block"; String bDescription = "A test block"; IGPModifiableBlock b = manager.createBlock( GPBlockType.BLOCK_TYPE_SEQUENTIAL, Locale.getDefault(), bName, bDescription, cat.getID() ); |
The example above implements a sequential block type. Currently, the GP API supports the following block types:
¡ BLOCK_TYPE_SEQUENTIAL
¡ BLOCK_TYPE_PARALLEL
For more information on block types, see Creating Blocks in Modeling and Configuring Workflows.
2. Add content to the block.
The block content is represented by a block structure (IGPModifiableBlockStructure). It is an indexed sequence of items (IGPModifiableBlockStructureItem), which hold object references to activities within the block.
Block structure items also hold information about parameter mappings, transitions between activities, exception handling and role information.
The GP design time API provides the following functionalities for block structure manipulation:
¡ Adding an item to the structure
We define a block b with three actions: a_0, a_1, a_2.
import com.sap.caf.eu.gp.process.api.IGPModifiableAction;
IGPModifiableBlock b = null;
try { // create the block and the actions ... // add the actions to the structure b.getModifiableStructure().addItem(a_0); b.getModifiableStructure().addItem(a_1); b.getModifiableStructure().addItem(a_2);
// save the block object manager.save(b); } finally { if (b != null) { // release the block object manager.release(b); } } |
For more information on how to implement actions, see Creating Actions.
¡ Inserting an item into a specific position in the structure
Suppose you have already created and saved block b, and for some reason you decide that you need to execute another activity before action a_1, a block named b_0 for example. You insert the block into the structure on position 2. Thus, action a_1 is shifted to position 3.
b.getModifiableStructure().insertItem(2, b_0);
|
¡ Replacing an item in the structure
To replace the item on position 3 (in our case, a_1) with b_0, write:
b.getModifiableStructure().setItem(3, b_0);
|
¡ Exchanging two items in the structure
To swap items on positions 3 and 4 (in our case, b_0 and a_2), write:
b.getModifiableStructure().swap(3, 4);
|
¡ Deleting an item from the structure
To delete the item on position 1 (a_0), write:
b.getModifiableStructure().removeItem(1);
|
3. Make sure you save and release the block after you have created and modified it.
manager.save(b); manager.release(b);
|
Once you have assigned actions to the block, you can also:
● Map local, input and output parameters
See Implementing Parameter Mapping.
● Set targets for the result states of the callable objects
See Defining Transitions.
● Implement exception handlers
See Implementing Exception Handling.
For more information about block editing, see Editing GP Development Objects.