OIM API To Get Manual Fulfilment Tasks From SOA

package com.massiveGaze.SOA;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import oracle.bpel.services.workflow.IWorkflowConstants;
import oracle.bpel.services.workflow.WorkflowException;
import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.repos.Column;
import oracle.bpel.services.workflow.repos.Predicate;
import oracle.bpel.services.workflow.repos.TableConstants;
import oracle.bpel.services.workflow.repos.table.WFTaskConstants;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpel.services.workflow.verification.IWorkflowContext;
import oracle.iam.platform.workflowservice.exception.IAMWorkflowException;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class GetManualFulfilmentTasksFromSOA {
 private IWorkflowContext wfCtx = null;
 HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String > bpelprops = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String>();
  {     
    bpelprops.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,"t3://localhost:8001/soa-infra");
    bpelprops.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,"weblogic1");
    bpelprops.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,"weblogic");
    bpelprops.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
  }
 
 IWorkflowServiceClient  wfSvcClient = WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT,bpelprops,null);
 
 
 public static void main(String[] args) throws IAMWorkflowException {
  GetManualFulfilmentTasksFromSOA getManualFulfilmentTasksFromSOA = new GetManualFulfilmentTasksFromSOA();
  List<Task> listOfTasksFrmSOA =getManualFulfilmentTasksFromSOA.getManualFulfilmentTasks();
  getManualFulfilmentTasksFromSOA.displaySOAEntitlementsTask(new HashSet(listOfTasksFrmSOA));
 }
  public List<Task> getManualFulfilmentTasks() throws IAMWorkflowException{       
         ITaskQueryService querySvc =  wfSvcClient.getTaskQueryService();
         try{
             wfCtx = getAdminWorkflowContext(querySvc);
             System.out.println( "Creating Predicate Object to filter only DisconnectedProvisioning tasks from SOA.");              
            Predicate compositenamePredicate = new Predicate(TableConstants.WFTASKMETADATA_NAMESPACE_COLUMN,Predicate.OP_CONTAINS, "DisconnectedProvisioning");
            
             System.out.println( "Adding Predicate Object to filter TASK_STATE_ASSIGNED OR TASK_STATE_INFO_REQUESTED from SOA.");
             Predicate predicate = new Predicate(Column.getColumn(WFTaskConstants.STATE_COLUMN), Predicate.OP_EQ, IWorkflowConstants.TASK_STATE_ASSIGNED);
             predicate.addClause(Predicate.OR, Column.getColumn(WFTaskConstants.STATE_COLUMN), Predicate.OP_EQ,IWorkflowConstants.TASK_STATE_INFO_REQUESTED);
             
             System.out.println( "Adding Object to filter Title which Contains Entitlement from SOA.");
             Predicate titlePredicate = new Predicate(Column.getColumn(WFTaskConstants.TITLE_COLUMN), Predicate.OP_CONTAINS, "Entitlement");
             predicate = new Predicate(predicate, Predicate.AND, titlePredicate);
            
             System.out.println( "Adding Object to filter TEXTATTRIBUTE10_COLUMN User from SOA.");
             Predicate textAttribute10Predicate = new Predicate(Column.getColumn(WFTaskConstants.TEXTATTRIBUTE10_COLUMN), Predicate.OP_EQ, "APP7");
             textAttribute10Predicate.addClause(Predicate.OR, Column.getColumn(WFTaskConstants.TEXTATTRIBUTE10_COLUMN), Predicate.OP_EQ,"APP8");
             
             predicate = new Predicate(predicate, Predicate.AND, textAttribute10Predicate);
             
           
             compositenamePredicate = new Predicate(compositenamePredicate, Predicate.AND, predicate);
             
             System.out.println( "Preparing list query columns,which should exist in SOA result...!");
             List<String> queryColumns = new ArrayList<String>();
             queryColumns.add("TASKID");
             queryColumns.add("TASKNUMBER");
             queryColumns.add("TITLE");
             queryColumns.add("OUTCOME");
             queryColumns.add("STATE");
             queryColumns.add("ASSIGNEDDATE");
             queryColumns.add("ROOTTASKID");
             queryColumns.add("ASSIGNEES");
             queryColumns.add("ASSIGNEEGROUPS");
     
             List optionalInfo = new ArrayList();      
             optionalInfo.add("Comments"); 
             
             List<Task> listOfTasksFrmSOA= null;
             listOfTasksFrmSOA = querySvc.queryTasks(wfCtx, queryColumns, optionalInfo,ITaskQueryService.AssignmentFilter.ALL, null, compositenamePredicate,null, 0, 0);
           System.out.println( " Returning  List object listOfTasksFrmSOA with Task details.");
             return listOfTasksFrmSOA;
             
         } catch(WorkflowException e) {
             throw new IAMWorkflowException(e);
         }finally {
                System.out.println( "Restoring run as subject");              
                 }
     }
  
  
  public void displaySOAEntitlementsTask(Set<String> entAssgnKeys){   
      System.out.println( " validatePendingEntitlements Method getting called with entAssgnKeys ->"+entAssgnKeys);
      try {           
       
       List<Task> listOfTasksFrmSOA  = getManualFulfilmentTasks();
       if(listOfTasksFrmSOA!=null && listOfTasksFrmSOA.size() > 0){
           System.out.println( " Size of listOfTasksFrmSOA -> "+listOfTasksFrmSOA.size());
           for (Task task : listOfTasksFrmSOA) {
               String taskId = task.getSystemAttributes().getTaskId();
               String title =  task.getTitle();
               System.out.println("************************************************************");         
               System.out.println("task-id = " + taskId  + "   \ntask-title = "+ title);               
               Task currentTask =   getTaskDetailsByID(taskId);
               Element payload = currentTask.getPayloadAsElement();
               HashMap<String,String> payloadValuesMap = getPayloadValues(payload);
               for (Map.Entry<String, String> entry : payloadValuesMap.entrySet()) {
                   System.out.println("key = " + entry.getKey() + "  value = " + entry.getValue());
               }
               System.out.println("************************************************************\n\n");      
              /* String entityType = (payloadValuesMap.get("EntityType") != null) ? (String) payloadValuesMap.get("EntityType") :"";
               String provOperation=(payloadValuesMap.get("ProvisioningOperation") != null) ? (String) payloadValuesMap.get("ProvisioningOperation") :"";*/
          }                                
       }else{
           System.out.println( " listOfTasksFrmSOA Is NULL, There were no Matching records found in SOA...!"); 
       }                                   
           
       }catch (Exception e){
           System.out.println("validatePendingEntitlements :  RejectTask method returns exception " +e);          
       }
   }
  
   public Task getTaskDetailsByID(String taskId) throws IAMWorkflowException{
       try {       
         ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
            wfCtx = getAdminWorkflowContext(querySvc);
            Task task=querySvc.getTaskDetailsById(wfCtx,taskId);
           return task;           
       } catch(WorkflowException e) {
           throw new IAMWorkflowException(e);
       }
   }  
   
   private static HashMap<String,String> getPayloadValues(Element pElement) {
       HashMap<String,String> map = new HashMap<String,String>();
       NodeList nl = pElement.getChildNodes();
       if(nl != null && nl.getLength() > 0) {
         for (int i = 0; i < nl.getLength(); i++) {
            String nodeName = nl.item(i).getNodeName();
             NodeList subList = nl.item(i).getChildNodes();
             if(subList != null && subList.getLength() > 0) {
                   String nodeValue = subList.item(0).getNodeValue();
                  // logger("Element is " + nodeName +
                    //                " with a value of " + nodeValue);
                   map.put(nodeName,nodeValue);
             }

         }
       }
         return map;
     }
  private IWorkflowContext getAdminWorkflowContext(ITaskQueryService querySvc) throws WorkflowException {       
         IWorkflowContext adminCtx;
         String username = "weblogic";
         String password = "weblogic1";
         adminCtx = querySvc.authenticate(username, password.toCharArray(), "jazn.com");
         return adminCtx;
     }
}

No comments:

Post a Comment

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts