Editing GP Development Objects

Use

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.

Prerequisites

Procedure

  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
importjava.util.Iterator;
importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager;
importcom.sap.caf.eu.gp.process.api.IGPCategory;
importcom.sap.caf.eu.gp.base.api.GPDevelopmentObjectStatus;
 
// retrieve actions with a category and status ACTIVE
Iteratorlist = manager.getActions(
                                  newString[] {cat.getID()},
                                   newGPDevelopmentObjectStatus[] {GPDevelopmentObjectStatus.ACTIVE_STATUS}
                                 );
  1. 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).

Retrieving Objects Information
importcom.sap.caf.eu.gp.base.api.IGPDevelopmentObjectInfo;
 
while(list.hasNext()) {
         // get object info
         IGPDevelopmentObjectInfo info = (IGPDevelopmentObjectInfo) list.next();
...
}
  1. 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
importcom.sap.caf.eu.gp.process.api.IGPModifiableAction;
 
IGPModifiableAction a= manager.openAction(info.getId(), info.getVersionNumber());
 
  1. 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
importcom.sap.caf.eu.gp.process.api.IGPModifiableAction;
importcom.sap.caf.eu.gp.co.api.IGPCallableObject;
importcom.sap.caf.eu.gp.process.api.IGPModifiableBlock;
importcom.sap.caf.eu.gp.process.api.IGPModifiableProcess;
 
action.replaceExecuteCallableObject(co);
co.setConfigProperty("CONFIG","value");
block.addRole("approver","Approver");
process.setDefaultRuntimeView(viewID);
 
  1. 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
importcom.sap.caf.eu.gp.exception.api.GPBaseException;
 
IGPModifiableActiona = 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);
}
  1. 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);

Example

Retrieving Callable Objects Based on Category
importcom.sap.caf.eu.gp.base.api.IGPDevelopmentObjectInfo;
importcom.sap.caf.eu.gp.process.api.IGPCategory;
importcom.sap.caf.eu.gp.co.api.IGPCallableObject;
importjava.util.Iterator;
importjava.util.Locale;
importcom.sap.caf.eu.gp.context.api.IGPUserContext;
importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager;
importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeManager;
importcom.sap.caf.eu.gp.process.api.GPProcessFactory;
importcom.sap.caf.eu.gp.exception.api.GPEngineException;
importcom.sap.caf.eu.gp.exception.api.GPInvocationException;
 
// find category "test" in the root category
String catName ="test";
IGPCategory cat =null;
IGPDesigntimeManagerdtManager = GPProcessFactory.getDesigntimeManager();
IGPCategoryroot = 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
StringcoTitle = "Title";
StringcoDescription = "Description";
IGPCallableObjectco = null;
try{
     //retrieve callable objects of any status in category cat
     Iteratorlist = 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
importcom.sap.caf.eu.gp.base.api.GPDevelopmentObjectStatus;
importjava.util.Iterator;
importcom.sap.caf.eu.gp.base.api.IGPDevelopmentObjectInfo;
importcom.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
Iteratorprocesses = manager.getProcesses(null, statusArray);
// for each process in the list
while(processes.hasNext()) {
     // get object info
     IGPDevelopmentObjectInfo gpDevelopmentObjectInfo = (IGPDevelopmentObjectInfo)processes.next();
 
     // edit objects...
   }