Thursday 11 May 2017

Update OIM 11gR2 PS3 catalog attributes using API

In OIM, catalog default attributes can be easily updated by Catalog Sync schedule job. But if you add any custom attributes in the catalog, those field are very difficult to update using the Catalog Sync job.


You can use the below code snippet to update catalog default and custom attributes. While using this code in real implementation, use a CSV file with all the data and attaché the code in a schedule task.


 /**
  * This method update catalog form of specified entity
  * @param DBColumnName Catalog form field name
  * @param DBColumnValue Catalog form field value
  * @throws SchedulerException
  */

 private void updateCatalogDetailsValue(String DBColumnName, Object DBColumnValue) throws SchedulerException{
 
  oracle.iam.platform.utils.vo.OIMType oimtype = null;
 
  CatalogService catalogAPI = (CatalogService)oimClientObj.getService(CatalogService.class);
 
  System.out.println("ItemName::"+ItemName);
  System.out.println("ItemType::"+ItemType);

  try {
 
   //Set catalog entity type
   if(ItemType.equals("Entitlement")){
    oimtype = oracle.iam.platform.utils.vo.OIMType.Entitlement;
   }
   if(ItemType.equals("Role")){
    oimtype = oracle.iam.platform.utils.vo.OIMType.Role;
   }
   if(ItemType.equals("ApplicationInstance")){
    oimtype = oracle.iam.platform.utils.vo.OIMType.ApplicationInstance;
   }
  
   //Get catalog form of a specified entity
   Catalog catalog = catalogAPI.getCatalogItemDetails(null, ItemName, oimtype, null);
  
   System.out.println("Found Catalog item Display Name: "+catalog.getEntityDisplayName());
  
   //Set default catalog fields
   if(DBColumnName.equalsIgnoreCase("Catagory")){
   
    catalog.setCategoryName(String.valueOf(DBColumnValue));
   }else if(DBColumnName.equalsIgnoreCase("Audit Objective")){
   
    catalog.setAuditObjectives(String.valueOf(DBColumnValue));
   }else if(DBColumnName.equalsIgnoreCase("User Defined Tags")){
   
    catalog.setUserDefinedTags(String.valueOf(DBColumnValue));
   }else if(DBColumnName.equalsIgnoreCase("Certifiable")){
   
    catalog.setCertifiable(Boolean.valueOf(DBColumnValue.toString()));
   }else if(DBColumnName.equalsIgnoreCase("Approver User")){
   
    catalog.setApproverUserLogin(String.valueOf(DBColumnValue));
    catalog.setApproverUser(getUserKey(String.valueOf(DBColumnValue)));
   }else if(DBColumnName.equalsIgnoreCase("Approver Role")){
   
    catalog.setApproverRoleDisplayName(String.valueOf(DBColumnValue));
    catalog.setApproverRole(getRoleKey(String.valueOf(DBColumnValue)));
   }else if(DBColumnName.equalsIgnoreCase("Certifier User")){
   
    catalog.setCertifierUser(getUserKey(String.valueOf(DBColumnValue)));
    catalog.setCertifierUserLogin(String.valueOf(DBColumnValue));
   
   }else if(DBColumnName.equalsIgnoreCase("Certifier Role")){
   
    catalog.setCertifierRoleDisplayName(String.valueOf(DBColumnValue));
    catalog.setCertfierRole(getRoleKey(String.valueOf(DBColumnValue)));
   }else if(DBColumnName.equalsIgnoreCase("Fulfilment User")){
   
    catalog.setFulFillMentUser(getUserKey(String.valueOf(DBColumnValue)));
    catalog.setFulFillMentUserLogin(String.valueOf(DBColumnValue));
   }else if(DBColumnName.equalsIgnoreCase("Fulfilment Role")){
   
    catalog.setFulFillmentRoleDisplayName(String.valueOf(DBColumnValue));
    catalog.setFulFillMentRole(getRoleKey(String.valueOf(DBColumnValue)));
   }else if(DBColumnName.equalsIgnoreCase("Risk Level")){
   
    if(String.valueOf(DBColumnValue)== "High Risk")
     catalog.setItemRisk(7);
    else if(String.valueOf(DBColumnValue)== "Medium Risk")
     catalog.setItemRisk(5);
    else if(String.valueOf(DBColumnValue)== "Low Risk")
     catalog.setItemRisk(3);
    else
     System.out.println("Wrong Risk Value");
   }else{
   
    //Updating custom field
    List<MetaData> catalogMetaDataList = catalog.getMetadata();
    MetaData catalogMetaData = null;
    for(int j=0; j< catalogMetaDataList.size(); j++){
    
     catalogMetaData = catalogMetaDataList.get(j);
     MetaDataDefinition catalogMetaDataDef = catalogMetaData.getMetaDataDefinition();
    
     System.out.println(j+":::catalogMetaDataDef.getDisplayName():::::"+catalogMetaDataDef.getDisplayName());
    
     if(catalogMetaDataDef.getDisplayName().equalsIgnoreCase(DBColumnName)){
     
      catalogMetaData.setValue(String.valueOf(DBColumnValue));
      catalogMetaDataList.set(j, catalogMetaData);
      break;
     }
    }
   
    //Set catalog metadata
    catalog.setMetadata(catalogMetaDataList);
   
   }
   //Update catalog
   catalogAPI.updateCatalogItems(catalog);
  
  } catch (CatalogException e) {
  
   e.printStackTrace();
  
   if ((e.toString().indexOf("No Detail found for specified catalog item") > 0)){
    System.out.println("Ignore msg");
   
   }else{
   
    throw new Exception("ERROR: Catalog Exception, see server log and server log for more details ");
   }
  
  }
 }

No comments:

Post a Comment

Followers

OIM API for adding process task and retry failed task

 In this blog you can find how to add new process task and retry any failed/rejected tasks using API. Adding new process task: /************...