Skip to content

Commit fd43cf1

Browse files
author
Alena Prokharchyk
committed
Revert "CLOUDSTACK-5872: Async response from addAccountToProject doesn't contain useful information"
This reverts commit ebcaec8. Reverting as it breaks API compatibility
1 parent 6726b7f commit fd43cf1

7 files changed

Lines changed: 38 additions & 42 deletions

File tree

api/src/com/cloud/projects/ProjectService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public interface ProjectService {
6969

7070
Project updateProject(long id, String displayText, String newOwnerName) throws ResourceAllocationException;
7171

72-
Project addAccountToProject(long projectId, String accountName, String email);
72+
boolean addAccountToProject(long projectId, String accountName, String email);
7373

74-
Project deleteAccountFromProject(long projectId, String accountName);
74+
boolean deleteAccountFromProject(long projectId, String accountName);
7575

76-
Project updateInvitation(long projectId, String accountName, String token, boolean accept);
76+
boolean updateInvitation(long projectId, String accountName, String token, boolean accept);
7777

7878
Project activateProject(long projectId);
7979

api/src/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ public void execute() {
8888
}
8989

9090
CallContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName);
91-
Project project = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail());
92-
if (project != null) {
93-
ProjectResponse response = _responseGenerator.createProjectResponse(project);
94-
response.setResponseName(getCommandName());
91+
boolean result = _projectService.addAccountToProject(getProjectId(), getAccountName(), getEmail());
92+
if (result) {
93+
SuccessResponse response = new SuccessResponse(getCommandName());
9594
this.setResponseObject(response);
9695
} else {
9796
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add account to the project");

api/src/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ public String getAccountName() {
7777
@Override
7878
public void execute() {
7979
CallContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName);
80-
Project project = _projectService.deleteAccountFromProject(projectId, accountName);
81-
if (project != null) {
82-
ProjectResponse response = _responseGenerator.createProjectResponse(project);
83-
response.setResponseName(getCommandName());
80+
boolean result = _projectService.deleteAccountFromProject(projectId, accountName);
81+
if (result) {
82+
SuccessResponse response = new SuccessResponse(getCommandName());
8483
this.setResponseObject(response);
8584
} else {
8685
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete account from the project");

api/src/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.project;
1818

19-
import com.cloud.projects.Project;
2019
import org.apache.log4j.Logger;
2120

2221
import org.apache.cloudstack.api.APICommand;
@@ -95,10 +94,9 @@ public long getEntityOwnerId() {
9594
@Override
9695
public void execute() {
9796
CallContext.current().setEventDetails("Project id: " + projectId + "; accountName " + accountName + "; accept " + getAccept());
98-
Project project = _projectService.updateInvitation(projectId, accountName, token, getAccept());
99-
if (project != null) {
100-
ProjectResponse response = _responseGenerator.createProjectResponse(project);
101-
response.setResponseName(getCommandName());
97+
boolean result = _projectService.updateInvitation(projectId, accountName, token, getAccept());
98+
if (result) {
99+
SuccessResponse response = new SuccessResponse(getCommandName());
102100
this.setResponseObject(response);
103101
} else {
104102
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to join the project");

server/src/com/cloud/projects/ProjectManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface ProjectManager extends ProjectService {
2525

2626
boolean canModifyProjectAccount(Account caller, long accountId);
2727

28-
Project deleteAccountFromProject(long projectId, long accountId);
28+
boolean deleteAccountFromProject(long projectId, long accountId);
2929

3030
List<Long> listPermittedProjectAccounts(long accountId);
3131

server/src/com/cloud/projects/ProjectManagerImpl.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ public ProjectAccount assignAccountToProject(Project project, long accountId, Pr
373373

374374
@Override
375375
@DB
376-
public Project deleteAccountFromProject(final long projectId, final long accountId) {
377-
return Transaction.execute(new TransactionCallback<Project>() {
376+
public boolean deleteAccountFromProject(final long projectId, final long accountId) {
377+
return Transaction.execute(new TransactionCallback<Boolean>() {
378378
@Override
379-
public Project doInTransaction(TransactionStatus status) {
379+
public Boolean doInTransaction(TransactionStatus status) {
380380
boolean success = true;
381381

382382
//remove account
@@ -392,7 +392,7 @@ public Project doInTransaction(TransactionStatus status) {
392392
}
393393
}
394394

395-
return success ? getProject(projectAccount.getProjectId()) : null;
395+
return success;
396396
}
397397
});
398398
}
@@ -514,7 +514,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws Resour
514514

515515
@Override
516516
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_ADD, eventDescription = "adding account to project", async = true)
517-
public Project addAccountToProject(long projectId, String accountName, String email) {
517+
public boolean addAccountToProject(long projectId, String accountName, String email) {
518518
Account caller = CallContext.current().getCallingAccount();
519519

520520
//check that the project exists
@@ -556,7 +556,7 @@ public Project addAccountToProject(long projectId, String accountName, String em
556556
ProjectAccount projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, account.getId());
557557
if (projectAccount != null) {
558558
s_logger.debug("Account " + accountName + " already added to the project id=" + projectId);
559-
return project;
559+
return true;
560560
}
561561
}
562562

@@ -567,41 +567,41 @@ public Project addAccountToProject(long projectId, String accountName, String em
567567
throw new InvalidParameterValueException("Account information is required for assigning account to the project");
568568
}
569569
if (assignAccountToProject(project, account.getId(), ProjectAccount.Role.Regular) != null) {
570-
return project;
570+
return true;
571571
} else {
572572
s_logger.warn("Failed to add account " + accountName + " to project id=" + projectId);
573-
return null;
573+
return false;
574574
}
575575
}
576576
}
577577

578-
private Project inviteAccountToProject(Project project, Account account, String email) {
578+
private boolean inviteAccountToProject(Project project, Account account, String email) {
579579
if (account != null) {
580580
if (createAccountInvitation(project, account.getId()) != null) {
581-
return project;
581+
return true;
582582
} else {
583583
s_logger.warn("Failed to generate invitation for account " + account.getAccountName() + " to project id=" + project);
584-
return null;
584+
return false;
585585
}
586586
}
587587

588588
if (email != null) {
589589
//generate the token
590590
String token = generateToken(10);
591591
if (generateTokenBasedInvitation(project, email, token) != null) {
592-
return project;
592+
return true;
593593
} else {
594594
s_logger.warn("Failed to generate invitation for email " + email + " to project id=" + project);
595-
return null;
595+
return false;
596596
}
597597
}
598598

599-
return null;
599+
return false;
600600
}
601601

602602
@Override
603603
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_REMOVE, eventDescription = "removing account from project", async = true)
604-
public Project deleteAccountFromProject(long projectId, String accountName) {
604+
public boolean deleteAccountFromProject(long projectId, String accountName) {
605605
Account caller = CallContext.current().getCallingAccount();
606606

607607
//check that the project exists
@@ -725,7 +725,7 @@ private boolean expireInvitation(ProjectInvitationVO invite) {
725725
@Override
726726
@DB
727727
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_INVITATION_UPDATE, eventDescription = "updating project invitation", async = true)
728-
public Project updateInvitation(final long projectId, String accountName, String token, final boolean accept) {
728+
public boolean updateInvitation(final long projectId, String accountName, String token, final boolean accept) {
729729
Account caller = CallContext.current().getCallingAccount();
730730
Long accountId = null;
731731
boolean result = true;
@@ -806,7 +806,7 @@ public Boolean doInTransaction(TransactionStatus status) {
806806
throw new InvalidParameterValueException("Unable to find invitation for account name=" + accountName + " to the project id=" + projectId);
807807
}
808808

809-
return result ? project : null;
809+
return result;
810810
}
811811

812812
@Override

server/test/com/cloud/projects/MockProjectManagerImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,21 @@ public Project updateProject(long id, String displayText, String newOwnerName) t
8787
}
8888

8989
@Override
90-
public Project addAccountToProject(long projectId, String accountName, String email) {
90+
public boolean addAccountToProject(long projectId, String accountName, String email) {
9191
// TODO Auto-generated method stub
92-
return null;
92+
return false;
9393
}
9494

9595
@Override
96-
public Project deleteAccountFromProject(long projectId, String accountName) {
96+
public boolean deleteAccountFromProject(long projectId, String accountName) {
9797
// TODO Auto-generated method stub
98-
return null;
98+
return false;
9999
}
100100

101101
@Override
102-
public Project updateInvitation(long projectId, String accountName, String token, boolean accept) {
102+
public boolean updateInvitation(long projectId, String accountName, String token, boolean accept) {
103103
// TODO Auto-generated method stub
104-
return null;
104+
return false;
105105
}
106106

107107
@Override
@@ -165,9 +165,9 @@ public boolean canModifyProjectAccount(Account caller, long accountId) {
165165
}
166166

167167
@Override
168-
public Project deleteAccountFromProject(long projectId, long accountId) {
168+
public boolean deleteAccountFromProject(long projectId, long accountId) {
169169
// TODO Auto-generated method stub
170-
return null;
170+
return false;
171171
}
172172

173173
@Override

0 commit comments

Comments
 (0)