@Test void postHandlePluginidWithQueryString() { PluginInterceptor molgenisPluginInterceptor = new PluginInterceptor(menuReaderService, permissionService); String uri = PluginController.PLUGIN_URI_PREFIX + "plugin_id_test"; HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class); when(mockHttpServletRequest.getQueryString()).thenReturn("entity=entityTypeId"); HandlerMethod handlerMethod = mock(HandlerMethod.class); when(handlerMethod.getBean()).thenReturn(createMolgenisPluginController(uri)); ModelAndView modelAndView = new ModelAndView(); molgenisPluginInterceptor.postHandle(mockHttpServletRequest, null, handlerMethod, modelAndView); assertEquals("plugin_id_test", modelAndView.getModel().get(KEY_PLUGIN_ID)); assertNotNull(modelAndView.getModel().get(PluginAttributes.KEY_MENU)); assertEquals(false, modelAndView.getModel().get(KEY_AUTHENTICATED)); assertEquals( "plugin_id_test?entity=entityTypeId", modelAndView.getModel().get(KEY_PLUGIN_ID_WITH_QUERY_STRING)); }
@Transactional(readOnly = true) @Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { PluginController molgenisPlugin = validateHandler(handler); String pluginId = molgenisPlugin.getId(); if (!modelAndView.getModel().containsKey(PluginAttributes.KEY_PLUGIN_ID)) { modelAndView.addObject(PluginAttributes.KEY_PLUGIN_ID, pluginId); } Entity pluginSettings = molgenisPlugin.getPluginSettings(); boolean pluginSettingsCanWrite; if (pluginSettings != null) { String pluginSettingsEntityName = pluginSettings.getEntityType().getId(); pluginSettingsCanWrite = permissionService.hasPermission( new EntityTypeIdentity(pluginSettingsEntityName), EntityTypePermission.UPDATE_DATA); modelAndView.addObject(PluginAttributes.KEY_PLUGIN_SETTINGS, pluginSettings); } else { pluginSettingsCanWrite = false; } modelAndView.addObject( PluginAttributes.KEY_PLUGIN_SHOW_SETTINGS_COG, pluginSettingsCanWrite); modelAndView.addObject(PluginAttributes.KEY_MENU, menuReaderService.getMenu().orElse(null)); modelAndView.addObject( PluginAttributes.KEY_AUTHENTICATED, SecurityUtils.currentUserIsAuthenticated()); modelAndView.addObject( PluginAttributes.KEY_PLUGIN_ID_WITH_QUERY_STRING, getPluginIdWithQueryString(request, pluginId)); } } }
PluginInterceptor extends HandlerInterceptorAdapter { @Transactional(readOnly = true) @Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { PluginController molgenisPlugin = validateHandler(handler); String pluginId = molgenisPlugin.getId(); if (!modelAndView.getModel().containsKey(PluginAttributes.KEY_PLUGIN_ID)) { modelAndView.addObject(PluginAttributes.KEY_PLUGIN_ID, pluginId); } Entity pluginSettings = molgenisPlugin.getPluginSettings(); boolean pluginSettingsCanWrite; if (pluginSettings != null) { String pluginSettingsEntityName = pluginSettings.getEntityType().getId(); pluginSettingsCanWrite = permissionService.hasPermission( new EntityTypeIdentity(pluginSettingsEntityName), EntityTypePermission.UPDATE_DATA); modelAndView.addObject(PluginAttributes.KEY_PLUGIN_SETTINGS, pluginSettings); } else { pluginSettingsCanWrite = false; } modelAndView.addObject( PluginAttributes.KEY_PLUGIN_SHOW_SETTINGS_COG, pluginSettingsCanWrite); modelAndView.addObject(PluginAttributes.KEY_MENU, menuReaderService.getMenu().orElse(null)); modelAndView.addObject( PluginAttributes.KEY_AUTHENTICATED, SecurityUtils.currentUserIsAuthenticated()); modelAndView.addObject( PluginAttributes.KEY_PLUGIN_ID_WITH_QUERY_STRING, getPluginIdWithQueryString(request, pluginId)); } } } }
PluginInterceptor extends HandlerInterceptorAdapter { @Transactional(readOnly = true) @Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { PluginController molgenisPlugin = validateHandler(handler); String pluginId = molgenisPlugin.getId(); if (!modelAndView.getModel().containsKey(PluginAttributes.KEY_PLUGIN_ID)) { modelAndView.addObject(PluginAttributes.KEY_PLUGIN_ID, pluginId); } Entity pluginSettings = molgenisPlugin.getPluginSettings(); boolean pluginSettingsCanWrite; if (pluginSettings != null) { String pluginSettingsEntityName = pluginSettings.getEntityType().getId(); pluginSettingsCanWrite = permissionService.hasPermission( new EntityTypeIdentity(pluginSettingsEntityName), EntityTypePermission.UPDATE_DATA); modelAndView.addObject(PluginAttributes.KEY_PLUGIN_SETTINGS, pluginSettings); } else { pluginSettingsCanWrite = false; } modelAndView.addObject( PluginAttributes.KEY_PLUGIN_SHOW_SETTINGS_COG, pluginSettingsCanWrite); modelAndView.addObject(PluginAttributes.KEY_MENU, menuReaderService.getMenu().orElse(null)); modelAndView.addObject( PluginAttributes.KEY_AUTHENTICATED, SecurityUtils.currentUserIsAuthenticated()); modelAndView.addObject( PluginAttributes.KEY_PLUGIN_ID_WITH_QUERY_STRING, getPluginIdWithQueryString(request, pluginId)); } } } PluginInterceptor(
      MenuReaderService menuReaderService, UserPermissionEvaluator permissionService); }
PluginInterceptor extends HandlerInterceptorAdapter { @Transactional(readOnly = true) @Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { PluginController molgenisPlugin = validateHandler(handler); String pluginId = molgenisPlugin.getId(); if (!modelAndView.getModel().containsKey(PluginAttributes.KEY_PLUGIN_ID)) { modelAndView.addObject(PluginAttributes.KEY_PLUGIN_ID, pluginId); } Entity pluginSettings = molgenisPlugin.getPluginSettings(); boolean pluginSettingsCanWrite; if (pluginSettings != null) { String pluginSettingsEntityName = pluginSettings.getEntityType().getId(); pluginSettingsCanWrite = permissionService.hasPermission( new EntityTypeIdentity(pluginSettingsEntityName), EntityTypePermission.UPDATE_DATA); modelAndView.addObject(PluginAttributes.KEY_PLUGIN_SETTINGS, pluginSettings); } else { pluginSettingsCanWrite = false; } modelAndView.addObject( PluginAttributes.KEY_PLUGIN_SHOW_SETTINGS_COG, pluginSettingsCanWrite); modelAndView.addObject(PluginAttributes.KEY_MENU, menuReaderService.getMenu().orElse(null)); modelAndView.addObject( PluginAttributes.KEY_AUTHENTICATED, SecurityUtils.currentUserIsAuthenticated()); modelAndView.addObject( PluginAttributes.KEY_PLUGIN_ID_WITH_QUERY_STRING, getPluginIdWithQueryString(request, pluginId)); } } } PluginInterceptor(
      MenuReaderService menuReaderService, UserPermissionEvaluator permissionService); @Override boolean preHandle(
      HttpServletRequest request, HttpServletResponse response, Object handler); @Transactional(readOnly = true) @Override void postHandle(
      HttpServletRequest request,
      HttpServletResponse response,
      Object handler,
      ModelAndView modelAndView); PluginController validateHandler(Object handler); }
PluginInterceptor extends HandlerInterceptorAdapter { @Transactional(readOnly = true) @Override public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (modelAndView != null) { String viewName = modelAndView.getViewName(); if (viewName == null || !viewName.startsWith("forward:")) { PluginController molgenisPlugin = validateHandler(handler); String pluginId = molgenisPlugin.getId(); if (!modelAndView.getModel().containsKey(PluginAttributes.KEY_PLUGIN_ID)) { modelAndView.addObject(PluginAttributes.KEY_PLUGIN_ID, pluginId); } Entity pluginSettings = molgenisPlugin.getPluginSettings(); boolean pluginSettingsCanWrite; if (pluginSettings != null) { String pluginSettingsEntityName = pluginSettings.getEntityType().getId(); pluginSettingsCanWrite = permissionService.hasPermission( new EntityTypeIdentity(pluginSettingsEntityName), EntityTypePermission.UPDATE_DATA); modelAndView.addObject(PluginAttributes.KEY_PLUGIN_SETTINGS, pluginSettings); } else { pluginSettingsCanWrite = false; } modelAndView.addObject( PluginAttributes.KEY_PLUGIN_SHOW_SETTINGS_COG, pluginSettingsCanWrite); modelAndView.addObject(PluginAttributes.KEY_MENU, menuReaderService.getMenu().orElse(null)); modelAndView.addObject( PluginAttributes.KEY_AUTHENTICATED, SecurityUtils.currentUserIsAuthenticated()); modelAndView.addObject( PluginAttributes.KEY_PLUGIN_ID_WITH_QUERY_STRING, getPluginIdWithQueryString(request, pluginId)); } } } PluginInterceptor(
      MenuReaderService menuReaderService, UserPermissionEvaluator permissionService); @Override boolean preHandle(
      HttpServletRequest request, HttpServletResponse response, Object handler); @Transactional(readOnly = true) @Override void postHandle(
      HttpServletRequest request,
      HttpServletResponse response,
      Object handler,
      ModelAndView modelAndView); PluginController validateHandler(Object handler);  }