1 2 Previous Next 23 Replies Latest reply: May 11, 2012 3:33 AM by Srivatsa.kashyap RSS

    Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)

    Anil Bansal
      Hi,

      We had Custom event handlers for generating some fields on user form.
      Everytime there is update on user profile on any field, All the event handlers fired, (As seen from logs).

      I want to fire particular event handlers on particular update. Like if first name is updated then only display name event handler should fire. (not all)

      How can i achieve this???
        • 1. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
          Prakash Bajiya
          The custom event handler will fire every time since plugins fire based on operation type(create,update, etc.). The only thing you can do is, in your custom event handler code put check for particular update. If a particular field is updated then only execute the code inside plugin.
          • 2. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
            Anil Bansal
            Hi,

            Thanks for ur reply...

            Yes that's what i want to know.. How can i check in the code that particular field is updated to new one??
            • 3. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
              Prakash Bajiya
              Get Parameters from orchestration. Here parameters var will have only updated parameters in case of update operation.
              HashMap<String, Serializable> parameters =
              orchestration.getParameters();

              you can check particular field in parameters var above.
              • 4. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                Mounika
                Hi,
                you can get old values as well as updated values for each field from Orchestration during Update operation. Here is a sample code for the same.

                //***********Sample Code *******************

                HashMap<String , Serializable> eventDataMap = new HashMap<String , Serializable>();
                eventDataMap.putAll(orchestration.getInterEventData());

                HashMap currentUserState = new HashMap(); //HashMap that contains old values
                HashMap newUserState = new HashMap(); //HashMap that contains new values

                currentUserState.putAll(((User) eventDataMap.get(CURRENT_USER)).getAttributes());
                newUserState.putAll(((User) eventDataMap.get(NEW_USER_STATE)).getAttributes());

                //******************************************

                You can compare both the hashmaps to get modified attributes.

                Hope, this will be helpful.

                Regards,
                Mounika
                • 5. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                  Srivatsa.kashyap
                  in the above code can you please tell me what are these 2 values

                  CURRENT_USER
                  NEW_USER_STATE

                  for me it is showing type or variable not found..
                  Thanks
                  • 6. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                    Kuldeep
                    Hi,

                    HashMap<String, Serializable> interEvtDataMap = orchestration.getInterEventData();
                    User newUserState = (oracle.iam.identity.usermgmt.vo.User) interEvtDataMap.get("NEW_USER_STATE");
                    User oldUserState = (oracle.iam.identity.usermgmt.vo.User) interEvtDataMap.get("OLD_USER_STATE");

                    Now compare theattribute value from newUserState (new value) and oldUserState (existing value), based on requirement :

                    you can set the attribute for modification,

                    Thanks,
                    Kuldeep
                    • 7. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                      Srivatsa.kashyap
                      hi kuldeep,

                      thanks for the reply

                      i am getting Caused By: java.lang.NullPointerException error at User newUserState = (oracle.iam.identity.usermgmt.vo.User) interEvtDataMap.get("NEW_USER_STATE");

                      is there any other way other than this to get all the user value while updating the user.??
                      cause i had validation eventhandler. it is returning null values for non-modified field which is stopping my validation on modifying users.

                      thanks
                      • 8. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                        Kuldeep
                        Hi
                        You can get
                        User user = getUser(orchestration);
                         Object passwdOrchParam = orchParams.get(oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName.PASSWORD.getId());
                        
                        
                         private User getUser(Orchestration orchestration)
                            {
                                if(orchestration.getTarget() != null && orchestration.getTarget().getEntityId() != null)
                                    return new User(orchestration.getTarget().getEntityId());
                                HashMap orchParams = orchestration.getParameters();
                                User user = new User(null);
                                Set orchParamNames = orchParams.keySet();
                                String orchParamName;
                                for(Iterator i$ = orchParamNames.iterator(); i$.hasNext(); user.setAttribute(orchParamName, orchParams.get(orchParamName)))
                                    orchParamName = (String)i$.next();
                        
                                MLSUtils.setStringValuesForMLSAttributes(user);
                                return user;
                            }
                        For your refernce you can check the class
                        oracle.iam.passwordmgmt.eventhandlers.UserPasswordValidationHandler

                        Also just try to iterate these three map

                        HashMap orchParams = orchestration.getParameters();

                        HashMap orchParams = orchestration.getParameters();

                        HashMap<String, Serializable> interEvtDataMap = orchestration.getInterEventData();

                        hope you will get the information.

                        Thanks,
                        Kuldeep
                        • 9. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                          Mounika
                          You are getting variable not found error because you didnot specify it as a String. Please provide these values in duoble quotes to specify it as String object.

                          Regards,
                          Mounika
                          • 10. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                            Srivatsa.kashyap
                            Here is my code..it is working fine for creation of the user. but when i am updating the user i am getting all null values except the updated one.

                            Example if there are 5 fields in that i am updating 2 .apart from those 2 fields the other 3 are coming as null which is making validation to fail.


                            package flatfilevalidation;

                            import java.io.Serializable;


                            import java.util.Date;
                            import java.util.HashMap;


                            import oracle.iam.platform.context.ContextAware;
                            import oracle.iam.platform.kernel.ValidationException;
                            import oracle.iam.platform.kernel.ValidationFailedException;
                            import oracle.iam.platform.kernel.spi.ValidationHandler;
                            import oracle.iam.platform.kernel.vo.BulkOrchestration;
                            import oracle.iam.platform.kernel.vo.Orchestration;
                            import oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName;
                            import Thor.API.*;
                            import Thor.API.Exceptions.tcAPIException;
                            import Thor.API.Operations.*;

                            import java.util.Iterator;
                            import java.util.List;

                            import java.util.Set;

                            import oracle.iam.identity.usermgmt.api.UserManagerConstants;
                            import oracle.iam.identity.usermgmt.vo.User;
                            import oracle.iam.passwordmgmt.utils.MLSUtils;
                            import oracle.iam.platform.Platform;
                            import oracle.iam.platform.kernel.vo.OrchestrationTarget;

                            import oracle.iam.upgrade.changes.jaxb.Entity;


                            public class FFValidation implements ValidationHandler {
                            int count;
                            tcUserOperationsIntf userOperationsService;
                            Entity ent = null;


                            @Override
                            public void validate(long arg0, long arg1, Orchestration orchestration)
                            throws ValidationException, ValidationFailedException {

                            System.out.println("entered the Validation methode");

                            HashMap<String, Serializable> parameters = orchestration.getParameters();

                            System.out.println("****************************************************************");


                            User user = getUser(orchestration);
                            Object passwdOrchParam = parameters.get(UserManagerConstants.AttributeName.EMPLOYEE_NUMBER.getId());

                            System.out.println("***************************"+passwdOrchParam+"*************************************");















                            System.out.println("orch.getParameters() ============================ " + parameters);
                            String ceo="CEO";
                            String trainee="Trainee";
                            String Emp="EMP";
                            String Contractor="Contractor";
                            //int Skypecount,Empcount,phonecount;
                            String Role= getParameterValue(parameters, "Role");
                            String Designation = getParameterValue(parameters, "Designation");
                            Long Manager =getManagerid(parameters, "USR_MANAGER_KEY");
                            Date EndDate =getDate(parameters, "End Date");
                            String EmpNo=getParameterValue(parameters, "Employee Number");
                            String skypeid=getParameterValue(parameters, "SkypeId");
                            String Mobile=getParameterValue(parameters, "Mobile");
                            String skypeidDb="usr_udf_skypeid";
                            String MobileDb="usr_mobile";
                            String EmpDB="usr_emp_no";



                            //validating SkypeID
                            uniquevalidate(skypeid,skypeidDb);

                            //Validating Employee Number
                            uniquevalidate(EmpNo,EmpDB);

                            //Validating Employee Number
                            uniquevalidate(Mobile,MobileDb);


                            //CEO Validation
                            if(Designation.equals(ceo)){
                            if(Manager!=null){
                            String msg="ManagerID not required";
                            System.out.println("ManagerID not required ");
                            throw new ValidationFailedException(msg);
                            }
                            }
                            //Cotractor Validation
                            if(Role.equals(Contractor) && Designation.equals(ceo)) {
                            System.out.println(Designation.equals(ceo));
                            String msg="Contractor Cannot be CEO";
                            System.out.println("Contractor Cannot be CEO");
                            throw new ValidationFailedException(msg);
                            }
                            if(Role.equals(Contractor)&& EndDate==null) {
                            String msg="Contractor Endate is not provided";
                            System.out.println("Contractor Endate is not provided");
                            throw new ValidationFailedException(msg);

                            }
                            //Trainee Validation
                            if(Role.equals(trainee) && Designation.equals(ceo)) {
                            System.out.println(Designation.equals(ceo));
                            if(Designation.equals(ceo)) {
                            String msg="Trainee Cannot be CEO";
                            System.out.println("Trainee Cannot be CEO");
                            throw new ValidationFailedException(msg);
                            }
                            }

                            //manager validation
                            if(!Designation.equals(ceo)){
                            if(Manager==null){
                            String msg="ManagerID Can not be Null";
                            System.out.println("ManagerID Can not be Null");
                            throw new ValidationFailedException(msg);
                            }

                            }


                            //Employee Validation
                            if(Role.equals(Emp)){
                            if(EndDate!=null) {
                            String msg="Employee End Date Should be empty";
                            System.out.println("Employee End Date Should be empty");
                            throw new ValidationFailedException(msg);

                            }
                            }



                            }

                            @Override
                            public void validate(long arg0, long arg1, BulkOrchestration arg2)
                            throws ValidationException, ValidationFailedException {
                            System.out.println("**************Inside BulkOrchestration****************");
                            HashMap<String, Serializable> parameters = arg2.getParameters();
                            System.out.println("orch.getParameters() ============================ " + parameters);
                            }



                            @Override
                            public void initialize(HashMap<String, String> arg0) {


                            }



                            private String getParameterValue(HashMap<String, Serializable> parameters,
                            String key) {
                            String value = (parameters.get(key) instanceof ContextAware) ? (String) ((ContextAware) parameters
                            .get(key)).getObjectValue()
                            : (String) parameters.get(key);
                            System.out.println("VALUE::" + value);

                            return value;
                            }



                            private boolean isNullOrEmpty(String str) {
                            return str == null || str.isEmpty();
                            }

                            private Long getManagerid(HashMap<String, Serializable> parameters,
                            String key) {

                            System.out.println(parameters);

                            Long managerLogin = (parameters.get(AttributeName.MANAGER_KEY.getId()) instanceof ContextAware)
                            ? (Long) ((ContextAware) parameters.get(AttributeName.MANAGER_KEY.getId())).getObjectValue()
                            : (Long) parameters.get(AttributeName.MANAGER_KEY.getId());

                            System.out.println("managerLogin "+managerLogin);
                            return managerLogin;


                            }
                            private Date getDate(HashMap<String, Serializable> parameters,
                            String key) {

                            System.out.println("date "+ parameters);

                            Date date = (parameters.get(AttributeName.ACCOUNT_END_DATE.getId()) instanceof ContextAware)
                            ? (Date) ((ContextAware) parameters.get(AttributeName.ACCOUNT_END_DATE.getId())).getObjectValue()
                            : (Date) parameters.get(AttributeName.ACCOUNT_END_DATE.getId());

                            System.out.println("EndDate "+date);
                            return date;


                            }
                            void uniquevalidate(String idvalue,String idDbvalue){


                            userOperationsService = Platform.getService(tcUserOperationsIntf.class);
                            HashMap<String, String> UMAttr = new HashMap<String, String>();
                            String msg="Entered Value is not unique" + idvalue;
                            System.out.println("idvalue="+ idvalue);
                            System.out.println("idDbvalue="+ idDbvalue);
                            if(idvalue!=null){
                            try {
                            System.out.println("in try block");
                            UMAttr.put(idDbvalue, idvalue);
                            tcResultSet USAttr = userOperationsService.findUsers(UMAttr);
                            System.out.println(USAttr);

                            System.out.println("User set count ========================= " + USAttr.getRowCount());
                            count=USAttr.getRowCount();
                            if(count>0)
                            throw new ValidationFailedException(msg);
                            }
                            catch (tcAPIException e) {
                            e.printStackTrace();
                            }
                            }

                            }
                            private User getUser(Orchestration orchestration)
                            {
                            if(orchestration.getTarget() != null && orchestration.getTarget().getEntityId() != null)
                            return new User(orchestration.getTarget().getEntityId());
                            HashMap orchParams = orchestration.getParameters();
                            User user = new User(null);
                            Set orchParamNames = orchParams.keySet();
                            String orchParamName;
                            for(Iterator i$ = orchParamNames.iterator(); i$.hasNext(); user.setAttribute(orchParamName, orchParams.get(orchParamName)))
                            orchParamName = (String)i$.next();

                            MLSUtils.setStringValuesForMLSAttributes(user);
                            System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"+user);
                            return user;
                            }


                            }
                            • 11. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                              Srivatsa.kashyap
                              yes i did provide these values in duoble quotes.
                              • 12. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                                Kuldeep
                                private Object getOldUserStates(BulkOrchestration orchestration){
                                          logger.debug("UserAttrUpdateEvtHndler/getOldUserStates START");
                                          Object oldUserStates = null;
                                          HashMap interEventData = orchestration.getInterEventData();
                                          if (interEventData != null)
                                               newUserStates = interEventData.get("OLD_USER_STATE");
                                          return oldUserStates ;
                                     }

                                     private Object getNewUserStates(BulkOrchestration orchestration){
                                          logger.debug("UserAttrUpdateEvtHndler/getNewUserStates START");
                                          Object newUserStates = null;
                                          HashMap interEventData = orchestration.getInterEventData();
                                          if (interEventData != null)
                                               newUserStates = interEventData.get("NEW_USER_STATE");
                                          return newUserStates;
                                     }
                                Expalin the case: for "create" and "update"
                                1. what is happenning with oldUserStates and newUserStates
                                If you can not handle null pointer for you requirement.

                                create separate event handler for operation create and update
                                • 13. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                                  Mounika
                                  Seems you are confused. For update operation, you should use orchestration.getInterEventData() instead of orchestration.getParameters();

                                  For example:

                                  HashMap<String , Serializable> eventDataMap = new HashMap<String , Serializable>();
                                  eventDataMap.putAll( orchestration.getInterEventData());

                                  HashMap currentUserState = new HashMap();
                                  HashMap newUserState = new HashMap();
                                                 
                                  currentUserState.putAll(((User) eventDataMap.get("CURRENT_USER")).getAttributes());
                                  newUserState.putAll(((User) eventDataMap.get("NEW_USER_STATE")).getAttributes());

                                  //Use if-else condition to make your code works even if null values come. Here i am giving example for one attribute:SkypeId

                                  String newSkypeId = null;

                                  if(!((newUserState.get("SkypeId")) == null)){
                                       newSkypeId= (newUserState.get("SkypeId")).toString();
                                  }else{
                                       String newSkypeId=null;
                                  }



                                  Regards,
                                  Mounika
                                  • 14. Re: Event Handlers Invoked Everytime for update on User Profile.(OIM 11g)
                                    Kuldeep
                                    Hi Mounika,

                                    If you will check your code:

                                    --eventDataMap.putAll( orchestration.getInterEventData());

                                    you are acheving the same thing. Only diff is in param value "CURRENT_USER"

                                    Thanks,
                                    kuldeep
                                    1 2 Previous Next