Quantcast
Channel: Geek's kitchen » oim
Viewing all articles
Browse latest Browse all 10

OIM11G + Java: entity adapters vs event handlers

$
0
0

Today I will talk about entity adapter detailed and provide you a link that have a great explanation about event handler too.

Some definitions:

Adapter:Primarily used to automatically complete provisioning tasks.

Event handler:A resource object’s provisioning process contains tasks that must be completed automatically. Once this happened, you have to assign an event handler or an adapter to the RO. Basically an event handler is a software routine and it will process a specific information

Details:

–> It looks like the entity adapter is going to be deprecated. What will replace entity adapter? Probably Entity adapter will be replaced by Event handler. So, why I am writing an article related of entity adapter?Because there are specific cases that event handler can not apply yet. And for this specific case(Child table) pre-insert into OIM 11G.You have to use it to pre-insert entity adapter for a childform.

Starting: Basically my code example will check if the value of one variable column is unique or not. If yes, it will create a record into child form table. If not, it will raise an exception as I will show below:

First item: Java Code.

Using tcDataProviderObj

 Fig1: Using tcDataProviderObj
Fig2: Main method. Check uniqueness. Using only OIM API.
 
 Fig3: This method is another way to do same check, but now using SQL and OIM DataSet API.
Second Item: Screenshots of OIM configuration.
 Fig5: Adapter conditions.
Fig6- Adapter variables.
 Fig7: DataObject manager pre-insert handler.
 Fig8: Testing|provisioning a resource to an organization.
 Fig9: Value to test(Andrea).
 Fig10: Log results when value into that specific field and specific object exists.
 
 Fig11: Logs when value does not exist and the Resource will be added with that child table value successfully.

The complete java class:

/**

* Check ||| Collect unique information from ParentFormID

* @param object --> process form table name

* @param field  --> field that should be unique

* @param value  --> that need to be checked

* @param orckey --> process Instace Key

* @return

* @throws Exception

*/

public boolean checkParentID(String object, String field, String value,long orckey) throws Exception {

tcResultSet parentFormDef;

List list = new ArrayList();

try {

logger.info("Part1:Running CHECKPARENtID Object:"+object+" FIELD:"+field+" VALUE:"+value+" ORCKEY:"+orckey);

f = Platform.getService(tcFormInstanceOperationsIntf.class);

poIntf = Platform.getService(tcProvisioningOperationsIntf.class);

//Check if LIST contains this specfic value

logger.info( "Part1:BOOLEAN VALUE:"+list.contains(value));

//this call should be changed to OIMUtils.getOrgKey because I don't have all classes here.After that pls remove the method below.

String orgKey = getOrgKey(Constants.ORG_ENTS);

// Get all object assigned to the above Organization that have the given MD name as prefix in descriptive field

logger.info("|||================BEFORE NEW SEARCH CRITERIA=================|||");

Map<String, String> searchCriteria = new HashMap<String, String>();

logger.info( "Part1:"+searchCriteria);

//Provide SearchCriteria

searchCriteria.put("Process Instance.Descriptive Data", "*");//Organizations.Field.Parameter Value

logger.info("Part1:"+searchCriteria+"  X="+orgKey+" OrgKey:"+orgKey);

tcResultSet rsltSet = poIntf.findObjects("Revoke", new String[] { orgKey }, "O", searchCriteria);

logger.info("Part1:"+searchCriteria+" ResultSet:  "+rsltSet);

System.out.println("TOTAL VALUE NEW RESULTSET:"+rsltSet.getTotalRowCount());

for (int i=0; i<rsltSet.getRowCount(); i++){

rsltSet.goToRow(i);

logger.info("Part1:"+i);

//list.add(rsltSet.getStringValue(field));

logger.info("Part1:Process Instance.Descriptive Data:"+rsltSet.getStringValue("Process Instance.Descriptive Data"));

logger.info("Part1:Objects.Name:"+rsltSet.getStringValue("Objects.Name"));

logger.info("Part1:Process Instance.Key:"+rsltSet.getStringValue("Process Instance.Key"));

if(checkIfFormExists(rsltSet.getLongValue("Process Instance.Key"))){

parentFormDef = f.getProcessFormData(rsltSet.getLongValue("Process Instance.Key"));

logger.info( "Part2:COUNT TOTAL:"+parentFormDef.getTotalRowCount());

parentFormDef.goToRow (0);

list.add(parentFormDef.getStringValue(field));

logger.info("Part2:VALUE ADDED INTO LIST(Collections):"+parentFormDef.getStringValue(field));

}

}

parentFormDef = f.getProcessFormData(orckey);

logger.info("===============================================================================================");

logger.info("============COLUMNS===============");

String columns[]= parentFormDef.getColumnNames();

logger.info("============CHILD DATA FORM===============");

for( String column : columns ) {

logger.info( "COLUMN NAME:"+column );

}

logger.info("===============================================================================================");

//Check if the value is not unique.

if(list.contains(value))

uniqueCheck=true;

//throw new Exception(OIMConstants.ENT_ASSINGMENT_ERROR);

logger.info("HAVE MORE RECORDS:"+uniqueCheck);

logger.info("END");

}catch (Exception e) {

e.printStackTrace();

System.out.println("XX:ERROR E:"+e);

}finally {

f.close();

}

return uniqueCheck;

}

/**

* Check if FormData exists

* @param prInstanceKey --> process instance key

* @return true of false

* @throws Thor.API.Exceptions.tcFormNotFoundException || Exception

*/

public boolean checkIfFormExists(long prInstanceKey){

tcResultSet dataFormDef;

f = Platform.getService(tcFormInstanceOperationsIntf.class);

try{

dataFormDef = f.getProcessFormData(prInstanceKey);

}catch(Thor.API.Exceptions.tcFormNotFoundException s){

return false;

}catch(Exception e){

e.printStackTrace();

System.out.println("XX:ERROR E:"+e);

return false;

}

return true;

}

/**

* Contigence plan if first method using APIS did not work properly

* Check ||| Collect information from ParentID or childID

* @param object --> process form table name

* @param field  --> field that should be unique

* @param value  --> that need to be checked

* @return

* @throws Exception

*/

public boolean checkUniqueValue(String object, String field, String value) throws Exception {

try {

logger.info( "Running checkUniqueValue Object:"+object+" FIELD:"+field+" VALUE:"+value);

//writing a SQL to check(count) how many values are into the object(table) requested

String SQL_CHECK_IF_VALUE_EXISTS =

"select count("+field+

") as count from "+object+

" where "+field+

"='"+value+"'";

tcDataSet dataSet = new tcDataSet();

//tcDataProvider = dataSet.getDataBase();

System.out.println("CHECK count SQL:"+SQL_CHECK_IF_VALUE_EXISTS);

System.out.println("tcDataProvider:"+tcDataProviderObj);

logger.debug(" Sql Query is : "+SQL_CHECK_IF_VALUE_EXISTS);

dataSet.setQuery(tcDataProviderObj, SQL_CHECK_IF_VALUE_EXISTS);

System.out.println("1:SETQUERY");

dataSet.executeQuery();

System.out.println("2:EXECUTEQUERY");

//String columnValues = dataSet.getColumnValues();

dataSet.next();

System.out.println("3:GETTING COUNT VALUE");

countValue = dataSet.getInt("count");

System.out.println("4:COLUMN VALUE count SQL:"+countValue);

if(countValue>=1){

uniqueCheck=true;

System.out.println("NOT UNIQUE VALUE ||| RAISE AN EXCEPTION");

throw new Exception(OIMConstants.ENT_ASSINGMENT_ERROR);

}

}catch (Exception e) {

e.printStackTrace();

System.out.println("XX:ERROR E:"+e);

}finally {

f.close();

}

return uniqueCheck;

}
You can also see an example of Event Handler that my friend Daniel did on this site:
http://fusionsecurity.blogspot.com/2011/09/oim-11g-event-handler-example.html

Just be careful when you develop an event handler because if you do some bad coding it could be a disaster into OIM performance.
I hope this helps,
Thiago Leoncio

Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images