Search in sources :

Example 6 with Resource

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

the class ResourceManagerImpl method searchResource.

@Override
public Page<Resource> searchResource(Set<Resource> resourceSet, String word, Integer limit, Integer page, String filterType) {
    Page result = null;
    if (limit == null || limit == 0) {
        limit = 20;
    }
    if (page == null || page == 0) {
        page = 1;
    }
    List<Resource> content = new ArrayList<>();
    if (StringUtils.isEmpty(word)) {
        content.addAll(resourceSet);
    } else {
        content = searchText(word, resourceSet, filterType);
    }
    int index_s = (page - 1) * limit;
    int index_e = page * limit;
    if (index_s > content.size()) {
        content.clear();
    } else {
        result = new PageImpl(content.subList(index_s, index_e > content.size() ? content.size() : index_e), new PageRequest(page - 1, limit), content.size());
    }
    return result;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) Resource(com.topcom.cms.domain.Resource) Page(org.springframework.data.domain.Page)

Example 7 with Resource

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

the class UserController method mergeChild.

private List<Resource> mergeChild(List<Resource> resourceList) {
    Map<Long, Resource> resultMap = new HashMap<>();
    for (int i = 0; i < resourceList.size(); i++) {
        if (i == 23) {
            System.out.println("23");
        }
        Resource resource_i = resourceList.get(i);
        Long resourceId_i = resource_i.getId();
        for (int j = i + 1; j < resourceList.size(); j++) {
            Resource resource_j = resourceList.get(j);
            Long resourceId_j = resource_j.getId();
            if (resourceId_i.equals(resourceId_j)) {
                // List<Resource> childrenList = resource_i.getChildren();
                // childrenList.addAll(resource_j.getChildren());
                resource_i = mergeChild(resource_i, resource_j);
            }
        }
        if (!resultMap.keySet().contains(resourceId_i)) {
            resultMap.put(resourceId_i, resource_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)

Example 8 with Resource

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

the class UserController method resource.

/**
 * 返回登录用户的resource
 */
@ApiOperation("获取resource")
@RequestMapping(value = { "resource" }, method = { RequestMethod.GET })
@ResponseBody
public Set<Resource> resource(@CurrentUser User user) {
    // 缓存user懒加载,没有resource,需要在数据库查询
    User user1 = this.manager.findById(user.getId());
    // user.getPermissionNames();
    Set<Resource> resourceSet = user1.getResource();
    if (resourceSet == null || resourceSet.size() == 0) {
        return null;
    }
    for (Resource resource : resourceSet) {
        resource.sortByChildId();
    }
    return resourceSet;
}
Also used : 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) ApiOperation(io.swagger.annotations.ApiOperation)

Example 9 with Resource

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

the class UserController method getResourceParentId.

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

Example 10 with Resource

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

the class UserController method megerBtoA.

private Resource megerBtoA(Resource resource_a, Resource resource_b) {
    Long aId = resource_a.getId();
    Long bId = resource_b.getId();
    Long parentId_b = resource_b.getParentId();
    if (aId == bId) {
        return resource_b;
    }
    if (parentId_b == null) {
        return resource_a;
    }
    List<Resource> childrenList = resource_a.getChildren();
    if (parentId_b == aId) {
        childrenList = addToList(childrenList, resource_b);
    } else {
        for (int i = 0; i < childrenList.size(); i++) {
            Resource resouce_i = megerBtoA(childrenList.get(i), resource_b);
            childrenList = addToList(childrenList, resouce_i);
        }
    }
    resource_a.setChildren(childrenList);
    return resource_a;
}
Also used : PublicResource(com.topcom.cms.perm.annotation.PublicResource) 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