TargetSchedulesHandler extends TabHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { TargetSchedulesCommand command = (TargetSchedulesCommand) comm; AbstractTargetEditorContext ctx = getEditorContext(req); if(authorityManager.hasPrivilege(ctx.getAbstractTarget(), privilegeString)) { if(WebUtils.hasSubmitParameter(req, "_new")) { Tab tab = tc.getTabConfig().getTabByID("SCHEDULES").createSubTab("../target-schedule-edit.jsp"); TabbedModelAndView tmav = tc.new TabbedModelAndView(); tmav.getTabStatus().setCurrentTab(tab); tmav.getTabStatus().setEnabled(false); TargetSchedulesCommand newCommand = new TargetSchedulesCommand(); tmav.addObject(Constants.GBL_CMD_DATA, newCommand); tmav.addObject("patterns", patternFactory.getPatterns()); return tmav; } if(WebUtils.hasSubmitParameter(req, "_edit")) { Tab tab = tc.getTabConfig().getTabByID("SCHEDULES").createSubTab("../target-schedule-edit.jsp"); TabbedModelAndView tmav = tc.new TabbedModelAndView(); tmav.getTabStatus().setCurrentTab(tab); tmav.getTabStatus().setEnabled(false); Schedule aSchedule = (Schedule) ctx.getObject(Schedule.class, command.getSelectedItem()); TargetSchedulesCommand newCommand = TargetSchedulesCommand.buildFromModel(aSchedule); tmav.addObject(Constants.GBL_CMD_DATA, newCommand); tmav.addObject("patterns", patternFactory.getPatterns()); return tmav; } if(WebUtils.hasSubmitParameter(req, "_save")) { if(errors.hasErrors()) { TabbedModelAndView tmav = getEditTabModel(tc); tmav.addObject(Constants.GBL_CMD_DATA, errors.getTarget()); tmav.addObject(Constants.GBL_ERRORS, errors); tmav.addObject("patterns", patternFactory.getPatterns()); return tmav; } else { if( !Utils.isEmpty(command.getSelectedItem())) { Schedule aSchedule = (Schedule) ctx.getObject(Schedule.class, command.getSelectedItem()); ctx.getAbstractTarget().removeSchedule(aSchedule); } Schedule schedule = null; if(command.getScheduleType() == Schedule.CUSTOM_SCHEDULE) { schedule = businessObjectFactory.newSchedule(ctx.getAbstractTarget()); schedule.setStartDate(command.getStartDate()); schedule.setEndDate(command.getEndDate()); schedule.setScheduleType(command.getScheduleType()); schedule.setCronPattern(command.getCronExpression()); } else { SchedulePattern pattern = patternFactory.getPattern(command.getScheduleType()); schedule = pattern.makeSchedule(businessObjectFactory, ctx.getAbstractTarget(), command.getStartDate(), command.getEndDate()); } ctx.putObject(schedule); ctx.getAbstractTarget().addSchedule(schedule); TabbedModelAndView tmav = preProcessNextTab(tc, currentTab, req, res, comm, errors); tmav.getTabStatus().setCurrentTab(currentTab); return tmav; } } if(WebUtils.hasSubmitParameter(req, "_cancel")) { TabbedModelAndView tmav = preProcessNextTab(tc, currentTab, req, res, comm, errors); tmav.getTabStatus().setCurrentTab(currentTab); return tmav; } if(WebUtils.hasSubmitParameter(req, "_remove")) { Schedule scheduleToRemove = (Schedule) ctx.getObject(Schedule.class, command.getSelectedItem()); ctx.getAbstractTarget().removeSchedule(scheduleToRemove); TabbedModelAndView tmav = preProcessNextTab(tc, currentTab, req, res, comm, errors); tmav.getTabStatus().setCurrentTab(currentTab); return tmav; } if(WebUtils.hasSubmitParameter(req, "_test")) { if(errors.hasErrors()) { TabbedModelAndView tmav = getEditTabModel(tc); tmav.addObject("patterns", patternFactory.getPatterns()); tmav.addObject(Constants.GBL_CMD_DATA, errors.getTarget()); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } else { List<Date> testResults = new LinkedList<Date>(); TabbedModelAndView tmav = getEditTabModel(tc); tmav.addObject("patterns", patternFactory.getPatterns()); tmav.addObject(Constants.GBL_CMD_DATA, command); tmav.addObject("testResults", testResults); try { CronExpression expr = new CronExpression(command.getCronExpression()); Date d = DateUtils.latestDate(new Date(), command.getStartDate()); Date nextDate = null; for(int i = 0; i<10; i++) { nextDate = expr.getNextValidTimeAfter(d); if(nextDate == null || command.getEndDate() != null && nextDate.after(command.getEndDate())) { break; } testResults.add(nextDate); d = nextDate; } } catch(ParseException ex) { ex.printStackTrace(); } return tmav; } } } TabbedModelAndView tmav = preProcessNextTab(tc, currentTab, req, res, comm, errors); tmav.getTabStatus().setCurrentTab(currentTab); return tmav; }  AbstractTargetEditorContext getEditorContext(HttpServletRequest req); void setPatternFactory(SchedulePatternFactory patternFactory); @Override void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); void processTab(TabbedController tc, Tab currentTab,
			HttpServletRequest req, HttpServletResponse res, Object comm,
			BindException errors); TabbedModelAndView preProcessNextTab(TabbedController tc,
			Tab nextTabID, HttpServletRequest req, HttpServletResponse res,
			Object comm, BindException errors); ModelAndView processOther(TabbedController tc, Tab currentTab,
			HttpServletRequest req, HttpServletResponse res, Object comm,
			BindException errors); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setAuthorityManager(AuthorityManager authorityManager); void setTargetManager(TargetManager targetManager); String getContextSessionKey(); void setContextSessionKey(String contextSessionKey); String getPrivilegeString(); void setPrivilegeString(String privilegeString); void setEditControllerUrl(String editControllerUrl);  }
@Test public final void testProcessOther() { HttpServletRequest aReq = new MockHttpServletRequest(); TargetManager targetManager = new MockTargetManager(testFile); testInstance.setTargetManager(targetManager); testInstance.setAuthorityManager(new AuthorityManagerImpl()); testInstance.setPatternFactory(new SpringSchedulePatternFactory()); Target target = targetManager.load(4000L); TargetEditorContext targetEditorContext = new TargetEditorContext(targetManager,target,true); aReq.getSession().setAttribute(TabbedTargetController.EDITOR_CONTEXT, targetEditorContext); HttpServletResponse aResp = new MockHttpServletResponse(); TargetSchedulesCommand aCmd = new TargetSchedulesCommand(); TabbedController tc = new TabbedTargetController(); TabConfig tabConfig = new TabConfig(); tabConfig.setViewName("target"); List<Tab> tabs = getTabList(targetManager); tabConfig.setTabs(tabs); tc.setTabConfig(tabConfig); tc.setDefaultCommandClass(org.webcurator.ui.target.command.TargetDefaultCommand.class); Tab currentTab = tabs.get(1); aCmd.setHarvestNow(true); BindException aErrors = new BindException(aCmd, "TargetSchedulesCommand"); testInstance.setContextSessionKey(TabbedTargetController.EDITOR_CONTEXT); ModelAndView mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors); assertTrue(mav != null); }