use of org.molgenis.web.UiMenuItem in project molgenis by molgenis.
the class MenuItem method create.
public static MenuItem create(UiMenuItem item) {
List<MenuItem> items = null;
if (item.getType() == UiMenuItemType.MENU) {
UiMenu menu = (UiMenu) item;
items = menu.getItems().stream().map(menuItem -> MenuItem.create(menuItem)).collect(Collectors.toList());
}
return new AutoValue_MenuItem(item.getId(), item.getName(), item.getUrl(), item.getType(), items);
}
use of org.molgenis.web.UiMenuItem in project molgenis by molgenis.
the class XmlMolgenisUiMenuTest method getItems.
@Test
public void getItems() {
String menuId = "menuId";
MenuType menuType = new MenuType();
menuType.setName(menuId);
PluginType plugin1Type = new PluginType();
plugin1Type.setId("plugin1");
plugin1Type.setName("plugin1");
PluginType plugin2Type = new PluginType();
plugin2Type.setId("plugin2");
plugin2Type.setName("plugin2");
PluginType plugin3Type = new PluginType();
plugin3Type.setId("plugin3");
plugin3Type.setName("plugin3");
MenuType menu1Type = new MenuType();
menu1Type.setName("menu1");
menu1Type.getMenuOrPlugin().add(plugin3Type);
menuType.getMenuOrPlugin().add(plugin1Type);
menuType.getMenuOrPlugin().add(plugin2Type);
menuType.getMenuOrPlugin().add(menu1Type);
when(permissionService.hasPermission(new PluginIdentity("plugin1"), PluginPermission.READ)).thenReturn(true);
when(permissionService.hasPermission(new PluginIdentity("plugin2"), PluginPermission.READ)).thenReturn(false);
when(permissionService.hasPermission(new PluginIdentity("plugin3"), PluginPermission.READ)).thenReturn(true);
XmlMolgenisUiMenu xmlMolgenisUiMenu = new XmlMolgenisUiMenu(menuType, permissionService);
Iterator<UiMenuItem> it = xmlMolgenisUiMenu.getItems().iterator();
assertTrue(it.hasNext());
assertEquals(it.next().getName(), "plugin1");
assertEquals(it.next().getName(), "menu1");
}
use of org.molgenis.web.UiMenuItem in project molgenis by molgenis.
the class MenuUtilsTest method getMenuJson.
@Test
public void getMenuJson() {
UiMenu menu = mock(UiMenu.class);
when(menu.getType()).thenReturn(UiMenuItemType.MENU);
when(menu.getId()).thenReturn("main");
when(menu.getName()).thenReturn("mainmenu");
when(menu.getUrl()).thenReturn("/main");
UiMenu submenu = mock(UiMenu.class);
when(submenu.getType()).thenReturn(UiMenuItemType.MENU);
when(submenu.getId()).thenReturn("sub");
when(submenu.getName()).thenReturn("submenu");
when(submenu.getUrl()).thenReturn("/sub");
UiMenuItem menuItem1 = mock(UiMenuItem.class);
when(menuItem1.getType()).thenReturn(UiMenuItemType.PLUGIN);
when(menuItem1.getId()).thenReturn("item1");
when(menuItem1.getName()).thenReturn("label1");
when(menuItem1.getUrl()).thenReturn("/item1?test=test");
UiMenuItem menuItem2 = mock(UiMenuItem.class);
when(menuItem2.getType()).thenReturn(UiMenuItemType.PLUGIN);
when(menuItem2.getId()).thenReturn("item2");
when(menuItem2.getName()).thenReturn("label2");
when(menuItem2.getUrl()).thenReturn("/item2");
UiMenuItem submenuItem1 = mock(UiMenuItem.class);
when(submenuItem1.getType()).thenReturn(UiMenuItemType.PLUGIN);
when(submenuItem1.getId()).thenReturn("subitem1");
when(submenuItem1.getName()).thenReturn("sub2");
when(submenuItem1.getUrl()).thenReturn("/sub2");
UiMenuItem menuItem3 = mock(UiMenuItem.class);
when(menuItem3.getType()).thenReturn(UiMenuItemType.PLUGIN);
when(menuItem3.getId()).thenReturn("item3");
when(menuItem3.getName()).thenReturn("label3");
when(menuItem3.getUrl()).thenReturn("/item3");
when(menu.getItems()).thenReturn(Arrays.asList(menuItem1, menuItem2, submenu, menuItem3));
when(submenu.getItems()).thenReturn(Arrays.asList(submenuItem1));
String expected = "{\"id\":\"main\",\"label\":\"mainmenu\",\"href\":\"/main\",\"type\":\"MENU\",\"items\":[{\"id\":\"item1\",\"label\":\"label1\",\"href\":\"/item1?test\\u003dtest\",\"type\":\"PLUGIN\"},{\"id\":\"item2\",\"label\":\"label2\",\"href\":\"/item2\",\"type\":\"PLUGIN\"},{\"id\":\"sub\",\"label\":\"submenu\",\"href\":\"/sub\",\"type\":\"MENU\",\"items\":[{\"id\":\"subitem1\",\"label\":\"sub2\",\"href\":\"/sub2\",\"type\":\"PLUGIN\"}]},{\"id\":\"item3\",\"label\":\"label3\",\"href\":\"/item3\",\"type\":\"PLUGIN\"}]}";
assertEquals(MenuUtils.getMenuJson(menu), expected);
}
use of org.molgenis.web.UiMenuItem in project molgenis by molgenis.
the class MolgenisMenuController method forwardDefaultMenuDefaultPlugin.
@RequestMapping
public String forwardDefaultMenuDefaultPlugin(Model model) {
UiMenu menu = molgenisUi.getMenu();
if (menu == null)
throw new RuntimeException("main menu does not exist");
String menuId = menu.getId();
model.addAttribute(KEY_MENU_ID, menuId);
UiMenuItem activeItem = menu.getActiveItem();
if (activeItem == null) {
LOG.warn("main menu does not contain any (accessible) items");
return "forward:/login";
}
String pluginId = activeItem.getId();
String contextUri = URI + '/' + menuId + '/' + pluginId;
model.addAttribute(KEY_CONTEXT_URL, contextUri);
model.addAttribute(KEY_MOLGENIS_VERSION, molgenisVersion);
model.addAttribute(KEY_MOLGENIS_BUILD_DATE, molgenisBuildData);
return getForwardPluginUri(activeItem.getUrl(), null);
}
use of org.molgenis.web.UiMenuItem in project molgenis by molgenis.
the class MolgenisMenuController method forwardMenuDefaultPlugin.
@RequestMapping("/{menuId}")
public String forwardMenuDefaultPlugin(@Valid @NotNull @PathVariable String menuId, Model model) {
UiMenu menu = molgenisUi.getMenu(menuId);
if (menu == null)
throw new RuntimeException("menu with id [" + menuId + "] does not exist");
model.addAttribute(KEY_MENU_ID, menuId);
UiMenuItem activeItem = menu.getActiveItem();
String pluginId = activeItem != null ? activeItem.getId() : VoidPluginController.ID;
String contextUri = URI + '/' + menuId + '/' + pluginId;
model.addAttribute(KEY_CONTEXT_URL, contextUri);
model.addAttribute(KEY_MOLGENIS_VERSION, molgenisVersion);
model.addAttribute(KEY_MOLGENIS_BUILD_DATE, molgenisBuildData);
return getForwardPluginUri(pluginId, null);
}
Aggregations