/** * 返回实现IModule接口的列表 * * @param applicationId * @return */ @Override public List<ModuleBean> getModuleByApplication(String applicationId) { Subject subject = shiroService.getSubject(); List<IModule> moduleList = ModuleManager.getInstall().getModuleList(applicationId); List<ModuleBean> moduleBeanList = new ArrayList<ModuleBean>(); if (moduleList == null) moduleList = new ArrayList<IModule>(); Mapper mapper = new DozerBeanMapper(); // 找出所有对应权限的功能模块 if (moduleList != null && !moduleList.isEmpty()) { for (IModule module : moduleList) { // 调用isPermitted不能传入空字符,故此默认值为KALIX_NOT_PERMISSION String modulePermission = StringUtils.isEmpty(module.getPermission()) ? Const.KALIX_NO_PERMISSION : module.getPermission(); // 具有权限或不进行权限验证,都通过 if (subject.hasRole(modulePermission) || modulePermission.equals(Const.KALIX_NO_PERMISSION)) { ModuleBean moduleBean = mapper.map(module, ModuleBean.class); moduleBean.setText(module.getText()); moduleBeanList.add(moduleBean); } } } if (moduleBeanList != null && !moduleBeanList.isEmpty()) { for (ModuleBean moduleBean : moduleBeanList) { moduleBean.setChildren(new ArrayList<MenuBean>()); List<IMenu> menuList = new ArrayList<IMenu>(); List<IMenu> allMenu = MenuManager.getInstall().getMenuList(moduleBean.getId()); // 去掉没有权限的菜单 if (allMenu != null && !allMenu.isEmpty()) { for (IMenu menu : allMenu) { // 调用hasRole不能传入空字符,故此默认值为KALIX_NOT_PERMISSION String menuPermission = StringUtils.isEmpty(menu.getPermission()) ? Const.KALIX_NO_PERMISSION : menu.getPermission(); // 具有权限或不进行权限验证,都通过 if (subject.hasRole(menuPermission) || menuPermission.equals(Const.KALIX_NO_PERMISSION)) { menuList.add(menu); } } } List<IMenu> rootMenus = getRootMenus(menuList); if (rootMenus != null && !rootMenus.isEmpty()) { for (IMenu rootMenu : rootMenus) { MenuBean menuBean = null; if (rootMenu != null) { menuBean = mapper.map(rootMenu, MenuBean.class); menuBean.setText(rootMenu.getText()); getMenuChildren(menuBean, menuList, mapper); } moduleBean.getChildren().add(menuBean); } } } } return moduleBeanList; }
/** * 获得菜单根节点 * * @param menuList * @return */ private IMenu getRootMenu(List<IMenu> menuList) { if (menuList == null || menuList.isEmpty()) return null; for (IMenu menu : menuList) { if (menu.getParentMenuId() == null) { return menu; } } return null; }
/** * 获得菜单根节点 * * @param menuList * @return */ private List<IMenu> getRootMenus(List<IMenu> menuList) { List<IMenu> rootMenus = new ArrayList<IMenu>(); if (menuList == null || menuList.isEmpty()) return rootMenus; for (IMenu menu : menuList) { if (menu.getParentMenuId() == null) { rootMenus.add(menu); } } return rootMenus; }
/** * 递归函数加载子菜单 * * @param menuBean * @param menuList */ private void getMenuChildren(MenuBean menuBean, List<IMenu> menuList, Mapper mapper) { if (menuList == null || menuList.isEmpty()) return; List<MenuBean> childMenuList = new ArrayList<>(); for (IMenu menu : menuList) { if (menu.getParentMenuId() != null && menu.getParentMenuId().equals(menuBean.getId())) { MenuBean mBean = mapper.map(menu, MenuBean.class); mBean.setText(menu.getText()); childMenuList.add(mBean); getMenuChildren(mBean, menuList, mapper); } } menuBean.setChildren(childMenuList); }
/** * 返回实现IMenu接口的列表 * * @param moduleId * @return */ @Override public MenuBean getMenuByModule(String moduleId) { List<IMenu> menuList = MenuManager.getInstall().getMenuList(moduleId); IMenu rootMenu = getRootMenu(menuList); /*List<String> mapFile=new ArrayList<>(); mapFile.add("META-INF/MenuMapper.xml");*/ Mapper mapper = new DozerBeanMapper(); MenuBean menuBean = null; if (rootMenu != null) { menuBean = mapper.map(rootMenu, MenuBean.class); menuBean.setText(rootMenu.getText()); getMenuChildren(menuBean, menuList, mapper); } return menuBean; }
private EditeurConsole() { MenuCourant = Acceuil.getInstance(); do { MenuCourant.traitement(); MenuCourant.affichage(); MenuCourant.afficherText(); MenuCourant.afficherInfoSelection(); MenuCourant.afficherMenu(); MenuCourant = MenuCourant.gerrerChoix(EcouteClavier.getInstance().ecouteCaractere()); } while (!MenuCourant.equals(Quitter.getInstance())); MenuCourant.traitement(); MenuCourant.affichage(); }