Search in sources :

Example 1 with Resource

use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.

the class UserController method getTreeOn.

private List<Resource> getTreeOn(List<Resource> resourceList) {
    Map<Long, Resource> resultMap = new HashedMap();
    for (int i = 0; i < resourceList.size(); i++) {
        Resource resource_i = resourceList.get(i);
        Long parentId_i = getResourceParentId(resource_i);
        if (resultMap.keySet().contains(parentId_i)) {
            continue;
        }
        Resource superParent_i = getResourceParent(resource_i);
        for (int j = i + 1; j < resourceList.size(); j++) {
            Resource resource_j = resourceList.get(j);
            superParent_i = megerBtoA(superParent_i, resource_j);
        }
        if (!resultMap.keySet().contains(parentId_i)) {
            resultMap.put(parentId_i, superParent_i);
        }
    }
    resourceList.clear();
    for (Long l : resultMap.keySet()) {
        resourceList.add(resultMap.get(l));
    }
    return resourceList;
}
Also used : PublicResource(com.topcom.cms.perm.annotation.PublicResource) Resource(com.topcom.cms.domain.Resource) HashedMap(org.apache.commons.collections.map.HashedMap)

Example 2 with Resource

use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.

the class UserController method getResourceParent.

private Resource getResourceParent(Resource resource) {
    Resource parent = resource.getParent();
    if (parent != null) {
        List<Resource> resourceList = new ArrayList<>();
        resourceList.add(resource);
        parent.setChildren(resourceList);
        return getResourceParent(parent);
    } else {
        return resource;
    }
}
Also used : PublicResource(com.topcom.cms.perm.annotation.PublicResource) Resource(com.topcom.cms.domain.Resource)

Example 3 with Resource

use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.

the class UserController method mergeChild.

private Resource mergeChild(Resource resource1, Resource resource2) {
    List<Resource> children1 = resource1.getChildren();
    List<Resource> children2 = resource2.getChildren();
    if (children1 == null) {
        return resource2;
    } else {
        if (children2 == null) {
            return resource1;
        } else {
            children1.addAll(children2);
            Map<Long, Resource> resultMap = new HashMap<>();
            for (int i = 0; i < children1.size(); i++) {
                Resource resource_i = children1.get(i);
                Long id_i = resource_i.getId();
                for (int j = i + 1; j < children1.size(); j++) {
                    Resource resource_j = children1.get(j);
                    Long id_j = resource_j.getId();
                    if (id_i.equals(id_j)) {
                        resource_i = mergeChild(resource_i, resource_j);
                    }
                }
                if (!resultMap.keySet().contains(id_i)) {
                    resultMap.put(id_i, resource_i);
                }
            }
            children1.clear();
            for (Long l : resultMap.keySet()) {
                children1.add(resultMap.get(l));
            }
            resource1.setChildren(children1);
            return resource1;
        }
    }
}
Also used : PublicResource(com.topcom.cms.perm.annotation.PublicResource) Resource(com.topcom.cms.domain.Resource)

Example 4 with Resource

use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.

the class UserController method appResource.

/**
 * 返回登录用户指定app的resource
 */
@ApiOperation("获取指定app的resource")
@RequestMapping(value = { "appResource" }, method = { RequestMethod.GET })
@ResponseBody
public Set<Resource> appResource(@CurrentUser User user, @RequestParam(required = false) Long appId, @RequestParam(required = false) String appName) throws Exception {
    if (appId == null && StringUtils.isBlank(appName)) {
        throw new BusinessException("appId 和 appName 不能同时为空!");
    }
    if (appId == null) {
        Application app = applicationManager.findByName(appName);
        appId = app.getId();
    }
    // 缓存user懒加载,没有resource,需要在数据库查询
    User user1 = this.manager.findById(user.getId());
    Set<Resource> resourceSet = user1.getResource();
    if (resourceSet == null || resourceSet.size() == 0) {
        return null;
    }
    Set<Resource> filteredResourceSet = new LinkedHashSet<>();
    for (Resource resource : resourceSet) {
        if (appId.equals(resource.getAppId())) {
            filteredResourceSet.add(resource);
        }
    }
    for (Resource resource : filteredResourceSet) {
        resource.sortByChildId();
    }
    return filteredResourceSet;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) PublicResource(com.topcom.cms.perm.annotation.PublicResource) Resource(com.topcom.cms.domain.Resource) Application(com.topcom.cms.domain.Application) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with Resource

use of com.topcom.cms.domain.Resource in project topcom-cloud by 545314690.

the class ResourceManagerImpl method searchText.

private List<Resource> searchText(String keyWord, Set<Resource> resourceList, String filterType) {
    Map<Resource, Double> resourceMap = new HashMap<>();
    if ("description".equals(filterType)) {
        for (Resource resource : resourceList) {
            Double d = 0D;
            String description = resource.getDescription();
            if (description != null && description.indexOf(keyWord) != -1) {
                d = d + 1;
            }
            if (d > 0) {
                resourceMap.put(resource, d);
            }
        }
    } else if ("name".equals(filterType)) {
        for (Resource resource : resourceList) {
            Double d = 0D;
            String name = resource.getName();
            if (name != null && name.indexOf(keyWord) != -1) {
                d = d + 10;
            }
            if (d > 0) {
                resourceMap.put(resource, d);
            }
        }
    } else {
        for (Resource resource : resourceList) {
            Double d = 0D;
            String name = resource.getName();
            String description = resource.getDescription();
            if (name != null && name.indexOf(keyWord) != -1) {
                d = d + 10;
            }
            if (description != null && description.indexOf(keyWord) != -1) {
                d = d + 1;
            }
            if (d > 0) {
                resourceMap.put(resource, d);
            }
        }
    }
    return sort(resourceMap);
}
Also used : Resource(com.topcom.cms.domain.Resource)

Aggregations

Resource (com.topcom.cms.domain.Resource)11 PublicResource (com.topcom.cms.perm.annotation.PublicResource)8 User (com.topcom.cms.domain.User)3 CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Application (com.topcom.cms.domain.Application)1 BusinessException (com.topcom.cms.exception.BusinessException)1 ViewLogDto (com.topcom.cms.vo.ViewLogDto)1 ViewLogRequest (com.topcom.cms.vo.ViewLogRequest)1 ArrayList (java.util.ArrayList)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 Page (org.springframework.data.domain.Page)1 PageImpl (org.springframework.data.domain.PageImpl)1 PageRequest (org.springframework.data.domain.PageRequest)1