Creating Actions
Use
You can create your own actions using the GP design time API. The interface also allows you to assign callable objects for display and execution to the actions you implement and to define input and output parameter structures for them.
Prerequisites
You have instantiated the IGPDesigntimeUpdateManager . For more information, see Instantiating the Design Time Manager .
Procedure
- Implement the action by providing its basic data:
You need to specify a category for the newly-created action. For this purpose, you can create a new category or provide the Id of an existing one.
| Creating an Action |
|---|
importcom.sap.caf.eu.gp.process.api.IGPCategory; importcom.sap.caf.eu.gp.process.api.GPProcessFactory; importjava.util.Locale; importcom.sap.caf.eu.gp.context.api.IGPUserContext; importcom.sap.caf.eu.gp.process.api.IGPModifiableAction; importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeManager; importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager; // instantiate the design time manager to get the root category IGPDesigntimeManagerdtManager = GPProcessFactory.getDesigntimeManager(); IGPCategoryroot = dtManager.getRootCategory(userContext); // create a new category "test" in the root category IGPCategory cat = manager.createCategory("test","A test category", root);
StringaName = "Action"; StringaDescription = "A test action"; // create an action in the "test" category IGPModifiableActiona = manager.createAction( Locale.getDefault(), aName, aDescription, cat.getID() ); |
- Assign callable objects to the action.
You can assign two separate objects to one action:
- Callable object for execution (mandatory)
- Callable object for display
You should explicitly copy the input and output parameters of the object for execution to:
- The input and output parameter context of the action
- The local parameter context of the action
Once you have a copy of the parameters, you should also map them. Make sure that you also define the appropriate mappings between the existing callable objects. For more information, see Implementing Parameter Mapping .
| Assigning Execution Callable Object to an Action |
|---|
importcom.sap.caf.eu.gp.structure.api.IGPStructureInfo; importcom.sap.caf.eu.gp.co.api.IGPCallableObject; IGPModifiableActiona = null; IGPCallableObjectco = null; try{
// create the callable object and the action ... // save and activate the callable object manager.save(co); manager.activate(co); // assign execution object to the action a.setExecuteCallableObject(co); // copy object's input parameters to action's input IGPStructureInfo in = co.getInputParameters(); a.setInputParameters(in); // copy object's output parameters to action's output IGPStructureInfo out = co.getOutputParameters(); a.setOutputParameters(out); // retrieve action's local context IGPStructureInfolocal = a.getLocalParameters(); // copy object's input and output to action's local context ... // save changes to local context a.setLocalParameters(local); // save the action manager.save(a); }finally {
if (a != null) {
// release the action manager.release(a); } if (co != null) {
// release the callable object manager.release(co); } } |
For more information on how to create callable objects, see Creating Callable Objects .
The result states and exceptions of the callable object for execution are automatically copied from the object to the action. You can obtain information about them using the following methods:
| Accessing Action's Result States and Exceptions |
|---|
importcom.sap.caf.eu.gp.process.api.IGPResultStateInfo; importcom.sap.caf.eu.gp.process.api.IGPProcessExceptionInfo; IGPResultStateInfo[] rs = a.getResultStates(); IGPProcessExceptionInfo[] pe = a.getProcessExceptions(); |
The callable object for display is used to provide information about the action after it is completed. Unlike the execution callable object, the display callable object cannot change the state of the action, that is, modify its output parameters. Therefore, you only need to map its input parameters to the output of the callable object for execution.
| Assigning Display Callable Object to an Action |
|---|
// assign display object to the action a.setDisplayCallableObject(dco); |
- Optionally, you can replace the callable objects for execution and display using the following methods:
| Replacing Callable Objects in an Action |
|---|
a.replaceExecuteCallableObject(exco); a.replaceDisplayCallableObject(dco); |
- If the callable objects have been assigned and are not null, they can be accessed through the action in the following way:
| Accessing the Callable Objects for Execution and Display |
|---|
IGPCallableObject exco = a.getExecuteCallableObject().getCallableObject(); IGPCallableObject dispco = a.getDisplayCallableObject().getCallableObject(); |
- Define additional input and output parameters for the action:
| Defining Input and Output Parameters |
|---|
importcom.sap.caf.eu.gp.structure.api.IGPAttributeInfo; // get input parameters structure IGPStructureInfoin = a.getInputParameters(); // add structure "customer" and set its multiplicity IGPStructureInfocustomer = in.addStructure("customer", a.getTitle() + "_input");
customer.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1); // add attributes to the structure customer.addAttribute("first_name",IGPAttributeInfo.BASE_STRING);
customer.addAttribute("last_name",IGPAttributeInfo.BASE_STRING);
customer.addAttribute("address",IGPAttributeInfo.BASE_STRING);
customer.addAttribute("organization_id",IGPAttributeInfo.BASE_UNSIGNED_INT);
// save the input structure a.setInputParameters(in); // get output parameters structure IGPStructureInfoout = a.getOutputParameters(); // add structure "order" and set its multiplicity IGPStructureInfoorder = out.addStructure("order", a.getTitle() + "_output");
order.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_0_N); // add attributes to the structure order.addAttribute("product_id",IGPAttributeInfo.BASE_UNSIGNED_INT);
order.addAttribute("quantity",IGPAttributeInfo.BASE_UNSIGNED_INT);
order.addAttribute("price",IGPAttributeInfo.BASE_FLOAT);
// save the output structure a.setOutputParameters(out); |
- Make sure you save and release the action after you have created and modified it.
manager.save(a);
manager.release(a);
Result
Once you have created an action, you can:
- Include it in a block. See Creating Blocks .
- Open it for editing. See Editing GP Development Objects .
- Delete it from the database if you no longer need it. See Deleting GP Development Objects .
- Include it in the process flow as an ad-hoc item. For more information, refer to Including Additional Functionality .