29 Mart 2016 Salı

Custom tasks Oracle BPM 12c: example of restricting the list of users for operation "Delegate"


By default, the task in Oracle BPM can reassign or delegate to any user, role and group. But you can limit the list by creating a class BPM-project (in terms of JDeveloper), which implements the interface oracle.bpel.services.workflow.task.IRestrictedAssignmentCallback.

Consider an example where you want to restrict users to a list of "delegation" of the operation as follows:
If the contractor is a task group or role, the delegate can only be users of the composition of the group or role;
If the problem is the executor of the user, it can not be delegated (empty list of available users to delegate).
Example code:



import java.util.ArrayList;  
 import java.util.Collections;  
 import java.util.List;  
 import java.util.Map;  
   
 import oracle.bpel.services.workflow.IWorkflowConstants;  
 import oracle.bpel.services.workflow.task.IRestrictedAssignees;  
 import oracle.bpel.services.workflow.task.IRestrictedAssignmentCallback;  
 import oracle.bpel.services.workflow.task.impl.RestrictedAssignees;  
 import oracle.bpel.services.workflow.task.impl.TaskAssignee;  
 import oracle.bpel.services.workflow.task.model.Task;  
   
 import oracle.tip.pc.services.common.ServiceFactory;  
 import oracle.tip.pc.services.identity.BPMAppRole;  
 import oracle.tip.pc.services.identity.BPMAuthorizationService;  
 import oracle.tip.pc.services.identity.BPMGroup;  
 import oracle.tip.pc.services.identity.BPMIdentityService;  
 import oracle.tip.pc.services.identity.BPMUser;  
   
 import oracle.bpel.services.workflow.task.model.IdentityType;  
   
 public class RestrictedAssignmentCallbackImpl implements IRestrictedAssignmentCallback {  
   
   public IRestrictedAssignees getPermittedAssignees(Task task, Map map, String currentUser, String identityContext,  
                            String operation) {  
     List assignees = new ArrayList();  
     if (operation.equals(IRestrictedAssignmentCallback.OperationType.REASSIGN.toString())) {  
       //TODO реализовать логику для операции "Переназначение"  
     } else if (operation.equals(IRestrictedAssignmentCallback.OperationType.DELEGATE.toString())) {  
       try {  
         BPMIdentityService idenService = getIdentityServiceInstance(identityContext);  
         List<IdentityType> assigneesList = task.getSystemAttributes().getAssignees();  
         for (IdentityType assignee : assigneesList) {  
           if (IWorkflowConstants.IDENTITY_TYPE_GROUP.equals(assignee.getType())) {  
             List<BPMUser> usersInGroup =  
               idenService.getParticipantsToGroup(assignee.getDisplayName(), true);  
             for (BPMUser user : usersInGroup) {  
               assignees.add(new TaskAssignee(user.getName(), IWorkflowConstants.IDENTITY_TYPE_USER));  
             }  
           } else if (IWorkflowConstants.IDENTITY_TYPE_APPLICATION_ROLE.equals(assignee.getType())) {  
             List<BPMUser> usersInGroup =  
               idenService.getParticipantsToAppRole(assignee.getDisplayName(),  
                                  task.getApplicationContext(), false);  
             for (BPMUser user : usersInGroup) {  
               assignees.add(new TaskAssignee(user.getName(), IWorkflowConstants.IDENTITY_TYPE_USER));  
             }  
           } else if (IWorkflowConstants.IDENTITY_TYPE_USER.equals(assignee.getType())) {  
             // Пустой список  
             return new RestrictedAssignees(new ArrayList(), true);  
           }  
         }  
   
       } catch (Exception ex) {  
         ex.printStackTrace();  
       }  
     }   
   
     if (!assignees.isEmpty()) {  
       return new RestrictedAssignees(assignees, true);  
     }  
   
     return null;  
   }  
   
   public List<IRestrictedAssignmentCallback.OperationType> getRestrictedOperations(Task task, Map map,  
                                            String currentUser,  
                                            String identityContext) {  
     return Collections.emptyList();  
   }  
   
   private BPMAuthorizationService getAuthorizationService(String realmName) {  
     return ServiceFactory.getAuthorizationServiceInstance(realmName);  
   }  
   
   private BPMIdentityService getIdentityServiceInstance(String realmName) {  
     return ServiceFactory.getIdentityServiceInstance(realmName);  
   }  
 }  

Hiç yorum yok:

Yorum Gönder