Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 52B9F10AA9 for ; Thu, 6 Mar 2014 22:08:08 +0000 (UTC) Received: (qmail 11132 invoked by uid 500); 6 Mar 2014 22:06:59 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 10885 invoked by uid 500); 6 Mar 2014 22:06:53 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 10519 invoked by uid 99); 6 Mar 2014 22:06:45 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Mar 2014 22:06:45 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F2F5893FDF0; Thu, 6 Mar 2014 22:06:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mchen@apache.org To: commits@cloudstack.apache.org Date: Thu, 06 Mar 2014 22:06:54 -0000 Message-Id: <2a653b67ce2b409299ed14eb8c34431a@git.apache.org> In-Reply-To: <4ea5b3c85db3438ebfb801be6169eca8@git.apache.org> References: <4ea5b3c85db3438ebfb801be6169eca8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/50] [abbrv] git commit: updated refs/heads/rbac to 48e08fe CLOUDSTACK-5872: Async response from addAccountToProject doesn't contain useful information Signed-off-by: Daan Hoogland Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ebcaec86 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ebcaec86 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ebcaec86 Branch: refs/heads/rbac Commit: ebcaec8632dbd92c071317f3190915244a287afb Parents: 9045e41 Author: David Grizzanti Authored: Fri Jan 31 09:37:12 2014 -0500 Committer: Daan Hoogland Committed: Mon Mar 3 11:02:34 2014 +0100 ---------------------------------------------------------------------- api/src/com/cloud/projects/ProjectService.java | 6 ++-- .../user/account/AddAccountToProjectCmd.java | 7 ++-- .../account/DeleteAccountFromProjectCmd.java | 7 ++-- .../project/UpdateProjectInvitationCmd.java | 8 +++-- .../src/com/cloud/projects/ProjectManager.java | 2 +- .../com/cloud/projects/ProjectManagerImpl.java | 34 ++++++++++---------- .../cloud/projects/MockProjectManagerImpl.java | 16 ++++----- 7 files changed, 42 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ebcaec86/api/src/com/cloud/projects/ProjectService.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/projects/ProjectService.java b/api/src/com/cloud/projects/ProjectService.java index dc882ef..53dd44b 100644 --- a/api/src/com/cloud/projects/ProjectService.java +++ b/api/src/com/cloud/projects/ProjectService.java @@ -69,11 +69,11 @@ public interface ProjectService { Project updateProject(long id, String displayText, String newOwnerName) throws ResourceAllocationException; - boolean addAccountToProject(long projectId, String accountName, String email); + Project addAccountToProject(long projectId, String accountName, String email); - boolean deleteAccountFromProject(long projectId, String accountName); + Project deleteAccountFromProject(long projectId, String accountName); - boolean updateInvitation(long projectId, String accountName, String token, boolean accept); + Project updateInvitation(long projectId, String accountName, String token, boolean accept); Project activateProject(long projectId); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ebcaec86/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java index ef36038..8372b05 100644 --- a/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java @@ -88,9 +88,10 @@ public class AddAccountToProjectCmd extends BaseAsyncCmd { } CallContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName); - boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail()); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); + Project project = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail()); + if (project != null) { + ProjectResponse response = _responseGenerator.createProjectResponse(project); + response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add account to the project"); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ebcaec86/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java b/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java index 5c89173..4c6721a 100644 --- a/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java @@ -77,9 +77,10 @@ public class DeleteAccountFromProjectCmd extends BaseAsyncCmd { @Override public void execute() { CallContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName); - boolean result = _projectService.deleteAccountFromProject(projectId, accountName); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); + Project project = _projectService.deleteAccountFromProject(projectId, accountName); + if (project != null) { + ProjectResponse response = _responseGenerator.createProjectResponse(project); + response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete account from the project"); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ebcaec86/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java b/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java index 79e3f8a..0ceb4ac 100644 --- a/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java @@ -16,6 +16,7 @@ // under the License. package org.apache.cloudstack.api.command.user.project; +import com.cloud.projects.Project; import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; @@ -94,9 +95,10 @@ public class UpdateProjectInvitationCmd extends BaseAsyncCmd { @Override public void execute() { CallContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName + "; accept " + getAccept()); - boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept()); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); + Project project = _projectService.updateInvitation(projectId, accountName, token, getAccept()); + if (project != null) { + ProjectResponse response = _responseGenerator.createProjectResponse(project); + response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to join the project"); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ebcaec86/server/src/com/cloud/projects/ProjectManager.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/projects/ProjectManager.java b/server/src/com/cloud/projects/ProjectManager.java index f568146..538104b 100644 --- a/server/src/com/cloud/projects/ProjectManager.java +++ b/server/src/com/cloud/projects/ProjectManager.java @@ -25,7 +25,7 @@ public interface ProjectManager extends ProjectService { boolean canModifyProjectAccount(Account caller, long accountId); - boolean deleteAccountFromProject(long projectId, long accountId); + Project deleteAccountFromProject(long projectId, long accountId); List listPermittedProjectAccounts(long accountId); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ebcaec86/server/src/com/cloud/projects/ProjectManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/projects/ProjectManagerImpl.java b/server/src/com/cloud/projects/ProjectManagerImpl.java index 5a0ed1c..a3c7eda 100755 --- a/server/src/com/cloud/projects/ProjectManagerImpl.java +++ b/server/src/com/cloud/projects/ProjectManagerImpl.java @@ -373,10 +373,10 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager { @Override @DB - public boolean deleteAccountFromProject(final long projectId, final long accountId) { - return Transaction.execute(new TransactionCallback() { + public Project deleteAccountFromProject(final long projectId, final long accountId) { + return Transaction.execute(new TransactionCallback() { @Override - public Boolean doInTransaction(TransactionStatus status) { + public Project doInTransaction(TransactionStatus status) { boolean success = true; //remove account @@ -392,7 +392,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager { } } - return success; + return success ? getProject(projectAccount.getProjectId()) : null; } }); } @@ -514,7 +514,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager { @Override @ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_ADD, eventDescription = "adding account to project", async = true) - public boolean addAccountToProject(long projectId, String accountName, String email) { + public Project addAccountToProject(long projectId, String accountName, String email) { Account caller = CallContext.current().getCallingAccount(); //check that the project exists @@ -556,7 +556,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager { ProjectAccount projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, account.getId()); if (projectAccount != null) { s_logger.debug("Account " + accountName + " already added to the project id=" + projectId); - return true; + return project; } } @@ -567,21 +567,21 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager { throw new InvalidParameterValueException("Account information is required for assigning account to the project"); } if (assignAccountToProject(project, account.getId(), ProjectAccount.Role.Regular) != null) { - return true; + return project; } else { s_logger.warn("Failed to add account " + accountName + " to project id=" + projectId); - return false; + return null; } } } - private boolean inviteAccountToProject(Project project, Account account, String email) { + private Project inviteAccountToProject(Project project, Account account, String email) { if (account != null) { if (createAccountInvitation(project, account.getId()) != null) { - return true; + return project; } else { s_logger.warn("Failed to generate invitation for account " + account.getAccountName() + " to project id=" + project); - return false; + return null; } } @@ -589,19 +589,19 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager { //generate the token String token = generateToken(10); if (generateTokenBasedInvitation(project, email, token) != null) { - return true; + return project; } else { s_logger.warn("Failed to generate invitation for email " + email + " to project id=" + project); - return false; + return null; } } - return false; + return null; } @Override @ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE, eventDescription = "removing account from project", async = true) - public boolean deleteAccountFromProject(long projectId, String accountName) { + public Project deleteAccountFromProject(long projectId, String accountName) { Account caller = CallContext.current().getCallingAccount(); //check that the project exists @@ -725,7 +725,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager { @Override @DB @ActionEvent(eventType = EventTypes.EVENT_PROJECT_INVITATION_UPDATE, eventDescription = "updating project invitation", async = true) - public boolean updateInvitation(final long projectId, String accountName, String token, final boolean accept) { + public Project updateInvitation(final long projectId, String accountName, String token, final boolean accept) { Account caller = CallContext.current().getCallingAccount(); Long accountId = null; boolean result = true; @@ -806,7 +806,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager { throw new InvalidParameterValueException("Unable to find invitation for account name=" + accountName + " to the project id=" + projectId); } - return result; + return result ? project : null; } @Override http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ebcaec86/server/test/com/cloud/projects/MockProjectManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/projects/MockProjectManagerImpl.java b/server/test/com/cloud/projects/MockProjectManagerImpl.java index dc377ff..7afd671 100644 --- a/server/test/com/cloud/projects/MockProjectManagerImpl.java +++ b/server/test/com/cloud/projects/MockProjectManagerImpl.java @@ -87,21 +87,21 @@ public class MockProjectManagerImpl extends ManagerBase implements ProjectManage } @Override - public boolean addAccountToProject(long projectId, String accountName, String email) { + public Project addAccountToProject(long projectId, String accountName, String email) { // TODO Auto-generated method stub - return false; + return null; } @Override - public boolean deleteAccountFromProject(long projectId, String accountName) { + public Project deleteAccountFromProject(long projectId, String accountName) { // TODO Auto-generated method stub - return false; + return null; } @Override - public boolean updateInvitation(long projectId, String accountName, String token, boolean accept) { + public Project updateInvitation(long projectId, String accountName, String token, boolean accept) { // TODO Auto-generated method stub - return false; + return null; } @Override @@ -165,9 +165,9 @@ public class MockProjectManagerImpl extends ManagerBase implements ProjectManage } @Override - public boolean deleteAccountFromProject(long projectId, long accountId) { + public Project deleteAccountFromProject(long projectId, long accountId) { // TODO Auto-generated method stub - return false; + return null; } @Override