SitePermissionHandler extends AbstractSiteHandler { public ModelAndView processOther(TabbedController tc, Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { SiteEditorContext ctx = getEditorContext(req); if(WebUtils.hasSubmitParameter(req, "_new")) { Permission newPermission = businessObjectFactory.newPermission(ctx.getSite()); ctx.putObject(newPermission); SitePermissionCommand command = SitePermissionCommand.buildFromModel(newPermission); ModelAndView mav = new ModelAndView(); mav.addObject(Constants.GBL_CMD_DATA, command); mav.addObject("urls", ctx.getSortedUrlPatterns()); mav.addObject("agents", ctx.getSortedAuthAgents()); mav.addObject("accessStatusList", accessStatusList); mav.addObject("permissionEditMode", true); mav.addObject("permission", newPermission); mav.setViewName(Constants.VIEW_SITE_PERMISSIONS); return mav; } if(WebUtils.hasSubmitParameter(req, "_edit_permission")) { SitePermissionCommand command = (SitePermissionCommand) comm; Permission permission = (Permission) ctx.getObject(Permission.class, command.getSelectedPermission()); permission.sortAnnotations(); List<Annotation> oldPermissionAnnotations = new ArrayList<Annotation>(); req.getSession().setAttribute("oldPermissionAnnotations", oldPermissionAnnotations); SitePermissionCommand c2 = SitePermissionCommand.buildFromModel(permission); ModelAndView mav = new ModelAndView(); mav.addObject(Constants.GBL_CMD_DATA, c2); mav.addObject("urls", ctx.getSortedUrlPatterns()); mav.addObject("agents", ctx.getSortedAuthAgents()); mav.addObject("accessStatusList", accessStatusList); mav.addObject("permissionEditMode", true); mav.addObject("permission", permission); mav.setViewName(Constants.VIEW_SITE_PERMISSIONS); return mav; } if(WebUtils.hasSubmitParameter(req, "_view_permission")) { SitePermissionCommand command = (SitePermissionCommand) comm; Permission permission = (Permission) ctx.getObject(Permission.class, command.getSelectedPermission()); permission.sortAnnotations(); List<Annotation> oldPermissionAnnotations = new ArrayList<Annotation>(); if(permission.getAnnotations() != null) { oldPermissionAnnotations.addAll(permission.getAnnotations()); } req.getSession().setAttribute("oldPermissionAnnotations", oldPermissionAnnotations); SitePermissionCommand c2 = SitePermissionCommand.buildFromModel(permission); ModelAndView mav = new ModelAndView(); mav.addObject(Constants.GBL_CMD_DATA, c2); mav.addObject("urls", ctx.getSortedUrlPatterns()); mav.addObject("agents", ctx.getSortedAuthAgents()); mav.addObject("accessStatusList", accessStatusList); mav.addObject("permissionEditMode", false); mav.addObject("permission", permission); mav.setViewName(Constants.VIEW_SITE_PERMISSIONS); return mav; } if(WebUtils.hasSubmitParameter(req, "_remove_permission")) { SitePermissionCommand command = (SitePermissionCommand) comm; Site site = ctx.getSite(); Permission permission = (Permission) ctx.getObject(Permission.class, command.getSelectedPermission()); for(UrlPattern u: permission.getUrls()) { u.getPermissions().remove(permission); } permission.getUrls().clear(); if(!permission.isNew() && siteManager.countLinkedSeeds(permission.getOid()) > 0) { errors.reject("site.permission.delete.linked_seeds", "There are still seeds linked to this permission. Either unlink the seeds, or transfer them to another permission."); } if(errors.hasErrors()) { TabbedModelAndView tmav = preProcessNextTab(tc, currentTab, req, res, comm, errors); tmav.getTabStatus().setCurrentTab(currentTab); tmav.addObject(Constants.GBL_ERRORS, errors); return tmav; } else { site.removePermission(permission); TabbedModelAndView tmav = preProcessNextTab(tc, currentTab, req, res, comm, errors); tmav.getTabStatus().setCurrentTab(currentTab); return tmav; } } return null; }  @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 setSiteManager(SiteManager siteManager); void setAccessStatusList(List<String> accessStatusList); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory);  }
@Test public final void testProcessOther() { try { MockHttpServletRequest aReq = new MockHttpServletRequest(); SiteManager siteManager = new MockSiteManagerImpl(testFile); testInstance.setSiteManager(siteManager); testInstance.setBusinessObjectFactory(new BusinessObjectFactory()); Site site = siteManager.getSite(9000L, true); Set<Permission> permissions = site.getPermissions(); List<Annotation> list = createAnnotationList(); assertFalse(checkSortedList(list)); Iterator<Permission> it = permissions.iterator(); while(it.hasNext()) { Permission p = it.next(); if(p.getOid() == 7000L) { p.setAnnotations(list); } } SiteEditorContext ctx = new SiteEditorContext(site); aReq.getSession().setAttribute(SiteController.EDITOR_CONTEXT, ctx); HttpServletResponse aResp = new MockHttpServletResponse(); SitePermissionCommand aCmd = new SitePermissionCommand(); TabbedController tc = new SiteController(); TabConfig tabConfig = new TabConfig(); tabConfig.setViewName("site"); List<Tab> tabs = getTabList(siteManager); tabConfig.setTabs(tabs); tc.setTabConfig(tabConfig); Tab currentTab = tabs.get(1); BindException aErrors = new BindException(aCmd, aCmd.getActionCmd()); aReq.addParameter("_new", ""); ModelAndView mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors); assertNotNull(mav); aReq.removeParameter("_new"); aReq.addParameter("_edit_permission", ""); aCmd.setSelectedPermission("7000"); mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors); assertNotNull(mav); Permission permission = (Permission) ctx.getObject(Permission.class, "7000"); assertNotNull(permission); assertEquals(permission.getAnnotations().size(), ANNOTATIONS.length); assertTrue(checkSortedList(permission.getAnnotations())); } catch(Exception e) { fail(e.getMessage()); } }