Search in sources :

Example 1 with ProjectAccountVO

use of com.cloud.projects.ProjectAccountVO in project cloudstack by apache.

the class ProjectJoinDaoImpl method newProjectResponse.

@Override
public ProjectResponse newProjectResponse(EnumSet<DomainDetails> details, ProjectJoinVO proj) {
    ProjectResponse response = new ProjectResponse();
    response.setId(proj.getUuid());
    response.setName(proj.getName());
    response.setDisplaytext(proj.getDisplayText());
    if (proj.getState() != null) {
        response.setState(proj.getState().toString());
    }
    response.setDomainId(proj.getDomainUuid());
    response.setDomain(proj.getDomainName());
    List<ProjectAccountVO> projectAccounts = projectAccountDao.listByProjectId(proj.getId());
    projectAccounts = projectAccounts.stream().filter(projectAccount -> projectAccount.getAccountRole() == ProjectAccount.Role.Admin).collect(Collectors.toList());
    List<Map<String, String>> ownersList = new ArrayList<>();
    for (ProjectAccount projectAccount : projectAccounts) {
        Map<String, String> ownerDetails = new HashMap<>();
        if (projectAccount.getUserId() != null) {
            User user = userDao.findById(projectAccount.getUserId());
            ownerDetails.put("account", _accountDao.findById(projectAccount.getAccountId()).getAccountName());
            ownerDetails.put("user", user.getUsername());
            ownerDetails.put("userid", user.getUuid());
        } else {
            ownerDetails.put("account", _accountDao.findById(projectAccount.getAccountId()).getAccountName());
        }
        ownersList.add(ownerDetails);
    }
    response.setOwners(ownersList);
    response.setCreated(proj.getCreated());
    // update tag information
    List<ResourceTagJoinVO> tags = ApiDBUtils.listResourceTagViewByResourceUUID(proj.getUuid(), ResourceObjectType.Project);
    for (ResourceTagJoinVO vtag : tags) {
        response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
    }
    // set resource limit/count information for the project (by getting the info of the project's account)
    Account account = _accountDao.findByIdIncludingRemoved(proj.getProjectAccountId());
    if (details.contains(DomainDetails.all) || details.contains(DomainDetails.resource)) {
        AccountJoinVO accountJn = ApiDBUtils.newAccountView(account);
        _accountJoinDao.setResourceLimits(accountJn, false, response);
    }
    response.setProjectAccountName(account.getAccountName());
    response.setObjectName("project");
    return response;
}
Also used : Account(com.cloud.user.Account) ProjectAccount(com.cloud.projects.ProjectAccount) User(com.cloud.user.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectAccount(com.cloud.projects.ProjectAccount) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) ProjectAccountVO(com.cloud.projects.ProjectAccountVO) HashMap(java.util.HashMap) Map(java.util.Map) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO)

Example 2 with ProjectAccountVO

use of com.cloud.projects.ProjectAccountVO in project cloudstack by apache.

the class ProjectAccountDaoImpl method listByProjectId.

@Override
public List<ProjectAccountVO> listByProjectId(long projectId) {
    SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
    sc.setParameters("projectId", projectId);
    Filter filter = new Filter(ProjectAccountVO.class, "id", Boolean.TRUE, null, null);
    return listBy(sc, filter);
}
Also used : Filter(com.cloud.utils.db.Filter) ProjectAccountVO(com.cloud.projects.ProjectAccountVO)

Aggregations

ProjectAccountVO (com.cloud.projects.ProjectAccountVO)2 AccountJoinVO (com.cloud.api.query.vo.AccountJoinVO)1 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)1 ProjectAccount (com.cloud.projects.ProjectAccount)1 Account (com.cloud.user.Account)1 User (com.cloud.user.User)1 Filter (com.cloud.utils.db.Filter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ProjectResponse (org.apache.cloudstack.api.response.ProjectResponse)1