Friday, 6 April 2018

Steps to Create Custom Task with custom attribute


If you have any requirement for which you have to create a custom task with custom attribute then you can follow the below steps

This can be achieved by Create a TaskDefinition and Custom Java class that extends AbstractTaskExecutor.and override the methods to implement your business logic in java code.

The class name should be mentioned in as executor value in TaskDefinition like below. 

Note: Below is an example for a custom task that pulls search identity and display message on result screen.

      Create TaskDefinition

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE sailpoint PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<sailpoint>
<TaskDefinition executor="sailpoint.custom.task.SearchIdentityTask” name="Search Identity Custom Task" progressInterval="5000" progressMode="String" resultAction="Rename" template="true" type="Generic">
          <Description>
                   Runs a search for an identity against a specific First Name.
          </Description>
          <Signature>
          <Inputs>
                   <Argument name="search_name" type="string">
                   <Prompt>Search Identity Name:</Prompt>
                   </Argument>
          </Inputs>
          <Returns>
                   <Argument name="success" type="boolean">
                             <Prompt>Success: </Prompt>
                   </Argument>
                   <Argument name="messages" type="string">
                             <Prompt>Messages: </Prompt>
                   </Argument>
                   <Argument name="count" type="integer">
                             <Prompt>Count: </Prompt>
                   </Argument>
                   <Argument name="match_count" type="integer">
                             <Prompt>Match Count: </Prompt>
                   </Argument>
                   <Argument name="items" type="string">
                             <Prompt>Objects matching search term: </Prompt>
                   </Argument>
                   </Returns>
          </Signature>
</TaskDefinition>
</sailpoint>

è executor="sailpoint.custom.task.SearchIdentityTask” is the Custom JAVA Class that will be used to execute the task.
è  template="true" is set to get the TaskDefinition listed in “New Task” List




è Here Argument inside Input Tag is the custom attribute that needs input when the task is executed

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil3JafYCWbgyoH_-01oGl6IClrYGcMhFOgahpKdvk0bjH4o8hJD4PPjW0AfEs1ihOS2ZWPAS6v5byHvAUTqIXQ5x-Q4fsc095-HrQ_XVgaWufpYSKp-H2hg7OL8Sbyms-f6dYfpGn20Bmh/s320/Untitled.jpg
  2)      Now create a class file

NOTE: Business Logic will be written in the execute method and it will change based on your requirement.

package sailpoint.custom.task;

import sailpoint.api.SailPointContext;
import sailpoint.object.Attributes;
import sailpoint.object.Identity;
import sailpoint.object.TaskResult;
import sailpoint.object.TaskSchedule;
import sailpoint.task.AbstractTaskExecutor;
import sailpoint.task.TaskMonitor;
import sailpoint.tools.GeneralException;

public class SearchIdentityTask extends AbstractTaskExecutor {
          private String strSearchname = null;
          private boolean isSuccess = false;
          private String messages = null;

          public boolean isSuccess() {
                   return isSuccess;
          }

          public void setSuccess(boolean isSuccess) {
                   this.isSuccess = isSuccess;
          }

          public String getMessages() {
                   return messages;
          }

          public void setMessages(String messages) {
                   this.messages = messages;
          }

          public String getStrSearchname() {
                   return strSearchname;
          }

          public void setStrSearchname(String strSearchname) {
                   this.strSearchname = strSearchname;
          }

//method that will be executed when the task executes
          @Override
          public void execute(SailPointContext paramSailPointContext, TaskSchedule paramTaskSchedule,
                             TaskResult paramTaskResult, Attributes<String, Object> paramAttributes) throws Exception {
                   // TODO Auto-generated method stub

                   TaskMonitor localTaskMonitor = new TaskMonitor(paramSailPointContext, paramTaskResult);
                   setMonitor(localTaskMonitor);

                   localTaskMonitor.updateProgress("Parsing Arguments");
                    parseArgs(paramAttributes);   //Get Custom attribute value
                   System.out.println("First Name to be searched : " + this.getStrSearchname());
                   localTaskMonitor.updateProgress("Validating Arguments");
                   if (!validateArgs()) {
                             localTaskMonitor.updateProgress("Arguments failed validation");
                             setSuccess(false);
                   } else {
                             localTaskMonitor.updateProgress("Searching for term...");
                             Identity user = paramSailPointContext.getObjectByName(Identity.class, this.getStrSearchname());
                             System.out.println("First Name to be searched user.getEmail() : " + user.getEmail());
                             if (user != null)
                                      setMessages("User Found with Name : " + this.getStrSearchname());
                             else
                                      setMessages("No user Found with Name : " + this.getStrSearchname());

                             setSuccess(true);
                             localTaskMonitor.updateProgress("Finished.");
                   }
                   populateTaskResult(paramTaskResult);

          }
// Prepare Result Screen
          private void populateTaskResult(TaskResult paramTaskResult) {
                   paramTaskResult.setAttribute("success", Boolean.valueOf(isSuccess()));
                   paramTaskResult.setAttribute("messages", getMessages());
          }

          @Override
          public boolean terminate() {
                   // TODO Auto-generated method stub
                   return false;
          }

          public void parseArgs(Attributes<String, Object> paramAttributes) {
                   this.strSearchname = paramAttributes.getString("search_name");
          }

          public boolean validateArgs() throws GeneralException {
                   if ((this.strSearchname == null) || (this.strSearchname.trim().equals(""))) {
                             setMessages("Must specify a first name to be searched!");
                             return false;
                   } else {
                             return true;
                   }
          }

}

   3)      Compile the class file and copy it inside “\webapps\identityiq\WEB-INF\classes\sailpoint\custom\task”

   4)      Restart tomcat

   5)      Goto Setup -> Tasks; to configure your task and schedule if required.

1 comment:

  1. Betfair Slots Casino app not working on android - JTA Hub
    Betfair Slots 경주 출장안마 Casino App 대구광역 출장마사지 not working with android. Play at betfair slot casino on android. 구미 출장마사지 Download 포항 출장샵 Betfair Slots Casino app apk for 평택 출장샵 android.

    ReplyDelete

SOAPAPi Call and Reading

<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd"...