Implementing Role Consolidation

Use

After you design and create a composite activity (a block or a process), you may need to add, rename or consolidate roles. Roles are used to define processors for the different activities:

  • The
    IGPAction
    activity has a single default role.
    The default role of an action is created by adding the action to a block structure. Its name is the action's technical name. This role is accessible through
    IGPModifiableBlockStructureItem.getActionRole()
    .
  • The
    IGPBlockIGPProcess
    and activities have a collection of roles.

    If not modified, the block roles are the union of all the roles of its children. When adding a new child to the block, its roles are copied automatically to the parent.

The role information is accessed and modified through the
IGPModifiableRoleInfo
interface.

Prerequisites

Procedure

Adding New Roles

In addition to the roles copied from the child activities to the parent block, you can create more block roles through the
IGPModifiableBlock
interface:

Adding New Roles to a Block
importcom.sap.caf.eu.gp.process.api.IGPModifiableBlock;
 
// add role "Block role 1" with technical name "role1"
block.addRole("role1","Block Role 1");
// add role "Block role 2"with technical name "role2"
block.addRole("role2","Block Role 2");
// remove role "Block role 1"
block.removeRole("role1");

The technical name should not contain white spaces and should be no longer than 32 characters. It is unique amongst all the roles that have already been defined for the block.

By analogy, additional process roles can be created or removed through the
IGPModifiableProcess
interface. For these roles, you also have to specify one of the following role types:
  • ROLE_TYPE_INITIATION_DEFINED
    - the role is filled during the initiation with user-dependent data
  • ROLE_TYPE_INITIATOR
    - the role is filled with the initiator data
  • ROLE_TYPE_RT_DEFINED
    - the role is undefined during design time; it is filled at runtime by a specific action

Adding New Roles to a Process
importcom.sap.caf.eu.gp.process.api.IGPModifiableProcess;
importcom.sap.caf.eu.gp.process.api.GPRoleType;
 
// add role "Processor" of type Initiator
process.addRole("processor","Processor", GPRoleType.ROLE_TYPE_INITIATOR);
// add role "Advisor" of type Runtime Defined
process.addRole("advisor","Advisor", GPRoleType.ROLE_TYPE_RT_DEFINED);
// add role "Processor" of type Initiation Defined
process.addRole("employee","Employee", GPRoleType.ROLE_TYPE_INITIATION_DEFINED);

Modifying Existing Roles

You can modify the roles you have created and all other existing roles by changing their properties.

In addition to the roles that processes inherit from their child activities, there are three more automatically created built-in roles, which cannot be removed:

  • Administrator
  • Owner
  • Overseer

Modifying Roles
importcom.sap.caf.eu.gp.process.api.IGPModifiableProcess;
importcom.sap.caf.eu.gp.process.api.IGPModifiableBlock;
importcom.sap.caf.eu.gp.process.api.IGPModifiableRoleInfo;
importcom.sap.caf.eu.gp.process.api.GPRoleType;
 
// modify description of block role "Advisor"
IGPModifiableRoleInfo blockRole = block.getRole("advisor").setText("New Advisor");
 
// change type of built-in process role "Overseer"
IGPModifiableRoleInfo processRole = process.getModifiableOverseerRole().setRoleType(GPRoleType. ROLE_TYPE_INITIATOR);

Consolidating Roles

You can define mappings from child roles to parent roles to consolidate the processors of the parent activity. This is possible through the
IGPRoleMapIGPRoleMapping
interface, which holds information about block role mappings. For each mapping () you need to specify:
  • The role of the child activity that has to be consolidated
  • The corresponding item Id of the child activity in the block structure of the parent activity
  • A role in the parent activity

The example below maps the default roles of two child actions to a single block role, thus consolidating the roles.

Mapping Roles
importcom.sap.caf.eu.gp.process.api.IGPModifiableBlock;
importcom.sap.caf.eu.gp.process.api.IGPRoleMapping;
 
// map role of action_1 to block role "processor"
IGPRoleMapping mapping_1 = block.getRoleMap().mapRole(block.getRole("action_1"),block.getModifiableStructure().getItem(0).getID(), block.getRole("processor"));
 
// map role of action_2 to block role "processor"
IGPRoleMapping mapping_2 =
block.getRoleMap().mapRole(block.getRole("action_2"),block.getModifiableStructure().getItem(1).getID(), block.getRole("processor"));

You can also view available mappings or remove them if you no longer need them:

Retrieving and Removing Role Mappings
importcom.sap.caf.eu.gp.process.api.IGPModifiableBlock;
importcom.sap.caf.eu.gp.process.api.IGPRoleMapping;
importjava.util.Iterator;
 
// remove "mapping_1" created previously
block.getRoleMap().unmapRole(mapping_1);
 
// view all available role mappings for a block
Iterator listAll = block.getRoleMap().getRoleMappings();
 
// view available mappings for a given parent role in a block
Iterator listRole = block.getRoleMap().getRoleMappings("processor");