Skip to content

Commit 440adea

Browse files
author
Daniel Augusto Veronezi Salvador
committed
Merge branch 'implement-ordinal-to-string-param-conversion' into '4.20.0.0-scclouds'
Reversão do atributo `accounttype` para o valor ordinal em respostas de APIs e adição de suporte ao uso de ordinais para o parâmetro `accounttype` Closes #3220 See merge request scclouds/scclouds!1339
2 parents b242a29 + 0f89a17 commit 440adea

20 files changed

Lines changed: 84 additions & 41 deletions

File tree

api/src/main/java/com/cloud/user/Account.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
// under the License.
1717
package com.cloud.user;
1818

19+
import com.cloud.utils.StringUtils;
1920
import org.apache.cloudstack.acl.ControlledEntity;
2021
import org.apache.cloudstack.api.Identity;
2122
import org.apache.cloudstack.api.InternalIdentity;
23+
import org.apache.commons.lang3.ArrayUtils;
24+
import org.apache.commons.lang3.EnumUtils;
2225

2326
import java.util.Date;
2427

@@ -55,21 +58,22 @@ enum Type {
5558
NORMAL, ADMIN, DOMAIN_ADMIN, RESOURCE_DOMAIN_ADMIN, READ_ONLY_ADMIN, PROJECT, UNKNOWN;
5659

5760
public static Type getFromValue(Integer type){
58-
for(Type t : Type.values()){
59-
if(Integer.valueOf(t.ordinal()).equals(type)) {
60-
return t;
61-
}
61+
Type[] types = Type.values();
62+
63+
if (type == null || !ArrayUtils.isArrayIndexValid(types, type) || type.equals(Type.UNKNOWN.ordinal())) {
64+
return null;
6265
}
63-
return null;
66+
67+
return types[type];
6468
}
6569

6670
public static Type getFromValue(String type){
67-
for(Type t : Type.values()){
68-
if(t.name().equalsIgnoreCase(type)) {
69-
return t;
70-
}
71+
if (StringUtils.isNumeric(type)) {
72+
int inputOrdinal = Integer.parseInt(type);
73+
return getFromValue(inputOrdinal);
7174
}
72-
return null;
75+
76+
return EnumUtils.getEnumIgnoreCase(Account.Type.class, type);
7377
}
7478
}
7579

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ApiConstants {
2222
public static final String ACCOUNT_NAME = "accountname";
2323
public static final String ACCOUNT_STATE_TO_SHOW = "accountstatetoshow";
2424
public static final String ACCOUNT_TYPE = "accounttype";
25+
public static final String ACCOUNT_TYPE_NAME = "accounttypename";
2526
public static final String ACCOUNT_ID = "accountid";
2627
public static final String ACCOUNT_IDS = "accountids";
2728
public static final String ACCUMULATE = "accumulate";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class CreateAccountCmd extends BaseCmd {
5555

5656
@Parameter(name = ApiConstants.ACCOUNT_TYPE,
5757
type = CommandType.STRING,
58-
description = "Type of the account. Specify 'normal' for user, 'admin' for root admin, and 'domain_admin' for domain admin.")
58+
description = "Type of the account. Specify 0 or 'normal' for user, 1 or 'admin' for root admin, 2 or 'domain_admin' for domain admin and 5 or 'project' for project account. This field is case insensitive.")
5959
private String accountType;
6060

6161
@Parameter(name = ApiConstants.ROLE_ID, type = CommandType.UUID, entityType = RoleResponse.class, description = "Creates the account under the specified role.")

api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class ListUsersCmd extends BaseListAccountResourcesCmd {
4141

4242
@Parameter(name = ApiConstants.ACCOUNT_TYPE,
4343
type = CommandType.STRING,
44-
description = "List users by account type. Valid types include admin, domain_admin, read_only_admin or normal (for user).")
44+
description = "List users by account type. Valid types include 0 or normal (for user), 1 or 'admin', 2 or 'domain_admin'.")
4545
private String accountType;
4646

4747
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = UserResponse.class, description = "List user by ID.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserC
5050

5151
@Parameter(name = ApiConstants.ACCOUNT_TYPE,
5252
type = CommandType.STRING,
53-
description = "list accounts by account type. Valid account types are admin, domain_admin, and normal (for user).")
53+
description = "list accounts by account type. Valid types include 0 or normal (for user), 1 or 'admin', 2 or 'domain_admin'.")
5454
private String accountType;
5555

5656
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "list account by account ID")

api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ public class AccountResponse extends BaseResponse implements ResourceLimitAndCou
4040
private String name;
4141

4242
@SerializedName(ApiConstants.ACCOUNT_TYPE)
43-
@Param(description = "account type (admin, domain-admin, user)")
44-
private String accountType;
43+
@Param(description = "account type (0 (NORMAL), 1 (ADMIN), 2 (DOMAIN_ADMIN), 5 (PROJECT)")
44+
private Integer accountType;
45+
46+
@SerializedName(ApiConstants.ACCOUNT_TYPE_NAME)
47+
@Param(description = "account type name (NORMAL, ADMIN, DOMAIN-ADMIN, PROJECT)")
48+
private String accountTypeName;
4549

4650
@SerializedName(ApiConstants.ROLE_ID)
4751
@Param(description = "the ID of the role")
@@ -356,10 +360,14 @@ public void setName(String name) {
356360
this.name = name;
357361
}
358362

359-
public void setAccountType(String accountType) {
363+
public void setAccountType(Integer accountType) {
360364
this.accountType = accountType;
361365
}
362366

367+
public void setAccountTypeName(String accountTypeName) {
368+
this.accountTypeName = accountTypeName;
369+
}
370+
363371
public void setRoleId(String roleId) {
364372
this.roleId = roleId;
365373
}

api/src/main/java/org/apache/cloudstack/api/response/ProjectAccountResponse.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ public class ProjectAccountResponse extends BaseResponse implements ControlledVi
5050
private String username;
5151

5252
@SerializedName(ApiConstants.ACCOUNT_TYPE)
53-
@Param(description = "account type (admin, domain-admin, user)")
54-
private String accountType;
53+
@Param(description = "account type: 0 (NORMAL), 1 (ADMIN), 2 (DOMAIN_ADMIN), 5 (PROJECT)")
54+
private Integer accountType;
55+
56+
@SerializedName(ApiConstants.ACCOUNT_TYPE_NAME)
57+
@Param(description = "account type name (NORMAL, ADMIN, DOMAIN_ADMIN, PROJECT)")
58+
private String accountTypeName;
5559

5660
@SerializedName(ApiConstants.USER_ID)
5761
@Param(description = "Id of the user")
@@ -100,10 +104,14 @@ public void setAccountName(String accountName) {
100104
this.accountName = accountName;
101105
}
102106

103-
public void setAccountType(String accountType) {
107+
public void setAccountType(Integer accountType) {
104108
this.accountType = accountType;
105109
}
106110

111+
public void setAccountTypeName(String accountTypeName) {
112+
this.accountTypeName = accountTypeName;
113+
}
114+
107115
@Override
108116
public void setDomainId(String domainId) {
109117
this.domainId = domainId;

api/src/main/java/org/apache/cloudstack/api/response/UserResponse.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ public class UserResponse extends BaseResponse implements SetResourceIconRespons
6464
private String accountName;
6565

6666
@SerializedName("accounttype")
67-
@Param(description = "the account type of the user")
68-
private String accountType;
67+
@Param(description = "the type of the user's account: 0 (NORMAL), 1 (ADMIN), 2 (DOMAIN_ADMIN), 5 (PROJECT)")
68+
private Integer accountType;
69+
70+
@SerializedName(ApiConstants.ACCOUNT_TYPE_NAME)
71+
@Param(description = "account type name (NORMAL, ADMIN, DOMAIN_ADMIN, PROJECT)")
72+
private String accountTypeName;
6973

7074
@SerializedName("usersource")
7175
@Param(description = "the source type of the user in lowercase, such as native, ldap, saml2")
@@ -206,12 +210,16 @@ public void setAccountName(String accountName) {
206210
this.accountName = accountName;
207211
}
208212

209-
public String getAccountType() {
213+
public Integer getAccountType() {
210214
return accountType;
211215
}
212216

213217
public void setAccountType(Account.Type accountType) {
214-
this.accountType = accountType.name();
218+
this.accountType = accountType.ordinal();
219+
}
220+
221+
public void setAccountTypeName(String accountTypeName) {
222+
this.accountTypeName = accountTypeName;
215223
}
216224

217225
public void setRoleId(String roleId) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class LdapCreateAccountCmd extends BaseCmd {
5454
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "Creates the user under the specified account. If no account is specified, the username will be used as the account name.")
5555
private String accountName;
5656

57-
@Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.STRING, description = "Type of the account. Specify 'normal' for user, 'admin' for root admin, and 'domain_admin' for domain admin.")
57+
@Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.STRING, description = "Type of the account. Specify 0 or 'normal' for user, 1 or 'admin' for root admin, and 2 or 'domain_admin' for domain admin.")
5858
private String accountType;
5959

6060
@Parameter(name = ApiConstants.ROLE_ID, type = CommandType.UUID, entityType = RoleResponse.class, description = "Creates the account under the specified role.")

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapImportUsersCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class LdapImportUsersCmd extends BaseListCmd {
6666
@Parameter(name = ApiConstants.TIMEZONE, type = CommandType.STRING, description = "Specifies a timezone for this command. For more information on the timezone parameter, see Time Zone Format.")
6767
private String timezone;
6868

69-
@Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.STRING, description = "Type of the account. Specify 'normal' for user, 'admin' for root admin, and 'domain_admin' for domain admin.")
69+
@Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.STRING, description = "Type of the account. Specify 0 or 'normal' for user, 1 or 'admin' for root admin, and 2 or 'domain_admin' for domain admin.")
7070
private String accountType;
7171

7272
@Parameter(name = ApiConstants.ROLE_ID, type = CommandType.UUID, entityType = RoleResponse.class, description = "Creates the account under the specified role.")

0 commit comments

Comments
 (0)