13 Replies Latest reply: Jan 9, 2013 12:18 AM by Srivatsa.kashyap RSS

    Post Update Event Handler Unable to get updated attributes

    raajesh
      Hi,

      I am using OIM 11.1.1.5.0. I wrote a post update event handler to update customAttribute based on Last Name. The event handler is invoking fine but I am unable to get the updated fields. Below is the code block that I am using.I will get the updates through schedular.

      public BulkEventResult execute(long processID, long eventID, BulkOrchestration orchestration) {
      System.out.println("Inside BulkEvent.execute()");
      String[] entityIDArray = orchestration.getTarget().getAllEntityId();
      for (int i = 0; i < entityIDArray.length; i++) {
      HashMap<String, Object> params = new HashMap<String, Object>();
      String usrKey = entityIDArray;
      System.out.println("Got User Key::" + usrKey);

      HashMap<String, Serializable> eventDataMap = orchestration.getInterEventData();
      System.out.println("Got Data form Event::" + eventDataMap);

      HashMap oldDataMap = new HashMap(); //HashMap that contains old values
      HashMap newDataMap = new HashMap(); //HashMap that contains new values

      System.out.println("Trying to get user attributes from event Data");
      oldDataMap.putAll(((User) eventDataMap.get("CURRENT_USER")).getAttributes());
      System.out.println("Got Attibutes::"+oldDataMap);
      newDataMap.putAll(((User) eventDataMap.get("NEW_USER_STATE")).getAttributes());
      System.out.println("Got Attibutes::"+newDataMap);

      System.out.println("Checking if last name is updated with new value or not");
      if (oldDataMap.get("Last Name") != null && newDataMap.get("Last Name") != null
      && !oldDataMap.get("Last Name").toString().equalsIgnoreCase(newDataMap.get("Last Name").toString())) {

      System.out.println("Last Name is modified so updating the email and User ID values");
      UserManager userManager = Platform.getService(UserManager.class);
      try {
      User user = userManager.getDetails("usr_key", usrKey, null);
      String userID = (String) user.getAttribute("WinNTLogin");
      System.out.println("Got User ID::" + userID );
      if (userID != null) {
      userID = userID.replace(oldDataMap.get("Last Name").toString(), newDataMap.get("Last Name").toString());
      System.out.println("New User ID::"+userID);
      params.put("WinNTLogin", userID);
      EntityManager entityManager = Platform.getService(EntityManager.class);
      entityManager.modifyEntity(orchestration.getTarget().getType(), usrKey, params);
      }
      } catch (NoSuchUserException e) {
      System.out.println("Error in execute" + e);
      } catch (UserLookupException e) {
      System.out.println("Error in execute" + e);
      } catch (SearchKeyNotUniqueException e) {
      System.out.println("Error in execute" + e);
      } catch (AccessDeniedException e) {
      System.out.println("Error in execute" + e);
      } catch (InvalidDataTypeException e) {
      System.out.println("Error in execute" + e);
      } catch (InvalidDataFormatException e) {
      System.out.println("Error in execute" + e);
      } catch (NoSuchEntityException e) {
      System.out.println("Error in execute" + e);
      } catch (StaleEntityException e) {
      System.out.println("Error in execute" + e);
      } catch (UnsupportedOperationException e) {
      System.out.println("Error in execute" + e);
      } catch (UnknownAttributeException e) {
      System.out.println("Error in execute" + e);
      } catch (ProviderException e) {
      System.out.println("Error in execute" + e);
      }

      } else if (oldDataMap.get("Last Name") != null && newDataMap.get("Last Name") != null
      && oldDataMap.get("Last Name").toString().equalsIgnoreCase(newDataMap.get("Last Name").toString())) {
      System.out.println("Last Name is not updated with a new Value");
      } else {
      System.out.println("Cannot find lastame in the updated list");
      }
      }
      return new BulkEventResult();
      }

      I implemented the same functionality in EventResult execute() but it is not getting invoked.
      Output I could see in the logger is ::

      Inside BulkEvent.execute()
      Got User Key::9641
      Got Data form Event::{CURRENT_USER=[Loracle.iam.identity.vo.Identity;@56c716da,
      NEW_USER_STATE=[Loracle.iam.identity.vo.Identity;@28ad6eb8}
      Trying to get user attributes from event Data.

      I tried different different ways for fetching the attributes but nothing worked.

      Another Way:

      User currentUser = (User) eventDataMap.get("CURRENT_USER");
      User newUser = (User) eventDataMap.get("NEW_USER_STATE");
      System.out.println("Checking if last name is updated with new value or not");
      if (currentUser.getLastName() != null && newUser.getLastName() != null
      && !currentUser.getLastName().equalsIgnoreCase(newUser.getLastName())) {
      //Custom logic here
      }

      Another Way:

      Identity oldStateObj = (Identity) eventDataMap.get("CURRENT_USER");
      System.out.println("Got Old State Data");
      Identity newStateObj = (Identity) eventDataMap.get("NEW_USER_STATE");
      System.out.println("Got New State Data");

      HashMap oldDataMap = oldStateObj.getAttributes();
      System.out.println("Got Attibutes::"+oldDataMap);

      HashMap newDataMap = newStateObj.getAttributes();
      System.out.println("Got Attibutes::"+newDataMap);

      System.out.println("Checking if last name is updated with new value or not");
      if (oldDataMap.get("Last Name") != null && newDataMap.get("Last Name") != null
      && !oldDataMap.get("Last Name").toString().equalsIgnoreCase(newDataMap.get("Last Name").toString())) {
      //Custom Logic Here
      }

      Please help me if anyone had worked on this.

      Regards,
      Rajesh