Search in sources :

Example 1 with ProjectInvitation

use of com.cloud.projects.ProjectInvitation in project CloudStack-archive by CloudStack-extras.

the class ListProjectInvitationsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    List<? extends ProjectInvitation> invites = _projectService.listProjectInvitations(id, projectId, this.getAccountName(), this.getDomainId(), state, activeOnly, this.getStartIndex(), this.getPageSizeVal(), this.isRecursive(), this.listAll());
    ListResponse<ProjectInvitationResponse> response = new ListResponse<ProjectInvitationResponse>();
    List<ProjectInvitationResponse> projectInvitationResponses = new ArrayList<ProjectInvitationResponse>();
    for (ProjectInvitation invite : invites) {
        ProjectInvitationResponse projectResponse = _responseGenerator.createProjectInvitationResponse(invite);
        projectInvitationResponses.add(projectResponse);
    }
    response.setResponses(projectInvitationResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ProjectInvitationResponse(com.cloud.api.response.ProjectInvitationResponse) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) ProjectInvitation(com.cloud.projects.ProjectInvitation)

Example 2 with ProjectInvitation

use of com.cloud.projects.ProjectInvitation 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)

Aggregations

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