Sunday 26 February 2017

OIM API - Stand Alone Code to Fetch Failed Process Task.

To execute below code you have to add following jars in classpath:

  • commons-logging.jar
  • eclipselink.jar
  • jrf-api.jar
  • oimclient.jar
  • spring.jar
  • wlfullclient.jar

Stand Alone Code:


import Thor.API.Operations.tcProvisioningOperationsIntf;
import Thor.API.tcResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;

public class FetchFailedProcessTask {
    OIMClient oimClient = null;
   
    //identity self service details
    String username = "xelsysadm";
    String password = "<password>"; //xelsysadm password
    String t3url = "t3://<hostname>:<port>"; //OIM HostName and Port
    String authwl_location = "<location of authwl.conf file in your local machine>"; //eg. D:\\authwl.conf
   
    public void getOIMConnection() {
        System.out.println("getOIMConnection() : Start");
       
        //set system properties
        System.setProperty("java.security.auth.login.config", authwl_location);
        System.setProperty("OIM.AppServerType", "wls");
        System.setProperty("APPSERVER_TYPE", "wls");

        Hashtable oimenv = new Hashtable();
        oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
        oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url);
        oimClient = new OIMClient(oimenv);
        try {
            oimClient.login(username, password.toCharArray());
            System.out.println("Connected");
        } catch (LoginException e) {
            e.printStackTrace();
        }
        System.out.println("getOIMConnection() : End");
    }
   
    public void getOpenTasks(String resourceName, String taskName, String taskStatus) {
        try {
            System.out.println("getOpenTasks() : Start");
            tcProvisioningOperationsIntf tcOp = oimClient.getService(tcProvisioningOperationsIntf.class);

            Map<String, String> filter = new HashMap<String, String>();
            filter.put("Objects.Name", resourceName);
            filter.put("Process Definition.Tasks.Task Name", taskName);

            //Failed Task Status
            String taskStaus[] = new String[] {taskStatus};
            tcResultSet trs = tcOp.findAllOpenProvisioningTasks(filter, taskStaus);
            List<Map<String, Object>> taskLists = new ArrayList<Map<String, Object>>();

            int rowCount = trs.getRowCount();
            System.out.println("Total " + taskStatus + " Task(s) for Application Instance("  + resourceName + ") : " + trs.getRowCount());

            if (rowCount > 0) {
                for (int i = 0; i < rowCount; i++) {
                    trs.goToRow(i);
                    System.out.println("Process Instance.Task Information.Target User : " + trs.getStringValue("Process Instance.Task Information.Target User"));
                    System.out.println("Process Instance.Task Details.Key : " + trs.getLongValue("Process Instance.Task Details.Key"));
                    System.out.println("*****************************************************");
                }
            }
            System.out.println("getOpenTasks() : End");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            FetchFailedProcessTask fetchFailedProcessTask = new FetchFailedProcessTask();
           
            //Get OIM Connection
            fetchFailedProcessTask.getOIMConnection();

            //Resource Object Name
            String resourceName = "AD User";
            //Failed Task Name
            String taskName = "Create User";
            // If you need pending task, replace Rejected with 'Pending'
            String taskStatus = "Rejected";
           
            //Get Failed Tasks
            fetchFailedProcessTask.getOpenTasks(resourceName, taskName, taskStatus);

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}


Happy Learning!!!

No comments:

Post a Comment