- package com.oimacademy.scheduler;
- import java.io.Serializable;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import com.oimacademy.connection.DataSource;
- import com.oimacademy.connection.OIMConnection;
- import oracle.iam.scheduler.api.SchedulerService;
- import oracle.iam.scheduler.vo.CronTrigger;
- import oracle.iam.scheduler.vo.JobDetails;
- import oracle.iam.scheduler.vo.JobParameter;
- import oracle.iam.scheduler.vo.Trigger;
- public class UpdateScheduledJobCron {
- public static void main(String[] args){
- new UpdateScheduledJobCron().updateScheduledJobParameter();
- }
- public HashMap getCronTriggerJobs(){
- HashMap cronJobMap = new HashMap();
- Connection con = DataSource.getConnection();
- String cronQuery = "select T.TRIGGER_NAME,CT.CRON_EXPRESSION from QRTZ92_CRON_TRIGGERS CT,QRTZ92_TRIGGERS T where T.TRIGGER_NAME=CT.TRIGGER_NAME AND T.TRIGGER_TYPE='CRON'";
- try {
- PreparedStatement prepStmt = con.prepareStatement(cronQuery);
- ResultSet rs = prepStmt.executeQuery();
- while(rs.next()) {
- cronJobMap.put(rs.getString("TRIGGER_NAME"),rs.getString("CRON_EXPRESSION"));
- }
- rs.close();
- prepStmt.close();
- } catch (SQLException ex) {
- ex.printStackTrace();
- } finally {
- DataSource.closeConnection();
- }
- return cronJobMap;
- }
- public void updateScheduledJobParameter() {
- SchedulerService schedulerService = null;
- HashMap<String,String> cronMap = getCronTriggerJobs();
- for (Map.Entry<String,String> entry : cronMap.entrySet()) {
- JobParameter jbParam = new JobParameter();
- String jobName = entry.getKey();
- String cronExpression = entry.getValue();
- try{
- //get scheduler service
- schedulerService = OIMConnection.getConnection().getService(SchedulerService.class);
- JobDetails jobDetail = schedulerService.getJobDetail(jobName);
- HashMap jobAttributes = jobDetail.getAttributes();
- System.out.println("JobDetails Object Getting Params ");
- HashMap<String, JobParameter> jobParameters = jobDetail.getParams();
- if(null!=jobParameters && jobParameters.size()>0){
- Iterator itrJobParams = jobParameters.keySet().iterator();
- while (itrJobParams.hasNext()) {
- String hashKey=itrJobParams.next().toString();
- Object obj = jobParameters.get(hashKey);
- JobParameter jp = null;
- if (null != obj && obj instanceof JobParameter) {
- jp = (JobParameter) obj;
- Serializable val = jp.getValue();
- jbParam.setName(jp.getName());
- jbParam.setValue(jp.getValue());
- jbParam.setParameterKey(jp.getParameterKey());
- jbParam.setDataType(jp.getDataType());
- jobAttributes.put(jp.getName(), jbParam);
- }
- }
- }else{
- System.out.println(" jobParameters Null in the task Name -> "+jobDetail.getTaskName());
- }
- System.out.println( "Updated job attributes - " + jobAttributes);
- Trigger[] triggers= schedulerService.getTriggersOfJob(jobName);
- for(Trigger trigg : triggers ){
- schedulerService.deleteTrigger(trigg.getName());
- }
- JobDetails jb = new JobDetails();
- jb.setName(jobDetail.getName());
- jb.setJobScheduleType(jobDetail.getJobScheduleType());
- jb.setCronScheduleType(jobDetail.getCronScheduleType());
- jb.setRetrycount(jobDetail.getRetrycount());
- jb.setAttributes(jobAttributes);
- //Update Job with Job Details.
- schedulerService.updateJob(jobDetail);
- System.out.println("Job updated successfully");
- //Schedule Trigger
- schedulerService.scheduleJob(jobDetail.getName(), new CronTrigger(jobDetail.getName(),new Date(),null, cronExpression));
- System.out.println("Job scheduled successfully");
- }catch(Exception e){
- System.out.println( "Exception occured while updating scheduled job parameters - " + e);
- }
- }
- System.out.println("END");
- }
- }
Oracle Identity Manager(OIM) is the Provisioning Solution from oracle. This page contains an index with references to all OIM related posts in the oracle identity manager Academy blog. The posts included herein are intended to provide oracle identity management customers and developers with technical information about best practices for implementing OIM based solutions.
API Code to scheduleJob / Delete Trigger / Update Job for CRON Triggers
Subscribe to:
Post Comments (Atom)
-
Connection Related API's : OIM DB Connection/ Data Source connection OIMClient API / OIMConnection API OIM Platform API to getSer...
-
Error : Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.springframewor...
-
In this post, we set the middle name as “MiddleName” if user does not provide middle name during user create operation. Below are high...
No comments:
Post a Comment