Skip to content

Commit d2922b9

Browse files
committed
Separate ListAccounts cmd to use two different views.
1 parent 312ff76 commit d2922b9

15 files changed

Lines changed: 115 additions & 67 deletions

File tree

‎api/src/org/apache/cloudstack/api/ResponseGenerator.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
public interface ResponseGenerator {
199199
UserResponse createUserResponse(UserAccount user);
200200

201-
AccountResponse createAccountResponse(Account account);
201+
AccountResponse createAccountResponse(ResponseView view, Account account);
202202

203203
DomainResponse createDomainResponse(Domain domain);
204204

@@ -317,7 +317,7 @@ LBHealthCheckResponse createLBHealthCheckPolicyResponse(List<? extends HealthChe
317317

318318
UserResponse createUserResponse(User user);
319319

320-
AccountResponse createUserAccountResponse(UserAccount user);
320+
AccountResponse createUserAccountResponse(ResponseView view, UserAccount user);
321321

322322
Long getSecurityGroupId(String groupName, long accountId);
323323

‎api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.account;
1818

19-
import com.cloud.user.Account;
20-
import com.cloud.user.UserAccount;
19+
import java.util.Collection;
20+
import java.util.Map;
21+
22+
import org.apache.log4j.Logger;
2123

2224
import org.apache.cloudstack.api.APICommand;
2325
import org.apache.cloudstack.api.ApiConstants;
2426
import org.apache.cloudstack.api.ApiErrorCode;
2527
import org.apache.cloudstack.api.BaseCmd;
2628
import org.apache.cloudstack.api.Parameter;
29+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2730
import org.apache.cloudstack.api.ServerApiException;
2831
import org.apache.cloudstack.api.response.AccountResponse;
2932
import org.apache.cloudstack.api.response.DomainResponse;
3033
import org.apache.cloudstack.context.CallContext;
3134

32-
import org.apache.log4j.Logger;
33-
34-
import java.util.Collection;
35-
import java.util.Map;
35+
import com.cloud.user.Account;
36+
import com.cloud.user.UserAccount;
3637

3738
@APICommand(name = "createAccount", description="Creates an account", responseObject=AccountResponse.class)
3839
public class CreateAccountCmd extends BaseCmd {
@@ -166,9 +167,9 @@ public void execute(){
166167
UserAccount userAccount = _accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(),
167168
getDomainId(), getNetworkDomain(), getDetails(), getAccountUUID(), getUserUUID());
168169
if (userAccount != null) {
169-
AccountResponse response = _responseGenerator.createUserAccountResponse(userAccount);
170+
AccountResponse response = _responseGenerator.createUserAccountResponse(ResponseView.Full, userAccount);
170171
response.setResponseName(getCommandName());
171-
this.setResponseObject(response);
172+
setResponseObject(response);
172173
} else {
173174
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a user account");
174175
}

‎api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@
1818

1919
import javax.inject.Inject;
2020

21+
import org.apache.log4j.Logger;
22+
2123
import org.apache.cloudstack.api.APICommand;
2224
import org.apache.cloudstack.api.ApiCommandJobType;
2325
import org.apache.cloudstack.api.ApiConstants;
2426
import org.apache.cloudstack.api.ApiErrorCode;
2527
import org.apache.cloudstack.api.BaseAsyncCmd;
2628
import org.apache.cloudstack.api.Parameter;
29+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2730
import org.apache.cloudstack.api.ServerApiException;
2831
import org.apache.cloudstack.api.response.AccountResponse;
2932
import org.apache.cloudstack.api.response.DomainResponse;
3033
import org.apache.cloudstack.context.CallContext;
3134
import org.apache.cloudstack.region.RegionService;
3235

33-
import org.apache.log4j.Logger;
34-
3536
import com.cloud.event.EventTypes;
3637
import com.cloud.exception.ConcurrentOperationException;
3738
import com.cloud.exception.ResourceUnavailableException;
@@ -120,9 +121,9 @@ public void execute() throws ConcurrentOperationException, ResourceUnavailableEx
120121
CallContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
121122
Account result = _regionService.disableAccount(this);
122123
if (result != null){
123-
AccountResponse response = _responseGenerator.createAccountResponse(result);
124+
AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
124125
response.setResponseName(getCommandName());
125-
this.setResponseObject(response);
126+
setResponseObject(response);
126127
} else {
127128
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, lockRequested == true ? "Failed to lock account" : "Failed to disable account" );
128129
}

‎api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818

1919
import javax.inject.Inject;
2020

21+
import org.apache.log4j.Logger;
22+
2123
import org.apache.cloudstack.api.APICommand;
2224
import org.apache.cloudstack.api.ApiConstants;
2325
import org.apache.cloudstack.api.ApiErrorCode;
2426
import org.apache.cloudstack.api.BaseCmd;
2527
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2629
import org.apache.cloudstack.api.ServerApiException;
2730
import org.apache.cloudstack.api.response.AccountResponse;
2831
import org.apache.cloudstack.api.response.DomainResponse;
2932
import org.apache.cloudstack.region.RegionService;
30-
import org.apache.log4j.Logger;
3133

3234
import com.cloud.user.Account;
3335

@@ -96,9 +98,9 @@ public long getEntityOwnerId() {
9698
public void execute(){
9799
Account result = _regionService.enableAccount(this);
98100
if (result != null){
99-
AccountResponse response = _responseGenerator.createAccountResponse(result);
101+
AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
100102
response.setResponseName(getCommandName());
101-
this.setResponseObject(response);
103+
setResponseObject(response);
102104
} else {
103105
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable account");
104106
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.admin.account;
18+
19+
import org.apache.cloudstack.api.APICommand;
20+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
21+
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
22+
import org.apache.cloudstack.api.response.AccountResponse;
23+
24+
@APICommand(name = "listAccounts", description = "Lists accounts and provides detailed account information for listed accounts", responseObject = AccountResponse.class, responseView = ResponseView.Full)
25+
public class ListAccountsCmdByAdmin extends ListAccountsCmd {
26+
}

‎api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121

2222
import javax.inject.Inject;
2323

24+
import org.apache.log4j.Logger;
25+
2426
import org.apache.cloudstack.api.APICommand;
2527
import org.apache.cloudstack.api.ApiConstants;
2628
import org.apache.cloudstack.api.ApiErrorCode;
2729
import org.apache.cloudstack.api.BaseCmd;
2830
import org.apache.cloudstack.api.Parameter;
31+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2932
import org.apache.cloudstack.api.ServerApiException;
3033
import org.apache.cloudstack.api.response.AccountResponse;
3134
import org.apache.cloudstack.api.response.DomainResponse;
3235
import org.apache.cloudstack.region.RegionService;
33-
import org.apache.log4j.Logger;
3436

3537
import com.cloud.user.Account;
3638

@@ -126,9 +128,9 @@ public long getEntityOwnerId() {
126128
public void execute(){
127129
Account result = _regionService.updateAccount(this);
128130
if (result != null){
129-
AccountResponse response = _responseGenerator.createAccountResponse(result);
131+
AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
130132
response.setResponseName(getCommandName());
131-
this.setResponseObject(response);
133+
setResponseObject(response);
132134
} else {
133135
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update account");
134136
}

‎api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@
1717

1818
package org.apache.cloudstack.api.command.admin.zone;
1919

20+
import org.apache.log4j.Logger;
21+
2022
import org.apache.cloudstack.api.APICommand;
2123
import org.apache.cloudstack.api.ApiCommandJobType;
2224
import org.apache.cloudstack.api.ApiConstants;
2325
import org.apache.cloudstack.api.ApiErrorCode;
2426
import org.apache.cloudstack.api.BaseAsyncCmd;
2527
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2629
import org.apache.cloudstack.api.ServerApiException;
2730
import org.apache.cloudstack.api.response.AccountResponse;
2831
import org.apache.cloudstack.api.response.DomainResponse;
2932
import org.apache.cloudstack.api.response.ZoneResponse;
30-
import org.apache.log4j.Logger;
3133

3234
import com.cloud.event.EventTypes;
3335
import com.cloud.user.Account;
@@ -103,9 +105,9 @@ public ApiCommandJobType getInstanceType() {
103105
public void execute(){
104106
Account result = _configService.markDefaultZone(getAccountName(),getDomainId(), getDefaultZoneId());
105107
if (result != null) {
106-
AccountResponse response = _responseGenerator.createAccountResponse(result);
108+
AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
107109
response.setResponseName(getCommandName());
108-
this.setResponseObject(response);
110+
setResponseObject(response);
109111
}
110112
else {
111113
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to mark the account with the default zone");

‎api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java‎

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

19+
import org.apache.log4j.Logger;
20+
1921
import org.apache.cloudstack.api.APICommand;
2022
import org.apache.cloudstack.api.ApiConstants;
2123
import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
2224
import org.apache.cloudstack.api.Parameter;
25+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2326
import org.apache.cloudstack.api.response.AccountResponse;
2427
import org.apache.cloudstack.api.response.ListResponse;
25-
import org.apache.log4j.Logger;
2628

27-
@APICommand(name = "listAccounts", description="Lists accounts and provides detailed account information for listed accounts", responseObject=AccountResponse.class)
29+
@APICommand(name = "listAccounts", description = "Lists accounts and provides detailed account information for listed accounts", responseObject = AccountResponse.class, responseView = ResponseView.Restricted)
2830
public class ListAccountsCmd extends BaseListDomainResourcesCmd {
2931
public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName());
3032
private static final String s_name = "listaccountsresponse";
@@ -87,6 +89,6 @@ public String getCommandName() {
8789
public void execute(){
8890
ListResponse<AccountResponse> response = _queryService.searchForAccounts(this);
8991
response.setResponseName(getCommandName());
90-
this.setResponseObject(response);
92+
setResponseObject(response);
9193
}
9294
}

‎plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@
2323
import javax.inject.Inject;
2424
import javax.naming.NamingException;
2525

26+
import org.apache.log4j.Logger;
27+
import org.bouncycastle.util.encoders.Base64;
28+
2629
import org.apache.cloudstack.api.APICommand;
2730
import org.apache.cloudstack.api.ApiConstants;
2831
import org.apache.cloudstack.api.ApiErrorCode;
2932
import org.apache.cloudstack.api.BaseCmd;
3033
import org.apache.cloudstack.api.Parameter;
34+
import org.apache.cloudstack.api.ResponseObject.ResponseView;
3135
import org.apache.cloudstack.api.ServerApiException;
3236
import org.apache.cloudstack.api.response.AccountResponse;
3337
import org.apache.cloudstack.api.response.DomainResponse;
3438
import org.apache.cloudstack.context.CallContext;
3539
import org.apache.cloudstack.ldap.LdapManager;
3640
import org.apache.cloudstack.ldap.LdapUser;
37-
import org.apache.log4j.Logger;
38-
import org.bouncycastle.util.encoders.Base64;
3941

4042
import com.cloud.user.Account;
4143
import com.cloud.user.AccountService;
@@ -106,7 +108,7 @@ public void execute() throws ServerApiException {
106108
final UserAccount userAccount = createCloudstackUserAccount(user);
107109
if (userAccount != null) {
108110
final AccountResponse response = _responseGenerator
109-
.createUserAccountResponse(userAccount);
111+
.createUserAccountResponse(ResponseView.Full, userAccount);
110112
response.setResponseName(getCommandName());
111113
setResponseObject(response);
112114
} else {

‎server/src/com/cloud/api/ApiDBUtils.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,8 +1607,8 @@ public static List<ImageStoreJoinVO> newImageStoreView(ImageStore vr){
16071607
}
16081608

16091609

1610-
public static AccountResponse newAccountResponse(AccountJoinVO ve) {
1611-
return _accountJoinDao.newAccountResponse(ve);
1610+
public static AccountResponse newAccountResponse(ResponseView view, AccountJoinVO ve) {
1611+
return _accountJoinDao.newAccountResponse(view, ve);
16121612
}
16131613

16141614
public static AccountJoinVO newAccountView(Account e){

0 commit comments

Comments
 (0)