Monday, 18 February 2019

OIM API - How to Update Account Process Form Data using ProvisioningService API?

public void modifyAccountProcessFormData() throws Exception {
String userKey = "117507"; //Replace User Key
String resObjName = "LDAP User"; //Replace Resource Object Name
Account userActiveAccount = null;

ProvisioningService provisioningService = Platform.getService(ProvisioningService.class);

SearchCriteria criteria =  new SearchCriteria(ProvisioningConstants.AccountSearchAttribute.OBJ_NAME.getId(), resObjName, SearchCriteria.Operator.EQUAL);
    List<Account> accounts = provisioningService.getAccountsProvisionedToUser(userKey, criteria, null, true);
     
    for(Account account : accounts) {
        String accountStatus = account.getAccountStatus();
         
        if(ProvisioningConstants.ObjectStatus.PROVISIONED.getId().equals(accountStatus) || 
        ProvisioningConstants.ObjectStatus.ENABLED.getId().equals(accountStatus) || 
        ProvisioningConstants.ObjectStatus.DISABLED.getId().equals(accountStatus)){
        userActiveAccount = account;
        break;
        }
    }
    
    if(null != userActiveAccount){
    //Add attributes which need to be modified
        HashMap<String, Object> modParentFrmDataMap = new HashMap<String, Object>();
        modParentFrmDataMap.put("UD_LDAP_USR_FIRST_NAME", "Anand");
        modParentFrmDataMap.put("UD_LDAP_USR_LAST_NAME", "Badal");
   
    String accountId  = userActiveAccount.getAccountID();
        String processFormInstanceKey = userActiveAccount.getProcessInstanceKey();
        Account modAccount = new Account(accountId, processFormInstanceKey, userKey);

        String parentFormKey = userActiveAccount.getAccountData().getFormKey();
        String udTablePrimaryKey = userActiveAccount.getAccountData().getUdTablePrimaryKey();
        AccountData accountData = new AccountData(parentFormKey, udTablePrimaryKey , modParentFrmDataMap);
         
        modAccount.setAccountData(accountData);
        modAccount.setAppInstance(userActiveAccount.getAppInstance());

        provisioningService.modify(modAccount);
        System.out.println("Process form data successfully updated!!!");
    }
}

Wednesday, 13 February 2019

OIM API - How to get Database Connection through Data Source Name in Standalone Code?

public Connection getDBConnection(){
    Connection conn = null;
    javax.sql.DataSource ds = null;
    Hashtable env = new Hashtable();

    env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    env.put(Context.PROVIDER_URL, "t3://<REPLACE_HOST_NAME>:14000");

    try {
          Context context = new InitialContext(env);
          ds = (javax.sql.DataSource) context.lookup("jdbc/operationsDB");
          System.out.println("Successfully looked up OIM datasource");

          if(null != ds) {
              conn = ds.getConnection();
              System.out.println("Successfully obtained OIM database connection");
          }
}catch (Exception e) {
System.out.println("Exception is : " + e.getMessage());
}
return conn;
}