Monday, 9 December 2019

Get Decode Value From Lookup Using API



                                           Get Decode Value Lookup Using API


package demo.com;

import Thor.API.Exceptions.tcAPIException;
import Thor.API.Exceptions.tcColumnNotFoundException;
import Thor.API.Exceptions.tcInvalidLookupException;

import java.util.HashMap;
import java.util.Hashtable;
import oracle.iam.platform.OIMClient;
import Thor.API.tcResultSet;
import Thor.API.Operations.tcLookupOperationsIntf;


import oracle.core.ojdl.logging.ODLLevel;

public class UpdateLookup {
  private static final String CLASS_NAME = UpdateLookup.class.getSimpleName();
    private static String OIMUserName = "xelsysadm";
    private static String OIMPassword = "*****";
    private static String OIMURL = "t3://localhost:14000";
    private static String OIMInitialContextFactory ="weblogic.jndi.WLInitialContextFactory";
      //OIM Client Initiallization
        public static OIMClient loginWithCustomEnv() {
        Hashtable env = new Hashtable();
        env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, OIMInitialContextFactory);
        env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, OIMURL);
     // New Properties needs to be added into system property.
        System.setProperty("OIM.AppServerType", "wls");
        System.setProperty("APPSERVER_TYPE", "wls");
        System.setProperty("java.security.auth.login.config","C:\\Users\\RK\\TestReconEvent\\oimclient\\conf\\authwl.conf");
        OIMClient oimClient = new OIMClient(env);
         try {
              System.out.println("12");
              oimClient = new OIMClient(env);
              System.out.println("Initiating Oim Client");
              oimClient.login(OIMUserName, OIMPassword.toCharArray());
              System.out.println("got OIM client successfully");
              System.out.println("Client - " + oimClient);
             } catch (Exception e) {
              System.out.println("Error: " + e);
               oimClient = null;
                          }
        return oimClient;
     
        }
//        public void addLookupEntry(OIMClient oimClient,String lookupName,String lookupCodekey,String Decode)  {
//             oimClient= null;
//            OIMClient oimClient=this.loginWithCustomEnv();
//            System.out.println("Got the value of lookupName:"+lookupName);
//            System.out.println("Got the value of lookupCodekey:"+lookupCodekey);
//            System.out.println("Got the value of Decode:"+Decode);
//         try {
//          tcLookupOperationsIntf lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
//          lookupOps.addLookupValue(lookupName,lookupCodekey, Decode, "", "");
//         
//         } catch (Exception e) {
//          e.printStackTrace();
//         }
//        }
   //     public void readLookupValues(String lookupname) {
//            OIMClient client=this.loginWithCustomEnv();
//         try {
//          tcLookupOperationsIntf lookupOps = client.getService(tcLookupOperationsIntf.class);
//          tcResultSet values = lookupOps.getLookupValues(lookupname);
//          for (int i = 0; i < values.getRowCount(); i++) {
//           values.goToRow(i);
//           System.out.print(values.getStringValue("Lookup Definition.Lookup Code Information.Decode"));
//           System.out.println("," + values.getStringValue("Lookup Definition.Lookup Code Information.Code Key"));
//          }
//         } catch (Exception e) {
//          e.printStackTrace();
//         }
//        }
     
     
     
   
  private String readLookupValues(String lookupName,String lookupCodekey)
        {
           String methodName = "::getLookupData::";
         
            OIMClient client=this.loginWithCustomEnv();
           String Decode=null;
           tcLookupOperationsIntf lookupOpsIntf = null;
           System.out.println("getLookupValue " + lookupName + "," + lookupCodekey);
           try
                        {
                                lookupOpsIntf = client.getService(tcLookupOperationsIntf.class);
                                Decode = lookupOpsIntf.getDecodedValueForEncodedValue(lookupName, lookupCodekey);
                        }
                        catch (Exception e)
                        {
                                System.out.println("error looking up " + e);
                        }
                        finally
                        {
                                if ( lookupOpsIntf != null )
                                {
                                        lookupOpsIntf.close();
                                }

                        }
                        System.out.println("getLookupValue return " + Decode);
                        return Decode;
                }
        private boolean empIdExit(String emp)
          {
                  boolean isExit=false;
           
                 // HashMap<String, String> map=null;
                  String map=null;
              try
                    {
                  if(map==null)
                  {
                    map= readLookupValues("Lookup.Workday.EmpNumber.ReconValidation",emp);
                      System.out.println(map);
                    //  logger.info("#### map $$$$ " + map);
           
              if(map.equals(emp))
                 {
                     System.out.println(emp);
                         return isExit=true;
                       
                 }
               
                 else{
                         return isExit;
       
           
          }
     

//private boolean empIdExit(String emp)
//      {
//              boolean isExit=false;
//              HashMap<String, String> map=null;
//              if(map==null)
//              {
//                map= readLookupValues("Lookup.Workday.EmpNumber.ReconValidation", emp, emp);
//                 // logger.info("#### map $$$$ " + map);
//                 System.out.println("map"+map);
//              }
//             if(map.containsKey(emp))
//             {
//                     return isExit=true;
//             }
//             else{
//                     return isExit;
//             }
//      }
 
 
//    private HashMap<String, String> readLookupValues(String lookupName,String lookupCode,String lookupDecode)
//            {
//              String methodName = "::readLookupValues::";
//                OIMClient client=this.loginWithCustomEnv();
//              HashMap<String, String> lookupValues = new HashMap();
//              tcResultSet lookupResultSet = null;
//                     
//                tcLookupOperationsIntf lookupOps = (tcLookupOperationsIntf)client.getService(tcLookupOperationsIntf.class);
//              //  logger.info
//              System.out.println("#### lookupOps $$$$ " + lookupOps);
//             
//              try
//              {
//                lookupResultSet = lookupOps.getLookupValues(lookupName);
//                int i;
//                if ((lookupResultSet != null) && (lookupResultSet.getRowCount() > 0))
//                {
//                  for (i = 0; i < lookupResultSet.getRowCount(); i++)
//                  {
//                    lookupResultSet.goToRow(i);
//                    try
//                    {
//                      lookupCode = lookupResultSet.getStringValue("Lookup Definition.Lookup Code Information.Code Key");
//                      //  logger.info
//                            System.out.println("#### lookupCode $$$$ " + lookupCode);
//                     
//                    }
//                    catch (tcColumnNotFoundException localtcColumnNotFoundException1) {}
//
//                        try {
//                            lookupDecode = lookupResultSet.getStringValue("Lookup Definition.Lookup Code Information.Decode");
//                          //  logger.info
//                          System.out.println("#### lookupDecode $$$$ " + lookupDecode);
//                         
//                        } catch (tcColumnNotFoundException e) {
//                        }
//                        lookupValues.put(lookupCode, lookupDecode);
//                  }
//                }
//             
//                if ((lookupValues == null) && (lookupValues.size() == 0))
//                {
//               
//                  return null;
//                }
//              } catch (tcInvalidLookupException e) {
//            } catch (tcAPIException e) {
//            }
//            System.out.println("#################### Reading Lookup Completed ################");
//            return lookupValues;
//           
//            }
        public static void main(String args[]) {
          UpdateLookup obj = new UpdateLookup();
         //  obj.addLookupEntry(null,"Lookup.Data.AAPName","AAPNam26","AAPData26");
       obj.empIdExit(null);
      // obj.empIdExit(null);
       
        }
    }

Wednesday, 20 November 2019

Add Delete and Update Lookup Values From Standalone Code:

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;
//
//
//}





}

Get Decode Value From Lookup Using API

                                            Get Decode Value Lookup Using API package demo.com; import Thor.API.Exceptions.tcAPIExce...