public HashMap validateForm( FormProcessor fp, HttpServletRequest request, String[] triggerNames, String properName) { Validator v = new Validator(request); v.addValidation(JOB_NAME, Validator.NO_BLANKS); // need to be unique too v.addValidation(JOB_DESC, Validator.NO_BLANKS); v.addValidation(EMAIL, Validator.IS_A_EMAIL); v.addValidation(PERIOD, Validator.NO_BLANKS); v.addValidation(DATE_START_JOB + "Date", Validator.IS_A_DATE); // v.addValidation(DATE_START_JOB + "Date", new Date(), Validator.DATE_IS_AFTER_OR_EQUAL); // TODO job names will have to be unique, tbh 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); String spss = fp.getString(SPSS); Date jobDate = fp.getDateTime(DATE_START_JOB); HashMap errors = v.validate(); if ((tab == "") && (cdisc == "") && (spss == "") && (cdisc12 == "") && (cdisc13 == "") && (cdisc13oc == "")) { // throw an error here, at least one should work // errors.put(TAB, "Error Message - Pick one of the below"); v.addError(errors, TAB, "Please pick at least one of the below."); } for (String triggerName : triggerNames) { if (triggerName.equals(fp.getString(JOB_NAME)) && (!triggerName.equals(properName))) { v.addError( errors, JOB_NAME, "A job with that name already exists. Please pick another name."); } } if (jobDate.before(new Date())) { v.addError( errors, DATE_START_JOB + "Date", "This date needs to be later than the present time."); } return errors; }
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; }