@Test void testForwardDefaultMenuPlugin() { when(menuReaderService.getMenu()).thenReturn(Optional.of(menu)); when(dataService.findOneById(PLUGIN, "home", Plugin.class)).thenReturn(plugin); when(plugin.getPath()).thenReturn("home"); assertEquals( "forward:/plugin/home", molgenisMenuController.forwardDefaultMenuDefaultPlugin(model)); verify(model).addAttribute("menu_id", "main"); verify(model).addAttribute("context_url", "/menu/main/home"); verify(model).addAttribute("molgenis_version", "1.2.3"); verify(model).addAttribute("molgenis_build_date", "2019-01-02 01:11 UTC"); verifyNoMoreInteractions(model); }
@Transactional(readOnly = true) @SuppressWarnings("java:S3752") @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}) public String forwardDefaultMenuDefaultPlugin(Model model) { Menu menu = menuReaderService .getMenu() .orElseThrow(() -> new RuntimeException("main menu does not exist")); String menuId = menu.getId(); model.addAttribute(KEY_MENU_ID, menuId); Optional<MenuItem> optionalActiveItem = menu.firstItem(); if (!optionalActiveItem.isPresent()) { LOG.warn("main menu does not contain any (accessible) items"); return "forward:/login"; } MenuItem activeItem = optionalActiveItem.get(); String pluginId = activeItem.getId(); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(activeItem.getId(), null, getQueryString(activeItem)); }
MolgenisMenuController { @Transactional(readOnly = true) @SuppressWarnings("java:S3752") @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}) public String forwardDefaultMenuDefaultPlugin(Model model) { Menu menu = menuReaderService .getMenu() .orElseThrow(() -> new RuntimeException("main menu does not exist")); String menuId = menu.getId(); model.addAttribute(KEY_MENU_ID, menuId); Optional<MenuItem> optionalActiveItem = menu.firstItem(); if (!optionalActiveItem.isPresent()) { LOG.warn("main menu does not contain any (accessible) items"); return "forward:/login"; } MenuItem activeItem = optionalActiveItem.get(); String pluginId = activeItem.getId(); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(activeItem.getId(), null, getQueryString(activeItem)); } }
MolgenisMenuController { @Transactional(readOnly = true) @SuppressWarnings("java:S3752") @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}) public String forwardDefaultMenuDefaultPlugin(Model model) { Menu menu = menuReaderService .getMenu() .orElseThrow(() -> new RuntimeException("main menu does not exist")); String menuId = menu.getId(); model.addAttribute(KEY_MENU_ID, menuId); Optional<MenuItem> optionalActiveItem = menu.firstItem(); if (!optionalActiveItem.isPresent()) { LOG.warn("main menu does not contain any (accessible) items"); return "forward:/login"; } MenuItem activeItem = optionalActiveItem.get(); String pluginId = activeItem.getId(); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(activeItem.getId(), null, getQueryString(activeItem)); } MolgenisMenuController(
      MenuReaderService menuReaderService,
      @Value("${molgenis.version}") String molgenisVersion,
      @Value("${molgenis.build.date}") String molgenisBuildData,
      DataService dataService); }
MolgenisMenuController { @Transactional(readOnly = true) @SuppressWarnings("java:S3752") @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}) public String forwardDefaultMenuDefaultPlugin(Model model) { Menu menu = menuReaderService .getMenu() .orElseThrow(() -> new RuntimeException("main menu does not exist")); String menuId = menu.getId(); model.addAttribute(KEY_MENU_ID, menuId); Optional<MenuItem> optionalActiveItem = menu.firstItem(); if (!optionalActiveItem.isPresent()) { LOG.warn("main menu does not contain any (accessible) items"); return "forward:/login"; } MenuItem activeItem = optionalActiveItem.get(); String pluginId = activeItem.getId(); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(activeItem.getId(), null, getQueryString(activeItem)); } 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 { @Transactional(readOnly = true) @SuppressWarnings("java:S3752") @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}) public String forwardDefaultMenuDefaultPlugin(Model model) { Menu menu = menuReaderService .getMenu() .orElseThrow(() -> new RuntimeException("main menu does not exist")); String menuId = menu.getId(); model.addAttribute(KEY_MENU_ID, menuId); Optional<MenuItem> optionalActiveItem = menu.firstItem(); if (!optionalActiveItem.isPresent()) { LOG.warn("main menu does not contain any (accessible) items"); return "forward:/login"; } MenuItem activeItem = optionalActiveItem.get(); String pluginId = activeItem.getId(); String contextUri = URI + '/' + menuId + '/' + pluginId; addModelAttributes(model, contextUri); return getForwardPluginUri(activeItem.getId(), null, getQueryString(activeItem)); } 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; }