@Override
  public Trigger getTrigger() throws Exception {
    if ((repeatInterval <= 0) && (repeatCount != 0)) {
      logger.error(
          "Job "
              + getBeanName()
              + " - repeatInterval/repeatIntervalMinutes cannot be 0 (or -ve) unless repeatCount is also 0");
      return null;
    }

    SimpleTrigger trigger = new SimpleTrigger(getBeanName(), Scheduler.DEFAULT_GROUP);
    trigger.setStartTime(new Date(System.currentTimeMillis() + this.startDelay));
    trigger.setRepeatCount(repeatCount);
    trigger.setRepeatInterval(repeatInterval);
    return trigger;
  }
  @RequestMapping("/cancelScheduledJob")
  public String cancelScheduledJob(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("theJobName") String theJobName,
      @RequestParam("theJobGroupName") String theJobGroupName,
      @RequestParam("theTriggerName") String triggerName,
      @RequestParam("theTriggerGroupName") String triggerGroupName,
      @RequestParam("redirection") String redirection,
      ModelMap model)
      throws SchedulerException {

    scheduler.getJobDetail(theJobName, theJobGroupName);
    logger.debug("About to pause the job-->" + theJobName + "Job Group Name -->" + theJobGroupName);

    SimpleTrigger oldTrigger = (SimpleTrigger) scheduler.getTrigger(triggerName, triggerGroupName);
    if (oldTrigger != null) {
      Date startTime =
          new Date(oldTrigger.getStartTime().getTime() + oldTrigger.getRepeatInterval());
      if (triggerGroupName.equals(ExtractController.TRIGGER_GROUP_NAME)) {
        interruptQuartzJob(scheduler, theJobName, theJobGroupName);
      }

      scheduler.pauseJob(theJobName, theJobGroupName);

      SimpleTrigger newTrigger = new SimpleTrigger(triggerName, triggerGroupName);
      newTrigger.setJobName(theJobName);
      newTrigger.setJobGroup(theJobGroupName);
      newTrigger.setJobDataMap(oldTrigger.getJobDataMap());
      newTrigger.setVolatility(false);
      newTrigger.setRepeatCount(oldTrigger.getRepeatCount());
      newTrigger.setRepeatInterval(oldTrigger.getRepeatInterval());
      newTrigger.setMisfireInstruction(
          SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT);
      newTrigger.setStartTime(startTime);
      newTrigger.setRepeatInterval(oldTrigger.getRepeatInterval());

      scheduler.unscheduleJob(
          triggerName,
          triggerGroupName); // these are the jobs which are from extract data and are not not
      // required to be rescheduled.

      ArrayList<String> pageMessages = new ArrayList<String>();

      if (triggerGroupName.equals(ExtractController.TRIGGER_GROUP_NAME)) {
        scheduler.rescheduleJob(triggerName, triggerGroupName, newTrigger);

        pageMessages.add("The Job  " + theJobName + " has been cancelled");
      } else if (triggerGroupName.equals(XsltTriggerService.TRIGGER_GROUP_NAME)) {

        JobDetailBean jobDetailBean = new JobDetailBean();
        jobDetailBean.setGroup(XsltTriggerService.TRIGGER_GROUP_NAME);
        jobDetailBean.setName(newTrigger.getName());
        jobDetailBean.setJobClass(org.akaza.openclinica.job.XsltStatefulJob.class);
        jobDetailBean.setJobDataMap(newTrigger.getJobDataMap());
        jobDetailBean.setDurability(true); // need durability?
        jobDetailBean.setVolatility(false);

        scheduler.deleteJob(theJobName, theJobGroupName);
        scheduler.scheduleJob(jobDetailBean, newTrigger);
        pageMessages.add("The Job " + theJobName + "  has been rescheduled");
      }

      request.setAttribute("pageMessages", pageMessages);

      logger.debug("jobDetails>" + scheduler.getJobDetail(theJobName, theJobGroupName));
    }
    sdvUtil.forwardRequestFromController(request, response, "/pages/" + redirection);
    return null;
  }
  @Deprecated
  public void scheduleLoanArrearsAndPortfolioAtRisk(
      Date initialTime,
      long delay,
      JobRegistry jobRegistry,
      final JobRepository jobRepository,
      Map<String, Object> jobData,
      ResourcelessTransactionManager transactionManager)
      throws TaskSystemException {
    final String jobName = "LoanArrearsAndPortfolioAtRiskTask";
    try {
      final TaskletStep step1 = new TaskletStep();
      step1.setName("LoanArrearsAndPortfolioAtRiskTask-step-1");
      step1.setTasklet(
          (Tasklet)
              Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + getHelperName("LoanArrearsTask"))
                  .newInstance());
      step1.setJobRepository(jobRepository);
      step1.setTransactionManager(transactionManager);
      step1.afterPropertiesSet();

      final TaskletStep step2 = new TaskletStep();
      step2.setName("LoanArrearsAndPortfolioAtRiskTask-step-2");
      step2.setTasklet(
          (Tasklet)
              Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + getHelperName("PortfolioAtRiskTask"))
                  .newInstance());
      step2.setJobRepository(jobRepository);
      step2.setTransactionManager(transactionManager);
      step2.afterPropertiesSet();
      jobRegistry.register(
          new JobFactory() {

            @Override
            public Job createJob() {
              SimpleJob job = new SimpleJob(jobName + "Job");
              job.setJobRepository(jobRepository);
              job.setRestartable(true);
              job.registerJobExecutionListener(new BatchJobListener());
              job.addStep(step1);
              job.addStep(step2);
              return job;
            }

            @Override
            public String getJobName() {
              return jobName + "Job";
            }
          });
    } catch (Exception e) {
      throw new TaskSystemException(e);
    }

    JobDetailBean jobDetailBean = new JobDetailBean();
    jobDetailBean.setJobDataAsMap(jobData);
    try {
      jobDetailBean.setJobClass(Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + "PortfolioAtRiskTask"));
    } catch (ClassNotFoundException cnfe) {
      throw new TaskSystemException(cnfe);
    }
    jobDetailBean.setName(jobName + "Job");
    jobDetailBean.setGroup(Scheduler.DEFAULT_GROUP);
    jobDetailBean.afterPropertiesSet();

    SimpleTrigger trigger = new SimpleTrigger();
    trigger.setName(jobName + "Job");
    trigger.setGroup(Scheduler.DEFAULT_GROUP);
    trigger.setStartTime(initialTime);
    trigger.setRepeatInterval(delay);
    trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
    try {
      scheduler.scheduleJob(jobDetailBean, trigger);
    } catch (SchedulerException se) {
      throw new TaskSystemException(se);
    }
  }