@Test public final void testProcessInitial() { try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); DefaultSiteCommand comm = new DefaultSiteCommand(); comm.setEditMode(true); comm.setSiteOid(null); BindException aError = new BindException(new DefaultSiteCommand(), null); ModelAndView mav = testInstance.processInitial(request, response, comm, aError); assertTrue(mav != null); assertTrue(mav.getViewName().equals("site")); SiteEditorContext context = testInstance.getEditorContext(request); assertSame(context.getSite().getOwningAgency(), AuthUtil.getRemoteUserObject().getAgency()); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }
@Override protected ModelAndView processInitial(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { if (log.isDebugEnabled()) { log.debug("Processing intial in SiteController."); } DefaultSiteCommand command = (DefaultSiteCommand) comm; Site theSite = null; log.debug("------------------------hasSubmitParameter:-------------------------------"); log.debug(WebUtils.hasSubmitParameter(req, "_tab_edit")); if(command.getSiteOid() != null) { theSite = siteManager.getSite(command.getSiteOid(), true); List<Annotation> annotations = siteManager.getAnnotations(theSite); theSite.setAnnotations(annotations); for(Permission p: theSite.getPermissions()) { p.setAnnotations(siteManager.getAnnotations(p)); } } else { theSite = new Site(); theSite.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); } if (command.isCopyMode()) { if (log.isDebugEnabled()) { log.debug("About to process copy of site " + command.getSiteOid()); } Site siteCopy = new Site(); siteCopy.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); siteCopy.setDescription(theSite.getDescription()); siteCopy.setLibraryOrderNo(theSite.getLibraryOrderNo()); siteCopy.setPublished(theSite.isPublished()); HashSet<AuthorisingAgent> agents = new HashSet<AuthorisingAgent>(); agents.addAll(theSite.getAuthorisingAgents()); siteCopy.setAuthorisingAgents(agents); UrlPattern p = null; HashSet<UrlPattern> patterns = new HashSet<UrlPattern>(); for (UrlPattern pattern : theSite.getUrlPatterns()) { p = businessObjectFactory.newUrlPattern(siteCopy); p.setPattern(pattern.getPattern()); patterns.add(p); } siteCopy.setUrlPatterns(patterns); theSite = siteCopy; command.setCopyMode(false); command.setEditMode(true); } SiteEditorContext ctx = new SiteEditorContext(theSite); if (command.isEditMode()) { String[] privs = {Privilege.CREATE_SITE, Privilege.MODIFY_PERMISSION, Privilege.CONFIRM_PERMISSION}; if (authorityManager.hasAtLeastOnePrivilege(privs)) { ctx.setEditMode(command.isEditMode()); } else { ctx.setEditAnnotations(true); } } ctx.setCanEdit(false); if (!command.isEditMode() && command.getSiteOid() != null) { if (theSite.getOwningAgency() != null && authorityManager.hasPrivilege(theSite, Privilege.MODIFY_SITE)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); TabbedModelAndView tmav = new TabbedModelAndView(); tmav.addObject("command", SiteCommand.buildFromModel(ctx.getSite())); tmav.addObject("editMode", ctx.isEditMode()); tmav.getTabStatus().setCurrentTab(getTabConfig().getTabByID("GENERAL")); return tmav; }
SiteController extends TabbedController { @Override protected ModelAndView processInitial(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { if (log.isDebugEnabled()) { log.debug("Processing intial in SiteController."); } DefaultSiteCommand command = (DefaultSiteCommand) comm; Site theSite = null; log.debug("------------------------hasSubmitParameter:-------------------------------"); log.debug(WebUtils.hasSubmitParameter(req, "_tab_edit")); if(command.getSiteOid() != null) { theSite = siteManager.getSite(command.getSiteOid(), true); List<Annotation> annotations = siteManager.getAnnotations(theSite); theSite.setAnnotations(annotations); for(Permission p: theSite.getPermissions()) { p.setAnnotations(siteManager.getAnnotations(p)); } } else { theSite = new Site(); theSite.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); } if (command.isCopyMode()) { if (log.isDebugEnabled()) { log.debug("About to process copy of site " + command.getSiteOid()); } Site siteCopy = new Site(); siteCopy.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); siteCopy.setDescription(theSite.getDescription()); siteCopy.setLibraryOrderNo(theSite.getLibraryOrderNo()); siteCopy.setPublished(theSite.isPublished()); HashSet<AuthorisingAgent> agents = new HashSet<AuthorisingAgent>(); agents.addAll(theSite.getAuthorisingAgents()); siteCopy.setAuthorisingAgents(agents); UrlPattern p = null; HashSet<UrlPattern> patterns = new HashSet<UrlPattern>(); for (UrlPattern pattern : theSite.getUrlPatterns()) { p = businessObjectFactory.newUrlPattern(siteCopy); p.setPattern(pattern.getPattern()); patterns.add(p); } siteCopy.setUrlPatterns(patterns); theSite = siteCopy; command.setCopyMode(false); command.setEditMode(true); } SiteEditorContext ctx = new SiteEditorContext(theSite); if (command.isEditMode()) { String[] privs = {Privilege.CREATE_SITE, Privilege.MODIFY_PERMISSION, Privilege.CONFIRM_PERMISSION}; if (authorityManager.hasAtLeastOnePrivilege(privs)) { ctx.setEditMode(command.isEditMode()); } else { ctx.setEditAnnotations(true); } } ctx.setCanEdit(false); if (!command.isEditMode() && command.getSiteOid() != null) { if (theSite.getOwningAgency() != null && authorityManager.hasPrivilege(theSite, Privilege.MODIFY_SITE)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); TabbedModelAndView tmav = new TabbedModelAndView(); tmav.addObject("command", SiteCommand.buildFromModel(ctx.getSite())); tmav.addObject("editMode", ctx.isEditMode()); tmav.getTabStatus().setCurrentTab(getTabConfig().getTabByID("GENERAL")); return tmav; } }
SiteController extends TabbedController { @Override protected ModelAndView processInitial(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { if (log.isDebugEnabled()) { log.debug("Processing intial in SiteController."); } DefaultSiteCommand command = (DefaultSiteCommand) comm; Site theSite = null; log.debug("------------------------hasSubmitParameter:-------------------------------"); log.debug(WebUtils.hasSubmitParameter(req, "_tab_edit")); if(command.getSiteOid() != null) { theSite = siteManager.getSite(command.getSiteOid(), true); List<Annotation> annotations = siteManager.getAnnotations(theSite); theSite.setAnnotations(annotations); for(Permission p: theSite.getPermissions()) { p.setAnnotations(siteManager.getAnnotations(p)); } } else { theSite = new Site(); theSite.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); } if (command.isCopyMode()) { if (log.isDebugEnabled()) { log.debug("About to process copy of site " + command.getSiteOid()); } Site siteCopy = new Site(); siteCopy.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); siteCopy.setDescription(theSite.getDescription()); siteCopy.setLibraryOrderNo(theSite.getLibraryOrderNo()); siteCopy.setPublished(theSite.isPublished()); HashSet<AuthorisingAgent> agents = new HashSet<AuthorisingAgent>(); agents.addAll(theSite.getAuthorisingAgents()); siteCopy.setAuthorisingAgents(agents); UrlPattern p = null; HashSet<UrlPattern> patterns = new HashSet<UrlPattern>(); for (UrlPattern pattern : theSite.getUrlPatterns()) { p = businessObjectFactory.newUrlPattern(siteCopy); p.setPattern(pattern.getPattern()); patterns.add(p); } siteCopy.setUrlPatterns(patterns); theSite = siteCopy; command.setCopyMode(false); command.setEditMode(true); } SiteEditorContext ctx = new SiteEditorContext(theSite); if (command.isEditMode()) { String[] privs = {Privilege.CREATE_SITE, Privilege.MODIFY_PERMISSION, Privilege.CONFIRM_PERMISSION}; if (authorityManager.hasAtLeastOnePrivilege(privs)) { ctx.setEditMode(command.isEditMode()); } else { ctx.setEditAnnotations(true); } } ctx.setCanEdit(false); if (!command.isEditMode() && command.getSiteOid() != null) { if (theSite.getOwningAgency() != null && authorityManager.hasPrivilege(theSite, Privilege.MODIFY_SITE)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); TabbedModelAndView tmav = new TabbedModelAndView(); tmav.addObject("command", SiteCommand.buildFromModel(ctx.getSite())); tmav.addObject("editMode", ctx.isEditMode()); tmav.getTabStatus().setCurrentTab(getTabConfig().getTabByID("GENERAL")); return tmav; } SiteController(); }
SiteController extends TabbedController { @Override protected ModelAndView processInitial(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { if (log.isDebugEnabled()) { log.debug("Processing intial in SiteController."); } DefaultSiteCommand command = (DefaultSiteCommand) comm; Site theSite = null; log.debug("------------------------hasSubmitParameter:-------------------------------"); log.debug(WebUtils.hasSubmitParameter(req, "_tab_edit")); if(command.getSiteOid() != null) { theSite = siteManager.getSite(command.getSiteOid(), true); List<Annotation> annotations = siteManager.getAnnotations(theSite); theSite.setAnnotations(annotations); for(Permission p: theSite.getPermissions()) { p.setAnnotations(siteManager.getAnnotations(p)); } } else { theSite = new Site(); theSite.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); } if (command.isCopyMode()) { if (log.isDebugEnabled()) { log.debug("About to process copy of site " + command.getSiteOid()); } Site siteCopy = new Site(); siteCopy.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); siteCopy.setDescription(theSite.getDescription()); siteCopy.setLibraryOrderNo(theSite.getLibraryOrderNo()); siteCopy.setPublished(theSite.isPublished()); HashSet<AuthorisingAgent> agents = new HashSet<AuthorisingAgent>(); agents.addAll(theSite.getAuthorisingAgents()); siteCopy.setAuthorisingAgents(agents); UrlPattern p = null; HashSet<UrlPattern> patterns = new HashSet<UrlPattern>(); for (UrlPattern pattern : theSite.getUrlPatterns()) { p = businessObjectFactory.newUrlPattern(siteCopy); p.setPattern(pattern.getPattern()); patterns.add(p); } siteCopy.setUrlPatterns(patterns); theSite = siteCopy; command.setCopyMode(false); command.setEditMode(true); } SiteEditorContext ctx = new SiteEditorContext(theSite); if (command.isEditMode()) { String[] privs = {Privilege.CREATE_SITE, Privilege.MODIFY_PERMISSION, Privilege.CONFIRM_PERMISSION}; if (authorityManager.hasAtLeastOnePrivilege(privs)) { ctx.setEditMode(command.isEditMode()); } else { ctx.setEditAnnotations(true); } } ctx.setCanEdit(false); if (!command.isEditMode() && command.getSiteOid() != null) { if (theSite.getOwningAgency() != null && authorityManager.hasPrivilege(theSite, Privilege.MODIFY_SITE)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); TabbedModelAndView tmav = new TabbedModelAndView(); tmav.addObject("command", SiteCommand.buildFromModel(ctx.getSite())); tmav.addObject("editMode", ctx.isEditMode()); tmav.getTabStatus().setCurrentTab(getTabConfig().getTabByID("GENERAL")); return tmav; } SiteController(); void bindEditorContext(HttpServletRequest req, SiteEditorContext context); void unbindEditorContext(HttpServletRequest req); SiteEditorContext getEditorContext(HttpServletRequest req); void checkSave(HttpServletRequest req, BindException errors); ModelAndView getErrorsView(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors); void setSiteManager(SiteManager siteManager); void setAuthorityManager(AuthorityManager authorityManager); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setMessageSource(MessageSource messageSource); void setSiteSearchController(SiteSearchController siteSearchController); }
SiteController extends TabbedController { @Override protected ModelAndView processInitial(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) { if (log.isDebugEnabled()) { log.debug("Processing intial in SiteController."); } DefaultSiteCommand command = (DefaultSiteCommand) comm; Site theSite = null; log.debug("------------------------hasSubmitParameter:-------------------------------"); log.debug(WebUtils.hasSubmitParameter(req, "_tab_edit")); if(command.getSiteOid() != null) { theSite = siteManager.getSite(command.getSiteOid(), true); List<Annotation> annotations = siteManager.getAnnotations(theSite); theSite.setAnnotations(annotations); for(Permission p: theSite.getPermissions()) { p.setAnnotations(siteManager.getAnnotations(p)); } } else { theSite = new Site(); theSite.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); } if (command.isCopyMode()) { if (log.isDebugEnabled()) { log.debug("About to process copy of site " + command.getSiteOid()); } Site siteCopy = new Site(); siteCopy.setOwningAgency(AuthUtil.getRemoteUserObject().getAgency()); siteCopy.setDescription(theSite.getDescription()); siteCopy.setLibraryOrderNo(theSite.getLibraryOrderNo()); siteCopy.setPublished(theSite.isPublished()); HashSet<AuthorisingAgent> agents = new HashSet<AuthorisingAgent>(); agents.addAll(theSite.getAuthorisingAgents()); siteCopy.setAuthorisingAgents(agents); UrlPattern p = null; HashSet<UrlPattern> patterns = new HashSet<UrlPattern>(); for (UrlPattern pattern : theSite.getUrlPatterns()) { p = businessObjectFactory.newUrlPattern(siteCopy); p.setPattern(pattern.getPattern()); patterns.add(p); } siteCopy.setUrlPatterns(patterns); theSite = siteCopy; command.setCopyMode(false); command.setEditMode(true); } SiteEditorContext ctx = new SiteEditorContext(theSite); if (command.isEditMode()) { String[] privs = {Privilege.CREATE_SITE, Privilege.MODIFY_PERMISSION, Privilege.CONFIRM_PERMISSION}; if (authorityManager.hasAtLeastOnePrivilege(privs)) { ctx.setEditMode(command.isEditMode()); } else { ctx.setEditAnnotations(true); } } ctx.setCanEdit(false); if (!command.isEditMode() && command.getSiteOid() != null) { if (theSite.getOwningAgency() != null && authorityManager.hasPrivilege(theSite, Privilege.MODIFY_SITE)) { ctx.setCanEdit(true); } } bindEditorContext(req, ctx); TabbedModelAndView tmav = new TabbedModelAndView(); tmav.addObject("command", SiteCommand.buildFromModel(ctx.getSite())); tmav.addObject("editMode", ctx.isEditMode()); tmav.getTabStatus().setCurrentTab(getTabConfig().getTabByID("GENERAL")); return tmav; } SiteController(); void bindEditorContext(HttpServletRequest req, SiteEditorContext context); void unbindEditorContext(HttpServletRequest req); SiteEditorContext getEditorContext(HttpServletRequest req); void checkSave(HttpServletRequest req, BindException errors); ModelAndView getErrorsView(Tab currentTab, HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors); void setSiteManager(SiteManager siteManager); void setAuthorityManager(AuthorityManager authorityManager); void setBusinessObjectFactory(BusinessObjectFactory businessObjectFactory); void setMessageSource(MessageSource messageSource); void setSiteSearchController(SiteSearchController siteSearchController); static final String EDITOR_CONTEXT; }