From 472f4f91b9af18802d34e3a8631441b1752c18f3 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Tue, 11 Dec 2012 22:36:25 -0800 Subject: [PATCH] Refactor ListProjectInvitationsCmd and ProjectInvitationResponse. --- .../com/cloud/projects/ProjectService.java | 3 +- .../cloudstack/api/ResponseGenerator.java | 3 + .../project/ListProjectInvitationsCmd.java | 12 +- .../response/ProjectInvitationResponse.java | 20 +- .../api/view/vo/ProjectInvitationJoinVO.java | 232 ++++++++++++++++++ server/src/com/cloud/api/ApiDBUtils.java | 15 ++ .../src/com/cloud/api/ApiResponseHelper.java | 33 ++- .../DefaultComponentLibrary.java | 2 + .../cloud/projects/ProjectManagerImpl.java | 20 +- .../dao/ProjectInvitationJoinDao.java | 29 +++ .../dao/ProjectInvitationJoinDaoImpl.java | 86 +++++++ .../projects/MockProjectManagerImpl.java | 3 +- setup/db/create-schema.sql | 24 ++ 13 files changed, 438 insertions(+), 44 deletions(-) create mode 100644 api/src/org/apache/cloudstack/api/view/vo/ProjectInvitationJoinVO.java create mode 100644 server/src/com/cloud/projects/dao/ProjectInvitationJoinDao.java create mode 100644 server/src/com/cloud/projects/dao/ProjectInvitationJoinDaoImpl.java diff --git a/api/src/com/cloud/projects/ProjectService.java b/api/src/com/cloud/projects/ProjectService.java index 1e58a9b8ab1..0f58ef915d4 100644 --- a/api/src/com/cloud/projects/ProjectService.java +++ b/api/src/com/cloud/projects/ProjectService.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO; +import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO; import org.apache.cloudstack.api.view.vo.ProjectJoinVO; import com.cloud.exception.ConcurrentOperationException; @@ -85,7 +86,7 @@ public interface ProjectService { Pair, Integer> listProjectAccounts(long projectId, String accountName, String role, Long startIndex, Long pageSizeVal); - Pair, Integer> listProjectInvitations(Long id, Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal, boolean isRecursive, + Pair, Integer> listProjectInvitations(Long id, Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal, boolean isRecursive, boolean listAll); boolean updateInvitation(long projectId, String accountName, String token, boolean accept); diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java index 97fd6d970e3..ccdf93ced1a 100644 --- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java +++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java @@ -154,6 +154,7 @@ import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO; import org.apache.cloudstack.api.view.vo.EventJoinVO; import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO; import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO; +import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO; import org.apache.cloudstack.api.view.vo.ProjectJoinVO; import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO; import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO; @@ -309,6 +310,8 @@ public interface ResponseGenerator { ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite); + List createProjectInvitationResponse(ProjectInvitationJoinVO... invites); + SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine systemVM); SwiftResponse createSwiftResponse(Swift swift); diff --git a/api/src/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java index 206a9a9e80f..6b6a7a7c39d 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java @@ -28,6 +28,8 @@ import org.apache.cloudstack.api.Implementation; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ProjectInvitationResponse; +import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO; + import com.cloud.projects.ProjectInvitation; import com.cloud.utils.Pair; @@ -83,15 +85,13 @@ public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd { @Override public void execute() { - Pair, Integer> invites = _projectService.listProjectInvitations(id, projectId, + Pair, Integer> invites = _projectService.listProjectInvitations(id, projectId, this.getAccountName(), this.getDomainId(), state, activeOnly, this.getStartIndex(), this.getPageSizeVal(), this.isRecursive(), this.listAll()); ListResponse response = new ListResponse(); - List projectInvitationResponses = new ArrayList(); - for (ProjectInvitation invite : invites.first()) { - ProjectInvitationResponse projectResponse = _responseGenerator.createProjectInvitationResponse(invite); - projectInvitationResponses.add(projectResponse); - } + List projectInvitationResponses = + _responseGenerator.createProjectInvitationResponse(invites.first().toArray(new ProjectInvitationJoinVO[invites.first().size()])); + response.setResponses(projectInvitationResponses, invites.second()); response.setResponseName(getCommandName()); diff --git a/api/src/org/apache/cloudstack/api/response/ProjectInvitationResponse.java b/api/src/org/apache/cloudstack/api/response/ProjectInvitationResponse.java index 80202a51d4c..1c616d1e866 100644 --- a/api/src/org/apache/cloudstack/api/response/ProjectInvitationResponse.java +++ b/api/src/org/apache/cloudstack/api/response/ProjectInvitationResponse.java @@ -23,18 +23,18 @@ import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; @SuppressWarnings("unused") -public class ProjectInvitationResponse extends BaseResponse implements ControlledEntityResponse{ +public class ProjectInvitationResponse extends BaseResponse implements ControlledViewEntityResponse{ @SerializedName(ApiConstants.ID) @Param(description="the id of the invitation") - private IdentityProxy id = new IdentityProxy("project_invitations"); + private String id; @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the id of the project") - private IdentityProxy projectId = new IdentityProxy("projects"); + private String projectId; @SerializedName(ApiConstants.PROJECT) @Param(description="the name of the project") private String projectName; @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain id the project belongs to") - private IdentityProxy domainId = new IdentityProxy("domain"); + private String domainId; @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name where the project belongs to") private String domainName; @@ -48,20 +48,20 @@ public class ProjectInvitationResponse extends BaseResponse implements Controlle @SerializedName(ApiConstants.STATE) @Param(description="the invitation state") private String invitationState; - public void setId(Long id) { - this.id.setValue(id); + public void setId(String id) { + this.id = id; } - public void setProjectId(Long projectId) { - this.projectId.setValue(projectId); + public void setProjectId(String projectId) { + this.projectId = projectId; } public void setProjectName(String projectName) { this.projectName = projectName; } - public void setDomainId(Long domainId) { - this.domainId.setValue(domainId); + public void setDomainId(String domainId) { + this.domainId = domainId; } public void setDomainName(String domain) { diff --git a/api/src/org/apache/cloudstack/api/view/vo/ProjectInvitationJoinVO.java b/api/src/org/apache/cloudstack/api/view/vo/ProjectInvitationJoinVO.java new file mode 100644 index 00000000000..b33df0428bb --- /dev/null +++ b/api/src/org/apache/cloudstack/api/view/vo/ProjectInvitationJoinVO.java @@ -0,0 +1,232 @@ +// 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.utils.db.GenericDao; +import com.cloud.vm.VirtualMachine.State; + +@Entity +@Table(name="project_invitation_view") +public class ProjectInvitationJoinVO extends BaseViewVO implements ControlledViewEntity { + + @Column(name="id", updatable=false, nullable = false) + private long id; + + @Column(name="uuid") + private String uuid; + + @Column(name = "email") + private String email; + + @Column(name = "state") + @Enumerated(value = EnumType.STRING) + private State state; + + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + @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="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 ProjectInvitationJoinVO() { + } + + @Override + public long getId() { + return id; + } + + + @Override + public void setId(long id) { + this.id = id; + + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + + @Override + public long getDomainId() { + return domainId; + } + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + @Override + public String getDomainUuid() { + return domainUuid; + } + + public void setDomainUuid(String domainUuid) { + this.domainUuid = domainUuid; + } + + @Override + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + + + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + @Override + public long getAccountId() { + return accountId; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @Override + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public long getProjectId() { + return projectId; + } + + public void setProjectId(long projectId) { + this.projectId = projectId; + } + + @Override + public String getProjectUuid() { + return projectUuid; + } + + public void setProjectUuid(String projectUuid) { + this.projectUuid = projectUuid; + } + + @Override + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + @Override + public String getAccountUuid() { + return accountUuid; + } + + public void setAccountUuid(String accountUuid) { + this.accountUuid = accountUuid; + } + + @Override + public short getAccountType() { + return accountType; + } + + public void setAccountType(short accountType) { + this.accountType = accountType; + } + + @Override + public String getDomainPath() { + return domainPath; + } + + public void setDomainPath(String domainPath) { + this.domainPath = domainPath; + } + + +} diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 459df8d91a6..d5cce52e5f9 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -27,6 +27,7 @@ import org.apache.cloudstack.api.response.DomainRouterResponse; import org.apache.cloudstack.api.response.EventResponse; import org.apache.cloudstack.api.response.InstanceGroupResponse; import org.apache.cloudstack.api.response.ProjectAccountResponse; +import org.apache.cloudstack.api.response.ProjectInvitationResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ResourceTagResponse; import org.apache.cloudstack.api.response.SecurityGroupResponse; @@ -36,6 +37,7 @@ import org.apache.cloudstack.api.view.vo.DomainRouterJoinVO; import org.apache.cloudstack.api.view.vo.EventJoinVO; import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO; import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO; +import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO; import org.apache.cloudstack.api.view.vo.ProjectJoinVO; import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO; import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO; @@ -118,8 +120,10 @@ import com.cloud.offerings.NetworkOfferingVO; import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.projects.Project; import com.cloud.projects.ProjectAccount; +import com.cloud.projects.ProjectInvitation; import com.cloud.projects.ProjectService; import com.cloud.projects.dao.ProjectAccountJoinDao; +import com.cloud.projects.dao.ProjectInvitationJoinDao; import com.cloud.projects.dao.ProjectJoinDao; import com.cloud.resource.ResourceManager; import com.cloud.server.Criteria; @@ -270,6 +274,7 @@ public class ApiDBUtils { private static UserAccountJoinDao _userAccountJoinDao; private static ProjectJoinDao _projectJoinDao; private static ProjectAccountJoinDao _projectAccountJoinDao; + private static ProjectInvitationJoinDao _projectInvitationJoinDao; static { _ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name); @@ -345,6 +350,7 @@ public class ApiDBUtils { _userAccountJoinDao = locator.getDao(UserAccountJoinDao.class); _projectJoinDao = locator.getDao(ProjectJoinDao.class); _projectAccountJoinDao = locator.getDao(ProjectAccountJoinDao.class); + _projectInvitationJoinDao = locator.getDao(ProjectInvitationJoinDao.class); // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned @@ -1052,4 +1058,13 @@ public class ApiDBUtils { return _projectAccountJoinDao.newProjectAccountView(proj); } + public static ProjectInvitationResponse newProjectInvitationResponse(ProjectInvitationJoinVO proj) { + return _projectInvitationJoinDao.newProjectInvitationResponse(proj); + } + + public static ProjectInvitationJoinVO newProjectInvitationView(ProjectInvitation proj) { + return _projectInvitationJoinDao.newProjectInvitationView(proj); + } + + } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 604df8191da..1e2b87d0941 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -117,6 +117,7 @@ import org.apache.cloudstack.api.view.vo.ControlledViewEntity; import org.apache.cloudstack.api.view.vo.EventJoinVO; import org.apache.cloudstack.api.view.vo.InstanceGroupJoinVO; import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO; +import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO; import org.apache.cloudstack.api.view.vo.ProjectJoinVO; import org.apache.cloudstack.api.view.vo.ResourceTagJoinVO; import org.apache.cloudstack.api.view.vo.SecurityGroupJoinVO; @@ -2873,26 +2874,22 @@ public class ApiResponseHelper implements ResponseGenerator { @Override public ProjectInvitationResponse createProjectInvitationResponse(ProjectInvitation invite) { - ProjectInvitationResponse response = new ProjectInvitationResponse(); - response.setId(invite.getId()); - response.setProjectId(invite.getProjectId()); - response.setProjectName(ApiDBUtils.findProjectById(invite.getProjectId()).getName()); - response.setInvitationState(invite.getState().toString()); - - if (invite.getForAccountId() != null) { - Account account = ApiDBUtils.findAccountById(invite.getForAccountId()); - response.setAccountName(account.getAccountName()); - - } else { - response.setEmail(invite.getEmail()); - } - - populateDomain(response, invite.getInDomainId()); - - response.setObjectName("projectinvitation"); - return response; + ProjectInvitationJoinVO vInvite = ApiDBUtils.newProjectInvitationView(invite); + return ApiDBUtils.newProjectInvitationResponse(vInvite); } + + + @Override + public List createProjectInvitationResponse(ProjectInvitationJoinVO... invites) { + List respList = new ArrayList(); + for (ProjectInvitationJoinVO v : invites){ + respList.add(ApiDBUtils.newProjectInvitationResponse(v)); + } + return respList; + } + + @Override public SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm) { SystemVmInstanceResponse vmResponse = new SystemVmInstanceResponse(); diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index 0dcdfd2e10e..2dd46fd9ad9 100755 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -139,6 +139,7 @@ import com.cloud.projects.ProjectManagerImpl; import com.cloud.projects.dao.ProjectAccountDaoImpl; import com.cloud.projects.dao.ProjectDaoImpl; import com.cloud.projects.dao.ProjectInvitationDaoImpl; +import com.cloud.projects.dao.ProjectInvitationJoinDaoImpl; import com.cloud.projects.dao.ProjectJoinDaoImpl; import com.cloud.resource.ResourceManagerImpl; import com.cloud.resourcelimit.ResourceLimitManagerImpl; @@ -233,6 +234,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com addDao("UserAccountJoinDao", UserAccountJoinDaoImpl.class); addDao("ProjectJoinDao", ProjectJoinDaoImpl.class); addDao("ProjectAccountJoinDao", ProjectAccountJoinDaoImpl.class); + addDao("ProjectInvitationJoinDao", ProjectInvitationJoinDaoImpl.class); ComponentInfo> info = addDao("ServiceOfferingDao", ServiceOfferingDaoImpl.class); info.addParameter("cache.size", "50"); info.addParameter("cache.time.to.live", "600"); diff --git a/server/src/com/cloud/projects/ProjectManagerImpl.java b/server/src/com/cloud/projects/ProjectManagerImpl.java index c84395d6227..7c97af2699d 100755 --- a/server/src/com/cloud/projects/ProjectManagerImpl.java +++ b/server/src/com/cloud/projects/ProjectManagerImpl.java @@ -39,6 +39,7 @@ import javax.mail.internet.InternetAddress; import javax.naming.ConfigurationException; import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO; +import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO; import org.apache.cloudstack.api.view.vo.ProjectJoinVO; import org.apache.cloudstack.api.view.vo.UserVmJoinVO; import org.apache.log4j.Logger; @@ -64,6 +65,7 @@ import com.cloud.projects.dao.ProjectAccountDao; import com.cloud.projects.dao.ProjectAccountJoinDao; import com.cloud.projects.dao.ProjectDao; import com.cloud.projects.dao.ProjectInvitationDao; +import com.cloud.projects.dao.ProjectInvitationJoinDao; import com.cloud.projects.dao.ProjectJoinDao; import com.cloud.server.ResourceTag.TaggedResourceType; import com.cloud.tags.ResourceTagVO; @@ -127,6 +129,8 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ @Inject private ProjectInvitationDao _projectInvitationDao; @Inject + private ProjectInvitationJoinDao _projectInvitationJoinDao; + @Inject protected ResourceTagDao _resourceTagDao; protected boolean _invitationRequired = false; @@ -875,7 +879,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ } @Override - public Pair, Integer> listProjectInvitations(Long id, Long projectId, + public Pair, Integer> listProjectInvitations(Long id, Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal, boolean isRecursive, boolean listAll) { Account caller = UserContext.current().getCaller(); List permittedAccounts = new ArrayList(); @@ -886,17 +890,17 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ isRecursive = domainIdRecursiveListProject.second(); ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); - Filter searchFilter = new Filter(ProjectInvitationVO.class, "id", true, startIndex, pageSizeVal); - SearchBuilder sb = _projectInvitationDao.createSearchBuilder(); - _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + Filter searchFilter = new Filter(ProjectInvitationJoinVO.class, "id", true, startIndex, pageSizeVal); + SearchBuilder 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); - SearchCriteria sc = sb.create(); - _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + SearchCriteria sc = sb.create(); + _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); if (projectId != null){ @@ -916,8 +920,8 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ sc.setParameters("created", new Date((DateUtil.currentGMTTime().getTime()) - _invitationTimeOut)); } - Pair, Integer> result = _projectInvitationDao.searchAndCount(sc, searchFilter); - return new Pair, Integer>(result.first(), result.second()); + return _projectInvitationJoinDao.searchAndCount(sc, searchFilter); + } @Override @DB diff --git a/server/src/com/cloud/projects/dao/ProjectInvitationJoinDao.java b/server/src/com/cloud/projects/dao/ProjectInvitationJoinDao.java new file mode 100644 index 00000000000..2ee7de095f0 --- /dev/null +++ b/server/src/com/cloud/projects/dao/ProjectInvitationJoinDao.java @@ -0,0 +1,29 @@ +// 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 org.apache.cloudstack.api.response.ProjectInvitationResponse; +import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO; +import com.cloud.projects.ProjectInvitation; +import com.cloud.utils.db.GenericDao; + +public interface ProjectInvitationJoinDao extends GenericDao { + + ProjectInvitationResponse newProjectInvitationResponse(ProjectInvitationJoinVO proj); + + ProjectInvitationJoinVO newProjectInvitationView(ProjectInvitation proj); +} diff --git a/server/src/com/cloud/projects/dao/ProjectInvitationJoinDaoImpl.java b/server/src/com/cloud/projects/dao/ProjectInvitationJoinDaoImpl.java new file mode 100644 index 00000000000..0ee0ef8fce9 --- /dev/null +++ b/server/src/com/cloud/projects/dao/ProjectInvitationJoinDaoImpl.java @@ -0,0 +1,86 @@ +// 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.ProjectInvitationResponse; +import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO; + +import com.cloud.api.ApiDBUtils; +import com.cloud.projects.ProjectInvitation; +import com.cloud.user.Account; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Local(value={ProjectInvitationJoinDao.class}) +public class ProjectInvitationJoinDaoImpl extends GenericDaoBase implements ProjectInvitationJoinDao { + public static final Logger s_logger = Logger.getLogger(ProjectInvitationJoinDaoImpl.class); + + + private SearchBuilder vrIdSearch; + + protected ProjectInvitationJoinDaoImpl() { + + vrIdSearch = createSearchBuilder(); + vrIdSearch.and("id", vrIdSearch.entity().getId(), SearchCriteria.Op.EQ); + vrIdSearch.done(); + + this._count = "select count(distinct id) from project_invitation_view WHERE "; + } + + + + @Override + public ProjectInvitationResponse newProjectInvitationResponse(ProjectInvitationJoinVO invite) { + ProjectInvitationResponse response = new ProjectInvitationResponse(); + response.setId(invite.getUuid()); + response.setProjectId(invite.getProjectUuid()); + response.setProjectName(invite.getProjectName()); + response.setInvitationState(invite.getState().toString()); + + if (invite.getAccountName() != null) { + response.setAccountName(invite.getAccountName()); + } else { + response.setEmail(invite.getEmail()); + } + + response.setDomainId(invite.getDomainUuid()); + response.setDomainName(invite.getDomainName()); + + response.setObjectName("projectinvitation"); + return response; + } + + + + @Override + public ProjectInvitationJoinVO newProjectInvitationView(ProjectInvitation proj) { + SearchCriteria sc = vrIdSearch.create(); + sc.setParameters("id", proj.getId()); + List grps = searchIncludingRemoved(sc, null, null, false); + assert grps != null && grps.size() == 1 : "No project invitation found for id " + proj.getId(); + return grps.get(0); + } + + +} diff --git a/server/test/com/cloud/projects/MockProjectManagerImpl.java b/server/test/com/cloud/projects/MockProjectManagerImpl.java index 6529d12721e..3911ceb8eb3 100644 --- a/server/test/com/cloud/projects/MockProjectManagerImpl.java +++ b/server/test/com/cloud/projects/MockProjectManagerImpl.java @@ -23,6 +23,7 @@ import javax.ejb.Local; import javax.naming.ConfigurationException; import org.apache.cloudstack.api.view.vo.ProjectAccountJoinVO; +import org.apache.cloudstack.api.view.vo.ProjectInvitationJoinVO; import org.apache.cloudstack.api.view.vo.ProjectJoinVO; import com.cloud.exception.ConcurrentOperationException; @@ -116,7 +117,7 @@ public class MockProjectManagerImpl implements ProjectManager, Manager { } @Override - public Pair, Integer> listProjectInvitations(Long id, + public Pair, Integer> listProjectInvitations(Long id, Long projectId, String accountName, Long domainId, String state, boolean activeOnly, Long startIndex, Long pageSizeVal, boolean isRecursive, boolean listAll) { diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 8e8c448fdd8..9891371bbb2 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2944,3 +2944,27 @@ 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; + +DROP VIEW IF EXISTS `cloud`.`project_invitation_view`; +CREATE VIEW project_invitation_view AS +select +project_invitations.id, +project_invitations.uuid, +project_invitations.email, +project_invitations.created, +project_invitations.state, +projects.id project_id, +projects.uuid project_uuid, +projects.name project_name, +account.id account_id, +account.uuid account_uuid, +account.account_name, +account.type account_type, +domain.id domain_id, +domain.uuid domain_uuid, +domain.name domain_name, +domain.path domain_path +from project_invitations +left join account on project_invitations.account_id = account.id +left join domain on project_invitations.domain_id=domain.id +left join projects on projects.id = project_invitations.project_id;