OIM API To Grant Entitlement To User Request API


  1. package com.oimacademy.request;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import oracle.iam.api.OIMService;
  5. import oracle.iam.exception.OIMServiceException;
  6. import oracle.iam.identity.exception.NoSuchUserException;
  7. import oracle.iam.identity.exception.UserLookupException;
  8. import oracle.iam.platform.utils.vo.OIMType;
  9. import oracle.iam.request.vo.Beneficiary;
  10. import oracle.iam.request.vo.RequestBeneficiaryEntity;
  11. import oracle.iam.request.vo.RequestConstants;
  12. import oracle.iam.request.vo.RequestData;
  13. import oracle.iam.vo.OperationResult;
  14. import com.oimacademy.connection.Platform;
  15. public class RequestToGrantEntitlementToUser {
  16.  private final OIMService oimService  =Platform.getService(OIMService.class); 
  17.   public OperationResult grantEntitlement(String usrKey, String entitlementName, String entKey) throws NoSuchUserException, UserLookupException, OIMServiceException
  18.      {
  19.          RequestBeneficiaryEntity reqBenefEntity = new RequestBeneficiaryEntity();
  20.          reqBenefEntity.setRequestEntityType(OIMType.Entitlement);
  21.          reqBenefEntity.setEntitySubType(entitlementName);
  22.          reqBenefEntity.setEntityKey(entKey);
  23.          reqBenefEntity.setOperation(RequestConstants.MODEL_PROVISION_ENTITLEMENT_OPERATION);
  24.          List<RequestBeneficiaryEntity>  entities = new ArrayList<RequestBeneficiaryEntity>();
  25.          entities.add(reqBenefEntity);         
  26.          Beneficiary beneficiary = new Beneficiary();
  27.          beneficiary.setBeneficiaryKey(usrKey);
  28.          beneficiary.setBeneficiaryType(Beneficiary.USER_BENEFICIARY);
  29.          beneficiary.setTargetEntities(entities);        
  30.          List<Beneficiary> beneficiaries = new ArrayList<Beneficiary>();
  31.          beneficiaries.add(beneficiary);
  32.          RequestData reqData = new RequestData();
  33.          reqData.setBeneficiaries(beneficiaries); // Set list of request entity        
  34.          OperationResult result = oimService.doOperation(reqData, OIMService.Intent.REQUEST);         
  35.          return result;
  36.      }
  37. }

No comments:

Post a Comment