Logger.debug(this, "Inside EditSchedulerAction cmd=" + cmd);
//get the user
User user = _getUser(req);
CronScheduledTask scheduler = null;
try {
Logger.debug(this, "I'm retrieving the schedule");
scheduler = _retrieveScheduledJob(req, res, config, form);
}
catch (Exception ae) {
_handleException(ae, req);
}
/*
* if we are saving,
*
*/
if ((cmd != null) && cmd.equals(Constants.ADD)) {
try {
SchedulerForm schedulerForm = (SchedulerForm) form;
boolean hasErrors = false;
if (!UtilMethods.isSet(schedulerForm.getJobName())) {
SessionMessages.add(req, "error", "message.Scheduler.invalidJobName");
hasErrors = true;
} else if (!schedulerForm.isEditMode() && (scheduler != null)) {
SessionMessages.add(req, "error", "message.Scheduler.jobAlreadyExists");
hasErrors = true;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date endDate = null;
if (schedulerForm.isHaveEndDate()) {
try {
endDate = sdf.parse(schedulerForm.getEndDate());
} catch (Exception e) {
}
}
if ((endDate != null) && !hasErrors) {
Date startDate = null;
if (schedulerForm.isHaveStartDate()) {
try {
startDate = sdf.parse(schedulerForm.getStartDate());
} catch (Exception e) {
}
}
if (startDate == null) {
SessionMessages.add(req, "error", "message.Scheduler.startDateNeeded");
hasErrors = true;
} else if (endDate.before(startDate)) {
SessionMessages.add(req, "error", "message.Scheduler.endDateBeforeStartDate");
hasErrors = true;
} else if (endDate.before(new Date())) {
SessionMessages.add(req, "error", "message.Scheduler.endDateBeforeActualDate");
hasErrors = true;
}
}
if ((!UtilMethods.isSet(schedulerForm.getJavaClass())) && !hasErrors) {
SessionMessages.add(req, "error", "message.Scheduler.invalidJavaClass");
hasErrors = true;
}
if (Validator.validate(req,form,mapping) && !hasErrors) {
Logger.debug(this, "I'm Saving the scheduler");
if (_saveScheduler(req, res, config, form, user)) {
scheduler = _retrieveScheduledJob(req, res, config, form);
if (scheduler != null) {
_populateForm(form, scheduler);
schedulerForm.setMap(scheduler.getProperties());
}
String redirect = req.getParameter("referrer");
if (UtilMethods.isSet(redirect)) {
redirect = URLDecoder.decode(redirect, "UTF-8") + "&group=" + scheduler.getJobGroup();
_sendToReferral(req, res, redirect);
return;
}
} else {
SessionMessages.clear(req);
SessionMessages.add(req, "error", "message.Scheduler.invalidJobSettings");
schedulerForm.setMap(getSchedulerProperties(req, schedulerForm));
loadEveryDayForm(form, req);
}
} else {
schedulerForm.setMap(getSchedulerProperties(req, schedulerForm));
loadEveryDayForm(form, req);
}
}
catch (Exception ae) {
if (!ae.getMessage().equals(WebKeys.UNIQUE_SCHEDULER_EXCEPTION)){
SessionMessages.add(req, "error", ae.getMessage());
_handleException(ae, req);
}
}
}
/*
* deleting the list, return to listing page
*
*/
else if ((cmd != null) && cmd.equals(Constants.DELETE)) {
try {
Logger.debug(this, "I'm deleting the scheduler");
_deleteScheduler(req, res, config, form,user);
}
catch (Exception ae) {
try{
_forceTodDeleteScheduler(req, res, config, form,user);
}catch(Exception a){
_handleException(a, req);
}
}
String redirect = req.getParameter("referrer");
if (UtilMethods.isSet(redirect)) {
redirect = URLDecoder.decode(redirect, "UTF-8");
_sendToReferral(req, res, redirect);
return;
}
}
/*
* Copy copy props from the db to the form bean
*
*/
if ((cmd != null) && cmd.equals(Constants.EDIT)) {
if (scheduler != null) {
_populateForm(form, scheduler);
SchedulerForm schedulerForm = (SchedulerForm) form;
schedulerForm.setMap(scheduler.getProperties());
schedulerForm.setEditMode(true);
if (!UtilMethods.isSet(scheduler.getCronExpression())) {
SessionMessages.add(req, "message", "message.Scheduler.jobExpired");
}
}
}