Sunday, 26 February 2017

OIM API - Stand Alone Code to Retry 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 java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import Thor.API.tcResultSet;
import java.util.List;
import java.util.Map;
import Thor.API.Operations.tcProvisioningOperationsIntf;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;

public class RetryProcessTask {
    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 retryTask(String resourceName, String taskName, String taskStatus) {
        try {
            System.out.println("retryTask() : 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(taskName + " Task retried for User : " + trs.getStringValue("Process Instance.Task Information.Target User"));
                    tcOp.retryTask(trs.getLongValue("Process Instance.Task Details.Key"));
                }
            }
            System.out.println("retryTask() : End");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
   
    public static void main(String[] args) {
        try {
            RetryProcessTask retryProcessTask = new RetryProcessTask();
           
            //Get OIM Connection
            retryProcessTask.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";
           
            //Retry Failed Task
            retryProcessTask.retryTask(resourceName, taskName, taskStatus);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

Happy Learning!!!

1 comment: