Scheduling Process Initiation Using the GP API

Use

The Guided Procedures (GP) framework allows you to initiate GP processes in two basic ways:

  • Manually, using the GP runtime workset or the GP runtime API
  • Automatically, with support for scheduled initiation, recurrence, and post-processing options, using the GP Administration workset or the Scheduled Process Initiation API

This procedure describes the steps needed to introduce scheduled initiation of processes to your composite application with the Scheduled Process Initiation API.

Prerequisites

Procedure

  1. Instantiate the scheduling service that allows access to the scheduling API functionality.

Instantiating the Scheduling Service
importcom.sap.caf.eu.gp.scheduling.api.GPScheduleFactory;
importcom.sap.caf.eu.gp.scheduling.api.IGPScheduleService;
 
IGPScheduleService scheduleService = GPScheduleFactory.getGPScheduleService();
  1. Create a user that is able to access process information and to schedule initiation.

Creating a User
importcom.sap.security.api.IUser;
importcom.sap.security.api.IUserFactory;
importcom.sap.security.api.UMFactory;
importcom.sap.caf.eu.gp.context.api.IGPUserContext;
importcom.sap.caf.eu.gp.context.api.IGPContextManager;
importcom.sap.caf.eu.gp.context.api.GPContextFactory;
 
IUserFactory userFactory = UMFactory.getUserFactory();IUser creator = userFactory.getUserByLogonID("Administrator");IGPContextManager gpCtxManager = GPContextFactory.getContextManager();IGPUserContext gpUserContext = gpCtxManager.createUserContext(creator);
  1. Retrieve the process whose initiation you want to schedule and create an instance for it.
    1. Retrieve the process template ID
    2. Retrieve and fill in the list of process roles
    3. Construct the input structure

    For detailed information about the relevant API, see Starting and Terminating Processes Using the GP API .

  2. Create a scheduled initiation object.

    You have to associate this object with the process template you have retrieved previously. You may also specify a post-processing implementation that provides a set of custom methods, including a callback method.

Creating a Scheduled Initiation Object for a Process
importcom.sap.caf.eu.gp.scheduling.api.IGPTask;
importcom.sap.caf.eu.gp.scheduling.api.IGPScheduledProcessInitiation;
 
String processName = "Process scheduled for initiation";
String processDescription = "Description";
 
intafterExCompType = IGPTask.APPLICATION_COMPONENT_TYPE_LIBRARY;
String afterExCompName = "test.sap.com~caf~jtest~eu~gp~api~demo~callback";
String afterExClass = "com.sap.test.caf.test.eu.gp.api.schedinst.postproc.ScheduledInitiationCallback";
 
IGPScheduledProcessInitiation initiation = GPScheduleFactory.createScheduledInititation(
                // the IGPProcess instance from step 2
                 process,
                // the relevant user
                 creator,
                // free text values for process name and description
                 processName,
                 processDescription,
                // the IGPProcessRoleInstanceList from step 2
                 roles,
                // type and name of the post-processing component
                 afterExCompType,
                 afterExCompName,
                // name of the post-processing class
                 afterExClass
                 );
  1. Create a task.

    You must associate the task with the initiation object you have created previously and provide additional information, such as the task name and a description, creator, time of creation and the input parameter structure of the process.

Creating a Task for Scheduled Process Initiation
String taskName = "Schedule process initiation task";
String taskDescription = "Description";
 
inttaskId = scheduleService.createTask(
              // initiation object from step 3
               initiation,
              // name and description of the task
               taskName,
               taskDescription,
              // the user that creates the task
               creator,
               // time of creation - current time
              newTimestamp(System.currentTimeMillis()),
              // the IGPStructure structure from step 2
               inputStr
               );
  1. Create a schedule and assign it to the task.
    To each task you can assign more than one schedule, for example, schedules that differ in their occurrence constraints. With the methods of the
    GPScheduleFactory
    class, you can create the following types of schedules:
    • Occurring once -
      createTimingOnce()
    • Recurrent daily -
      createTimingRecurrentDaily()
    • Recurrent monthly -
      createTimingRecurrentMonthly()
    • Recurrent weekly -
      createTimingRecurrentWeekly()
    • Recurrent yearly -
      createTimingRecurrentYearly()
    To create schedules, you use the
    IGPTimingCreation
    interface and specify a set of properties, which you can configure at the time of creation. Some basic schedule properties are listed below:

Schedule Properties

Property Possible Values

Priority

IGPScheduleService.PRIORITY_HIGH
IGPScheduleService.PRIORITY_LOW
IGPScheduleService.PRIORITY_STANDARD

Error Mode

IGPScheduleService.ERROR_MODE_DISMISS
IGPScheduleService.ERROR_MODE_TRY_AGAIN
IGPScheduleService.ERROR_MODE_TRY_UNTILL_SUCCESS

Creating a Schedule Occurring Once
importcom.sap.caf.eu.gp.scheduling.api.IGPTimingCreation;
 
longScheduleInitTimeOffset = 2000;
// set initial time of schedule - delayed with some offset
Timestamp scheduleInitTime =newTimestamp(System.currentTimeMillis()+ ScheduleInitTimeOffset);
 
IGPTimingCreation taskSchedule = GPScheduleFactory.createTimingOnce(
                               
// task id from step 4
               taskId,
                               
// schedule priority
               IGPScheduleService.PRIORITY_STANDARD,
                                
// initial time of schedule
               scheduleInitTime,
                               
// error mode of schedule
               IGPScheduleService.ERROR_MODE_DISMISS
               );
// assign the schedule to the task by persisting it in the database
intscheduleID = scheduleService.scheduleTask(taskSchedule);
  1. Optionally, you can modify or delete a schedule once you have created it.
    To access an existing schedule, use the
    IGPTiming
    interface. You cannot edit the schedule properties directly. Instead, you have to create a new schedule to replace the old one.

Modifying and Deleting a Schedule
importcom.sap.caf.eu.gp.scheduling.api.IGPTiming;
 
// get the schedule created previously from the database
IGPTiming oldSchedule = scheduleService.getSchedule(scheduleID);// create a new schedule as described in step 6IGPTimingCreation newSchedule = ...;// replace the old schedule with the new one and persist itscheduleService.rescheduleTask(oldSchedule, newSchedule);// delete a schedulescheduleService.deleteSchedule(scheduleID);

Result

The schedule that you created allows you to start a particular process according to the timing preferences you have specified.

In most cases, you need some feedback once the process has been started. For this purpose, you can create a post-processing class that implements the
initiatedProcess()IGPScheduledInitiationPostProcessingInterface
method of the . It provides a callback functionality that you can use in your custom implementations.

See: Implementing a Post-Processing Class with Callback