Description: This post demonstrates how to develop a custom scheduled task. Provided here is a sample custom scheduled task that creates a new OIM user with user data being provided through the scheduled task parameters.
1. Define the scheduled task metadata. The class tag contains the full package name of your Java class which you will need to create later on. The scheduled task parameters are defined in the metadata.
<?xml version="1.0" encoding="UTF-8"?> <scheduledTasks xmlns="http://xmlns.oracle.com/oim/scheduler"> <task> <name>Create New User</name> <class>oim.scheduledtasks.CreateNewUser</class> <description>Create a new OIM User</description> <retry>5</retry> <parameters> <string-param required="true" encrypted="false" helpText="First Name">First Name</string-param> <string-param required="true" encrypted="false" helpText="Last Name">Last Name</string-param> <string-param required="true" encrypted="false" helpText="User Login">User Login</string-param> </parameters> </task> </scheduledTasks>
2. Write a Java class that extends the
oracle.iam.scheduler.vo.TaskSupport class and put your logic in the execute() method. The hashmap that is passed into the execute() method contains the scheduled task parameters, which are defined in your scheduled task metadata. Create a jar file of your project.package oim.scheduledtasks;
import java.util.HashMap;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.Platform;
import oracle.iam.scheduler.vo.TaskSupport;
public class CreateNewUser extends TaskSupport
{
@Override
public void execute(HashMap hm) throws Exception
{
// Lookup a service
UserManager usermgr = Platform.getService(UserManager.class);
// Build new User
String userKey = null; // USR_KEY
String firstName = (String) hm.get("First Name"); // USR_FIRST_NAME
String lastName = (String) hm.get("Last Name"); // USR_LAST_NAME
String userLogin = (String) hm.get("User Login"); // USR_LOGIN
String organizationKey = "1"; // ACT_KEY [Organization]
String userType = "End-User"; // USR_TYPE
String role = "Full-Time"; // USR_EMP_TYPE [User Type]
User newUser = new User(userKey);
newUser.setLogin(userLogin);
newUser.setFirstName(firstName);
newUser.setLastName(lastName);
newUser.setOrganizationKey(organizationKey);
newUser.setUserType(userType);
newUser.setEmployeeType(role);
// Call a method from a service
usermgr.create(newUser);
}
@Override
public HashMap getAttributes()
{
return null;
}
@Override
public void setAttributes()
{
}
}
3. Create the plugin.xml file. The pluginclass parameter should be the name of the Java class that implements the scheduled task.
<?xml version="1.0" encoding="UTF-8"?> <oimplugins xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <plugins pluginpoint="oracle.iam.scheduler.vo.TaskSupport"> <plugin pluginclass= "oim.scheduledtasks.CreateNewUser" version="1.0.1" name="CreateNewUser"> </plugin> </plugins> </oimplugins>4. Package the schedule task plugin. The plugion zip file should have the following directory structure:
mycustomplugin.zip | |-------- lib/ | | ---------- JAR FILE | |--------- plugin.xml | |--------- META-INF/ | ------ METADATA XML
5. Register the plugin using APIs or the Plugin Registration Utility.
No comments:
Post a Comment