@Test public final void shouldReturnMenu() { Entity homeItem = mockItem(PLUGIN_IDENTIFIER, "homeItem", true, null, PLUGIN_IDENTIFIER, "homeView"); Iterable<Entity> homeItems = Lists.newArrayList(homeItem); Entity homeCategory = mockCategory(PLUGIN_IDENTIFIER, "home", null, homeItems); Entity administrationItem = mockItem(PLUGIN_IDENTIFIER, "administrationItem", true, null, PLUGIN_IDENTIFIER, "administrationView"); Iterable<Entity> administrationItems = Lists.newArrayList(administrationItem); Entity administrationCategory = mockCategory(PLUGIN_IDENTIFIER, "administration", null, administrationItems); Entity cat1item1 = mockItem(PLUGIN_IDENTIFIER, "cat1item1Name", true, ROLE_VISIBLE, PLUGIN_IDENTIFIER, "view1"); Entity cat1item2 = mockItem(PLUGIN_IDENTIFIER, "cat1item2Name", false, ROLE_VISIBLE, PLUGIN_IDENTIFIER, "view2"); Entity cat1item3 = mockItem(PLUGIN_IDENTIFIER, "cat1item3Name", true, ROLE_INVISIBLE, PLUGIN_IDENTIFIER, "view3"); Entity cat1item4 = mockItem(PLUGIN_IDENTIFIER, "cat1item4Name", false, ROLE_INVISIBLE, PLUGIN_IDENTIFIER, "view4"); Entity cat1item5 = mockItem(PLUGIN_IDENTIFIER, "cat1item5Name", false, ROLE_VISIBLE, DISABLED_PLUGIN_IDENTIFIER, "view5"); Entity cat1item6 = mockItem(PLUGIN_IDENTIFIER, "cat1item6Name", false, ROLE_VISIBLE, PLUGIN_IDENTIFIER, "view6"); stubRoleForView(PLUGIN_IDENTIFIER, "view6", false); List<Entity> cat1items = Lists.newArrayList(cat1item1, cat1item2, cat1item3, cat1item4, cat1item5, cat1item6); Entity cat1 = mockCategory(PLUGIN_IDENTIFIER, "cat1", ROLE_VISIBLE, cat1items); Entity cat2item1 = mockItem(PLUGIN_IDENTIFIER, "cat2item1Name", true, ROLE_VISIBLE, PLUGIN_IDENTIFIER, "view7"); Entity cat2item2 = mockItem(PLUGIN_IDENTIFIER, "cat2item2Name", true, ROLE_VISIBLE, PLUGIN_IDENTIFIER, "view8"); List<Entity> cat2items = Lists.newArrayList(cat2item1, cat2item2); Entity cat2 = mockCategory(PLUGIN_IDENTIFIER, "cat2", ROLE_INVISIBLE, cat2items); Entity cat3item1 = mockItem(PLUGIN_IDENTIFIER, "cat3item1Name", true, ROLE_VISIBLE, DISABLED_PLUGIN_IDENTIFIER, "view9"); List<Entity> cat3items = Lists.newArrayList(cat3item1); Entity cat3 = mockCategory(DISABLED_PLUGIN_IDENTIFIER, "cat3", ROLE_VISIBLE, cat3items); stubGetSortedMenuCategories(Lists.newArrayList(homeCategory, cat1, cat2, cat3, administrationCategory)); stubGetSortedMenuCategoryItems(homeCategory, homeItems); stubGetSortedMenuCategoryItems(cat1, cat1items); stubGetSortedMenuCategoryItems(cat2, cat2items); stubGetSortedMenuCategoryItems(cat3, cat3items); stubGetSortedMenuCategoryItems(administrationCategory, administrationItems); MenuDefinition menuDefinition = menuService.getMenu(Locale.ENGLISH); assertCategory(menuDefinition.getHomeCategory(), "home", Lists.newArrayList("homeItem")); Assert.assertEquals(1, menuDefinition.getItems().size()); assertCategory(menuDefinition.getItems().get(0), "cat1", Lists.newArrayList("cat1item1Name")); assertCategory(menuDefinition.getAdministrationCategory(), "administration", Lists.newArrayList("administrationItem")); }
@Override @Transactional(readOnly = true) @Monitorable public MenuDefinition getMenu(final Locale locale) { MenuDefinition menuDefinition = new MenuDefinition(); List<Entity> menuCategories = menuCrudService.getSortedMenuCategories(); for (Entity menuCategory : menuCategories) { String authRoleIdentifier = menuCategory.getStringField(MenuCategoryFields.AUTH_ROLE); if (!currentUserHasPrivilegesOf(authRoleIdentifier)) { continue; } MenuItemsGroup category = buildCategoryWithItems(menuCategory, locale); if (ADMINISTRATION_CATEGORY.equals(category.getName())) { menuDefinition.setAdministrationCategory(category); } else if (HOME_CATEGORY.equals(category.getName())) { menuDefinition.setHomeCategory(category); } else if (!category.getItems().isEmpty()) { menuDefinition.addItem(category); } } return menuDefinition; }
MenuServiceImpl implements InternalMenuService { @Override @Transactional(readOnly = true) @Monitorable public MenuDefinition getMenu(final Locale locale) { MenuDefinition menuDefinition = new MenuDefinition(); List<Entity> menuCategories = menuCrudService.getSortedMenuCategories(); for (Entity menuCategory : menuCategories) { String authRoleIdentifier = menuCategory.getStringField(MenuCategoryFields.AUTH_ROLE); if (!currentUserHasPrivilegesOf(authRoleIdentifier)) { continue; } MenuItemsGroup category = buildCategoryWithItems(menuCategory, locale); if (ADMINISTRATION_CATEGORY.equals(category.getName())) { menuDefinition.setAdministrationCategory(category); } else if (HOME_CATEGORY.equals(category.getName())) { menuDefinition.setHomeCategory(category); } else if (!category.getItems().isEmpty()) { menuDefinition.addItem(category); } } return menuDefinition; } }
MenuServiceImpl implements InternalMenuService { @Override @Transactional(readOnly = true) @Monitorable public MenuDefinition getMenu(final Locale locale) { MenuDefinition menuDefinition = new MenuDefinition(); List<Entity> menuCategories = menuCrudService.getSortedMenuCategories(); for (Entity menuCategory : menuCategories) { String authRoleIdentifier = menuCategory.getStringField(MenuCategoryFields.AUTH_ROLE); if (!currentUserHasPrivilegesOf(authRoleIdentifier)) { continue; } MenuItemsGroup category = buildCategoryWithItems(menuCategory, locale); if (ADMINISTRATION_CATEGORY.equals(category.getName())) { menuDefinition.setAdministrationCategory(category); } else if (HOME_CATEGORY.equals(category.getName())) { menuDefinition.setHomeCategory(category); } else if (!category.getItems().isEmpty()) { menuDefinition.addItem(category); } } return menuDefinition; }  }
MenuServiceImpl implements InternalMenuService { @Override @Transactional(readOnly = true) @Monitorable public MenuDefinition getMenu(final Locale locale) { MenuDefinition menuDefinition = new MenuDefinition(); List<Entity> menuCategories = menuCrudService.getSortedMenuCategories(); for (Entity menuCategory : menuCategories) { String authRoleIdentifier = menuCategory.getStringField(MenuCategoryFields.AUTH_ROLE); if (!currentUserHasPrivilegesOf(authRoleIdentifier)) { continue; } MenuItemsGroup category = buildCategoryWithItems(menuCategory, locale); if (ADMINISTRATION_CATEGORY.equals(category.getName())) { menuDefinition.setAdministrationCategory(category); } else if (HOME_CATEGORY.equals(category.getName())) { menuDefinition.setHomeCategory(category); } else if (!category.getItems().isEmpty()) { menuDefinition.addItem(category); } } return menuDefinition; }  @Override @Transactional(readOnly = true) @Monitorable MenuDefinition getMenu(final Locale locale); @Override @Transactional void addView(final MenuItemDefinition itemDefinition); @Override @Transactional void removeView(final MenuItemDefinition itemDefinition); @Override @Transactional void createCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void removeCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void createItem(final MenuItemDefinition itemDefinition); @Override @Transactional void removeItem(final MenuItemDefinition itemDefinition); }
MenuServiceImpl implements InternalMenuService { @Override @Transactional(readOnly = true) @Monitorable public MenuDefinition getMenu(final Locale locale) { MenuDefinition menuDefinition = new MenuDefinition(); List<Entity> menuCategories = menuCrudService.getSortedMenuCategories(); for (Entity menuCategory : menuCategories) { String authRoleIdentifier = menuCategory.getStringField(MenuCategoryFields.AUTH_ROLE); if (!currentUserHasPrivilegesOf(authRoleIdentifier)) { continue; } MenuItemsGroup category = buildCategoryWithItems(menuCategory, locale); if (ADMINISTRATION_CATEGORY.equals(category.getName())) { menuDefinition.setAdministrationCategory(category); } else if (HOME_CATEGORY.equals(category.getName())) { menuDefinition.setHomeCategory(category); } else if (!category.getItems().isEmpty()) { menuDefinition.addItem(category); } } return menuDefinition; }  @Override @Transactional(readOnly = true) @Monitorable MenuDefinition getMenu(final Locale locale); @Override @Transactional void addView(final MenuItemDefinition itemDefinition); @Override @Transactional void removeView(final MenuItemDefinition itemDefinition); @Override @Transactional void createCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void removeCategory(final MenuCategoryDefinition menuCategoryDefinition); @Override @Transactional void createItem(final MenuItemDefinition itemDefinition); @Override @Transactional void removeItem(final MenuItemDefinition itemDefinition);  }