protected SchedulerResponse getScheduledJob(Scheduler scheduler, JobKey jobKey) throws Exception { JobDetail jobDetail = scheduler.getJobDetail(jobKey); if (jobDetail == null) { return null; } SchedulerResponse schedulerResponse = new SchedulerResponse(); JobDataMap jobDataMap = jobDetail.getJobDataMap(); String description = jobDataMap.getString(SchedulerEngine.DESCRIPTION); schedulerResponse.setDescription(description); String destinationName = jobDataMap.getString(SchedulerEngine.DESTINATION_NAME); schedulerResponse.setDestinationName(destinationName); Message message = getMessage(jobDataMap); JobState jobState = getJobState(jobDataMap); message.put(SchedulerEngine.JOB_STATE, jobState); schedulerResponse.setMessage(message); StorageType storageType = StorageType.valueOf(jobDataMap.getString(SchedulerEngine.STORAGE_TYPE)); schedulerResponse.setStorageType(storageType); String jobName = jobKey.getName(); String groupName = jobKey.getGroup(); TriggerKey triggerKey = new TriggerKey(jobName, groupName); Trigger trigger = scheduler.getTrigger(triggerKey); if (trigger == null) { schedulerResponse.setGroupName(groupName); schedulerResponse.setJobName(jobName); return schedulerResponse; } message.put(SchedulerEngine.END_TIME, trigger.getEndTime()); message.put(SchedulerEngine.FINAL_FIRE_TIME, trigger.getFinalFireTime()); message.put(SchedulerEngine.NEXT_FIRE_TIME, trigger.getNextFireTime()); message.put(SchedulerEngine.PREVIOUS_FIRE_TIME, trigger.getPreviousFireTime()); message.put(SchedulerEngine.START_TIME, trigger.getStartTime()); if (trigger instanceof CalendarIntervalTrigger) { CalendarIntervalTrigger calendarIntervalTrigger = CalendarIntervalTrigger.class.cast(trigger); IntervalUnit intervalUnit = calendarIntervalTrigger.getRepeatIntervalUnit(); schedulerResponse.setTrigger( new IntervalTrigger( jobName, groupName, calendarIntervalTrigger.getStartTime(), calendarIntervalTrigger.getEndTime(), calendarIntervalTrigger.getRepeatInterval(), TimeUnit.valueOf(intervalUnit.name()))); } else if (trigger instanceof CronTrigger) { CronTrigger cronTrigger = CronTrigger.class.cast(trigger); schedulerResponse.setTrigger( new com.liferay.portal.kernel.scheduler.CronTrigger( jobName, groupName, cronTrigger.getStartTime(), cronTrigger.getEndTime(), cronTrigger.getCronExpression())); } else if (trigger instanceof SimpleTrigger) { SimpleTrigger simpleTrigger = SimpleTrigger.class.cast(trigger); schedulerResponse.setTrigger( new IntervalTrigger( jobName, groupName, simpleTrigger.getStartTime(), simpleTrigger.getEndTime(), (int) simpleTrigger.getRepeatInterval(), TimeUnit.MILLISECOND)); } return schedulerResponse; }
protected Trigger getQuartzTrigger( com.liferay.portal.kernel.scheduler.Trigger trigger, StorageType storageType) throws SchedulerException { if (trigger == null) { return null; } Date endDate = trigger.getEndDate(); String jobName = fixMaxLength(trigger.getJobName(), _jobNameMaxLength, storageType); String groupName = fixMaxLength(trigger.getGroupName(), _groupNameMaxLength, storageType); Date startDate = trigger.getStartDate(); if (startDate == null) { startDate = new Date(System.currentTimeMillis()); } TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger(); triggerBuilder.endAt(endDate); triggerBuilder.forJob(jobName, groupName); triggerBuilder.startAt(startDate); triggerBuilder.withIdentity(jobName, groupName); TriggerType triggerType = trigger.getTriggerType(); if (triggerType == TriggerType.CRON) { triggerBuilder.withSchedule( CronScheduleBuilder.cronSchedule((String) trigger.getTriggerContent())); return triggerBuilder.build(); } ObjectValuePair<Integer, TimeUnit> objectValuePair = (ObjectValuePair<Integer, TimeUnit>) trigger.getTriggerContent(); int interval = objectValuePair.getKey(); if (interval < 0) { if (_log.isWarnEnabled()) { _log.warn("Not scheduling " + trigger.getJobName() + " because interval is less than 0"); } return null; } else if (interval == 0) { return triggerBuilder.build(); } TimeUnit timeUnit = objectValuePair.getValue(); if (timeUnit == TimeUnit.MILLISECOND) { SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule(); simpleScheduleBuilder.withIntervalInMilliseconds(interval); simpleScheduleBuilder.withRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY); triggerBuilder.withSchedule(simpleScheduleBuilder); } else { CalendarIntervalScheduleBuilder calendarIntervalScheduleBuilder = CalendarIntervalScheduleBuilder.calendarIntervalSchedule(); calendarIntervalScheduleBuilder.withInterval(interval, IntervalUnit.valueOf(timeUnit.name())); triggerBuilder.withSchedule(calendarIntervalScheduleBuilder); } return triggerBuilder.build(); }