Monday, January 5, 2015

OIM 11G R2 PS2 : StatusChangeEvent Plug-in

In this post, I will talk about the StatusChangeEvent plugin which allows running of custom code during request status change.

This plugin can be used to look the request data and perform any necessary actions  based on the status of a request.

I will provide here some sample implementation and hook point on how to use it.

import java.util.Date;
import java.util.List;

import oracle.iam.identity.exception.NoSuchUserException;
import oracle.iam.identity.exception.UserLookupException;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.Platform;
import oracle.iam.platform.authz.exception.AccessDeniedException;
import oracle.iam.request.api.RequestService;
import oracle.iam.request.exception.NoRequestPermissionException;
import oracle.iam.request.exception.RequestServiceException;
import oracle.iam.request.plugins.StatusChangeEvent;
import oracle.iam.request.vo.Beneficiary;
import oracle.iam.request.vo.Request;

public class StatusChangeEventPlugin implements StatusChangeEvent {

    @Override
    public void followUpActions(String requestID) {

        try {
            RequestService requestService = Platform
                    .getService(RequestService.class);
            Request request = requestService.getBasicRequestData(requestID);
            Date exDate = request.getExecutionDate();
            String requestModelName = request.getRequestModelName();
            List<Beneficiary> beneficiaries = request.getBeneficiaries();
            UserManager userManager = Platform
                        .getService(UserManager.class);
            for (Beneficiary beneficiary : beneficiaries) {
                String usrKey = beneficiary.getBeneficiaryKey();// usr_key
               
                User user = userManager.getDetails(usrKey, null, false);
                Date date = user.getCreationDate();
                // Update Request
                request.setExecutionDate(date);
                request.setJustification("Justified by system");
            }
        } catch (RequestServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoRequestPermissionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchUserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UserLookupException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (AccessDeniedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}