Search in sources :

Example 1 with Application

use of com.topcom.cms.domain.Application 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)

Aggregations

Application (com.topcom.cms.domain.Application)1 Resource (com.topcom.cms.domain.Resource)1 User (com.topcom.cms.domain.User)1 BusinessException (com.topcom.cms.exception.BusinessException)1 PublicResource (com.topcom.cms.perm.annotation.PublicResource)1 CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)1 ApiOperation (io.swagger.annotations.ApiOperation)1