Friday, August 1, 2008

How To - OIM : Updating Scheduled Task through API

In OIM 9.1 there are new API's added to manage the scheduled task. This allows you to update / start scheduled task outside of OIM admin console. Here is an example of
updating the scheduled task to run at specified time.

/**
*
*
* This class will update the scheduled task. You can schedule the start time , running interval
* etc using this schedule class.
*
* First search all the scheduled task's in OIM. this will give you key for
* the scheduled task Using the key you can update the scheduled task with
* attributes you need to modify.
*
* This API is only avilable in OIM 9.1 onwards.
*/


package workshop.lab;

import Thor.API.Operations.*;
import Thor.API.tcUtilityFactory;
import Thor.API.Security.*;
import com.thortech.xl.util.config.ConfigurationClient.ComplexSetting;
import com.thortech.xl.util.config.ConfigurationClient;
import com.thortech.xl.crypto.tcSignatureMessage;
import com.thortech.xl.crypto.tcCryptoUtil;
import com.thortech.xl.security.tcLoginException;
import com.thortech.xl.crypto.tcCryptoException;
import Thor.API.tcResultSet;

import java.util.HashMap;
import java.util.Hashtable;



public class updateScheduleTask {

private tcUtilityFactory utilityFactory;
private tcSchedulerOperationsIntf scIntf;

public updateScheduleTask() {

System.out.println(" ************* Inside Update Schedule Task constructor ****************");
try {
ComplexSetting config =
ConfigurationClient.getComplexSettingByPath("Discovery.CoreServer");
System.out.println(" Config is " + config.toString());
final Hashtable env = config.getAllSettings();
System.out.println(" Hash Table env is " + env);


tcSignatureMessage moSignature =
tcCryptoUtil.sign("xelsysadm", "PrivateKey");
utilityFactory = new tcUtilityFactory(env, moSignature);
System.out.println("utilityFactory = " + utilityFactory);
scIntf=(tcSchedulerOperationsIntf)utilityFactory.getUtility("Thor.API.Operations.tcSchedulerOperationsIntf");
System.out.println(" Scheduler Interface is ...."+scIntf);
} catch (Exception ee) {
System.out.println(" Exception in Constructor " + ee);
ee.printStackTrace();
}


}

public void updateScheduleTask(){

try{

tcResultSet oimset;

Hashtable scTable = new Hashtable();
scTable.put("Task Scheduler.Key","61");
oimset=scIntf.findScheduleTasks(scTable);
System.out.println(" Hash Table..."+scTable);
String cNames[] = oimset.getColumnNames();
int count=oimset.getRowCount();

/**
* Display all the attributes of all the schedules task's
*/

for (int i = 0; i < count; i++) {
for (int j = 0; j < cNames.length; j++) {
System.out.println(cNames[j] + " " +
oimset.getStringValue(cNames[j]));
}
oimset.goToRow(i);
}

/**
* Modify the task with attributes you need to change. In
* this example i am changing the start time so that
* the task gets triggred.
*/

scTable = new Hashtable();
scTable.put("Task Scheduler.Start Time","2008-07-02 18:13:30");
scIntf.updateScheduleTask(61,scTable);

}catch(Exception ee){
System.out.println(" Exception ......"+ee.toString());
}
}

public static void main(String args[]){
updateScheduleTask utask = new updateScheduleTask();
utask.updateScheduleTask();
}
}

No comments: