Search in sources :

Example 1 with ProjectInvitationJoinVO

use of com.cloud.api.query.vo.ProjectInvitationJoinVO in project cloudstack by apache.

the class QueryManagerImpl method listProjectInvitationsInternal.

public Pair<List<ProjectInvitationJoinVO>, Integer> listProjectInvitationsInternal(ListProjectInvitationsCmd cmd) {
    Long id = cmd.getId();
    Long projectId = cmd.getProjectId();
    String accountName = cmd.getAccountName();
    Long domainId = cmd.getDomainId();
    String state = cmd.getState();
    boolean activeOnly = cmd.isActiveOnly();
    Long startIndex = cmd.getStartIndex();
    Long pageSizeVal = cmd.getPageSizeVal();
    Long userId = cmd.getUserId();
    boolean isRecursive = cmd.isRecursive();
    boolean listAll = cmd.listAll();
    Account caller = CallContext.current().getCallingAccount();
    User callingUser = CallContext.current().getCallingUser();
    List<Long> permittedAccounts = new ArrayList<Long>();
    Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, true);
    domainId = domainIdRecursiveListProject.first();
    isRecursive = domainIdRecursiveListProject.second();
    ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    Filter searchFilter = new Filter(ProjectInvitationJoinVO.class, "id", true, startIndex, pageSizeVal);
    SearchBuilder<ProjectInvitationJoinVO> sb = _projectInvitationJoinDao.createSearchBuilder();
    _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    ProjectInvitation invitation = projectInvitationDao.findByUserIdProjectId(callingUser.getId(), callingUser.getAccountId(), projectId == null ? -1 : projectId);
    sb.and("projectId", sb.entity().getProjectId(), SearchCriteria.Op.EQ);
    sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
    sb.and("created", sb.entity().getCreated(), SearchCriteria.Op.GT);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    SearchCriteria<ProjectInvitationJoinVO> sc = sb.create();
    _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (projectId != null) {
        sc.setParameters("projectId", projectId);
    }
    if (invitation != null) {
        sc.setParameters("userId", invitation.getForUserId());
    } else if (userId != null) {
        sc.setParameters("userId", userId);
    }
    if (state != null) {
        sc.setParameters("state", state);
    }
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (activeOnly) {
        sc.setParameters("state", ProjectInvitation.State.Pending);
        sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - _projectMgr.getInvitationTimeout()));
    }
    Pair<List<ProjectInvitationJoinVO>, Integer> projectInvitations = _projectInvitationJoinDao.searchAndCount(sc, searchFilter);
    List<ProjectInvitationJoinVO> invitations = projectInvitations.first();
    invitations = invitations.stream().filter(invite -> invite.getUserId() == null || Long.parseLong(invite.getUserId()) == callingUser.getId()).collect(Collectors.toList());
    return new Pair<>(invitations, invitations.size());
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) ProjectInvitation(com.cloud.projects.ProjectInvitation) ProjectInvitationJoinVO(com.cloud.api.query.vo.ProjectInvitationJoinVO) Date(java.util.Date) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Example 2 with ProjectInvitationJoinVO

use of com.cloud.api.query.vo.ProjectInvitationJoinVO in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method listProjectInvitationsInternal.

public Pair<List<ProjectInvitationJoinVO>, Integer> listProjectInvitationsInternal(final ListProjectInvitationsCmd cmd) {
    final Long id = cmd.getId();
    final Long projectId = cmd.getProjectId();
    final String accountName = cmd.getAccountName();
    Long domainId = cmd.getDomainId();
    final String state = cmd.getState();
    final boolean activeOnly = cmd.isActiveOnly();
    final Long startIndex = cmd.getStartIndex();
    final Long pageSizeVal = cmd.getPageSizeVal();
    boolean isRecursive = cmd.isRecursive();
    final boolean listAll = cmd.listAll();
    final Account caller = CallContext.current().getCallingAccount();
    final List<Long> permittedAccounts = new ArrayList<>();
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, true);
    domainId = domainIdRecursiveListProject.first();
    isRecursive = domainIdRecursiveListProject.second();
    final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    final Filter searchFilter = new Filter(ProjectInvitationJoinVO.class, "id", true, startIndex, pageSizeVal);
    final SearchBuilder<ProjectInvitationJoinVO> sb = _projectInvitationJoinDao.createSearchBuilder();
    _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sb.and("projectId", sb.entity().getProjectId(), SearchCriteria.Op.EQ);
    sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
    sb.and("created", sb.entity().getCreated(), SearchCriteria.Op.GT);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    final SearchCriteria<ProjectInvitationJoinVO> sc = sb.create();
    _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (projectId != null) {
        sc.setParameters("projectId", projectId);
    }
    if (state != null) {
        sc.setParameters("state", state);
    }
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (activeOnly) {
        sc.setParameters("state", ProjectInvitation.State.Pending);
        sc.setParameters("created", new Date(DateUtil.currentGMTTime().getTime() - _projectMgr.getInvitationTimeout()));
    }
    return _projectInvitationJoinDao.searchAndCount(sc, searchFilter);
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) ProjectInvitationJoinVO(com.cloud.api.query.vo.ProjectInvitationJoinVO) Date(java.util.Date) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter)

Aggregations

ProjectInvitationJoinVO (com.cloud.api.query.vo.ProjectInvitationJoinVO)2 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)2 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)2 Account (com.cloud.user.Account)2 Ternary (com.cloud.utils.Ternary)2 Filter (com.cloud.utils.db.Filter)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ProjectInvitation (com.cloud.projects.ProjectInvitation)1 User (com.cloud.user.User)1 Pair (com.cloud.utils.Pair)1 List (java.util.List)1