use of org.molgenis.web.UiMenu in project molgenis by molgenis.
the class MenuItemToMolgenisUiMenuAdapter method getBreadcrumb.
@Override
public List<UiMenu> getBreadcrumb() {
if (menu.equals(rootMenu))
return Collections.singletonList(this);
Map<String, MenuItem> menuParentMap = new HashMap<>();
createMenuParentMapRec(rootMenu, null, menu, menuParentMap);
List<UiMenu> breadcrumb = new ArrayList<>();
MenuItem currentMenu = menu;
while (currentMenu != null) {
breadcrumb.add(new MenuItemToMolgenisUiMenuAdapter(currentMenu, rootMenu));
currentMenu = menuParentMap.get(currentMenu.getId());
}
return Lists.reverse(breadcrumb);
}
use of org.molgenis.web.UiMenu 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.UiMenu in project molgenis by molgenis.
the class MolgenisAccessDecisionVoterTest method setUp.
@BeforeMethod
public void setUp() {
UserPermissionEvaluator permissionService = mock(UserPermissionEvaluator.class);
when(permissionService.hasPermission(new PluginIdentity("plugingranted"), PluginPermission.READ)).thenReturn(true);
when(permissionService.hasPermission(new PluginIdentity("plugindenied"), PluginPermission.READ)).thenReturn(false);
Ui molgenisUi = mock(Ui.class);
UiMenu menu = mock(UiMenu.class);
when(molgenisUi.getMenu("menugranted")).thenReturn(menu);
when(molgenisUi.getMenu("menudenied")).thenReturn(null);
ApplicationContext ctx = mock(ApplicationContext.class);
when(ctx.getBean(UserPermissionEvaluator.class)).thenReturn(permissionService);
when(ctx.getBean(Ui.class)).thenReturn(molgenisUi);
new ApplicationContextProvider().setApplicationContext(ctx);
}
use of org.molgenis.web.UiMenu 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.UiMenu 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);
}
Aggregations