mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Refactor ListProjectAccountCmd and ProjectAccountResponse.
This commit is contained in:
parent
c455cf9271
commit
9c93fee0dc
@ -19,6 +19,7 @@ package com.cloud.projects;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
||||||
|
|
||||||
import com.cloud.exception.ConcurrentOperationException;
|
import com.cloud.exception.ConcurrentOperationException;
|
||||||
@ -82,7 +83,7 @@ public interface ProjectService {
|
|||||||
|
|
||||||
boolean deleteAccountFromProject(long projectId, String accountName);
|
boolean deleteAccountFromProject(long projectId, String accountName);
|
||||||
|
|
||||||
Pair<List<? extends ProjectAccount>, Integer> listProjectAccounts(long projectId, String accountName, String role, Long startIndex, Long pageSizeVal);
|
Pair<List<ProjectAccountJoinVO>, Integer> listProjectAccounts(long projectId, String accountName, String role, Long startIndex, Long pageSizeVal);
|
||||||
|
|
||||||
Pair<List<? extends ProjectInvitation>, Integer> listProjectInvitations(Long id, Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal, boolean isRecursive,
|
Pair<List<? extends ProjectInvitation>, Integer> listProjectInvitations(Long id, Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal, boolean isRecursive,
|
||||||
boolean listAll);
|
boolean listAll);
|
||||||
|
|||||||
@ -153,6 +153,7 @@ import com.cloud.vm.InstanceGroup;
|
|||||||
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
|
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.EventJoinVO;
|
import org.apache.cloudstack.api.view.vo.EventJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
|
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
|
||||||
|
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
|
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
|
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
|
||||||
@ -304,6 +305,8 @@ public interface ResponseGenerator {
|
|||||||
|
|
||||||
ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount);
|
ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount);
|
||||||
|
|
||||||
|
List<ProjectAccountResponse> createProjectAccountResponse(ProjectAccountJoinVO... projectAccounts);
|
||||||
|
|
||||||
ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite);
|
ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite);
|
||||||
|
|
||||||
SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine systemVM);
|
SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine systemVM);
|
||||||
|
|||||||
@ -29,6 +29,8 @@ import org.apache.cloudstack.api.Parameter;
|
|||||||
import org.apache.cloudstack.api.response.ListResponse;
|
import org.apache.cloudstack.api.response.ListResponse;
|
||||||
import org.apache.cloudstack.api.response.ProjectAccountResponse;
|
import org.apache.cloudstack.api.response.ProjectAccountResponse;
|
||||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||||
|
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
|
||||||
|
|
||||||
import com.cloud.projects.ProjectAccount;
|
import com.cloud.projects.ProjectAccount;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
@ -79,14 +81,10 @@ public class ListProjectAccountsCmd extends BaseListCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(){
|
public void execute(){
|
||||||
Pair<List<? extends ProjectAccount>, Integer> projectAccounts = _projectService.listProjectAccounts(projectId,
|
Pair<List<ProjectAccountJoinVO>, Integer> projectAccounts = _projectService.listProjectAccounts(projectId,
|
||||||
accountName, role, this.getStartIndex(), this.getPageSizeVal());
|
accountName, role, this.getStartIndex(), this.getPageSizeVal());
|
||||||
ListResponse<ProjectAccountResponse> response = new ListResponse<ProjectAccountResponse>();
|
ListResponse<ProjectAccountResponse> response = new ListResponse<ProjectAccountResponse>();
|
||||||
List<ProjectAccountResponse> projectResponses = new ArrayList<ProjectAccountResponse>();
|
List<ProjectAccountResponse> projectResponses = _responseGenerator.createProjectAccountResponse(projectAccounts.first().toArray(new ProjectAccountJoinVO[projectAccounts.first().size()]));
|
||||||
for (ProjectAccount projectAccount : projectAccounts.first()) {
|
|
||||||
ProjectAccountResponse projectAccountResponse = _responseGenerator.createProjectAccountResponse(projectAccount);
|
|
||||||
projectResponses.add(projectAccountResponse);
|
|
||||||
}
|
|
||||||
response.setResponses(projectResponses, projectAccounts.second());
|
response.setResponses(projectResponses, projectAccounts.second());
|
||||||
response.setResponseName(getCommandName());
|
response.setResponseName(getCommandName());
|
||||||
|
|
||||||
|
|||||||
@ -25,10 +25,10 @@ import com.google.gson.annotations.SerializedName;
|
|||||||
import org.apache.cloudstack.api.BaseResponse;
|
import org.apache.cloudstack.api.BaseResponse;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class ProjectAccountResponse extends BaseResponse implements ControlledEntityResponse {
|
public class ProjectAccountResponse extends BaseResponse implements ControlledViewEntityResponse {
|
||||||
@SerializedName(ApiConstants.PROJECT_ID)
|
@SerializedName(ApiConstants.PROJECT_ID)
|
||||||
@Param(description = "project id")
|
@Param(description = "project id")
|
||||||
private IdentityProxy projectId = new IdentityProxy("projects");
|
private String projectId;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.PROJECT)
|
@SerializedName(ApiConstants.PROJECT)
|
||||||
@Param(description = "project name")
|
@Param(description = "project name")
|
||||||
@ -36,7 +36,7 @@ public class ProjectAccountResponse extends BaseResponse implements ControlledEn
|
|||||||
|
|
||||||
@SerializedName(ApiConstants.ACCOUNT_ID)
|
@SerializedName(ApiConstants.ACCOUNT_ID)
|
||||||
@Param(description = "the id of the account")
|
@Param(description = "the id of the account")
|
||||||
private IdentityProxy id = new IdentityProxy("account");
|
private String accountId;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.ACCOUNT)
|
@SerializedName(ApiConstants.ACCOUNT)
|
||||||
@Param(description = "the name of the account")
|
@Param(description = "the name of the account")
|
||||||
@ -52,7 +52,7 @@ public class ProjectAccountResponse extends BaseResponse implements ControlledEn
|
|||||||
|
|
||||||
@SerializedName(ApiConstants.DOMAIN_ID)
|
@SerializedName(ApiConstants.DOMAIN_ID)
|
||||||
@Param(description = "id of the Domain the account belongs too")
|
@Param(description = "id of the Domain the account belongs too")
|
||||||
private IdentityProxy domainId = new IdentityProxy("domain");
|
private String domainId;
|
||||||
|
|
||||||
@SerializedName(ApiConstants.DOMAIN)
|
@SerializedName(ApiConstants.DOMAIN)
|
||||||
@Param(description = "name of the Domain the account belongs too")
|
@Param(description = "name of the Domain the account belongs too")
|
||||||
@ -62,16 +62,16 @@ public class ProjectAccountResponse extends BaseResponse implements ControlledEn
|
|||||||
@Param(description = "the list of users associated with account", responseObject = UserResponse.class)
|
@Param(description = "the list of users associated with account", responseObject = UserResponse.class)
|
||||||
private List<UserResponse> users;
|
private List<UserResponse> users;
|
||||||
|
|
||||||
public void setProjectId(Long projectId) {
|
public void setProjectId(String projectId) {
|
||||||
this.projectId.setValue(projectId);
|
this.projectId = projectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProjectName(String projectName) {
|
public void setProjectName(String projectName) {
|
||||||
this.projectName = projectName;
|
this.projectName = projectName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Long id) {
|
public void setAccountId(String id) {
|
||||||
this.id.setValue(id);
|
this.accountId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccountName(String accountName) {
|
public void setAccountName(String accountName) {
|
||||||
@ -82,8 +82,8 @@ public class ProjectAccountResponse extends BaseResponse implements ControlledEn
|
|||||||
this.accountType = accountType;
|
this.accountType = accountType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDomainId(Long domainId) {
|
public void setDomainId(String domainId) {
|
||||||
this.domainId.setValue(domainId);
|
this.domainId = domainId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDomainName(String domainName) {
|
public void setDomainName(String domainName) {
|
||||||
|
|||||||
@ -0,0 +1,205 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with the License. You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing,
|
||||||
|
// software distributed under the License is distributed on an
|
||||||
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
// KIND, either express or implied. See the License for the
|
||||||
|
// specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
package org.apache.cloudstack.api.view.vo;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import com.cloud.projects.ProjectAccount.Role;
|
||||||
|
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
import com.cloud.vm.VirtualMachine.State;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="project_account_view")
|
||||||
|
public class ProjectAccountJoinVO extends BaseViewVO {
|
||||||
|
|
||||||
|
@Column(name="account_id")
|
||||||
|
private long accountId;
|
||||||
|
|
||||||
|
@Column(name="account_uuid")
|
||||||
|
private String accountUuid;
|
||||||
|
|
||||||
|
@Column(name="account_name")
|
||||||
|
private String accountName;
|
||||||
|
|
||||||
|
@Column(name="account_type")
|
||||||
|
private short accountType;
|
||||||
|
|
||||||
|
@Column(name="account_role")
|
||||||
|
@Enumerated(value=EnumType.STRING)
|
||||||
|
private Role accountRole;
|
||||||
|
|
||||||
|
@Column(name="domain_id")
|
||||||
|
private long domainId;
|
||||||
|
|
||||||
|
@Column(name="domain_uuid")
|
||||||
|
private String domainUuid;
|
||||||
|
|
||||||
|
@Column(name="domain_name")
|
||||||
|
private String domainName;
|
||||||
|
|
||||||
|
@Column(name="domain_path")
|
||||||
|
private String domainPath;
|
||||||
|
|
||||||
|
@Column(name="project_id")
|
||||||
|
private long projectId;
|
||||||
|
|
||||||
|
@Column(name="project_uuid")
|
||||||
|
private String projectUuid;
|
||||||
|
|
||||||
|
@Column(name="project_name")
|
||||||
|
private String projectName;
|
||||||
|
|
||||||
|
|
||||||
|
public ProjectAccountJoinVO() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public long getDomainId() {
|
||||||
|
return domainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDomainId(long domainId) {
|
||||||
|
this.domainId = domainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomainUuid() {
|
||||||
|
return domainUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDomainUuid(String domainUuid) {
|
||||||
|
this.domainUuid = domainUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomainName() {
|
||||||
|
return domainName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDomainName(String domainName) {
|
||||||
|
this.domainName = domainName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomainPath() {
|
||||||
|
return domainPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDomainPath(String domainPath) {
|
||||||
|
this.domainPath = domainPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAccountId() {
|
||||||
|
return accountId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccountId(long accountId) {
|
||||||
|
this.accountId = accountId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getAccountUuid() {
|
||||||
|
return accountUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setAccountUuid(String accountUuid) {
|
||||||
|
this.accountUuid = accountUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getAccountName() {
|
||||||
|
return accountName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setAccountName(String accountName) {
|
||||||
|
this.accountName = accountName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public short getAccountType() {
|
||||||
|
return accountType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setAccountType(short accountType) {
|
||||||
|
this.accountType = accountType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Role getAccountRole() {
|
||||||
|
return accountRole;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setAccountRole(Role accountRole) {
|
||||||
|
this.accountRole = accountRole;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public long getProjectId() {
|
||||||
|
return projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setProjectId(long projectId) {
|
||||||
|
this.projectId = projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getProjectUuid() {
|
||||||
|
return projectUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setProjectUuid(String projectUuid) {
|
||||||
|
this.projectUuid = projectUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getProjectName() {
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setProjectName(String projectName) {
|
||||||
|
this.projectName = projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -26,6 +26,7 @@ import org.apache.cloudstack.api.ApiConstants.VMDetails;
|
|||||||
import org.apache.cloudstack.api.response.DomainRouterResponse;
|
import org.apache.cloudstack.api.response.DomainRouterResponse;
|
||||||
import org.apache.cloudstack.api.response.EventResponse;
|
import org.apache.cloudstack.api.response.EventResponse;
|
||||||
import org.apache.cloudstack.api.response.InstanceGroupResponse;
|
import org.apache.cloudstack.api.response.InstanceGroupResponse;
|
||||||
|
import org.apache.cloudstack.api.response.ProjectAccountResponse;
|
||||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||||
import org.apache.cloudstack.api.response.ResourceTagResponse;
|
import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||||
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
import org.apache.cloudstack.api.response.SecurityGroupResponse;
|
||||||
@ -34,6 +35,7 @@ import org.apache.cloudstack.api.response.UserVmResponse;
|
|||||||
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
|
import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.EventJoinVO;
|
import org.apache.cloudstack.api.view.vo.EventJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
|
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
|
||||||
|
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
|
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
|
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
|
||||||
@ -115,7 +117,9 @@ import com.cloud.offering.ServiceOffering;
|
|||||||
import com.cloud.offerings.NetworkOfferingVO;
|
import com.cloud.offerings.NetworkOfferingVO;
|
||||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||||
import com.cloud.projects.Project;
|
import com.cloud.projects.Project;
|
||||||
|
import com.cloud.projects.ProjectAccount;
|
||||||
import com.cloud.projects.ProjectService;
|
import com.cloud.projects.ProjectService;
|
||||||
|
import com.cloud.projects.dao.ProjectAccountJoinDao;
|
||||||
import com.cloud.projects.dao.ProjectJoinDao;
|
import com.cloud.projects.dao.ProjectJoinDao;
|
||||||
import com.cloud.resource.ResourceManager;
|
import com.cloud.resource.ResourceManager;
|
||||||
import com.cloud.server.Criteria;
|
import com.cloud.server.Criteria;
|
||||||
@ -265,6 +269,7 @@ public class ApiDBUtils {
|
|||||||
private static InstanceGroupJoinDao _vmGroupJoinDao;
|
private static InstanceGroupJoinDao _vmGroupJoinDao;
|
||||||
private static UserAccountJoinDao _userAccountJoinDao;
|
private static UserAccountJoinDao _userAccountJoinDao;
|
||||||
private static ProjectJoinDao _projectJoinDao;
|
private static ProjectJoinDao _projectJoinDao;
|
||||||
|
private static ProjectAccountJoinDao _projectAccountJoinDao;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
_ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name);
|
_ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name);
|
||||||
@ -1030,4 +1035,17 @@ public class ApiDBUtils {
|
|||||||
public static List<ProjectJoinVO> newProjectView(Project proj){
|
public static List<ProjectJoinVO> newProjectView(Project proj){
|
||||||
return _projectJoinDao.newProjectView(proj);
|
return _projectJoinDao.newProjectView(proj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<UserAccountJoinVO> findUserViewByAccountId(Long accountId){
|
||||||
|
return _userAccountJoinDao.searchByAccountId(accountId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProjectAccountResponse newProjectAccountResponse(ProjectAccountJoinVO proj) {
|
||||||
|
return _projectAccountJoinDao.newProjectAccountResponse(proj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProjectAccountJoinVO newProjectAccountView(ProjectAccount proj) {
|
||||||
|
return _projectAccountJoinDao.newProjectAccountView(proj);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -116,6 +116,7 @@ import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO;
|
|||||||
import org.apache.cloudstack.api.view.vo.ControlledViewEntity;
|
import org.apache.cloudstack.api.view.vo.ControlledViewEntity;
|
||||||
import org.apache.cloudstack.api.view.vo.EventJoinVO;
|
import org.apache.cloudstack.api.view.vo.EventJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
|
import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO;
|
||||||
|
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
|
import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
|
import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO;
|
||||||
@ -2850,31 +2851,24 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount) {
|
public ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount) {
|
||||||
Account account = ApiDBUtils.findAccountById(projectAccount.getAccountId());
|
ProjectAccountJoinVO vProj = ApiDBUtils.newProjectAccountView(projectAccount);
|
||||||
ProjectAccountResponse projectAccountResponse = new ProjectAccountResponse();
|
List<ProjectAccountResponse> listProjs = createProjectAccountResponse(vProj);
|
||||||
|
assert listProjs != null && listProjs.size() == 1 : "There should be one project account returned";
|
||||||
long projectId = projectAccount.getProjectId();
|
return listProjs.get(0);
|
||||||
projectAccountResponse.setProjectId(projectId);
|
|
||||||
projectAccountResponse.setProjectName(ApiDBUtils.findProjectById(projectId).getName());
|
|
||||||
|
|
||||||
projectAccountResponse.setId(account.getId());
|
|
||||||
projectAccountResponse.setAccountName(account.getAccountName());
|
|
||||||
projectAccountResponse.setAccountType(account.getType());
|
|
||||||
projectAccountResponse.setRole(projectAccount.getAccountRole().toString());
|
|
||||||
populateDomain(projectAccountResponse, account.getDomainId());
|
|
||||||
|
|
||||||
// add all the users for an account as part of the response obj
|
|
||||||
List<UserVO> usersForAccount = ApiDBUtils.listUsersByAccount(account.getAccountId());
|
|
||||||
List<UserResponse> userResponseList = new ArrayList<UserResponse>();
|
|
||||||
for (UserVO user : usersForAccount) {
|
|
||||||
UserResponse userResponse = createUserResponse(user);
|
|
||||||
userResponseList.add(userResponse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
projectAccountResponse.setUsers(userResponseList);
|
|
||||||
projectAccountResponse.setObjectName("projectaccount");
|
|
||||||
|
|
||||||
return projectAccountResponse;
|
@Override
|
||||||
|
public List<ProjectAccountResponse> createProjectAccountResponse(ProjectAccountJoinVO... projectAccounts) {
|
||||||
|
List<ProjectAccountResponse> responseList = new ArrayList<ProjectAccountResponse>();
|
||||||
|
for (ProjectAccountJoinVO proj : projectAccounts){
|
||||||
|
ProjectAccountResponse resp = ApiDBUtils.newProjectAccountResponse(proj);
|
||||||
|
// update user list
|
||||||
|
List<UserAccountJoinVO> users = ApiDBUtils.findUserViewByAccountId(proj.getAccountId());
|
||||||
|
resp.setUsers(createUserResponse(users.toArray(new UserAccountJoinVO[users.size()])));
|
||||||
|
responseList.add(resp);
|
||||||
|
}
|
||||||
|
return responseList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -213,6 +213,7 @@ import com.cloud.vm.dao.UserVmJoinDaoImpl;
|
|||||||
import com.cloud.vm.dao.UserVmDetailsDaoImpl;
|
import com.cloud.vm.dao.UserVmDetailsDaoImpl;
|
||||||
import com.cloud.vm.dao.VMInstanceDaoImpl;
|
import com.cloud.vm.dao.VMInstanceDaoImpl;
|
||||||
import com.cloud.event.dao.EventJoinDaoImpl;
|
import com.cloud.event.dao.EventJoinDaoImpl;
|
||||||
|
import com.cloud.projects.dao.ProjectAccountJoinDaoImpl;
|
||||||
|
|
||||||
|
|
||||||
public class DefaultComponentLibrary extends ComponentLibraryBase implements ComponentLibrary {
|
public class DefaultComponentLibrary extends ComponentLibraryBase implements ComponentLibrary {
|
||||||
@ -231,6 +232,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
|
|||||||
addDao("EventJoinDao", EventJoinDaoImpl.class);
|
addDao("EventJoinDao", EventJoinDaoImpl.class);
|
||||||
addDao("UserAccountJoinDao", UserAccountJoinDaoImpl.class);
|
addDao("UserAccountJoinDao", UserAccountJoinDaoImpl.class);
|
||||||
addDao("ProjectJoinDao", ProjectJoinDaoImpl.class);
|
addDao("ProjectJoinDao", ProjectJoinDaoImpl.class);
|
||||||
|
addDao("ProjectAccountJoinDao", ProjectAccountJoinDaoImpl.class);
|
||||||
ComponentInfo<? extends GenericDao<?, ? extends Serializable>> info = addDao("ServiceOfferingDao", ServiceOfferingDaoImpl.class);
|
ComponentInfo<? extends GenericDao<?, ? extends Serializable>> info = addDao("ServiceOfferingDao", ServiceOfferingDaoImpl.class);
|
||||||
info.addParameter("cache.size", "50");
|
info.addParameter("cache.size", "50");
|
||||||
info.addParameter("cache.time.to.live", "600");
|
info.addParameter("cache.time.to.live", "600");
|
||||||
|
|||||||
@ -38,6 +38,7 @@ import javax.mail.URLName;
|
|||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.UserVmJoinVO;
|
import org.apache.cloudstack.api.view.vo.UserVmJoinVO;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -60,6 +61,7 @@ import com.cloud.projects.Project.ListProjectResourcesCriteria;
|
|||||||
import com.cloud.projects.Project.State;
|
import com.cloud.projects.Project.State;
|
||||||
import com.cloud.projects.ProjectAccount.Role;
|
import com.cloud.projects.ProjectAccount.Role;
|
||||||
import com.cloud.projects.dao.ProjectAccountDao;
|
import com.cloud.projects.dao.ProjectAccountDao;
|
||||||
|
import com.cloud.projects.dao.ProjectAccountJoinDao;
|
||||||
import com.cloud.projects.dao.ProjectDao;
|
import com.cloud.projects.dao.ProjectDao;
|
||||||
import com.cloud.projects.dao.ProjectInvitationDao;
|
import com.cloud.projects.dao.ProjectInvitationDao;
|
||||||
import com.cloud.projects.dao.ProjectJoinDao;
|
import com.cloud.projects.dao.ProjectJoinDao;
|
||||||
@ -117,6 +119,8 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||||||
@Inject
|
@Inject
|
||||||
private ProjectAccountDao _projectAccountDao;
|
private ProjectAccountDao _projectAccountDao;
|
||||||
@Inject
|
@Inject
|
||||||
|
private ProjectAccountJoinDao _projectAccountJoinDao;
|
||||||
|
@Inject
|
||||||
private AccountDao _accountDao;
|
private AccountDao _accountDao;
|
||||||
@Inject
|
@Inject
|
||||||
private ConfigurationDao _configDao;
|
private ConfigurationDao _configDao;
|
||||||
@ -762,7 +766,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<List<? extends ProjectAccount>, Integer> listProjectAccounts(long projectId, String accountName, String role, Long startIndex, Long pageSizeVal) {
|
public Pair<List<ProjectAccountJoinVO>, Integer> listProjectAccounts(long projectId, String accountName, String role, Long startIndex, Long pageSizeVal) {
|
||||||
Account caller = UserContext.current().getCaller();
|
Account caller = UserContext.current().getCaller();
|
||||||
|
|
||||||
//check that the project exists
|
//check that the project exists
|
||||||
@ -777,19 +781,17 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||||||
throw new PermissionDeniedException("Account " + caller + " is not authorized to list users of the project id=" + projectId);
|
throw new PermissionDeniedException("Account " + caller + " is not authorized to list users of the project id=" + projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Filter searchFilter = new Filter(ProjectAccountVO.class, "id", false, startIndex, pageSizeVal);
|
Filter searchFilter = new Filter(ProjectAccountJoinVO.class, "id", false, startIndex, pageSizeVal);
|
||||||
SearchBuilder<ProjectAccountVO> sb = _projectAccountDao.createSearchBuilder();
|
SearchBuilder<ProjectAccountJoinVO> sb = _projectAccountJoinDao.createSearchBuilder();
|
||||||
sb.and("accountRole", sb.entity().getAccountRole(), Op.EQ);
|
sb.and("accountRole", sb.entity().getAccountRole(), Op.EQ);
|
||||||
sb.and("projectId", sb.entity().getProjectId(), Op.EQ);
|
sb.and("projectId", sb.entity().getProjectId(), Op.EQ);
|
||||||
|
|
||||||
SearchBuilder<AccountVO> accountSearch;
|
SearchBuilder<AccountVO> accountSearch;
|
||||||
if (accountName != null) {
|
if (accountName != null) {
|
||||||
accountSearch = _accountDao.createSearchBuilder();
|
sb.and("accountName", sb.entity().getAccountName(), Op.EQ);
|
||||||
accountSearch.and("accountName", accountSearch.entity().getAccountName(), SearchCriteria.Op.EQ);
|
|
||||||
sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchCriteria<ProjectAccountVO> sc = sb.create();
|
SearchCriteria<ProjectAccountJoinVO> sc = sb.create();
|
||||||
|
|
||||||
sc.setParameters("projectId", projectId);
|
sc.setParameters("projectId", projectId);
|
||||||
|
|
||||||
@ -798,11 +800,10 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (accountName != null) {
|
if (accountName != null) {
|
||||||
sc.setJoinParameters("accountSearch", "accountName", accountName);
|
sc.setParameters("accountName", accountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<List<ProjectAccountVO>, Integer> result = _projectAccountDao.searchAndCount(sc, searchFilter);
|
return _projectAccountJoinDao.searchAndCount(sc, searchFilter);
|
||||||
return new Pair<List<? extends ProjectAccount>, Integer>(result.first(), result.second());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectInvitation createAccountInvitation(Project project, Long accountId) {
|
public ProjectInvitation createAccountInvitation(Project project, Long accountId) {
|
||||||
|
|||||||
33
server/src/com/cloud/projects/dao/ProjectAccountJoinDao.java
Normal file
33
server/src/com/cloud/projects/dao/ProjectAccountJoinDao.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with the License. You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing,
|
||||||
|
// software distributed under the License is distributed on an
|
||||||
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
// KIND, either express or implied. See the License for the
|
||||||
|
// specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
package com.cloud.projects.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.api.response.ProjectAccountResponse;
|
||||||
|
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
|
||||||
|
import com.cloud.projects.ProjectAccount;
|
||||||
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
|
public interface ProjectAccountJoinDao extends GenericDao<ProjectAccountJoinVO, Long> {
|
||||||
|
|
||||||
|
ProjectAccountResponse newProjectAccountResponse(ProjectAccountJoinVO proj);
|
||||||
|
|
||||||
|
ProjectAccountJoinVO newProjectAccountView(ProjectAccount proj);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with the License. You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing,
|
||||||
|
// software distributed under the License is distributed on an
|
||||||
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
// KIND, either express or implied. See the License for the
|
||||||
|
// specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
package com.cloud.projects.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Local;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.api.response.ProjectAccountResponse;
|
||||||
|
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
|
||||||
|
import com.cloud.projects.ProjectAccount;
|
||||||
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
|
||||||
|
@Local(value={ProjectAccountJoinDao.class})
|
||||||
|
public class ProjectAccountJoinDaoImpl extends GenericDaoBase<ProjectAccountJoinVO, Long> implements ProjectAccountJoinDao {
|
||||||
|
public static final Logger s_logger = Logger.getLogger(ProjectAccountJoinDaoImpl.class);
|
||||||
|
|
||||||
|
|
||||||
|
private SearchBuilder<ProjectAccountJoinVO> vrIdSearch;
|
||||||
|
|
||||||
|
protected ProjectAccountJoinDaoImpl() {
|
||||||
|
|
||||||
|
vrIdSearch = createSearchBuilder();
|
||||||
|
vrIdSearch.and("accountId", vrIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||||
|
vrIdSearch.and("projectId", vrIdSearch.entity().getProjectId(), SearchCriteria.Op.EQ);
|
||||||
|
vrIdSearch.done();
|
||||||
|
|
||||||
|
this._count = "select count(distinct id) from project_account_view WHERE ";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProjectAccountResponse newProjectAccountResponse(ProjectAccountJoinVO proj) {
|
||||||
|
ProjectAccountResponse projectAccountResponse = new ProjectAccountResponse();
|
||||||
|
|
||||||
|
projectAccountResponse.setProjectId(proj.getProjectUuid());
|
||||||
|
projectAccountResponse.setProjectName(proj.getProjectName());
|
||||||
|
|
||||||
|
projectAccountResponse.setAccountId(proj.getAccountUuid());
|
||||||
|
projectAccountResponse.setAccountName(proj.getAccountName());
|
||||||
|
projectAccountResponse.setAccountType(proj.getAccountType());
|
||||||
|
projectAccountResponse.setRole(proj.getAccountRole().toString());
|
||||||
|
projectAccountResponse.setDomainId(proj.getDomainUuid());
|
||||||
|
projectAccountResponse.setDomainName(proj.getDomainName());
|
||||||
|
|
||||||
|
projectAccountResponse.setObjectName("projectaccount");
|
||||||
|
|
||||||
|
return projectAccountResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProjectAccountJoinVO newProjectAccountView(ProjectAccount proj) {
|
||||||
|
SearchCriteria<ProjectAccountJoinVO> sc = vrIdSearch.create();
|
||||||
|
sc.setParameters("accountId", proj.getAccountId());
|
||||||
|
sc.setParameters("projectId", proj.getProjectId());
|
||||||
|
List<ProjectAccountJoinVO> grps = searchIncludingRemoved(sc, null, null, false);
|
||||||
|
assert grps != null && grps.size() == 1 : "No project account found for account id = " + proj.getAccountId() + " and project id = " + proj.getProjectId();
|
||||||
|
return grps.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -35,4 +35,6 @@ public interface UserAccountJoinDao extends GenericDao<UserAccountJoinVO, Long>
|
|||||||
|
|
||||||
List<UserAccountJoinVO> searchByIds(Long... ids);
|
List<UserAccountJoinVO> searchByIds(Long... ids);
|
||||||
|
|
||||||
|
List<UserAccountJoinVO> searchByAccountId(Long accountId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,6 +46,8 @@ public class UserAccountJoinDaoImpl extends GenericDaoBase<UserAccountJoinVO, Lo
|
|||||||
|
|
||||||
private SearchBuilder<UserAccountJoinVO> vrIdSearch;
|
private SearchBuilder<UserAccountJoinVO> vrIdSearch;
|
||||||
|
|
||||||
|
private SearchBuilder<UserAccountJoinVO> vrAcctIdSearch;
|
||||||
|
|
||||||
|
|
||||||
protected UserAccountJoinDaoImpl() {
|
protected UserAccountJoinDaoImpl() {
|
||||||
|
|
||||||
@ -57,6 +59,11 @@ public class UserAccountJoinDaoImpl extends GenericDaoBase<UserAccountJoinVO, Lo
|
|||||||
vrIdSearch.and("id", vrIdSearch.entity().getId(), SearchCriteria.Op.EQ);
|
vrIdSearch.and("id", vrIdSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||||
vrIdSearch.done();
|
vrIdSearch.done();
|
||||||
|
|
||||||
|
vrAcctIdSearch = createSearchBuilder();
|
||||||
|
vrAcctIdSearch.and("accountid", vrAcctIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||||
|
vrAcctIdSearch.done();
|
||||||
|
|
||||||
|
|
||||||
this._count = "select count(distinct id) from user_view WHERE ";
|
this._count = "select count(distinct id) from user_view WHERE ";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,5 +125,14 @@ public class UserAccountJoinDaoImpl extends GenericDaoBase<UserAccountJoinVO, Lo
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserAccountJoinVO> searchByAccountId(Long accountId) {
|
||||||
|
SearchCriteria<UserAccountJoinVO> sc = vrAcctIdSearch.create();
|
||||||
|
sc.setParameters("accountId", accountId);
|
||||||
|
return searchIncludingRemoved(sc, null, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import java.util.Map;
|
|||||||
import javax.ejb.Local;
|
import javax.ejb.Local;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO;
|
||||||
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
import org.apache.cloudstack.api.view.vo.ProjectJoinVO;
|
||||||
|
|
||||||
import com.cloud.exception.ConcurrentOperationException;
|
import com.cloud.exception.ConcurrentOperationException;
|
||||||
@ -108,7 +109,7 @@ public class MockProjectManagerImpl implements ProjectManager, Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<List<? extends ProjectAccount>, Integer> listProjectAccounts(long projectId,
|
public Pair<List<ProjectAccountJoinVO>, Integer> listProjectAccounts(long projectId,
|
||||||
String accountName, String role, Long startIndex, Long pageSizeVal) {
|
String accountName, String role, Long startIndex, Long pageSizeVal) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -2923,3 +2923,24 @@ inner join project_account on projects.id = project_account.project_id and proje
|
|||||||
inner join account on account.id = project_account.account_id
|
inner join account on account.id = project_account.account_id
|
||||||
left join resource_tags on resource_tags.resource_id = projects.id and resource_tags.resource_type = "Project"
|
left join resource_tags on resource_tags.resource_id = projects.id and resource_tags.resource_type = "Project"
|
||||||
left join project_account pacct on projects.id = pacct.project_id;
|
left join project_account pacct on projects.id = pacct.project_id;
|
||||||
|
|
||||||
|
DROP VIEW IF EXISTS `cloud`.`project_account_view`;
|
||||||
|
CREATE VIEW project_account_view AS
|
||||||
|
select
|
||||||
|
project_account.id,
|
||||||
|
account.id account_id,
|
||||||
|
account.uuid account_uuid,
|
||||||
|
account.account_name,
|
||||||
|
account.type account_type,
|
||||||
|
project_account.account_role,
|
||||||
|
projects.id project_id,
|
||||||
|
projects.uuid project_uuid,
|
||||||
|
projects.name project_name,
|
||||||
|
domain.id domain_id,
|
||||||
|
domain.uuid domain_uuid,
|
||||||
|
domain.name domain_name,
|
||||||
|
domain.path domain_path
|
||||||
|
from project_account
|
||||||
|
inner join account on project_account.account_id = account.id
|
||||||
|
inner join domain on account.domain_id=domain.id
|
||||||
|
inner join projects on projects.id = project_account.project_id;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user