To add custom messages in Approvals, we can add it through Build Approval Set variable in Workflow.
Requirement:
Add a rule in the Build Approval Set variable.
The message that is displayed is item.setValue().
Below Rule is added to the Build Approval Set.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule created="" id="" language="beanshell" modified="" name="Plugin Build Identity ApprovalSet" type="Workflow">
<Description>Build Identity ApprovalSet for request coming from vendor contract extension plugin</Description>
<Signature returnType="Object"/>
<Source>import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AttributeRequest;
import sailpoint.object.ProvisioningPlan.AccountRequest;
import sailpoint.object.ApprovalSet;
import sailpoint.object.ApprovalItem;
import sailpoint.object.Attributes;
import sailpoint.tools.Util;
import java.util.Date;
import java.text.SimpleDateFormat;
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.services.rules.workflow.PluginBuildIdentityApprovalSet");
serilog.debug("--------------------------------------------------");
serilog.debug(plan.toXml());
ApprovalSet set = new ApprovalSet();
if ( plan != null ) {
List accountRequests = plan.getAccountRequests();
for ( AccountRequest request : accountRequests ) {
ApprovalItem item = new ApprovalItem();
item.setApplication(request.getApplication());
item.setInstance(request.getInstance());
item.setNativeIdentity(request.getNativeIdentity());
item.setOperation(request.getOperation().toString());
List attrRequestFlat = flattenAttributeRequests(request.getAttributeRequests());
if( pluginAction.equalsIgnoreCase("vendor-contract-extension")) {
String contractExtensionComments = "Request to extend the vendor contract for "+ identityDisplayName + " from "+ currentEndDate + " to " + extensionDate;
item.setValue(contractExtensionComments);
} else if( pluginAction.equalsIgnoreCase("vendor-disable")) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String date = simpleDateFormat.format(terminationDate);
String disableComments = "Request to disable the vendor "+ identityDisplayName + " with Termination Date set to " + date;
item.setValue(disableComments);
}else if( attrRequestFlat != null ) {
item.setValue(attrRequestFlat);
}
Attributes attributes = getAttributeRequestArguments(request.getAttributeRequests());
item.setAttributes(attributes);
// for these requests comments come in on the plan
String comments = plan.getComments();
if ( Util.getString(comments) != null ) {
item.setRequesterComments(comments);
}
set.add(item);
}
// while we are here lets annotate the plan with previousValues
if ( flow.equals("IdentityEditRequest") ) {
AccountRequest iiqRequest = plan.getAccountRequest("IIQ");
if ( iiqRequest != null ) {
List attributeRequests = iiqRequest.getAttributeRequests();
if ( Util.size(attributeRequests) > 0 ) {
Identity id = context.getObject(Identity.class, identityName);
if ( id != null ) {
for ( AttributeRequest req : attributeRequests ) {
String name = req.getName();
if ( name != null ) {
// We have to be carefull here, if we see manager display
// the displayName
Object prevValue = id.getAttribute(name);
if ( prevValue != null ) {
if (name.equals("manager") ) {
String displayName = getIdentityProperty((String)prevValue, "displayName");
if ( displayName != null ) {
prevValue = displayName;
}
}
else if (prevValue instanceof Identity) {
prevValue = (String)prevValue.getDisplayableName();
}
else if(prevValue instanceof List) {
/* Thanks to type erasure there is no way for us to write something like
* prevValue instanceof List&lt;Identity> so break it into steps. Check if
* prevValue is a List. If it has any elements get the first one. If that
* is an instance of Identity then assume the rest of the elements are too
* and then build a List of displayable names, because that is what we do
* with Identitys. */
List prevValueList = (List) prevValue;
if(prevValueList.size() > 0) {
if(prevValueList.get(0) instanceof Identity) {
List identityIds = new ArrayList(prevValueList.size());
for (Object value : prevValueList) {
Identity identity = (Identity) value;
identityIds.add(identity.getDisplayableName());
}
prevValue = identityIds;
}
}
}
req.put(ProvisioningPlan.ARG_PREVIOUS_VALUE, prevValue);
}
}
}
}
}
}
}
}
return set;</Source>
</Rule>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule created="" id="" language="beanshell" modified="" name="Plugin Build Identity ApprovalSet" type="Workflow">
<Description>Build Identity ApprovalSet for request coming from vendor contract extension plugin</Description>
<Signature returnType="Object"/>
<Source>import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AttributeRequest;
import sailpoint.object.ProvisioningPlan.AccountRequest;
import sailpoint.object.ApprovalSet;
import sailpoint.object.ApprovalItem;
import sailpoint.object.Attributes;
import sailpoint.tools.Util;
import java.util.Date;
import java.text.SimpleDateFormat;
serilog=org.apache.commons.logging.LogFactory.getLog("sailpoint.services.rules.workflow.PluginBuildIdentityApprovalSet");
serilog.debug("--------------------------------------------------");
serilog.debug(plan.toXml());
ApprovalSet set = new ApprovalSet();
if ( plan != null ) {
List accountRequests = plan.getAccountRequests();
for ( AccountRequest request : accountRequests ) {
ApprovalItem item = new ApprovalItem();
item.setApplication(request.getApplication());
item.setInstance(request.getInstance());
item.setNativeIdentity(request.getNativeIdentity());
item.setOperation(request.getOperation().toString());
List attrRequestFlat = flattenAttributeRequests(request.getAttributeRequests());
if( pluginAction.equalsIgnoreCase("vendor-contract-extension")) {
String contractExtensionComments = "Request to extend the vendor contract for "+ identityDisplayName + " from "+ currentEndDate + " to " + extensionDate;
item.setValue(contractExtensionComments);
} else if( pluginAction.equalsIgnoreCase("vendor-disable")) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String date = simpleDateFormat.format(terminationDate);
String disableComments = "Request to disable the vendor "+ identityDisplayName + " with Termination Date set to " + date;
item.setValue(disableComments);
}else if( attrRequestFlat != null ) {
item.setValue(attrRequestFlat);
}
Attributes attributes = getAttributeRequestArguments(request.getAttributeRequests());
item.setAttributes(attributes);
// for these requests comments come in on the plan
String comments = plan.getComments();
if ( Util.getString(comments) != null ) {
item.setRequesterComments(comments);
}
set.add(item);
}
// while we are here lets annotate the plan with previousValues
if ( flow.equals("IdentityEditRequest") ) {
AccountRequest iiqRequest = plan.getAccountRequest("IIQ");
if ( iiqRequest != null ) {
List attributeRequests = iiqRequest.getAttributeRequests();
if ( Util.size(attributeRequests) > 0 ) {
Identity id = context.getObject(Identity.class, identityName);
if ( id != null ) {
for ( AttributeRequest req : attributeRequests ) {
String name = req.getName();
if ( name != null ) {
// We have to be carefull here, if we see manager display
// the displayName
Object prevValue = id.getAttribute(name);
if ( prevValue != null ) {
if (name.equals("manager") ) {
String displayName = getIdentityProperty((String)prevValue, "displayName");
if ( displayName != null ) {
prevValue = displayName;
}
}
else if (prevValue instanceof Identity) {
prevValue = (String)prevValue.getDisplayableName();
}
else if(prevValue instanceof List) {
/* Thanks to type erasure there is no way for us to write something like
* prevValue instanceof List&lt;Identity> so break it into steps. Check if
* prevValue is a List. If it has any elements get the first one. If that
* is an instance of Identity then assume the rest of the elements are too
* and then build a List of displayable names, because that is what we do
* with Identitys. */
List prevValueList = (List) prevValue;
if(prevValueList.size() > 0) {
if(prevValueList.get(0) instanceof Identity) {
List identityIds = new ArrayList(prevValueList.size());
for (Object value : prevValueList) {
Identity identity = (Identity) value;
identityIds.add(identity.getDisplayableName());
}
prevValue = identityIds;
}
}
}
req.put(ProvisioningPlan.ARG_PREVIOUS_VALUE, prevValue);
}
}
}
}
}
}
}
}
return set;</Source>
</Rule>
No comments:
Post a Comment