
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.
You have instantiated the IGPDesigntimeUpdateManager . For more information, see Instantiating the Design Time Manager .
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() ); |
You can assign two separate objects to one action:
You should explicitly copy the input and output parameters of the object for execution to:
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); |
setExecuteCallableObject()setDisplayCallableObject()
| Replacing Callable Objects in an Action |
|---|
a.replaceExecuteCallableObject(exco); a.replaceDisplayCallableObject(dco); |
replaceExecuteCallableObject()replaceDisplayCallableObject()
| Accessing the Callable Objects for Execution and Display |
|---|
IGPCallableObject exco = a.getExecuteCallableObject().getCallableObject(); IGPCallableObject dispco = a.getDisplayCallableObject().getCallableObject(); |
| 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); |
manager.save(a); manager.release(a); |
Once you have created an action, you can: