Skip to content

Commit a9b49f3

Browse files
eznttEduardo Zanetta
andauthored
Cleanup APIs getCommandName (apache#7022)
Co-authored-by: Eduardo Zanetta <eduardo.zanetta@scclouds.com.br>
1 parent 4133f0e commit a9b49f3

560 files changed

Lines changed: 481 additions & 3831 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,30 +247,36 @@ public void setResponseType(final String responseType) {
247247
this.responseType = responseType;
248248
}
249249

250-
/**
251-
* For some reason this method does not return the actual command name, but more a name that
252-
* is used to create the response. So you can expect for a XCmd a value like xcmdresponse. Anyways
253-
* this methods is used in too many places so for now instead of changing it we just create another
254-
* method {@link BaseCmd#getActualCommandName()} that returns the value from {@link APICommand#name()}
255-
*
256-
* @return
257-
*/
258-
public abstract String getCommandName();
259-
260-
261250
/**
262251
* Gets the CommandName based on the class annotations: the value from {@link APICommand#name()}
263252
*
264253
* @return the value from {@link APICommand#name()}
265254
*/
266-
public String getActualCommandName() {
255+
public static String getCommandNameByClass(Class<?> clazz) {
267256
String cmdName = null;
268-
if (this.getClass().getAnnotation(APICommand.class) != null) {
269-
cmdName = this.getClass().getAnnotation(APICommand.class).name();
257+
APICommand apiClassAnnotation = clazz.getAnnotation(APICommand.class);
258+
259+
if (apiClassAnnotation != null && apiClassAnnotation.name() != null) {
260+
cmdName = apiClassAnnotation.name();
270261
} else {
271-
cmdName = this.getClass().getName();
262+
cmdName = clazz.getName();
272263
}
273-
return cmdName;
264+
return cmdName;
265+
}
266+
267+
public String getActualCommandName() {
268+
return getCommandNameByClass(this.getClass());
269+
}
270+
271+
public String getCommandName() {
272+
return getResponseNameByClass(this.getClass());
273+
}
274+
275+
/**
276+
* Retrieves the name defined in {@link APICommand#name()}, in lower case, with the prefix {@link BaseCmd#RESPONSE_SUFFIX}
277+
*/
278+
public static String getResponseNameByClass(Class<?> clazz) {
279+
return getCommandNameByClass(clazz).toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
274280
}
275281

276282
/**

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
public class CreateAccountCmd extends BaseCmd {
4646
public static final Logger s_logger = Logger.getLogger(CreateAccountCmd.class.getName());
4747

48-
private static final String s_name = "createaccountresponse";
4948

5049
/////////////////////////////////////////////////////
5150
//////////////// API parameters /////////////////////
@@ -172,11 +171,6 @@ public String getUserUUID() {
172171
/////////////// API Implementation///////////////////
173172
/////////////////////////////////////////////////////
174173

175-
@Override
176-
public String getCommandName() {
177-
return s_name;
178-
}
179-
180174
@Override
181175
public long getEntityOwnerId() {
182176
return Account.ACCOUNT_ID_SYSTEM;

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
4141
public class DeleteAccountCmd extends BaseAsyncCmd {
4242
public static final Logger s_logger = Logger.getLogger(DeleteAccountCmd.class.getName());
43-
private static final String s_name = "deleteaccountresponse";
4443

4544
/////////////////////////////////////////////////////
4645
//////////////// API parameters /////////////////////
@@ -64,15 +63,6 @@ public Long getId() {
6463
/////////////// API Implementation///////////////////
6564
/////////////////////////////////////////////////////
6665

67-
public static String getStaticName() {
68-
return s_name;
69-
}
70-
71-
@Override
72-
public String getCommandName() {
73-
return s_name;
74-
}
75-
7666
@Override
7767
public long getEntityOwnerId() {
7868
Account account = CallContext.current().getCallingAccount();// Let's give the caller here for event logging.

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
4545
public class DisableAccountCmd extends BaseAsyncCmd {
4646
public static final Logger s_logger = Logger.getLogger(DisableAccountCmd.class.getName());
47-
private static final String s_name = "disableaccountresponse";
4847

4948
/////////////////////////////////////////////////////
5049
//////////////// API parameters /////////////////////
@@ -89,11 +88,6 @@ public Boolean getLockRequested() {
8988
/////////////// API Implementation///////////////////
9089
/////////////////////////////////////////////////////
9190

92-
@Override
93-
public String getCommandName() {
94-
return s_name;
95-
}
96-
9791
@Override
9892
public String getEventType() {
9993
return EventTypes.EVENT_ACCOUNT_DISABLE;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
4141
public class EnableAccountCmd extends BaseCmd {
4242
public static final Logger s_logger = Logger.getLogger(EnableAccountCmd.class.getName());
43-
private static final String s_name = "enableaccountresponse";
4443

4544
/////////////////////////////////////////////////////
4645
//////////////// API parameters /////////////////////
@@ -78,11 +77,6 @@ public Long getDomainId() {
7877
/////////////// API Implementation///////////////////
7978
/////////////////////////////////////////////////////
8079

81-
@Override
82-
public String getCommandName() {
83-
return s_name;
84-
}
85-
8680
@Override
8781
public long getEntityOwnerId() {
8882
Account account = _entityMgr.findById(Account.class, getId());

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
public class LockAccountCmd extends BaseCmd {
3838
public static final Logger s_logger = Logger.getLogger(LockAccountCmd.class.getName());
3939

40-
private static final String s_name = "lockaccountresponse";
4140

4241
/////////////////////////////////////////////////////
4342
//////////////// API parameters /////////////////////
@@ -69,11 +68,6 @@ public Long getDomainId() {
6968
/////////////// API Implementation///////////////////
7069
/////////////////////////////////////////////////////
7170

72-
@Override
73-
public String getCommandName() {
74-
return s_name;
75-
}
76-
7771
@Override
7872
public long getEntityOwnerId() {
7973
final Account account = _accountService.getActiveAccountByName(getAccountName(), getDomainId());

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
4545
public class UpdateAccountCmd extends BaseCmd {
4646
public static final Logger s_logger = Logger.getLogger(UpdateAccountCmd.class.getName());
47-
private static final String s_name = "updateaccountresponse";
4847

4948
/////////////////////////////////////////////////////
5049
//////////////// API parameters /////////////////////
@@ -116,11 +115,6 @@ public Map getDetails() {
116115
/////////////// API Implementation///////////////////
117116
/////////////////////////////////////////////////////
118117

119-
@Override
120-
public String getCommandName() {
121-
return s_name;
122-
}
123-
124118
@Override
125119
public long getEntityOwnerId() {
126120
Account account = _entityMgr.findById(Account.class, getId());

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/CreateRoleCmd.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,18 @@
2323
import org.apache.cloudstack.api.ApiCommandResourceType;
2424
import org.apache.cloudstack.api.ApiConstants;
2525
import org.apache.cloudstack.api.ApiErrorCode;
26-
import org.apache.cloudstack.api.BaseCmd;
2726
import org.apache.cloudstack.api.Parameter;
2827
import org.apache.cloudstack.api.ServerApiException;
2928
import org.apache.cloudstack.api.response.RoleResponse;
3029
import org.apache.cloudstack.context.CallContext;
3130

3231
import com.cloud.user.Account;
3332

34-
@APICommand(name = CreateRoleCmd.APINAME, description = "Creates a role", responseObject = RoleResponse.class,
33+
@APICommand(name = "createRole", description = "Creates a role", responseObject = RoleResponse.class,
3534
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
3635
since = "4.9.0",
3736
authorized = {RoleType.Admin})
3837
public class CreateRoleCmd extends RoleCmd {
39-
public static final String APINAME = "createRole";
4038

4139
/////////////////////////////////////////////////////
4240
//////////////// API parameters /////////////////////
@@ -66,11 +64,6 @@ public Long getRoleId() {
6664
/////////////// API Implementation///////////////////
6765
/////////////////////////////////////////////////////
6866

69-
@Override
70-
public String getCommandName() {
71-
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
72-
}
73-
7467
@Override
7568
public long getEntityOwnerId() {
7669
return Account.ACCOUNT_ID_SYSTEM;

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/CreateRolePermissionCmd.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.cloudstack.api.ApiArgValidator;
2525
import org.apache.cloudstack.api.ApiConstants;
2626
import org.apache.cloudstack.api.ApiErrorCode;
27-
import org.apache.cloudstack.api.BaseCmd;
2827
import org.apache.cloudstack.api.Parameter;
2928
import org.apache.cloudstack.api.ServerApiException;
3029
import org.apache.cloudstack.api.response.RolePermissionResponse;
@@ -33,12 +32,11 @@
3332

3433
import com.cloud.user.Account;
3534

36-
@APICommand(name = CreateRolePermissionCmd.APINAME, description = "Adds an API permission to a role", responseObject = RolePermissionResponse.class,
35+
@APICommand(name = "createRolePermission", description = "Adds an API permission to a role", responseObject = RolePermissionResponse.class,
3736
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
3837
since = "4.9.0",
3938
authorized = {RoleType.Admin})
4039
public class CreateRolePermissionCmd extends BaseRolePermissionCmd {
41-
public static final String APINAME = "createRolePermission";
4240

4341
/////////////////////////////////////////////////////
4442
//////////////// API parameters /////////////////////
@@ -60,11 +58,6 @@ public Long getRoleId() {
6058
/////////////// API Implementation///////////////////
6159
/////////////////////////////////////////////////////
6260

63-
@Override
64-
public String getCommandName() {
65-
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
66-
}
67-
6861
@Override
6962
public long getEntityOwnerId() {
7063
return Account.ACCOUNT_ID_SYSTEM;

api/src/main/java/org/apache/cloudstack/api/command/admin/acl/DeleteRoleCmd.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@
3333

3434
import com.cloud.user.Account;
3535

36-
@APICommand(name = DeleteRoleCmd.APINAME, description = "Deletes a role", responseObject = SuccessResponse.class,
36+
@APICommand(name = "deleteRole", description = "Deletes a role", responseObject = SuccessResponse.class,
3737
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
3838
since = "4.9.0",
3939
authorized = {RoleType.Admin})
4040
public class DeleteRoleCmd extends BaseCmd {
41-
public static final String APINAME = "deleteRole";
4241

4342
/////////////////////////////////////////////////////
4443
//////////////// API parameters /////////////////////
@@ -60,11 +59,6 @@ public Long getRoleId() {
6059
/////////////// API Implementation///////////////////
6160
/////////////////////////////////////////////////////
6261

63-
@Override
64-
public String getCommandName() {
65-
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
66-
}
67-
6862
@Override
6963
public long getEntityOwnerId() {
7064
return Account.ACCOUNT_ID_SYSTEM;

0 commit comments

Comments
 (0)