Friday 15 February 2013

Post Process Event Handler


1. create "Eventhandlers.xml"

Sample Eventhandlers.xml

<eventhandlers xmlns="http://www.oracle.com/schema/oim/platform/kernel"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.oracle.com/schema/oim/platform/kernelorchestration-handlers
.xsd">
<action-handler class="oim.eventhandlers.UpdateManagerLogin"
entity-type="User" operation="CREATE" name="NamePostProcessEventHandlers"
stage="postprocess" order="FIRST" sync="TRUE"/>
<action-handler class="oim.eventhandlers.UpdateManagerLogin"
entity-type="User" operation="MODIFY" name="NamePostProcessEventHandlers"
stage="postprocess" order="SECOND" sync="TRUE"/>
</eventhandlers>


2. Export the Eventhandlers.xml to metadata

For knowing how to import: Click here


3. Create plugin.xml


Sample plugin.xml


<?xml version="1.0" encoding="UTF-8"?>
<oimplugins>
<plugins pluginpoint="oracle.iam.platform.kernel.spi.EventHandler">
<plugin pluginclass="iam.oim.eventhandlers.UpdateManagerLogin" version="1.0" name="UpdateManagerLogin"/>
</plugins>
</oimplugins>

3. Execute post process


Sample sourcecode


public EventResult execute(long processId, long eventId,
                               Orchestration orchestration) {
        System.out.println("Test fo Event Handler"); // Test fo Event Handler
        try {
           
            //Initilize variables
            UserManager userMgmt;
            userMgmt = Platform.getService(UserManager.class);
            String userKey = getUserKey(processId, orchestration);
           
            //Want to modify usr_mgr_key
            HashMap<String, Object> atrrMap= new HashMap<String, Object>();
           
            HashMap<String, Serializable> parameters = orchestration.getParameters();
            String mgrEmpID = getParamaterValue(parameters, "Manager Employee ID");
          
            Set<String> setMgr=new HashSet<String>();
            setMgr.add("usr_key");
            User usr_key_of_manager = userMgmt.getDetails("Employee Number", mgrEmpID,setMgr);
            String mgrUsrKey=usr_key_of_manager.getId();           
            System.out.println("Manager user key:"+mgrUsrKey);

            //user will upadated with the value of mgrUsrKey
            atrrMap.put("usr_manager_key", Long.valueOf(mgrUsrKey));
             //System.out.println("User key of the manager user"+usr_key_mgruser); 
            
             //get the user to whom you want to modify
            User user = userMgmt.getDetails("usr_key", Long.valueOf(userKey), null); 
            System.out.println("Before new"+user);
            user = new User(String.valueOf(user.getId()), atrrMap);          
            System.out.println("After new"+user);
                      
            UserManagerResult result = userMgmt.modify("usr_key", String.valueOf(userKey), user);          
            System.out.println("UserUpdate.process() "+result.getStatus());   

        return new EventResult();
    }
    private String getUserKey(long processID, Orchestration orchestration) {
        String userKey;
        String entityType = orchestration.getTarget().getType();
        EventResult result;
        result = new EventResult();     

        if (!orchestration.getOperation().equals("CREATE")) {
            userKey = orchestration.getTarget().getEntityId();
            System.out.println("UserKEY0" + userKey);
        } else {
            OrchestrationEngine orchEngine =
                Platform.getService(OrchestrationEngine.class);
            userKey = (String)orchEngine.getActionResult(processID);
            System.out.println("UserKEY-1" + userKey);
          
        }
        return userKey;
    }
4. add library - oimclient.jar file
5. register the plugin.xml and jar files (by zipping them into single file)

Move to : OIM_HOME/server/plugin_utility
ant -f pluginregistration.xml register/unregister

5. Restart the oim managed server
6. Test by creating/update the user


Reference documents from oracle:

Extending User Managemen bu Developing Event Handlers:
http://docs.oracle.com/cd/E14571_01/doc.1111/e14309/oper.htm#CCHHHGEC

Using API:
http://docs.oracle.com/cd/E14571_01/doc.1111/e14309/apis.htm

Forums Discussions:
https://forums.oracle.com/forums/message.jspa?messageID=10174401#10174401
https://forums.oracle.com/forums/thread.jspa?messageID=9792462
https://forums.oracle.com/forums/message.jspa?messageID=10176817

No comments:

Post a Comment