Show TOC Start of Content Area

Procedure documentation Scheduling Process Initiation Using the GP API  Locate the document in its SAP Library structure

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

      You have set up your project in the SAP NetWeaver Developer Studio.

See: Setting Up Your Project

      You have access to existing process templates or you have created them:

       In GP design time – Process Design

       Using the design time API – Creating Processes

Procedure

...

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

Example

Instantiating the Scheduling Service

import com.sap.caf.eu.gp.scheduling.api.GPScheduleFactory;

import com.sap.caf.eu.gp.scheduling.api.IGPScheduleService;

 

IGPScheduleService scheduleService = GPScheduleFactory.getGPScheduleService();

 

       2.      Create a user that is able to access process information and to schedule initiation.

Example

Creating a User

import com.sap.security.api.IUser;

import com.sap.security.api.IUserFactory;

import com.sap.security.api.UMFactory;

import com.sap.caf.eu.gp.context.api.IGPUserContext;

import com.sap.caf.eu.gp.context.api.IGPContextManager;

import com.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);

 

       3.      Retrieve the process whose initiation you want to schedule and create an instance for it.

                            a.      Retrieve the process template ID

                            b.      Retrieve and fill in the list of process roles

                            c.      Construct the input structure

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

       4.      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.

Example

Creating a Scheduled Initiation Object for a Process

import com.sap.caf.eu.gp.scheduling.api.IGPTask;

import com.sap.caf.eu.gp.scheduling.api.IGPScheduledProcessInitiation;

 

String processName = "Process scheduled for initiation";

String processDescription = "Description";

 

int afterExCompType = 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

                 );

       5.      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.

Example

Creating a Task for Scheduled Process Initiation

String taskName = "Schedule process initiation task";

String taskDescription = "Description";

 

int taskId = 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

               new Timestamp(System.currentTimeMillis()),

               // the IGPStructure structure from step 2

               inputStr

               );

       6.      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

Example

Creating a Schedule Occurring Once

import com.sap.caf.eu.gp.scheduling.api.IGPTimingCreation;

 

long ScheduleInitTimeOffset = 2000;

// set initial time of schedule – delayed with some offset

Timestamp scheduleInitTime = new Timestamp(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

int scheduleID = scheduleService.scheduleTask(taskSchedule);

       7.      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.

Example

Modifying and Deleting a Schedule

import com.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 6
IGPTimingCreation newSchedule = ...;
// replace the old schedule with the new one and persist it
scheduleService.rescheduleTask(oldSchedule, newSchedule);
// delete a schedule
scheduleService.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() method of the IGPScheduledInitiationPostProcessingInterface. It provides a callback functionality that you can use in your custom implementations.

See: Implementing a Post-Processing Class with Callback

End of Content Area