@Test void testForwardSpecificMenuNoPermissionsForwardsToVoidController() { Optional<Menu> admin = menu.filter(it -> ImmutableList.of("admin", "").contains(it.getId())).map(Menu.class::cast); when(menuReaderService.getMenu()).thenReturn(admin); when(dataService.findOneById(PLUGIN, "void", Plugin.class)).thenReturn(plugin); when(plugin.getPath()).thenReturn("void"); assertEquals( "forward:/plugin/void", molgenisMenuController.forwardMenuDefaultPlugin("admin", model)); verify(model).addAttribute("menu_id", "admin"); verify(model).addAttribute("context_url", "/menu/admin/void"); verify(model).addAttribute("molgenis_version", "1.2.3"); verify(model).addAttribute("molgenis_build_date", "2019-01-02 01:11 UTC"); verifyNoMoreInteractions(model); }
@SuppressWarnings("java:S3752") @RequestMapping( method = {RequestMethod.GET, RequestMethod.POST}, value = "/{menuId}") public String forwardMenuDefaultPlugin(@Valid @NotNull @PathVariable String menuId, Model model) { Menu filteredMenu = menuReaderService .getMenu() .flatMap(menu -> menu.findMenu(menuId)) .orElseThrow( () -> new RuntimeException("menu with id [" + menuId + "] does not exist")); model.addAttribute(KEY_MENU_ID, menuId); String pluginId = filteredMenu.firstItem().map(MenuItem::getId).orElse(VoidPluginController.ID); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(pluginId); }
MolgenisMenuController { @SuppressWarnings("java:S3752") @RequestMapping( method = {RequestMethod.GET, RequestMethod.POST}, value = "/{menuId}") public String forwardMenuDefaultPlugin(@Valid @NotNull @PathVariable String menuId, Model model) { Menu filteredMenu = menuReaderService .getMenu() .flatMap(menu -> menu.findMenu(menuId)) .orElseThrow( () -> new RuntimeException("menu with id [" + menuId + "] does not exist")); model.addAttribute(KEY_MENU_ID, menuId); String pluginId = filteredMenu.firstItem().map(MenuItem::getId).orElse(VoidPluginController.ID); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(pluginId); } }
MolgenisMenuController { @SuppressWarnings("java:S3752") @RequestMapping( method = {RequestMethod.GET, RequestMethod.POST}, value = "/{menuId}") public String forwardMenuDefaultPlugin(@Valid @NotNull @PathVariable String menuId, Model model) { Menu filteredMenu = menuReaderService .getMenu() .flatMap(menu -> menu.findMenu(menuId)) .orElseThrow( () -> new RuntimeException("menu with id [" + menuId + "] does not exist")); model.addAttribute(KEY_MENU_ID, menuId); String pluginId = filteredMenu.firstItem().map(MenuItem::getId).orElse(VoidPluginController.ID); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(pluginId); } MolgenisMenuController(
      MenuReaderService menuReaderService,
      @Value("${molgenis.version}") String molgenisVersion,
      @Value("${molgenis.build.date}") String molgenisBuildData,
      DataService dataService); }
MolgenisMenuController { @SuppressWarnings("java:S3752") @RequestMapping( method = {RequestMethod.GET, RequestMethod.POST}, value = "/{menuId}") public String forwardMenuDefaultPlugin(@Valid @NotNull @PathVariable String menuId, Model model) { Menu filteredMenu = menuReaderService .getMenu() .flatMap(menu -> menu.findMenu(menuId)) .orElseThrow( () -> new RuntimeException("menu with id [" + menuId + "] does not exist")); model.addAttribute(KEY_MENU_ID, menuId); String pluginId = filteredMenu.firstItem().map(MenuItem::getId).orElse(VoidPluginController.ID); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(pluginId); } MolgenisMenuController(
      MenuReaderService menuReaderService,
      @Value("${molgenis.version}") String molgenisVersion,
      @Value("${molgenis.build.date}") String molgenisBuildData,
      DataService dataService); @Transactional(readOnly = true) @SuppressWarnings("java:S3752") // multiple methods required @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}) String forwardDefaultMenuDefaultPlugin(Model model); @SuppressWarnings("java:S3752") // multiple methods required @RequestMapping( method = {RequestMethod.GET, RequestMethod.POST}, value = "/{menuId}") String forwardMenuDefaultPlugin(@Valid @NotNull @PathVariable String menuId, Model model); @SuppressWarnings("java:S3752") // multiple methods required @RequestMapping("/{menuId}/{pluginId}/**") String forwardMenuPlugin(
      HttpServletRequest request,
      @Valid @NotNull @PathVariable String menuId,
      @Valid @NotNull @PathVariable String pluginId,
      Model model); }
MolgenisMenuController { @SuppressWarnings("java:S3752") @RequestMapping( method = {RequestMethod.GET, RequestMethod.POST}, value = "/{menuId}") public String forwardMenuDefaultPlugin(@Valid @NotNull @PathVariable String menuId, Model model) { Menu filteredMenu = menuReaderService .getMenu() .flatMap(menu -> menu.findMenu(menuId)) .orElseThrow( () -> new RuntimeException("menu with id [" + menuId + "] does not exist")); model.addAttribute(KEY_MENU_ID, menuId); String pluginId = filteredMenu.firstItem().map(MenuItem::getId).orElse(VoidPluginController.ID); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(pluginId); } MolgenisMenuController(
      MenuReaderService menuReaderService,
      @Value("${molgenis.version}") String molgenisVersion,
      @Value("${molgenis.build.date}") String molgenisBuildData,
      DataService dataService); @Transactional(readOnly = true) @SuppressWarnings("java:S3752") // multiple methods required @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}) String forwardDefaultMenuDefaultPlugin(Model model); @SuppressWarnings("java:S3752") // multiple methods required @RequestMapping( method = {RequestMethod.GET, RequestMethod.POST}, value = "/{menuId}") String forwardMenuDefaultPlugin(@Valid @NotNull @PathVariable String menuId, Model model); @SuppressWarnings("java:S3752") // multiple methods required @RequestMapping("/{menuId}/{pluginId}/**") String forwardMenuPlugin(
      HttpServletRequest request,
      @Valid @NotNull @PathVariable String menuId,
      @Valid @NotNull @PathVariable String pluginId,
      Model model); static final String URI; }