When working with the GP design time API, you need access to development objects saved to the database. This procedure shows you how to search for persisted objects by specifying object attributes. Once you have found the development objects you need, you can use the design time update manager listing functionality to retrieve information about them or open them for editing. When an object is open for editing, it is locked until you save and release it.
● You have instantiated the IGPDesigntimeUpdateManager.
See Instantiating the Design Time Manager.
● You have previously created development objects and have saved them to the database.
See Creating GP Development Objects.
...
1. Retrieve objects from the database.
You can filter objects depending on their category and status. If you do not want to restrict object search to a given category or status, you should replace the search criteria with null.
Retrieving Actions with Status ACTIVE |
import java.util.Iterator; import com.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager; import com.sap.caf.eu.gp.process.api.IGPCategory; import com.sap.caf.eu.gp.base.api.GPDevelopmentObjectStatus;
// retrieve actions with a category and status ACTIVE Iterator list = manager.getActions( new String[] {cat.getID()}, new GPDevelopmentObjectStatus[] {GPDevelopmentObjectStatus.ACTIVE_STATUS} ); |
2. For each of the objects with corresponding category and status, create an IGPDevelopmentObjectInfo instance, which holds all relevant information about the object (Id, version number, title, description, metadata, status, type).
You can use this information, for example, to retrieve an object’s Id and version number by specifying a title and description for it.
Retrieving Objects Information |
import com.sap.caf.eu.gp.base.api.IGPDevelopmentObjectInfo;
while (list.hasNext()) { // get object info IGPDevelopmentObjectInfo info = (IGPDevelopmentObjectInfo) list.next(); ... } |
3. Open the objects that meet your criteria by providing Id and version number for them. The Id is assigned by persisting the object in the database at the time of creation and cannot be changed.
Opening a Development Object of Type Action |
import com.sap.caf.eu.gp.process.api.IGPModifiableAction;
IGPModifiableAction a = manager.openAction(info.getId(), info.getVersionNumber());
|
4. Edit the development object.
You can modify:
○ General object attributes – for example, title, description, permissions, input and output parameters, and so on
○ Type-specific attributes – such as execute and display callable objects for actions, configuration properties for callable objects, and so on
Modifying Development Objects |
import com.sap.caf.eu.gp.process.api.IGPModifiableAction; import com.sap.caf.eu.gp.co.api.IGPCallableObject; import com.sap.caf.eu.gp.process.api.IGPModifiableBlock; import com.sap.caf.eu.gp.process.api.IGPModifiableProcess;
action.replaceExecuteCallableObject(co); co.setConfigProperty("CONFIG", "value"); block.addRole("approver", "Approver"); process.setDefaultRuntimeView(viewID);
|
5. After you have made changes to the object, you need to save and release it.
The modification lock imposed on the object does not allow simultaneous editing and should be removed after all editing operations have been performed.
Saving and Releasing an Action |
import com.sap.caf.eu.gp.exception.api.GPBaseException;
IGPModifiableAction a = null; try { // open action or create a new one
// make some changes...
// save it manager.save(a); } catch (GPBaseException e) { // handle exception } finally { if (a != null) manager.release(a); } |
...
6. Activate the object only if you do not have to make any more changes or if you want to use it in a process at runtime.
Once activated, the current object version can no longer be edited. You can only modify the upgraded inactive version of the object.
Activating an Action |
manager.activate(a);
|
Retrieving Callable Objects Based on Category |
import com.sap.caf.eu.gp.base.api.IGPDevelopmentObjectInfo; import com.sap.caf.eu.gp.process.api.IGPCategory; import com.sap.caf.eu.gp.co.api.IGPCallableObject; import java.util.Iterator; import java.util.Locale; import com.sap.caf.eu.gp.context.api.IGPUserContext; 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.GPProcessFactory; import com.sap.caf.eu.gp.exception.api.GPEngineException; import com.sap.caf.eu.gp.exception.api.GPInvocationException;
// 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.getDefault()).equals(catName)) { cat = subs[i]; } } // specify search attributes for the callable object String coTitle = "Title"; String coDescription = "Description"; IGPCallableObject co = null; try { //retrieve callable objects of any status in category cat Iterator list = manager.getCallableObjects( new String[] {cat.getID()}, null ); //for each callable object in the list while (list.hasNext()) { // get object info IGPDevelopmentObjectInfo info = (IGPDevelopmentObjectInfo) list.next(); // open it if title and description match if (info.getTitle().equals(coTitle) && info.getDescription().equals(coDescription)) { co = manager.openCallableObject(info.getId(), info.getVersionNumber()); break; } } } catch (GPEngineException e) { // handle exception } catch (GPInvocationException e) { // handle exception } |
Retrieving Processes Based on Status |
import com.sap.caf.eu.gp.base.api.GPDevelopmentObjectStatus; import java.util.Iterator; import com.sap.caf.eu.gp.base.api.IGPDevelopmentObjectInfo; import com.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager;
// define the status of the processes you want to list GPDevelopmentObjectStatus[] statusArray = { GPDevelopmentObjectStatus.ACTIVE_STATUS, GPDevelopmentObjectStatus.INACTIVE_STATUS }; // list processes of any category, with status ACTIVE and INACTIVE Iterator processes = manager.getProcesses(null, statusArray); // for each process in the list while (processes.hasNext()) { // get object info IGPDevelopmentObjectInfo gpDevelopmentObjectInfo = (IGPDevelopmentObjectInfo)processes.next();
// edit objects... } |