advancedschedulewizardcontroller.java
来自「Java的框架」· Java 代码 · 共 784 行 · 第 1/3 页
JAVA
784 行
return currentPage;
}
/* (non-Javadoc)
* @see org.springframework.web.servlet.mvc.AbstractWizardFormController#processFinish(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
*/
protected ModelAndView processFinish (HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
AdvancedSchedule advSchedule = (AdvancedSchedule) command;
Locale locale = request.getLocale ();
try{
if (errors.getErrorCount() == 0){
if (StringUtils.equals (request.getParameter ("method"), "add")) {
logger.debug("Save schedule");
logger.info("AdvancedScheduleWizardController processFinish advSchedule.getStartTime()" + advSchedule.getStartTime());
logger.info("AdvancedScheduleWizardController processFinish advSchedule.getEndTime()" + advSchedule.getEndTime());
this.getScheduleManager().saveSchedule(advSchedule);
saveMessage (request, getText (NameConstants.SUCC_SCHEDULE_SAVE,
new Object[]{advSchedule.getName(), advSchedule.getGroup()}, locale));
}else{
logger.debug("Reschedule");
this.getScheduleManager().reSchedule(advSchedule);
saveMessage (request, getText (NameConstants.SUCC_SCHEDULE_UPDATE, new Object[]{advSchedule.getName(), advSchedule.getGroup()}, locale));
}
}
return getRedirectView(request,command);
}catch (Exception e){
logger.warn(e.getMessage());
errors.reject (NameConstants.ERROR_PROCESS_REQUEST,new Object[]{e.getMessage()},
e.getMessage());
return showFormEx (request, response, command, errors);
}
}
/* (non-Javadoc)
* @see org.springframework.web.servlet.mvc.AbstractWizardFormController#processCancel(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)
*/
protected ModelAndView processCancel (HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors) throws Exception{
return getRedirectView(request,command);
}
/**
* Method disallows duplicate form submission. Typically used to prevent
* duplicate insertion of entities into the datastore. Shows a new form with
* an error message.
*/
protected ModelAndView disallowDuplicateFormSubmission (
HttpServletRequest request, HttpServletResponse response)
throws Exception {
BindException errors = getErrorsForNewForm (request);
errors.reject ("errors.duplicateFormSubmission",
"Duplicate form submission");
return showForm (request, response, errors);
}
/**
* Function that sets the request attribute before calling the superclass showForm method.
* @param request HTTP request object
* @param response HTTP response object
* @param command The object bound to this controller
* @param errors Binding exception object
* @return Model and View object
* @throws Exception
*/
private ModelAndView showFormEx(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
setOtherRequestAttributes(request);
return super.showForm(request,response,errors);
}
/**
* Perform general validation
* @param request The HTTP request object
* @param jobName The job name
* @param jobGrp The job group
* @param advSchedule The advance schedule object
* @param errors The binding exception object
* @throws ScheduleException The schedule exception
*/
private void performGeneralValidation(HttpServletRequest request, String jobName,
String jobGrp,AdvancedSchedule advSchedule,
BindException errors)throws ScheduleException{
AdvancedSchedule tempSchedule =
(AdvancedSchedule)getSchedule(
advSchedule.getName(),advSchedule.getGroup(),
jobName,jobGrp);
//Check if an existing advSchedule already exists; if true show duplicate advSchedule error
if (StringUtils.equals (request.getParameter ("method"), "add")) {
if (tempSchedule != null){
errors.reject( NameConstants.ERROR_SCHEDULE_DUPLICATE,
new Object[] {advSchedule.getName(),advSchedule.getGroup()}, "Duplicate schedule");
}
}else{
//Check if an existing advSchedule already exists; if false show advSchedule not found for edit
if (tempSchedule == null){
errors.reject( NameConstants.ERROR_SCHEDULE_NOTFOUND,
new Object[] {advSchedule.getName(),advSchedule.getGroup()}, "Non-existing schedule");
}
}
}
/**
* Bind the schedule time using the date text box control and the time tag control.
* @param request The HTTP request object
* @param advSchedule The advanced schedule object
* @param errors The binding exception object
*/
private void bindScheduleTime(HttpServletRequest request, BindException errors,
AdvancedSchedule advSchedule){
Date startDate = advSchedule.getStartTime();
Date endDate = advSchedule.getEndTime();
//Bind start date time
if (startDate != null){
try {
startDate = DateTimeUtil.getDateTime(request,startDate,NameConstants.STARTTIME);
if (StringUtils.equals (request.getParameter ("method"), "add")) {
//Reject if the startTime is before the current time
if (startDate.before(new Date())) {
errors.reject( NameConstants.ERROR_BINDING_BEFORESTARTTIME, "Binding error.");
}
}
advSchedule.setStartTime(startDate);
logger.debug("StartDate : " + startDate);
} catch (Exception e) {
logger.warn("Error binding schedule start time. " + e.getMessage());
errors.reject( NameConstants.ERROR_BINDING,
new Object[] {NameConstants.STARTTIME}, "Binding error.");
}
}
//Bind end date time
if (endDate != null){
try {
endDate = DateTimeUtil.getDateTime(request,endDate,NameConstants.ENDTIME);
//Editted by Fenglei. "edit" and "add" both need check enddate
//if (StringUtils.equals (request.getParameter ("method"), "add")) {
//Reject if the endTime is before the start time
if (startDate != null) {
if (startDate != null && endDate.before(startDate)) {
errors.reject( NameConstants.ERROR_BINDING_ENDTIMEBEFORESTARTTIME, "Binding error.");
}
}else{
//Reject if the endTime is before the current time
if (endDate.before(new Date())) {
errors.reject( NameConstants.ERROR_BINDING_BEFOREENDTIME, "Binding error.");
}
}
advSchedule.setEndTime(endDate);
logger.debug("EndDate : " + endDate);
} catch (Exception e) {
logger.warn("Error binding schedule end time. " + e.getMessage() );
errors.reject( NameConstants.ERROR_BINDING,
new Object[] {NameConstants.ENDTIME}, "Binding error.");
}
}
//Editted by Jo-V. Should not set cron time expression if there is an error.
if (errors.getErrorCount() == 0){
setCronTimeExpression(request,errors,advSchedule);
}
}
/**
* Bind the advanced schedule properties using the cron expression. These property values
* are important for displaying the value of the cron expression in a user friendly value
* in the web page.
* @param advSchedule The advanced schedule object
* @throws ScheduleException The schedule exception object
*/
private void bindAdvScheduleProperties(AdvancedSchedule advSchedule) throws ScheduleException{
String cronExpr = advSchedule.getCronExpression();
if (cronExpr == null){
throw new NullPointerException("Unable to set schedule pattern. Null cron expression.");
}
if (cronExpr.length() == 0){
throw new ScheduleException("Error setting schedule pattern. Empty cron expression.");
}
String[] cronExprAr = cronExpr.split(" ");
if (cronExprAr.length != 6){
throw new ScheduleException("Error setting schedule pattern. Invalid cron expression.");
}
advSchedule.setSecValue(cronExprAr[0]);
advSchedule.setMinuteValue(cronExprAr[1]);
advSchedule.setHourValue(cronExprAr[2]);
String dayOfMonth = cronExprAr[3];
String month = cronExprAr[4];
String dayOfWeek = cronExprAr[5];
advSchedule.setDayOfMonthValue(dayOfMonth);
advSchedule.setMonthValue(month);
advSchedule.setDayOfWeekValue(dayOfWeek);
if (dayOfMonth.equals("*")){
advSchedule.setPattern(AdvancedSchedule.DAILY);
advSchedule.setPatternChoice(AdvancedSchedule.EVERYDAY);
}else if (dayOfMonth.equals("?")){
if (month.equals("*")){
if (dayOfWeek.equals("?") || dayOfWeek.indexOf("L") > 0 || dayOfWeek.indexOf("#") > 0){
advSchedule.setPattern(AdvancedSchedule.MONTHLY);
advSchedule.setPatternChoice(AdvancedSchedule.MONTHOPT2);
}else{
advSchedule.setPattern(AdvancedSchedule.DAILY);
if (dayOfWeek.equals(AdvancedSchedule.WEEKDAY_VALUE)){
advSchedule.setPatternChoice(AdvancedSchedule.WEEKDAY);
}else if (dayOfWeek.equals(AdvancedSchedule.WEEKEND_VALUE)){
advSchedule.setPatternChoice(AdvancedSchedule.WEEKEND);
}else{
advSchedule.setPatternChoice(AdvancedSchedule.CUSTOMDAY);
}
}
}else{
advSchedule.setPattern(AdvancedSchedule.YEARLY);
advSchedule.setPatternChoice(AdvancedSchedule.YEAROPT2);
}
}else{
if (month.equals("*")){
advSchedule.setPattern(AdvancedSchedule.MONTHLY);
advSchedule.setPatternChoice(AdvancedSchedule.MONTHOPT1);
}else{
advSchedule.setPattern(AdvancedSchedule.YEARLY);
advSchedule.setPatternChoice(AdvancedSchedule.YEAROPT1);
}
}
}
/**
* Gets the a redirect model and view when the cancal button or finish button is clicked.
* @param request The HTTP request object
* @param command The command object
* @return The redirect model and view object
* @throws ScheduleException The schedule exception
*/
private ModelAndView getRedirectView(HttpServletRequest request, Object command) throws ScheduleException{
Schedule schedule = (Schedule)command;
if(StringUtils.equals (request.getParameter ("from"), "job")) {
return new ModelAndView (
new RedirectView(NameConstants.JOB_VIEW_URL + "?jobName=" + schedule.getJob() +
"&groupName=" + schedule.getJobGroup()));
}else if(StringUtils.equals (request.getParameter ("from"), "joblist")) {
return new ModelAndView (new RedirectView(NameConstants.JOBS_VIEW_URL));
}else{
return new ModelAndView (new RedirectView(NameConstants.SCHEDULES_VIEW_URL));
}
}
/**
* Get the job object. This method enable the getJob by handling the
* DataRetrievalFailureException exception.
* @param jobName The name of the job.
* @param jobGrp The name of the job group.
* @return The job object.
*/
private Job getJob(String jobName, String jobGrp){
Job job = null;
try{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?