Friday, October 2, 2015

OIM 11g R2: Dynamically Updating Lookup Values using Java Code

In one of the scenario we have requirement where we need to update the lookup value dynamically. Say for.ex if there is addition of new cities or town in the particular it should get reflected immediately. So in this lab we are going to see how we can achieve this functionality using java code.In this lab we are going to read the value from the xlsx file. You can deploy this project using scheduler or run directly in Jdeveloper. I am going to use the second approach for this lab.

Note: Before starting this lab please create Lookup "Lookup.City.Configuration" in oim using design console.

1) Create the new Excel Sheet as shown in figure below. Save it to any location you want. Please make a note of this location because we are going to use this in our java program.












2) Create the new java project in Jdeveloper and add the following jar show in figure.

























3) Create the new class and copy and paste the below code.


  1. import java.util.HashMap;
  2. import java.util.Hashtable;
  3. import oracle.iam.platform.OIMClient;
  4. import Thor.API.tcResultSet;
  5. import Thor.API.Operations.tcLookupOperationsIntf;
  6. import java.io.File;
  7. import java.io.IOException;
  8. import java.util.Locale;
  9. import jxl.Cell;
  10. import jxl.Sheet;
  11. import jxl.Workbook;
  12. import jxl.read.biff.BiffException;
  13. import oracle.iam.scheduler.vo.TaskSupport;

  14. public class UpdateLookup 
  15. {
  16. private static final String OIM_URL = "t3://localhost:14000";
  17.  private static final String AUTH_CONF = "E:/Oracle/Middleware/Oracle_IDM1/server/config/authwl.conf";
  18.  private static final String OIM_USERNAME = "xelsysadm";
  19.  private static final String OIM_PASSWORD = "Welcome1";
  20.  private static OIMClient oimClient = null;
  21.  Hashtable env = new Hashtable();
  22.  public UpdateLookup() {
  23.   try {
  24.    env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL,"weblogic.jndi.WLInitialContextFactory");
  25.    env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, OIM_URL);
  26.    System.setProperty("java.security.auth.login.config", AUTH_CONF);
  27.    System.setProperty("OIM.AppServerType", "wls");
  28.    System.setProperty("APPSERVER_TYPE", "wls");
  29.    oimClient = new OIMClient(env);
  30.    oimClient.login(OIM_USERNAME, OIM_PASSWORD.toCharArray());
  31.   } catch (Exception e) {
  32.    e.printStackTrace();
  33.   }
  34.  }
  35.  public void addLookupEntry(String LookupCode,String Lookup) {
  36.   try {
  37.    tcLookupOperationsIntf lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
  38.    lookupOps.addLookupValue("Lookup.City.Configuration", LookupCode, Lookup, Locale.getDefault().getLanguage(), Locale.getDefault().getCountry());
  39.   } catch (Exception e) {
  40.    e.printStackTrace();
  41.   }
  42.  }
  43.  public void displayLookup(String lookupname) {
  44.   try {
  45.    tcLookupOperationsIntf lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
  46.    tcResultSet values = lookupOps.getLookupValues(lookupname);
  47.    for (int i = 0; i < values.getRowCount(); i++) {
  48.     values.goToRow(i);
  49.     System.outprint(values.getStringValue("Lookup Definition.Lookup Code Information.Decode"));
  50.     System.out.println("," + values.getStringValue("Lookup Definition.Lookup Code Information.Code Key"));
  51.    }
  52.  } 
  53. catch (Exception e)
  54.  {
  55.    e.printStackTrace();
  56.   }
  57.  } 
  58.  public static void main(String args[]) throws IOException, BiffException {
  59.          String s2;
  60.          String s1;
  61.          UpdateLookup obj = new UpdateLookup();
  62.          Workbook workbook = Workbook.getWorkbook(newFile("C:\Users\Desktop\test.xls"));
  63.          Sheet sheet = workbook.getSheet(0);
  64.          for(int i=1; i<2; i++)
  65.          {      Cell cell1 = sheet.getCell(0, i);
  66.              String s=sheet.getName();
  67.           System.out.print(cell1.getContents());
  68.               s2=cell1.getContents();
  69.           Cell cell2 = sheet.getCell(1, i);
  70.              s1= cell2.getContents();
  71.              obj.addLookupEntry(s2,s1); 
  72.     }
  73.          }
  74. }
4) Now run the program as shown in figure below.

























5) Once the program runs successfully, Login to OIM Design Console and provide the required username and password as shown in figure below.
















6) Open the lookup Lookup.City.Configuration and check its contents. It should be the same as that of Excel Sheet we have prepared in step 1.
















7) So if any changes you make to the excel sheet in future, you just need to run this program and the Lookup gets updated dynamically.

No comments:

Post a Comment

Other Posts