OIM API Code to get IT Resource Details Using IT resources Name

package com.adapters;

import java.util.HashMap;
import java.util.Map;
import Thor.API.tcResultSet;
import Thor.API.Operations.tcITResourceInstanceOperationsIntf;
import oracle.iam.platform.Platform;



public class PrintItResourceDetails {
  final String logp = "PrintItResourceDetails :: getITResourceMap - ";
   String serverAddr ;
   String port;
   String password;  
   
   public PrintItResourceDetails(){
    
   }  
   
 public void printDetails()
   {
     System.out.println(logp + " Server Address :-" + this.serverAddr);
     System.out.println(logp + " Port :-" + this.port);
     System.out.println(logp + " Password :-" + this.password);
   } 

 public void iterateMapToPrintDetails(String itKey){  
  
  Map<String, String> itResourceParamMap = getITResourceMap(itKey);
  for(Map.Entry<String, String> entry : itResourceParamMap.entrySet()) {
      String k = entry.getKey();
      String v = entry.getValue();
      
      if(k.equalsIgnoreCase("host")){
    this.serverAddr=v;
   }else if(k.equalsIgnoreCase("port")){
    this.port=v;
   }else if(k.equalsIgnoreCase("credentials")){
    this.password=v;
   }
      System.out.println("Key : "+  k + " value : "+v);
  }
  printDetails();
 }
 
 
 public Map<String, String> getITResourceMap(String itResName) {        
        System.out.println(logp + " START");
         Map<String, String> itResourceMap = new HashMap<String, String>();
         Thor.API.Operations.tcITResourceInstanceOperationsIntf itResourceInstOps = null;
         
         if (null == itResName || itResName.isEmpty()) {
                 return null;
         }
         
        System.out.println(logp + " IT resources Name :: " + itResName);
     
         try {
             HashMap<String, String> itMap = new HashMap<String, String>();
             itMap.put("IT Resources.Name", itResName);
             itResourceInstOps = Platform.getService(tcITResourceInstanceOperationsIntf.class);
         
             tcResultSet itRS = itResourceInstOps.findITResourceInstances(itMap);
            System.out.println(logp + " Number of IT resources found for " + itResName + " = " + itRS.getRowCount());

             if (!itRS.isEmpty() && itRS.getRowCount() == 1) {
                 itRS.goToRow(0);
                 long itKey = itRS.getLongValue("IT Resource.Key");
                 itRS = itResourceInstOps.getITResourceInstanceParameters(itKey);
                 String name, value;
                 for (int i = 0; i < itRS.getRowCount(); i++) {
                     itRS.goToRow(i);
                     name = itRS.getStringValue("IT Resources Type Parameter.Name");
                     value = itRS.getStringValue("IT Resources Type Parameter Value.Value");
                     itResourceMap.put(name, value);
                 }
             }
         } catch (Exception e) {
             System.out.println(logp + " Exception while getting IT Resource details. " + e);
         } finally {
             if (null != itResourceInstOps) {
                 itResourceInstOps.close();
                System.out.println(logp + " tcITResourceInstanceOperationsIntf instance closed successfully.");
             }
         }

        System.out.println(logp + " END");
         return itResourceMap;
  }
 
 
 public static void main(String[] args) {
  PrintItResourceDetails printOject = new PrintItResourceDetails();
   new PrintItResourceDetails().iterateMapToPrintDetails("OUDAppInstance");   
 }

}

No comments:

Post a Comment

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts