All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tinygroup.menutree.manager.impl.MenuTreeManagerImpl Maven / Gradle / Ivy

The newest version!
package org.tinygroup.menutree.manager.impl;

import org.tinygroup.menutree.manager.MenuTreeManager;
import org.tinygroup.menutree.config.Menu;
import org.tinygroup.menutree.dto.MenuInfo;
import org.tinygroup.menutree.dto.MenuNode;
import org.tinygroup.menutree.util.MenuUtil;

import java.util.*;

/**
 * Created by wangwy11342 on 2016/10/18.
 */
public class MenuTreeManagerImpl implements MenuTreeManager{
    private Map loadMenuMap = new HashMap();

    private List allMenuList = new ArrayList();

    public void load(List menuList) {
        for(Menu menu:menuList){
            if(!loadMenuMap.containsKey(menu.getId())){
                allMenuList.add(menu);
                loadMenuMap.put(menu.getId(),menu);
            }
        }
    }

    public MenuInfo getAllMenuInfo(String currentUrl) {
        return getAuthMenuInfoByAuthMenus(allMenuList, currentUrl);
    }

    public MenuInfo getAuthMenuInfoByAuthMenus(List authMenuList, String currentUrl) {
        List authMenuIdList = new ArrayList();
        for(Menu menu : authMenuList){
            authMenuIdList.add(menu.getId());
        }
        return getAuthMenuInfo(authMenuIdList,currentUrl);
    }

    public MenuInfo getAuthMenuInfo(List authMenuIdList, String currentUrl) {

        List authMenuNodeList = getAuthMenuNodeList(authMenuIdList);
        try {
            MenuInfo menuInfo = getAuthMenuInfo(currentUrl,authMenuNodeList);
            return menuInfo;
        }catch(Exception e){
            throw new RuntimeException(e);
        }
    }

    public List getAuthMenuNodeList(List authMenuIdList){
        return getAuthMenuNodeList(allMenuList,authMenuIdList);
    }

    public List getAuthMenuNodeList(List allMenus, List authMenuIdList) {
        MenuNode[] treeNodes = new MenuUtil().toTreeByList(authMenuIdList,allMenus);
        List authMenuNodeList = Arrays.asList(treeNodes);
        return authMenuNodeList;
    }

    public MenuInfo getAuthMenuInfo(String currentUrl,List authMenuNodeList){
        List menuPaths = new ArrayList();
        getMyMenusPath(authMenuNodeList, currentUrl, menuPaths);
        MenuInfo menuInfo = new MenuInfo();
        menuInfo.setMenuList(authMenuNodeList);
        menuInfo.setMenuPaths(menuPaths);
        return menuInfo;
    }

    private void getMyMenusPath(List treeNodes, String currentUrl,
                                List pathList) {
        new MenuUtil().getSelectedPath(treeNodes, currentUrl,pathList);
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy