You can implement your own callable objects with the GP design time API. The interface allows you to define input, output and configuration parameters for the callable object, as well as result states and exceptions.
● You have instantiated the IGPDesigntimeUpdateManager.
See Instantiating the Design Time Manager.
● You know the type of the callable object you want to create.
Callable object types are resolved with the IGPCallableObjectTypeManager. Types are defined by a type name. You can retrieve the type, if you know the type name. For example, type name com.sap.gp.wd corresponds to type Web Dynpro Application.
...
1. Create the callable object by providing its basic data:
You need to specify a category for the newly-created callable object. For this purpose, you can create a new category or provide the Id of an existing one.
Creating a Callable Object of Type Web Dynpro Application |
import java.util.Locale; import com.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager; import com.sap.caf.eu.gp.process.dt.api.IGPDesigntimeManager; import com.sap.caf.eu.gp.process.api.IGPCategory; import com.sap.caf.eu.gp.process.api.GPProcessFactory; import com.sap.caf.eu.gp.co.type.api.IGPCallableObjectTypeManager; import com.sap.caf.eu.gp.co.type.api.IGPCallableObjectType; import com.sap.caf.eu.gp.co.api.IGPCallableObject; import com.sap.caf.eu.gp.exception.api.GPBaseException;
Locale locale = Locale.getDefault();
// get user info IUser loggedUser = WDClientUser.getCurrentUser().getSAPUser(); IGPUserContext userContext = GPContextFactory.getContextManager().createUserContext(loggedUser); // instantiate the design time update manager .. // find category “test” in the root category String catName = "test"; IGPCategory cat = null; IGPDesigntimeManager dtManager = GPProcessFactory.getDesigntimeManager(); IGPCategory root = dtManager.getRootCategory(userContext); IGPCategory[] subs = root.getSubCategories(); for (int i = 0; i < subs.length; i++) { if (subs[i].resolveTitle(locale).equals(catName)) { cat = subs[i]; } } String coTitle = "Title"; String coDescription = "Description"; String coType = "com.sap.gp.wd";
try { // resolve the callable object type IGPCallableObjectTypeManager coTypeManager = GPCallableObjectTypeFactory.getCallableObjectTypeManager(); IGPCallableObjectType wdCoType = coTypeManager.getCallableObjectType(coType); // create the callable object IGPCallableObject co = manager.createCallableObject( wdCoType, locale, coTitle, coDescription, cat.getID() ); } catch (GPBaseException e) { // handle GP exception } |
2. Populate the input and output parameter structures of the object as they are empty initially. You may create additional attributes and substructures and specify their type and multiplicity.
The following types of multiplicity are supported:
Singleton |
0_1 (at most one) |
1_1 (exactly one) |
|
List |
0_N (any number of occurrences) |
1_N (at least one) |
Populating the Input Parameters Structure |
import com.sap.caf.eu.gp.structure.api.IGPStructureInfo; import com.sap.caf.eu.gp.structure.api.IGPAttributeInfo; import com.sap.caf.eu.gp.exception.api.GPEngineException; import com.sap.caf.eu.gp.exception.api.GPInvocationException;
try { // obtain copy of the input parameter structure of our object IGPStructureInfo input = co.getInputParameters();
IGPAttributeInfo attr = null; // add attribute of type date, its multiplicity is by default 0_1 attr = input.addAttribute("param_input_date", IGPAttributeInfo.BASE_DATE);
// define string attribute and make it required attr = input.addAttribute("param_input_string", IGPAttributeInfo.BASE_STRING); attr.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1);
// define a list of doubles attr = input.addAttribute("param_input_double", IGPAttributeInfo.BASE_DOUBLE); attr.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_0_N);
//define a substructure IGPStructureInfo subStruct = input.addStructure("sub_structure"); // additionally define the substructure...
// at the end, save the changes co.setInputParameters(input);
} catch (GPEngineException e) { // internal exception occurred when getting or setting the input parameters } catch (GPInvocationException e) { // invalid parameters were passed by defining attribute or sub-structure } |
You may use the same logic to populate the output parameters structure:
// obtain copy of the output parameter structure IGPStructureInfo output = co.getOutputParameters(); // add substructures and attributes ... // save the changes co.setOutputParameters(output);
|
3. Depending on the particular implementation, specify additional properties.
To define result states, exceptions and other configuration parameters, use the IGPPhysicalCallableObject associated with the callable object.
The physical callable object stores technical information about the object that should be invoked during action execution. This includes:
■ Possible result states and process exceptions resulting from the object execution
■ Information about the UI behavior of the callable object in GP design time, such as visibility of the different configuration screens
Defining Result States, Exceptions and Configuration Properties |
import com.sap.caf.eu.gp.co.api.IGPPhysicalCallableObject;
IGPPhysicalCallableObject pco = co.resolvePhysicalCallableObject(); try { // set two result states: complete and incomplete pco.addResultState("COMPLETE", "complete"); pco.addResultState("INCOMPLETE", "incomplete");
// define an exception pco.addProcessException("EXCEPTION", "exception");
// set configuration property pco.setConfigProperty("property", "value");
// make the input view of the object visible when the object is created, edited and displayed (for all purposes) pco.setInputViewVisible(true, VIEW_VISIBILITY_PURPOSE_ALL);
} catch (GPInvocationException e) { // invalid parameters were passed } |
4. Save and release the object.
Once a new callable object has been created, it is locked for editing by other users until it has been saved and released.
Saving and Releasing a Callable Object |
IGPCallableObject co = null; try { // open callable object or create a new one ... // make some changes... ... // save it manager.save(co); } catch (GPBaseException e) { // handle error } finally { if (co != null) manager.release(co); } |
Once you have created a callable object, you can:
● Assign it to an action. See Creating Actions.
● 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.
● Use it as an info callable object and attach it to an activity in the process flow. For more information, refer to Including Additional Functionality.