Thursday, October 12, 2023

AfterProvisioning Rule

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import sailpoint.api.SailPointContext;

import sailpoint.object.EmailOptions;

import sailpoint.object.EmailTemplate;

import sailpoint.object.Identity;

import sailpoint.object.ProvisioningPlan;

import sailpoint.object.ProvisioningPlan.AccountRequest;

import sailpoint.object.ProvisioningResult;

import sailpoint.tools.GeneralException;


public class SendMail {

static SailPointContext context = null;

static ProvisioningPlan plan = null;

public static void main(String[] args) throws GeneralException {

Log logger = LogFactory.getLog("rule.active directory.Common.fieldvalue.create");

String userType = null;

Map emailTemplateArguments = new HashMap();

List toEmailList = new ArrayList();

EmailOptions options = new EmailOptions();

if (null != plan && null != plan.getNativeIdentity()) {

logger.debug("Got the falcon delete plan :");

List<AccountRequest> accReqList = plan.getAccountRequests();

Identity identity = context.getObjectByName(Identity.class, plan.getNativeIdentity());

if (null != identity) {

logger.debug("The identity is : " + identity);

userType = identity.getAttribute("type").toString();

for (AccountRequest acctReq: accReqList) {

ProvisioningResult provResult = acctReq.getResult();

if (AccountRequest.Operation.Modify.equals(acctReq.getOperation())

&& !provResult.getStatus().equalsIgnoreCase("faild") && null != userType

&& !userType.equalsIgnoreCase("service")) {


logger.debug("Display name" + identity.getDisplayName());

emailTemplateArguments.put("identityDiaplayName", identity.getDisplayName());


logger.debug("The email address" + identity.getAttribute("email"));

String mail = (identity.getAttribute("email") != null)? identity.getAttribute("email").toString(): null;


if (null != mail) {

toEmailList.add(mail);

options.setTo(toEmailList);

options.addVariables(emailTemplateArguments);

EmailTemplate emailTemplateUserID = context.getObjectByName(EmailTemplate.class, "emailTemplateName");

logger.debug("The emailTemplateUserID------------------------------" + emailTemplateUserID);

emailTemplateUserID.setBcc("abc@gmail.com");

context.sendEmailNotification(emailTemplateUserID, options);

logger.debug("email sent successfully-----------------------");

}

}


if (AccountRequest.Operation.Delete.equals(acctReq.getOperation())

&& !provResult.getStatus().equalsIgnoreCase("faild") && null != userType

&& !"service".equalsIgnoreCase(userType)) {

Map emailTemplaetArguments = new HashMap();

logger.debug("The falcon Display name" + identity.getDisplayName());

emailTemplaetArguments.put("identityDiaplayName", identity.getDisplayName());

String mail = (identity.getAttribute("email") != null)? identity.getAttribute("email").toString(): null;

logger.debug("Got the email address" + mail);

if (null != mail) {

logger.debug("Inside the loop testing");

toEmailList.add(mail);

options.setTo(toEmailList);

options.addVariables(emailTemplaetArguments);

EmailTemplate emailTemplateUserID = context.getObjectByName(EmailTemplate.class,"LeaveremailTemplateName");

emailTemplateUserID.setBcc("abc@gmail.com");

context.sendEmailNotification(emailTemplateUserID, options);

logger.debug("email sent successfully-----------------------");

}

}

}

}

}

}

}

No comments:

Post a Comment

Fetch Members from Workgroup

  import java.util.ArrayList;   import java.util.Iterator;   import java.util.List;   import sailpoint.api.ObjectUtil;   import sailpoint.ob...