public class UserManagerEventHandler implements PostProcessHandler {
private static final Logger LOGGER = Logger.getLogger(UserManagerEventHandler.class.getName());
private static final String CLASS_NAME = UserManagerEventHandler.class.getName();
@Override
public boolean cancel(long arg0, long arg1, AbstractGenericOrchestration arg2) {
return false;
}
@Override
public void compensate(long arg0, long arg1, AbstractGenericOrchestration arg2) {
}
@Override
public BulkEventResult execute(long arg0, long arg1, BulkOrchestration arg2) {
return null;
}
/**
* @param processId
* OIM.ORCHEVENTS.ProcessId
* @param eventId
* OIM.ORCHEVENTS.ID
* @param orchestration
* Holds useful data
*/
@Override
public EventResult execute(long processId, long eventId, Orchestration orchestration) {
String methodName = "execute";
System.out.println(CLASS_NAME + "/" + methodName + "; processId = " + processId + "; eventId = " + eventId
+ "; orchestration = " + orchestration);
LOGGER.debug(CLASS_NAME + "/" + methodName + "; processId = " + processId + "; eventId = " + eventId
+ "; orchestration = " + orchestration);
try {
// contains only the new values
HashMap<String, Serializable> newParameters = orchestration.getParameters();
// contains old and new
HashMap<String, Serializable> interParameters = orchestration.getInterEventData();
// values of user
System.out.println(String.format("Inter Parameters: %s ", interParameters));
System.out.println(String.format("New Parameters: %s ", newParameters));
User currentUserState = (User) interParameters.get("CURRENT_USER");
Long oldManagerKey = currentUserState.getAttribute("usr_manager_key") instanceof ContextAware
? (Long) ((ContextAware) currentUserState.getAttribute("usr_manager_key")).getObjectValue()
: (Long) currentUserState.getAttribute("usr_manager_key");
Long newManagerKey = getParamaterStringValue(newParameters, "usr_manager_key");
Long newMangerID = newParameters.get(AttributeName.MANAGER_KEY.getId()) instanceof ContextAware
? (Long) ((ContextAware) newParameters.get(AttributeName.MANAGER_KEY.getId())).getObjectValue()
: (Long) newParameters.get(AttributeName.MANAGER_KEY.getId());
Long oldManagerID = null;
oldManagerID = (Long) currentUserState.getAttribute(AttributeName.MANAGER_KEY.getId());
LOGGER.debug(CLASS_NAME + "newMangerID:\t" + newMangerID);
LOGGER.debug(CLASS_NAME + "newManagerKey:\t" + newManagerKey);
LOGGER.debug(CLASS_NAME + "oldManagerID" + oldManagerID);
LOGGER.debug(CLASS_NAME + "oldManagerKey" + oldManagerKey);
LOGGER.debug(CLASS_NAME + "User Login:\t" + currentUserState.getLogin());
String userLogin = currentUserState.getLogin().toUpperCase();
System.out.println("userLogin : " + userLogin);
LOGGER.debug("userLogin : " + userLogin);
String newMGRKey = String.valueOf(newManagerKey);
System.out.println("newMGRKey : " + newMGRKey);
LOGGER.debug("newMGRKey : " + newMGRKey);
String newManagerUserLogin = "";
String oldManagerUserLogin = "";
UserManager usrMgr = Platform.getService(UserManager.class);
// Check existence of manager key
if (newMGRKey != null) {
User newmanagerUser = usrMgr.getDetails(newMGRKey, new HashSet<String>(), false);
newManagerUserLogin = newmanagerUser.getLogin().toUpperCase();
LOGGER.debug("New Manager Login : " + newManagerUserLogin);
System.out.println("New Manager Login : " + newManagerUserLogin);
}
String oldMGRKey = String.valueOf(oldManagerKey);
System.out.println("oldMGRKey : " + oldMGRKey);
LOGGER.debug("oldMGRKey : " + oldMGRKey);
// Check existence of manager key
if (oldMGRKey != null) {
User oldManagerUser = usrMgr.getDetails(oldMGRKey, new HashSet<String>(), false);
oldManagerUserLogin = oldManagerUser.getLogin().toUpperCase();
LOGGER.debug("Old Manager Login : " + oldManagerUserLogin);
System.out.println("Old Manager Login : " + oldManagerUserLogin);
}
if (oldManagerID != null && newMangerID != null && newMangerID != oldManagerID) {
System.out.println("Manager update is invoking :");
LOGGER.debug("Manager update is invoking :");
String managerUpdateStatus = ManagerChange.managerChange(userLogin, oldManagerUserLogin, newManagerUserLogin);
}
}
catch (Exception ex) {
LOGGER.error(CLASS_NAME + "Error occured in Process Evenet Handler");
System.out.println(CLASS_NAME + "/" + " Exception : " + ex.getMessage());
ex.printStackTrace();
}
return new EventResult();
}
/**
* ContextAware object is obtained when the actor is a regular user. If the
* actor is an administrator, the exact value of the attribute is obtained.
*
* @param parameters
* parameters from the orchestration object
* @param key
* name of User Attribute in OIM Profile or column in USR table
* @return value of the corresponding key in parameters
*/
private Long getParamaterStringValue(HashMap<String, Serializable> parameters, String key) {
Long value = parameters.get(key) instanceof ContextAware
? (Long) ((ContextAware) parameters.get(key)).getObjectValue() : (Long) parameters.get(key);
return value;
}
@Override
public void initialize(HashMap<String, String> arg0) {
}
}
No comments:
Post a Comment