OracleIdentityManager
Add Delete and Update Lookup Values From Standalone Code:
import java.io.FileNotFoundException;
import java.io.IOException;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import javax.security.auth.login.LoginException;
import com.csvreader.CsvReader;
import Thor.API.Exceptions.tcAPIException;
import Thor.API.Exceptions.tcDuplicateLookupCodeException;
import Thor.API.Exceptions.tcInvalidAttributeException;
import Thor.API.Exceptions.tcInvalidLookupException;
import Thor.API.Exceptions.tcInvalidValueException;
import Thor.API.Operations.tcLookupOperationsIntf;
import oracle.iam.platform.OIMClient;
import oracle.iam.request.api.RequestService;
import oracle.iam.request.vo.RequestData;
public class LookupUtill {
/**
* Contains lookup operations (standalone code using OIMClient)
*/
public static OIMClient oimClient;
private tcLookupOperationsIntf lookupOps;
PreparedStatement pstmt= null ;
Connection con = null;
public static void main(String[] args) {
String oimInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";
java.util.Hashtable<String, String> env = new java.util.Hashtable<String, String>();
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL,oimInitialContextFactory);
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL, "t3://localhost:port");
System.setProperty("java.security.auth.login.config", "C:\\Users\\xyz\\TestReconEvent\\oimclient\\conf\\authwl.conf");
System.setProperty("OIM.AppServerType", "wls");
System.setProperty("APPSERVER_TYPE", "wls");
oimClient = new OIMClient(env);
try {
oimClient.login("xelsysadm","pwd".toCharArray());
System.out.println("Connected Successfully");
LookupUtill lu =new LookupUtill();
//lu.addLookup();
//lu.removeLookup();
//lu.AddLookUpValuestoLookups();
lu.AddLookUpValues();
//lu.AddLookUpValuestoLookups();
//lu.removeEntryFromLookup();
// lu.updateEntryFromLookup();
} catch (LoginException e) {
System.out.println("in LoginException ");
e.printStackTrace();
}
}
// public LookupUtill(){
// try{
// String usrname = "xyz_oim";
// String pwd = "pwd";
// String driver = "oracle.jdbc.driver.OracleDriver";
// String url = "jdbc:oracle:thin:@DBhost:port:servicename";
//
// Class.forName(driver);
// System.out.println(" after forname");
// con=DriverManager.getConnection(url,usrname,pwd);
// System.out.println(" database connection established successfully");
// }
// catch(Exception e){
//
// e.printStackTrace();
// }
// }
/*
* Creates a lookup definition.
* @param lookupOps tcLookupOperationsIntf service object
* @param lookupName Name of the lookup definition to be created
* Note: "Group" Field must be specified for lookup definition when using the Design Console.
* May need to call update operation on Group field.
*/
//public void addLookup()
//{
// CsvReader dataValue;
// try {
// lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
// String csvFileLoc="E:\\Code\\CSV\\LookupUtill\\addLookup.csv";
// String csvSeparator=",";
// char c[]=csvSeparator.toCharArray();
//
//
//
// dataValue = new CsvReader(csvFileLoc,c[0]);
// dataValue.readHeaders();
//
//
// while (dataValue.readRecord())
// {
// String lookupName = dataValue.get("lookupName");
// System.out.println("lookupName :::::" +lookupName);
// lookupOps.addLookupCode(lookupName);
// System.out.println(" Lookup created" +lookupName);
//
// }
// System.out.println("All Lookups created successfully ");
//
//
// } catch (tcAPIException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (tcDuplicateLookupCodeException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }catch(Exception e){
// e.printStackTrace();
// }
// //adds a lookup
//}
/*
* Removes an entry from a lookup. Delete is determined by an entry's code key.
* @param lookupOps tcLookupOperationsIntf service object
* @param lookupName Name of the lookup definition
* @param codeKey Value of an entry's code key
* Note: If there are duplicates of the code key in your lookup, only one of them will be removed.
*/
//public void removeLookup()
//{
// lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
// String lookupName="Lookup.demo.oim";
// try {
// lookupOps.removeLookupCode(lookupName);
// System.out.println("*********Lookup Removed *********");
// } catch (tcAPIException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (tcInvalidLookupException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//}
/*
* @Usage : Method to get Contractor values
* @parameters : NA
* @return : void
*/
public void AddLookUpValues() {
CsvReader dataValue;
try {
lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
//String lookupName="Lookupname";
//String lookupName="Lookupname";
//String lookupName="Lookupname";
//String lookupName="Lookupname";
//String lookupName = "Lookupname";
//String lookupName = "Lookupname";
// String lookupName="Lookupname";
// String lookupName="Lookupname";
String lookupName="Lookupname";
//String lookupName="Lookupname";
System.out.println("LookupName :::::" +lookupName);
String csvFileLoc="C:\\RK\\LOOKUP.csv";
String csvSeparator=",";
char c[]=csvSeparator.toCharArray();
dataValue = new CsvReader(csvFileLoc,c[0]);
dataValue.readHeaders();
while (dataValue.readRecord())
{
String code = dataValue.get("Code");
System.out.println("Code :::::" +code);
String meaning = dataValue.get("Meaning");
System.out.println("Meaning :::::"+meaning);
//** Get AppInstanceDisplayName to update Lookupname //**
// String appInstanceName = GetAppInstanceName(code);
// System.out.println("AppInstanceDisplayName " +appInstanceName);
try{
// lookupOps.addLookupValue(lookupName,appInstanceName,meaning,"","");
lookupOps.addLookupValue(lookupName,code,meaning,"","");
// System.out.println(" Added" +appInstanceName);
}
catch (Exception e) {
System.out.println(e);
}
}
System.out.println("*********Lookup values added successfully *********");
} catch (Exception e) {
System.out.println(e);
}
}
/*
* Removes an entry from a lookup. Delete is determined by an entry's code key.
* @param lookupOps tcLookupOperationsIntf service object
* @param lookupName Name of the lookup definition
* @param codeKey Value of an entry's code key
* Note: If there are duplicates of the code key in your lookup, only one of them will be removed.
*/
//public void removeEntryFromLookup()
//{
//
// CsvReader dataValue;
//
//
// lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
//
//
// String csvFileLoc="C:\\Users\\xyz\\CSV\\LookupUtill\\addLookupValues.csv";
// String csvSeparator=",";
// char c[]=csvSeparator.toCharArray();
//
//try{
//
// dataValue = new CsvReader(csvFileLoc,c[0]);
// dataValue.readHeaders();
//
// while (dataValue.readRecord())
// {
// String lookupName = dataValue.get("lookupName");
// System.out.println("lookupName :::::" +lookupName);
// String codeKey = dataValue.get("Code");
// System.out.println("code :::::" +codeKey);
//
// lookupOps.removeLookupValue(lookupName, codeKey);
//
//
// }
// System.out.println("*********Lookup values removed successfully *********");
//
// } catch (tcAPIException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (tcInvalidLookupException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (tcInvalidValueException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
//
// }catch(Exception e){
// e.printStackTrace();
// }
//
//
//}
/*
* Update an existing entry in a lookup. Update is determined by entry's code key.
* @param lookupOps tcLookupOperationsIntf service object
* @param lookupName Name of the lookup definition
* @param existingCodeKey An exisiting entry's code key
* @param newCodeKey code key to be changed to
* @param newDecode decode value to be changed to
* Note: If there are duplicates of the code key in your lookup, only one of them will be updated.
*/
//public void updateEntryFromLookup()
//{
// CsvReader dataValue;
//try{
// lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
// String lookupName="Lookupname";
// //String lookupName="Lookupname";
// //String lookupName="Lookupname";
// System.out.println("LookupName :::::" +lookupName);
// String csvFileLoc="C:\\Users\\xyz\\Code\\CSV\\LookupUtill\\addLookupValues.csv";
// String csvSeparator=",";
// char c[]=csvSeparator.toCharArray();
//
//
//
// dataValue = new CsvReader(csvFileLoc,c[0]);
// dataValue.readHeaders();
//
//
// while (dataValue.readRecord())
// {
// String existingCodeKey = dataValue.get("Code");
// System.out.println("existingCodeKey :::::" +existingCodeKey);
// String newCodeKey = dataValue.get("Code");
// System.out.println("newCodeKey :::::" +newCodeKey);
// String newDecode = dataValue.get("Meaning");
// System.out.println("Meaning :::::"+newDecode);
// try{
//
// HashMap<String,String> update = new HashMap<String,String>();
// update.put("LKV_ENCODED", newCodeKey);
// update.put("LKV_DECODED", newDecode);
//
// lookupOps.updateLookupValue(lookupName, existingCodeKey, update);
// System.out.println("updated *** "+newCodeKey);
// }
// catch (Exception e) {
// System.out.println(e);
// }
//
//
// }
// System.out.println("*********Lookup values added successfully *********");
//} catch (Exception e) {
// System.out.println(e);
//}
//}
//public void AddLookUpValuestoLookups() {
//
// CsvReader dataValue;
// try {
// lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
//
//
// String csvFileLoc="C:\\Users\\xyz\\addLookupValues.csv";
// String csvSeparator=",";
// char c[]=csvSeparator.toCharArray();
//
//
//
// dataValue = new CsvReader(csvFileLoc,c[0]);
// dataValue.readHeaders();
//
//
// while (dataValue.readRecord())
// {
// String lookupName = dataValue.get("lookupName");
// System.out.println("lookupName :::::" +lookupName);
// String code = dataValue.get("Code");
// System.out.println("code :::::" +code);
// String meaning = dataValue.get("Meaning");
// System.out.println("Meaning :::::"+meaning);
// lookupOps.addLookupValue(lookupName,code,meaning,"","");
// System.out.println("*********Lookup updated********" +lookupName);
// }
// System.out.println("*********Lookup values added successfully *********");
// } catch (Exception e) {
// System.out.println(e);
// }
//}
//private String GetAppInstanceName(String appInstanceDescription) {
//
//
// String appInstanceName = null;
//
// try{
// String query = "select APP_INSTANCE_DISPLAY_NAME from app_instance where app_instance_description = '"+appInstanceDescription+"'";
//
//
// Statement stmt=con.createStatement();
// ResultSet rs=stmt.executeQuery(query);
// while(rs.next()){
//
// appInstanceName = rs.getString("APP_INSTANCE_DISPLAY_NAME");
// //System.out.println("appInstanceName" +appInstanceName);
// }
//
//
// }
// catch(Exception e){
// System.out.println("App Instance not found " +appInstanceDescription);
// e.printStackTrace();
// }
//
// return appInstanceName;
//
//
//}
}