Search in sources :

Example 1 with InvalidResourcePermissionVO

use of com.diboot.iam.vo.InvalidResourcePermissionVO in project diboot by dibo-software.

the class IamResourcePermissionServiceImpl method extractCodeDiffDbPermissions.

@Override
public Map<String, Object> extractCodeDiffDbPermissions(String application) {
    List<IamResourcePermission> allResourcePermissions = getEntityList(Wrappers.<IamResourcePermission>lambdaQuery().orderByDesc(IamResourcePermission::getSortId, IamResourcePermission::getId));
    if (V.isEmpty(allResourcePermissions)) {
        return Collections.emptyMap();
    }
    List<InvalidResourcePermissionVO> voList = RelationsBinder.convertAndBind(allResourcePermissions, InvalidResourcePermissionVO.class);
    Map<Long, InvalidResourcePermissionVO> resultMap = new HashMap<>(32);
    for (InvalidResourcePermissionVO invalidIamResourcePermission : voList) {
        if (V.isEmpty(invalidIamResourcePermission.getApiSet())) {
            continue;
        }
        for (String uri : invalidIamResourcePermission.getApiSetList()) {
            // 根据uri获取code
            String permissionCode = IamCacheManager.getPermissionCode(uri);
            // code存在,表示该URI有效,否则无效
            if (V.isEmpty(permissionCode)) {
                invalidIamResourcePermission.addInvalidApiSet(uri);
                resultMap.put(invalidIamResourcePermission.getId(), invalidIamResourcePermission);
            }
        }
    }
    if (V.isEmpty(resultMap)) {
        return Collections.emptyMap();
    }
    List<InvalidResourcePermissionVO> outerPermissionList = new ArrayList<>();
    for (Map.Entry<Long, InvalidResourcePermissionVO> invalidResourcePermissionVOEntry : resultMap.entrySet()) {
        InvalidResourcePermissionVO invalidResourcePermissionVO = invalidResourcePermissionVOEntry.getValue();
        // 获取当前权限的上级元素
        Long parentId = invalidResourcePermissionVO.getParentId();
        InvalidResourcePermissionVO parentInvalidResourcePermissionVO = resultMap.get(parentId);
        // 如果上级元素不存在,表示,当前对象为最外层元素
        if (V.isEmpty(parentInvalidResourcePermissionVO)) {
            outerPermissionList.add(invalidResourcePermissionVO);
        }
    }
    List<InvalidResourcePermissionVO> result = new ArrayList<>(resultMap.values());
    List<Long> diffDataIdList = new ArrayList<>();
    for (InvalidResourcePermissionVO value : result) {
        List<InvalidResourcePermissionVO> childNodeChildren = BeanUtils.buildTreeChildren(value.getId(), result, Cons.FieldName.parentId.name(), Cons.FieldName.children.name());
        if (childNodeChildren == null) {
            childNodeChildren = new ArrayList<>();
        }
        BeanUtils.setProperty(value, Cons.FieldName.children.name(), childNodeChildren);
        diffDataIdList.add(value.getId());
    }
    return new HashMap<String, Object>() {

        {
            put("diffDataList", outerPermissionList);
            put("diffDataIdList", diffDataIdList);
        }
    };
}
Also used : InvalidResourcePermissionVO(com.diboot.iam.vo.InvalidResourcePermissionVO) IamResourcePermission(com.diboot.iam.entity.IamResourcePermission)

Aggregations

IamResourcePermission (com.diboot.iam.entity.IamResourcePermission)1 InvalidResourcePermissionVO (com.diboot.iam.vo.InvalidResourcePermissionVO)1