public void processIntervalTrigger(final IntervalTriggerDetail intervalTriggerDetails)
     throws ParseException, SchedulerException, InternalError {
   Trigger schedTrigger = null;
   if (SECOND.equals(intervalTriggerDetails.getRepeatUnit())) {
     schedTrigger = TriggerUtils.makeSecondlyTrigger(intervalTriggerDetails.getRepeatInterval());
   } else if (MINUTE.equals(intervalTriggerDetails.getRepeatUnit())) {
     schedTrigger = TriggerUtils.makeMinutelyTrigger(intervalTriggerDetails.getRepeatInterval());
   } else if (HOUR.equals(intervalTriggerDetails.getRepeatUnit())) {
     schedTrigger = TriggerUtils.makeHourlyTrigger(intervalTriggerDetails.getRepeatInterval());
   } else {
     throw new InternalError(
         "Could not work out which interval to use for the schedule of an @"
             + Every.class.getName()
             + " observer");
   }
   schedTrigger.setJobGroup(SCHEDULE_JOB_GROUP);
   scheduleJob(schedTrigger, intervalTriggerDetails);
 }
 @Override
 public void visit(FixedPeriodJobTrigger trigger) {
   switch (trigger.getTimeUnit()) {
     case SECOND:
       quartzTrigger = TriggerUtils.makeSecondlyTrigger(trigger.getTimeInterval());
       break;
     case MINUTE:
       quartzTrigger = TriggerUtils.makeMinutelyTrigger(trigger.getTimeInterval());
       break;
     case HOUR:
       quartzTrigger = TriggerUtils.makeHourlyTrigger(trigger.getTimeInterval());
       break;
   }
   if (trigger.getStartDate() != null) {
     quartzTrigger.setStartTime(trigger.getStartDate());
   } else {
     quartzTrigger.setStartTime(quartzTrigger.getFireTimeAfter(new Date()));
   }
 }
  public void run() throws Exception {
    Log log = LogFactory.getLog(JobExceptionExample.class);

    log.info("------- Initializing ----------------------");

    // First we must get a reference to a scheduler
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();

    log.info("------- Initialization Complete ------------");

    log.info("------- Scheduling Jobs -------------------");

    // jobs can be scheduled before start() has been called

    // get a "nice round" time a few seconds in the future...
    long ts = TriggerUtils.getNextGivenSecondDate(null, 15).getTime();

    // badJob1 will run every three seconds
    // this job will throw an exception and refire
    // immediately
    JobDetail job = new JobDetail("badJob1", "group1", BadJob1.class);
    SimpleTrigger trigger =
        new SimpleTrigger(
            "trigger1", "group1", new Date(ts), null, SimpleTrigger.REPEAT_INDEFINITELY, 3000L);
    Date ft = sched.scheduleJob(job, trigger);
    log.info(
        job.getFullName()
            + " will run at: "
            + ft
            + " and repeat: "
            + trigger.getRepeatCount()
            + " times, every "
            + trigger.getRepeatInterval() / 1000
            + " seconds");

    // badJob2 will run every three seconds
    // this job will throw an exception and never
    // refire
    job = new JobDetail("badJob2", "group1", BadJob2.class);
    trigger =
        new SimpleTrigger(
            "trigger2", "group1", new Date(ts), null, SimpleTrigger.REPEAT_INDEFINITELY, 3000L);
    ft = sched.scheduleJob(job, trigger);
    log.info(
        job.getFullName()
            + " will run at: "
            + ft
            + " and repeat: "
            + trigger.getRepeatCount()
            + " times, every "
            + trigger.getRepeatInterval() / 1000
            + " seconds");

    log.info("------- Starting Scheduler ----------------");

    // jobs don't start firing until start() has been called...
    sched.start();

    log.info("------- Started Scheduler -----------------");

    try {
      // sleep for 60 seconds
      Thread.sleep(60L * 1000L);
    } catch (Exception e) {
    }

    log.info("------- Shutting Down ---------------------");

    sched.shutdown(true);

    log.info("------- Shutdown Complete -----------------");

    SchedulerMetaData metaData = sched.getMetaData();
    log.info("Executed " + metaData.numJobsExecuted() + " jobs.");
  }
  public void run() throws Exception {
    Logger log = LoggerFactory.getLogger(SimpleTriggerExample.class);

    log.info("------- Initializing -------------------");
    // First we must get a reference to a scheduler
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();

    log.info("------- Initialization Complete --------");
    log.info("------- Scheduling Jobs ----------------");

    // jobs can be scheduled before sched.start() has been called
    // get a "nice round" time a few seconds in the future...
    long ts = TriggerUtils.getNextGivenSecondDate(null, 5).getTime();

    sched.start();
    log.info("------- Started Scheduler -----------------");

    // jobs can also be scheduled after start() has been called...
    // job7 will repeat 20 times, repeat every 3 sec
    JobDetail job = new JobDetail("job7", "group1", SimpleJob.class);
    SimpleTrigger trigger =
        new SimpleTrigger("trigger7", "group1", "job7", "group1", new Date(ts), null, 30, 2000L);
    Date ft = sched.scheduleJob(job, trigger);
    log.info(
        job.getFullName()
            + " will run at: "
            + ft
            + " and repeat: "
            + trigger.getRepeatCount()
            + " times, every "
            + trigger.getRepeatInterval() / 1000
            + " seconds");

    log.info("------- Waiting 15 seconds... --------------");
    try {
      Thread.sleep(15L * 1000L);
    } catch (Exception e) {
    }

    // jobs can be re-scheduled...
    // job 7 will run immediately and repeat 10 times for every second
    log.info("------- Rescheduling... --------------------");
    trigger =
        new SimpleTrigger("trigger7", "group1", "job7", "group1", new Date(), null, 10, 1000L);
    ft = sched.rescheduleJob("trigger7", "group1", trigger);
    log.info("job7 rescheduled to run at: " + ft);

    log.info("------- Waiting five minutes... ------------");
    try {
      Thread.sleep(300L * 1000L);
    } catch (Exception e) {
    }

    log.info("------- Shutting Down ---------------------");
    sched.shutdown(true);
    log.info("------- Shutdown Complete -----------------");

    // display some stats about the schedule that just ran
    SchedulerMetaData metaData = sched.getMetaData();
    log.info("Executed " + metaData.getNumberOfJobsExecuted() + " jobs.");
  }
  public static org.quartz.Trigger convertTriggerToNativeObject(Trigger spagobiTrigger) {
    org.quartz.Trigger quartzTrigger;

    logger.debug("IN");

    quartzTrigger = null;
    try {
      Assert.assertNotNull(spagobiTrigger, "Input parameter [spagobiTrigger] csannot be null");

      if (spagobiTrigger.isRunImmediately()) {

        quartzTrigger = TriggerUtils.makeImmediateTrigger(spagobiTrigger.getName(), 0, 10000);
        quartzTrigger.setJobName(spagobiTrigger.getJob().getName());
        quartzTrigger.setJobGroup(spagobiTrigger.getJob().getGroupName());
        JobDataMap jobDataMap =
            convertParametersToNativeObject(spagobiTrigger.getJob().getParameters());
        quartzTrigger.setJobDataMap(jobDataMap);

      } else {

        if (spagobiTrigger.isSimpleTrigger()) {
          quartzTrigger = new org.quartz.SimpleTrigger();
        } else {
          org.quartz.CronTrigger quartzCronTrigger = new org.quartz.CronTrigger();
          String quartzCronExpression =
              convertCronExpressionToNativeObject(
                  spagobiTrigger.getChronExpression(), spagobiTrigger.getStartTime());
          quartzCronTrigger.setCronExpression(quartzCronExpression);
          quartzTrigger = quartzCronTrigger;
          // dirty trick
          spagobiTrigger
              .getJob()
              .addParameter(
                  SPAGOBI_CRON_EXPRESSION, spagobiTrigger.getChronExpression().getExpression());
        }

        quartzTrigger.setName(spagobiTrigger.getName());
        quartzTrigger.setDescription(spagobiTrigger.getDescription());
        if (spagobiTrigger.getGroupName() == null) {
          quartzTrigger.setGroup(Scheduler.DEFAULT_GROUP);
        } else {
          quartzTrigger.setGroup(spagobiTrigger.getGroupName());
        }

        quartzTrigger.setStartTime(spagobiTrigger.getStartTime());
        if (spagobiTrigger.getEndTime() != null) {
          quartzTrigger.setEndTime(spagobiTrigger.getEndTime());
        }
        quartzTrigger.setJobName(spagobiTrigger.getJob().getName());
        if (spagobiTrigger.getJob().getGroupName() == null) {
          quartzTrigger.setJobGroup(Scheduler.DEFAULT_GROUP);
        } else {
          quartzTrigger.setJobGroup(spagobiTrigger.getJob().getGroupName());
        }

        quartzTrigger.setVolatility(spagobiTrigger.getJob().isVolatile());

        JobDataMap jobDataMap =
            convertParametersToNativeObject(spagobiTrigger.getJob().getParameters());
        quartzTrigger.setJobDataMap(jobDataMap);
      }
    } catch (Throwable t) {
      throw new SpagoBIRuntimeException(
          "An unexpected error occured while converting Trigger to native object", t);
    } finally {
      logger.debug("OUT");
    }

    return quartzTrigger;
  }