Search in sources :

Example 1 with ObjectMap

use of com.plumdo.common.model.ObjectMap in project plumdo-work by wengwh.

the class RoleResource method saveRoleAndMenu.

private Role saveRoleAndMenu(Role role, ObjectMap roleRequest) {
    if (role == null) {
        role = new Role();
    }
    role.setName(roleRequest.getAsString("name"));
    role.setRemark(roleRequest.getAsString("remark"));
    role.setTenantId(roleRequest.getAsString("tenantId"));
    roleRepository.save(role);
    roleMenuRepository.deleteByRoleId(role.getId());
    List<ObjectMap> menus = roleRequest.getAsList("roleMenus");
    for (ObjectMap menu : menus) {
        RoleMenu roleMenu = new RoleMenu();
        roleMenu.setMenuId(menu.getAsInteger("id"));
        roleMenu.setRoleId(role.getId());
        roleMenuRepository.save(roleMenu);
    }
    return role;
}
Also used : Role(com.plumdo.identity.domain.Role) ObjectMap(com.plumdo.common.model.ObjectMap) RoleMenu(com.plumdo.identity.domain.RoleMenu)

Example 2 with ObjectMap

use of com.plumdo.common.model.ObjectMap in project plumdo-work by wengwh.

the class RoleConverter method convertDetail.

public static ObjectMap convertDetail(Role role, List<Menu> allMenus, List<Menu> roleMenus) {
    ObjectMap detailMap = new ObjectMap();
    detailMap.put("id", role.getId());
    detailMap.put("name", role.getName());
    detailMap.put("remark", role.getRemark());
    detailMap.put("tenantId", role.getTenantId());
    List<ObjectMap> menuList = new ArrayList<>();
    for (Menu menu : allMenus) {
        if (menu.getType() == TableConstant.MENU_TYPE_CHILD) {
            continue;
        }
        menuList.add(ObjectMap.of("id", menu.getId(), "name", menu.getName(), "group", true));
        for (Menu childMenu : allMenus) {
            if (menu.getId().equals(childMenu.getParentId())) {
                ObjectMap menuMap = ObjectMap.of("id", childMenu.getId(), "name", childMenu.getName());
                if (roleMenus.contains(childMenu)) {
                    menuMap.put("selected", true);
                } else {
                    menuMap.put("selected", false);
                }
                menuList.add(menuMap);
            }
        }
        menuList.add(ObjectMap.of("group", false));
    }
    detailMap.put("menus", menuList);
    return detailMap;
}
Also used : ObjectMap(com.plumdo.common.model.ObjectMap) ArrayList(java.util.ArrayList) Menu(com.plumdo.identity.domain.Menu)

Example 3 with ObjectMap

use of com.plumdo.common.model.ObjectMap in project plumdo-work by wengwh.

the class MenuConverter method convertSelectedTree.

public static List<ObjectMap> convertSelectedTree(List<Menu> menus, List<Menu> roleMenus) {
    List<ObjectMap> menuList = new ArrayList<>();
    for (Menu menu : menus) {
        if (menu.getType() == TableConstant.MENU_TYPE_CHILD) {
            continue;
        }
        menuList.add(ObjectMap.of("id", menu.getId(), "name", menu.getName(), "group", true));
        for (Menu childMenu : menus) {
            if (menu.getId().equals(childMenu.getParentId())) {
                if (ObjectUtils.isNotEmpty(roleMenus) && roleMenus.contains(childMenu)) {
                    menuList.add(ObjectMap.of("id", childMenu.getId(), "name", childMenu.getName(), "selected", true));
                } else {
                    menuList.add(ObjectMap.of("id", childMenu.getId(), "name", childMenu.getName(), "selected", false));
                }
            }
        }
        menuList.add(ObjectMap.of("group", false));
    }
    return menuList;
}
Also used : ObjectMap(com.plumdo.common.model.ObjectMap) ArrayList(java.util.ArrayList) Menu(com.plumdo.identity.domain.Menu)

Aggregations

ObjectMap (com.plumdo.common.model.ObjectMap)3 Menu (com.plumdo.identity.domain.Menu)2 ArrayList (java.util.ArrayList)2 Role (com.plumdo.identity.domain.Role)1 RoleMenu (com.plumdo.identity.domain.RoleMenu)1