OIM API To Get Manual Fulfillment Tasks From SOA


  1. package com.oimacademy.SOA;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.HashSet;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.Set;
  8. import oracle.bpel.services.workflow.IWorkflowConstants;
  9. import oracle.bpel.services.workflow.WorkflowException;
  10. import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
  11. import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
  12. import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
  13. import oracle.bpel.services.workflow.query.ITaskQueryService;
  14. import oracle.bpel.services.workflow.repos.Column;
  15. import oracle.bpel.services.workflow.repos.Predicate;
  16. import oracle.bpel.services.workflow.repos.TableConstants;
  17. import oracle.bpel.services.workflow.repos.table.WFTaskConstants;
  18. import oracle.bpel.services.workflow.task.model.Task;
  19. import oracle.bpel.services.workflow.verification.IWorkflowContext;
  20. import oracle.iam.platform.workflowservice.exception.IAMWorkflowException;
  21. import org.w3c.dom.Element;
  22. import org.w3c.dom.NodeList;
  23. public class GetManualFulfilmentTasksFromSOA {
  24.  private IWorkflowContext wfCtx = null;
  25.  HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String > bpelprops = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String>();
  26.   {     
  27.     bpelprops.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,"t3://localhost:8001/soa-infra");
  28.     bpelprops.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,"weblogic1");
  29.     bpelprops.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,"weblogic");
  30.     bpelprops.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
  31.   } 
  32.  IWorkflowServiceClient  wfSvcClient = WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT,bpelprops,null);
  33.   public static void main(String[] args) throws IAMWorkflowException {
  34.   GetManualFulfilmentTasksFromSOA getManualFulfilmentTasksFromSOA = new GetManualFulfilmentTasksFromSOA();
  35.   List<Task> listOfTasksFrmSOA =getManualFulfilmentTasksFromSOA.getManualFulfilmentTasks();
  36.   getManualFulfilmentTasksFromSOA.displaySOAEntitlementsTask(new HashSet(listOfTasksFrmSOA));
  37.  }
  38.   public List<Task> getManualFulfilmentTasks() throws IAMWorkflowException{       
  39.          ITaskQueryService querySvc =  wfSvcClient.getTaskQueryService();
  40.          try{
  41.              wfCtx = getAdminWorkflowContext(querySvc);
  42.              System.out.println( "Creating Predicate Object to filter only DisconnectedProvisioning tasks from SOA.");              
  43.             Predicate compositenamePredicate = new Predicate(TableConstants.WFTASKMETADATA_NAMESPACE_COLUMN,Predicate.OP_CONTAINS, "DisconnectedProvisioning");
  44.              System.out.println( "Adding Predicate Object to filter TASK_STATE_ASSIGNED OR TASK_STATE_INFO_REQUESTED from SOA.");
  45.              Predicate predicate = new Predicate(Column.getColumn(WFTaskConstants.STATE_COLUMN), Predicate.OP_EQ, IWorkflowConstants.TASK_STATE_ASSIGNED);
  46.              predicate.addClause(Predicate.OR, Column.getColumn(WFTaskConstants.STATE_COLUMN), Predicate.OP_EQ,IWorkflowConstants.TASK_STATE_INFO_REQUESTED);
  47.              System.out.println( "Adding Object to filter Title which Contains Entitlement from SOA.");
  48.              Predicate titlePredicate = new Predicate(Column.getColumn(WFTaskConstants.TITLE_COLUMN), Predicate.OP_CONTAINS, "Entitlement");
  49.              predicate = new Predicate(predicate, Predicate.AND, titlePredicate);
  50.              System.out.println( "Adding Object to filter TEXTATTRIBUTE10_COLUMN User from SOA.");
  51.              Predicate textAttribute10Predicate = new Predicate(Column.getColumn(WFTaskConstants.TEXTATTRIBUTE10_COLUMN), Predicate.OP_EQ, "APP7");
  52.              textAttribute10Predicate.addClause(Predicate.OR, Column.getColumn(WFTaskConstants.TEXTATTRIBUTE10_COLUMN), Predicate.OP_EQ,"APP8");
  53.              predicate = new Predicate(predicate, Predicate.AND, textAttribute10Predicate);           
  54.              compositenamePredicate = new Predicate(compositenamePredicate, Predicate.AND, predicate);             
  55.              System.out.println( "Preparing list query columns,which should exist in SOA result...!");
  56.              List<String> queryColumns = new ArrayList<String>();
  57.              queryColumns.add("TASKID");
  58.              queryColumns.add("TASKNUMBER");
  59.              queryColumns.add("TITLE");
  60.              queryColumns.add("OUTCOME");
  61.              queryColumns.add("STATE");
  62.              queryColumns.add("ASSIGNEDDATE");
  63.              queryColumns.add("ROOTTASKID");
  64.              queryColumns.add("ASSIGNEES");
  65.              queryColumns.add("ASSIGNEEGROUPS");     
  66.              List optionalInfo = new ArrayList();      
  67.              optionalInfo.add("Comments");              
  68.              List<Task> listOfTasksFrmSOA= null;
  69.              listOfTasksFrmSOA = querySvc.queryTasks(wfCtx, queryColumns, optionalInfo,ITaskQueryService.AssignmentFilter.ALL, null, compositenamePredicate,null, 0, 0);
  70.            System.out.println( " Returning  List object listOfTasksFrmSOA with Task details.");
  71.              return listOfTasksFrmSOA;             
  72.          } catch(WorkflowException e) {
  73.              throw new IAMWorkflowException(e);
  74.          }finally {
  75.                 System.out.println( "Restoring run as subject");              
  76.                  }
  77.      }  
  78.   public void displaySOAEntitlementsTask(Set<String> entAssgnKeys){   
  79.       System.out.println( " validatePendingEntitlements Method getting called with entAssgnKeys ->"+entAssgnKeys);
  80.       try {           
  81.        
  82.        List<Task> listOfTasksFrmSOA  = getManualFulfilmentTasks();
  83.        if(listOfTasksFrmSOA!=null && listOfTasksFrmSOA.size() > 0){
  84.            System.out.println( " Size of listOfTasksFrmSOA -> "+listOfTasksFrmSOA.size());
  85.            for (Task task : listOfTasksFrmSOA) {
  86.                String taskId = task.getSystemAttributes().getTaskId();
  87.                String title =  task.getTitle();
  88.                System.out.println("************************************************************");         
  89.                System.out.println("task-id = " + taskId  + "   \ntask-title = "+ title);               
  90.                Task currentTask =   getTaskDetailsByID(taskId);
  91.                Element payload = currentTask.getPayloadAsElement();
  92.                HashMap<String,String> payloadValuesMap = getPayloadValues(payload);
  93.                for (Map.Entry<String, String> entry : payloadValuesMap.entrySet()) {
  94.                    System.out.println("key = " + entry.getKey() + "  value = " + entry.getValue());
  95.                }
  96.                System.out.println("************************************************************\n\n");      
  97.               /* String entityType = (payloadValuesMap.get("EntityType") != null) ? (String) payloadValuesMap.get("EntityType") :"";
  98.                String provOperation=(payloadValuesMap.get("ProvisioningOperation") != null) ? (String) payloadValuesMap.get("ProvisioningOperation") :"";*/
  99.           }                                
  100.        }else{
  101.            System.out.println( " listOfTasksFrmSOA Is NULL, There were no Matching records found in SOA...!"); 
  102.        }                                   
  103.            
  104.        }catch (Exception e){
  105.            System.out.println("validatePendingEntitlements :  RejectTask method returns exception " +e);          
  106.        }
  107.    }  
  108.    public Task getTaskDetailsByID(String taskId) throws IAMWorkflowException{
  109.        try {       
  110.          ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
  111.             wfCtx = getAdminWorkflowContext(querySvc);
  112.             Task task=querySvc.getTaskDetailsById(wfCtx,taskId);
  113.            return task;           
  114.        } catch(WorkflowException e) {
  115.            throw new IAMWorkflowException(e);
  116.        }
  117.    }    
  118.    private static HashMap<String,String> getPayloadValues(Element pElement) {
  119.        HashMap<String,String> map = new HashMap<String,String>();
  120.        NodeList nl = pElement.getChildNodes();
  121.        if(nl != null && nl.getLength() > 0) {
  122.          for (int i = 0; i < nl.getLength(); i++) {
  123.             String nodeName = nl.item(i).getNodeName();
  124.              NodeList subList = nl.item(i).getChildNodes();
  125.              if(subList != null && subList.getLength() > 0) {
  126.                    String nodeValue = subList.item(0).getNodeValue();
  127.                   // logger("Element is " + nodeName +
  128.                     //                " with a value of " + nodeValue);
  129.                    map.put(nodeName,nodeValue);
  130.              }
  131.          }
  132.        }
  133.          return map;
  134.      }
  135.   private IWorkflowContext getAdminWorkflowContext(ITaskQueryService querySvc) throws WorkflowException {       
  136.          IWorkflowContext adminCtx;
  137.          String username = "weblogic";
  138.          String password = "weblogic1";
  139.          adminCtx = querySvc.authenticate(username, password.toCharArray(), "jazn.com");
  140.          return adminCtx;
  141.      }
  142. }

1 comment:

  1. Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors. order fulfillment

    ReplyDelete