public SimpleTrigger generateImportTrigger( FormProcessor fp, UserAccountBean userAccount, StudyBean study, Date startDateTime, String locale) { String jobName = fp.getString(JOB_NAME); String email = fp.getString(EMAIL); String jobDesc = fp.getString(JOB_DESC); String directory = fp.getString(DIRECTORY); // what kinds of periods do we have? hourly, daily, weekly? long interval = 0; int hours = fp.getInt("hours"); int minutes = fp.getInt("minutes"); if (hours > 0) { long hoursInt = hours * 3600000; interval = interval + hoursInt; } if (minutes > 0) { long minutesInt = minutes * 60000; interval = interval + minutesInt; } SimpleTrigger trigger = new SimpleTrigger(jobName, IMPORT_TRIGGER, 64000, interval); trigger.setDescription(jobDesc); // set just the start date trigger.setStartTime(startDateTime); trigger.setName(jobName); // + datasetId); trigger.setGroup(IMPORT_TRIGGER); // + datasetId); trigger.setMisfireInstruction( SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT); // set job data map JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put(EMAIL, email); jobDataMap.put(USER_ID, userAccount.getId()); jobDataMap.put(STUDY_NAME, study.getName()); jobDataMap.put(STUDY_OID, study.getOid()); jobDataMap.put(DIRECTORY, directory); jobDataMap.put(ExampleSpringJob.LOCALE, locale); jobDataMap.put("hours", hours); jobDataMap.put("minutes", minutes); trigger.setJobDataMap(jobDataMap); trigger.setVolatility(false); 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; }
public SimpleTrigger generateTrigger( FormProcessor fp, UserAccountBean userAccount, StudyBean study, String locale) { Date startDateTime = fp.getDateTime(DATE_START_JOB); // check the above? int datasetId = fp.getInt(DATASET_ID); String period = fp.getString(PERIOD); String email = fp.getString(EMAIL); String jobName = fp.getString(JOB_NAME); String jobDesc = fp.getString(JOB_DESC); String spss = fp.getString(SPSS); String tab = fp.getString(TAB); String cdisc = fp.getString(CDISC); String cdisc12 = fp.getString(ExampleSpringJob.CDISC12); String cdisc13 = fp.getString(ExampleSpringJob.CDISC13); String cdisc13oc = fp.getString(ExampleSpringJob.CDISC13OC); BigInteger interval = new BigInteger("0"); if ("monthly".equalsIgnoreCase(period)) { interval = new BigInteger("2419200000"); // how many // milliseconds in // a month? should // be 24192000000 } else if ("weekly".equalsIgnoreCase(period)) { interval = new BigInteger("604800000"); // how many // milliseconds in // a week? should // be 6048000000 } else { // daily interval = new BigInteger("86400000"); // how many // milliseconds in a // day? } // set up and commit job here SimpleTrigger trigger = new SimpleTrigger(jobName, "DEFAULT", 64000, interval.longValue()); // set the job detail name, // based on our choice of format above // what if there is more than one detail? // what is the number of times it should repeat? // arbitrary large number, 64K should be enough :) trigger.setDescription(jobDesc); // set just the start date trigger.setStartTime(startDateTime); trigger.setName(jobName); // + datasetId); trigger.setGroup("DEFAULT"); // + datasetId); trigger.setMisfireInstruction( SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT); // set job data map JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put(DATASET_ID, datasetId); jobDataMap.put(PERIOD, period); jobDataMap.put(EMAIL, email); jobDataMap.put(TAB, tab); jobDataMap.put(CDISC, cdisc); jobDataMap.put(ExampleSpringJob.CDISC12, cdisc12); jobDataMap.put(ExampleSpringJob.LOCALE, locale); // System.out.println("found 1.2: " + // jobDataMap.get(ExampleSpringJob.CDISC12)); jobDataMap.put(ExampleSpringJob.CDISC13, cdisc13); // System.out.println("found 1.3: " + // jobDataMap.get(ExampleSpringJob.CDISC13)); jobDataMap.put(ExampleSpringJob.CDISC13OC, cdisc13oc); // System.out.println("found 1.3oc: " + // jobDataMap.get(ExampleSpringJob.CDISC13OC)); jobDataMap.put(SPSS, spss); jobDataMap.put(USER_ID, userAccount.getId()); // StudyDAO studyDAO = new StudyDAO(); jobDataMap.put(STUDY_ID, study.getId()); jobDataMap.put(STUDY_NAME, study.getName()); jobDataMap.put(STUDY_OID, study.getOid()); trigger.setJobDataMap(jobDataMap); // trigger.setRepeatInterval(interval.longValue()); // System.out.println("default for volatile: " + trigger.isVolatile()); trigger.setVolatility(false); return trigger; }