Sunday, July 19, 2015

OIM API- Update Schedule task attribute

Some time we need to update schedule task attribute like time stump; so that when the schedule task execute next time it can start executing after that time stump. we can use the below code to achieve that.

private void updateSchedulerTimeStamp(Date curTime,String scheduledTaskName)
{
try
{
String currentTime = curTime.toString();
SimpleDateFormat lastExecutionTimeParser1 = new SimpleDateFormat("E MMM dd hh:mm:ss z yyyy");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
curTime = lastExecutionTimeParser1.parse(currentTime);
String curDate=sdf.format(curTime);
HashMap <String,String> hashmap = new HashMap<String,String>();
hashmap.put("Task Scheduler.Name", scheduledTaskName);
tcSchedulerOperationsIntf tcSchOper = (tcSchedulerOperationsIntf) Platform.getService(tcSchedulerOperationsIntf.class);
tcResultSet tcresultset = tcSchOper.findScheduleTasks(hashmap);


if(tcresultset != null && tcresultset.getRowCount() > 0)
{
tcresultset.goToRow(0);
long schedularKey = tcresultset.getLongValue("Task Scheduler.Key");
String schedularKeyStr = String.valueOf(schedularKey);
hashmap.clear();
hashmap.put("Task Scheduler.Key", schedularKeyStr);
hashmap.put("Task Scheduler.Task Attributes.Name", "Last Execution Time");
tcResultSet tcresultset1 = tcSchOper.findScheduleTaskAttributes(hashmap);
if(tcresultset1 != null && tcresultset1.getRowCount()>0){
tcresultset1.goToRow(0);
long scheduleTaskAtrKey = tcresultset1.getLongValue("Task Scheduler.Task Attributes.Key");
hashmap.put("Task Scheduler.Task Attributes.Value", curDate);
tcSchOper.updateScheduleTaskAttribute(schedularKey,scheduleTaskAtrKey, hashmap);  

}
else{
logger.finest("CLASS_NAME - Nirupam - in updateSchedulerTimeStamp Method :Resultset is null: ");
}

}
}
catch(Exception e)
{
logger.finest("CLASS_NAME - Nirupam - in updateSchedulerTimeStamp Method :Exception:"+e);
}

}

OIM API read IT Resource Parameter

/**
* returns a HashMap with   IT resource field details
* @param itResourceName
* @return
*/
public HashMap<String, String> getITResourceAttributeInMap(String itResourceName)  {

HashMap<String, String>  adITResourcefileds = new HashMap<String, String> ();

try{
tcITResourceInstanceOperationsIntf tcITResourceIntf = Platform.getService(tcITResourceInstanceOperationsIntf.class);
HashMap<String, String>  searchcriteria = new HashMap<String, String>();
searchcriteria.put("IT Resources.Name", itResourceName);
tcResultSet resultSet = tcITResourceIntf.findITResourceInstances(searchcriteria);
resultSet = tcITResourceIntf.getITResourceInstanceParameters(resultSet.getLongValue("IT Resources.Key"));

for (int i = 0; i < resultSet.getRowCount(); i++) {
resultSet.goToRow(i);
String name = resultSet.getStringValue("IT Resources Type Parameter.Name");

String value= resultSet.getStringValue("IT Resources Type Parameter Value.Value");
adITResourcefileds.put(name,value);
}
}catch (Exception ae) {
ae.printStackTrace();
}
return adITResourcefileds;

}