//This class demonstrates the usage of OIM API's
import java.util.HashMap;
import java.util.Hashtable;
import com.thortech.util.logging.Logger;
import Thor.API.tcResultSet;
import Thor.API.tcUtilityFactory;
import Thor.API.Exceptions.tcAPIException;
import Thor.API.Exceptions.tcColumnNotFoundException;
import Thor.API.Operations.tcFormInstanceOperationsIntf;
import Thor.API.Operations.tcProvisioningOperationsIntf;
import Thor.API.Operations.tcUserOperationsClient;
import Thor.API.Operations.tcUserOperationsIntf;
import com.thortech.xl.dataaccess.tcDataSetException;
import com.thortech.xl.dataobj.tcDataSet;
import com.thortech.xl.dataobj.util.tcProcessUtilities;
import com.thortech.xl.util.config.ConfigurationClient;
public class OimApi {
tcUserOperationsIntf userOperationsintf=null;
tcFormInstanceOperationsIntf formInstanceOperationsIntf=null;
tcProvisioningOperationsIntf provisioningOperationsIntf=null;
Logger logger=Logger.getLogger("Sample");
tcUtilityFactory tcFactory=null;
//OIMCreateUser oimAPI=new OIMCreateUser();
private void init()
{
try{
getUtilityFactory();
userOperationsintf=(tcUserOperationsIntf)tcFactory.getUtility("Thor.API.Operations.tcUserOperationsIntf");
formInstanceOperationsIntf=(tcFormInstanceOperationsIntf)tcFactory.getUtility("Thor.API.Operations.tcFormInstanceOperationsIntf");
provisioningOperationsIntf=(tcProvisioningOperationsIntf)tcFactory.getUtility("Thor.API.Operations.tcProvisioningOperationsIntf");
}catch(Exception e){
logger.error(e.getLocalizedMessage());
}
}
public tcUtilityFactory getUtilityFactory()
{
try{
System.out.println("calling configuration Client");
ConfigurationClient.ComplexSetting config = ConfigurationClient.getComplexSettingByPath("Discovery.CoreServer");
final Hashtable env = config.getAllSettings();
/* env.put("java.naming.provider.url", "jnp://localhost:1099");
System.out.println("--------");
env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");*/
System.out.println(env);
tcFactory=new tcUtilityFactory(env,"xelsysadm","xelsysadm");
}catch(Exception e)
{
e.printStackTrace();
}
return tcFactory;
}
//This method gets the user key
/**
* @param employeeid This contains the employee User ID
*
*/
private long finduserkey(String employeeid) {
HashMap map = new HashMap();
map.put("Users.User ID", employeeid);
long userkey=0;
try{
tcResultSet result = userOperationsintf.findUsers(map);
printTcResultSet(result,"User Form", logger);
if(result.getRowCount()!=1){
return 0;
}else{
userkey = result.getLongValue("Users.Key");
}
}catch (Exception e) {
}
return userkey;
}
public static void main(String arg[])
{
OimApi mo=new OimApi();
mo.init();
long usrKey=mo.finduserkey("testusr");
System.out.println(usrKey);
long procinstKey=mo.getProcessInstKeyOfRes("DB USER", usrKey, "provisioned");
mo.setValueOnProcessForm(procinstKey, "UD_DBUSER1_EMAIL", "xxx_yyy@yahoo.com");
System.out.println("updated form details successfully");
System.out.println("goin to disable the user");
//mo.disableApp(usrKey, procinstKey);
System.out.println("Printing form data");
mo.getFormData(procinstKey);
mo.getProcesstaskDetails(procinstKey);
System.exit(0);
}
//This method is used to get the process instance key
/**
* @param res_Name This parameter contains the resource Object name
* @param userkey This parameter contains the user key
* @param ROState This parameter contains the state of the RO either provisioned,enabled or disabled or revoked
*/
private long getProcessInstKeyOfRes(String res_Name,long userkey, String ROState) {
ROState = ROState.toLowerCase();
long longProcessInstanceKey = 0;
try{
tcResultSet resultGetObjects = userOperationsintf.getObjects(userkey);
int countResultGetObjects = resultGetObjects.getRowCount();
System.out.println("--------------"+countResultGetObjects);
for(int i = 0; i < countResultGetObjects; i++) {
resultGetObjects.goToRow(i);
String objetcName = resultGetObjects.getStringValue("Objects.Name");
System.out.println("---------Object name"+objetcName);
if(res_Name.equalsIgnoreCase(objetcName)) {
String status = resultGetObjects.getStringValue("Objects.Object Status.Status");
status = status.toLowerCase();
if(ROState.indexOf(status) >= 0) {
longProcessInstanceKey = resultGetObjects.getLongValue("Process Instance.Key");
}
}
}
}catch (Exception e) {
}
return longProcessInstanceKey;
}
//This method is used to update the process form details
/**
* @param proInstKey This param contains the process Instance Key
* @param key This param contains the form column name
* @param value This param contains the value to be updated
*/
public String setValueOnProcessForm(long proInstKey, String key, String value){
String SUCCESS = "SUCCESS";
String FAILURE = "FAILURE";
HashMap hm = new HashMap();
hm.put(key, value);
try {
formInstanceOperationsIntf.setProcessFormData(proInstKey, hm);
} catch (Exception e) {
e.printStackTrace();
return FAILURE;
}
return SUCCESS;
}
//This method gets the child table data
/**
* @param procInstKey This parameter contains the process instance key
*/
public void getChildData(long procInstKey)
{
try{
long formDefKey=formInstanceOperationsIntf.getProcessFormDefinitionKey(procInstKey);
int iVersion=formInstanceOperationsIntf.getActiveVersion(formDefKey);
System.out.println("Printing the child table details");
tcResultSet childResult=formInstanceOperationsIntf.getChildFormDefinition(formDefKey, iVersion);
System.out.println("------------"+"Printing the child values");
printTcResultSet(childResult,"childResult", logger);
long lChildKey=childResult.getLongValue("Structure Utility.Child Tables.Child Key");
tcResultSet childTableData=formInstanceOperationsIntf.getProcessFormChildData(lChildKey, procInstKey);
printTcResultSet(childTableData,"Child Table Data", logger);
System.out.println(lChildKey);
}catch(Exception e){
logger.error(e.getMessage());
}
}
//This method disables the OIM user
/**
* @param usrKey This param contains the user key
*/
public void disableXellerateUser(long usrKey)
{
try{
userOperationsintf.disableUser(usrKey);
}catch(Exception e)
{
e.printStackTrace();
}
}
//This method is used to disable the App for the user
/**
* @param usrKey This param contains the user Key
* @param procInstKey This param contains the process instance key
*/
public void disableApp(long usrKey,long procInstKey)
{
try{
userOperationsintf.disableAppForUser(usrKey, procInstKey);
}catch(Exception e)
{
e.printStackTrace();
}
}
//This method prints the DataSet Data
/**
* @param tcdataset This param contaisn the dataset
* @param tcdatasetName This param contains the name of the dataset
* @param logger This is the logger reference
*/
private static void printTcDataSet(tcDataSet tcdataset, String tcdatasetName, Logger logger) {
if(! logger.isDebugEnabled()) {
return;
}
logger.debug("printTcDataSet Starts for " + tcdatasetName);
try {
if (tcdataset == null || tcdataset.isEmpty()) {
logger.debug("tcdataset is Empty or null");
return;
}
String columnNames = tcdataset.getColumnNames();
logger.debug("columnNames = " + columnNames);
String[] columnNamesArray = columnNames.split(",");
int rowCount = tcdataset.getRowCount();
logger.debug("rowCount = " + rowCount);
for (int j = 0; j < rowCount; j++) {
tcdataset.goToRow(j);
for (int i = 0; i < columnNamesArray.length; i++) {
if(! (isNullOrEmpty(columnNamesArray[i]) || columnNamesArray[i].toUpperCase().indexOf("NULL") >= 0)) {
logger.debug(columnNamesArray[i] + " = " + tcdataset.getString(columnNamesArray[i]));
}
}
logger.debug("---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----");
}
} catch (tcDataSetException e) {
}
}
private static boolean isNullOrEmpty(String s) {
return s == null || s.trim().length() == 0;
}
//This method gets the form data
/**
* @param procInstKey This contains the process Instance Key
*/
public void getFormData(long procInstKey)
{
try{
tcResultSet data=formInstanceOperationsIntf.getProcessFormData(procInstKey);
printTcResultSet(data,"Parent Form", logger);
getChildData(procInstKey);
}catch(Exception e)
{
logger.error(e.getMessage());
}
}
//This method prints the ResultSet Data
/**
* @param resultSet This param contaisn the dataset
* @param resultSetName This param contains the name of the dataset
* @param logger This is the logger reference
*/
private static void printTcResultSet(tcResultSet resultSet, String resultSetName, Logger logger) {
if(! logger.isDebugEnabled()) {
return;
}
System.out.println("printTcResultSet Starts for " + resultSetName);
try {
if (resultSet == null || resultSet.isEmpty()) {
System.out.println("resultSet is Empty or null");
return;
}
int rowCount = resultSet.getRowCount();
System.out.println("rowCount = " + rowCount);
for (int j = 0; j < rowCount; j++) {
resultSet.goToRow(j);
String[] columnNames = resultSet.getColumnNames();
for (int i = 0; i < columnNames.length; i++) {
System.out.println(columnNames[i] + " = " + resultSet.getStringValue(columnNames[i]));
}
logger.debug("---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----");
}
} catch (tcAPIException e) {
logger.error("printTcResultSet... tcAPIException:", e);
} catch (tcColumnNotFoundException e) {
logger.error("printTcResultSet... tcColumnNotFoundException:", e);
}
logger.debug("---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----");
logger.debug("---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----");
}
//This method is used to get the process task details for a user
/**
* @param procInstKey This contains the process instance key
*/
public void getProcesstaskDetails(long procInstKey)
{
try{
tcResultSet processTaskResult=provisioningOperationsIntf.getProcessDetail(procInstKey);
printTcResultSet(processTaskResult,"Process Task", logger);
}catch(Exception e){
logger.error(e.getMessage());
}
}
}
to run this program from eclipse then we hahve to do the following :
ReplyDelete1. Add all the OIM related jars from the lib and ext folder.
2. In eclipse open the run dialog and add the following in the VM Arguments:
-Djava.security.auth.login.config=E:/oim/server/xellerate/config/auth.conf
-DXL.HomeDir=E:/oim/server/xellerate
This comment has been removed by the author.
ReplyDeleteThe API doc can be got from the below link:
ReplyDeletehttp://otndnld.oracle.co.jp/document/products/id_mgmt/idm_903/doc_cd/javadocs/operations/Thor/API/Operations/package-summary.html
//This method takes the processInstanceKey as input and returns the IT Resource Name from the process form
ReplyDeletepublic String getFormValues(long sProcKey)
{
HashMap hmFormData=new HashMap();
String sParamValue="";
try {
long sProcInstKey=sProcKey;
tcResultSet formData=formInstanceOperationsIntf.getProcessFormData(sProcInstKey);
printTcResultSet(formData, "Form Data", logger);
int rowCount = formData.getRowCount();
System.out.println("rowCount = " + rowCount);
sParamValue=formData.getStringValue("UD_DBUSER1_ITRESOURCE");
/*hmFormData.put("UD_DBUSER1_USERNAME",sParamValue);
for (int j = 0; j < rowCount; j++) {
formData.goToRow(j);
String sParamValue=formData.getStringValue("UD_DBUSER1_USERNAME");
hmFormData.put("UD_DBUSER1_USERNAME",sParamValue);
}*/
} catch (tcAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (tcNotAtomicProcessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (tcFormNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (tcProcessNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
return sParamValue;
}
Code To Add Child Data
ReplyDelete-------------------------------------
--------------------------------------
public String addChildTableValue(long userKey, String group, String objectName, String fieldName tcDataProvider ioDatabase) {
log.debug("addChildTableValue() Parameter Variables passed are:" +
"userKey=[" + userKey + "]" +
"group=[" + group + "]" +
"fieldName=[" + fieldName + "]" +
"objectName=[" + objectName + "]");
try{
tcUserOperationsIntf userIntf = (tcUserOperationsIntf)tcUtilityFactory.getUtility(ioDatabase, "Thor.API.Operations.tcUserOperationsIntf");
tcFormInstanceOperationsIntf formIntf = (tcFormInstanceOperationsIntf)tcUtilityFactory.getUtility(ioDatabase, "Thor.API.Operations.tcFormInstanceOperationsIntf");
boolean roleExists = false;
//Result set of all Object for user
tcResultSet obResultSet = userIntf.getObjects(userKey);
if (obResultSet.isEmpty()){
log.error("User has no provisioned objects");
return "NO_OBJECTS_EXIST";
}else{
for (int ii=0; ii<obResultSet.getRowCount(); ii++){
obResultSet.goToRow(ii);
if ((obResultSet.getStringValue("Objects.Name").equals(objectName)) &&
(!(obResultSet.getStringValue("Objects.Object Status.Status").equals("Revoked")) &&
!(obResultSet.getStringValue("Objects.Object Status.Status").equals("Provisioning")))){
log.debug("Resource object found: " + objectName);
//Process Instance Key of the object
long plProcessInstanceKey = obResultSet.getLongValue("Process Instance.Key");
log.debug("Process instance key: " + plProcessInstanceKey);
//Process Key for the parent for
long plParentFormDefinitionKey = obResultSet.getLongValue("Process.Process Definition.Process Form Key");
log.debug("Parent form definition key: " + plParentFormDefinitionKey);
//Form version of the parent form
int pnParentFormVersion = formIntf.getProcessFormVersion(plProcessInstanceKey);
log.debug("Parent form version: " + pnParentFormVersion);
//Result set of Child Form information
tcResultSet childFormResultSet = formIntf.getChildFormDefinition(plParentFormDefinitionKey, pnParentFormVersion);
//Child form definition key
long plChildFormDefinitionKey = childFormResultSet.getLongValue("Structure Utility.Child Tables.Child Key");
String plChildTableName = childFormResultSet.getStringValue("Structure Utility.Table Name");
log.debug("Child form definition key: " + plChildFormDefinitionKey);
log.debug("Child table name: " + plChildTableName);
tcResultSet childFormData = formIntf.getProcessFormChildData(plChildFormDefinitionKey, plProcessInstanceKey);
if (!(childFormData.isEmpty())){
log.debug("Searching child table current values");
for (int iii=0; iii<childFormData.getRowCount();iii++){
childFormData.goToRow(iii);
String fieldValue = childFormData.getStringValue(fieldName);
log.debug("Child table entry: " + iii + " | value: " + fieldValue);
if (fieldValue.equals(group)){
roleExists = true;
log.debug("Value already exists in child table");
return "DUPLICATE_VALUE";
}
}
}
log.debug("Value not found in child table");
if (!roleExists){
Hashtable childFormHash = new Hashtable();
childFormHash.put(fieldName, group);
formIntf.addProcessFormChildData(plChildFormDefinitionKey, plProcessInstanceKey, childFormHash);
log.debug("Value successfully added to table");
return "VALUE_ADDED";
}
}
}
}
log.debug("Provisioned resource " + objectName + " object not found");
return "OBJECT_NOT_FOUND";
}
catch(Exception ex){
ex.printStackTrace();
}
return "ERROR";
}
Thank you. getChildFormData was very useful!
ReplyDelete