-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Cleanup APIs getCommandName #7022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
42a8326
6418b42
e656d27
4dc1a7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,30 +247,36 @@ public void setResponseType(final String responseType) { | |
| this.responseType = responseType; | ||
| } | ||
|
|
||
| /** | ||
| * For some reason this method does not return the actual command name, but more a name that | ||
| * is used to create the response. So you can expect for a XCmd a value like xcmdresponse. Anyways | ||
| * this methods is used in too many places so for now instead of changing it we just create another | ||
| * method {@link BaseCmd#getActualCommandName()} that returns the value from {@link APICommand#name()} | ||
| * | ||
| * @return | ||
| */ | ||
| public abstract String getCommandName(); | ||
|
|
||
|
|
||
| /** | ||
| * Gets the CommandName based on the class annotations: the value from {@link APICommand#name()} | ||
| * | ||
| * @return the value from {@link APICommand#name()} | ||
| */ | ||
| public String getActualCommandName() { | ||
| public static String getCommandNameByClass(Class<?> clazz) { | ||
| String cmdName = null; | ||
| if (this.getClass().getAnnotation(APICommand.class) != null) { | ||
| cmdName = this.getClass().getAnnotation(APICommand.class).name(); | ||
| APICommand apiClassAnnotation = clazz.getAnnotation(APICommand.class); | ||
|
|
||
| if (apiClassAnnotation != null && apiClassAnnotation.name() != null) { | ||
| cmdName = apiClassAnnotation.name(); | ||
| } else { | ||
| cmdName = this.getClass().getName(); | ||
| cmdName = clazz.getName(); | ||
|
weizhouapache marked this conversation as resolved.
|
||
| } | ||
| return cmdName; | ||
| return cmdName; | ||
| } | ||
|
|
||
| public String getActualCommandName() { | ||
| return getCommandNameByClass(this.getClass()); | ||
| } | ||
|
|
||
| public String getCommandName() { | ||
| return getResponseNameByClass(this.getClass()); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the name defined in {@link APICommand#name()}, in lower case, with the prefix {@link BaseCmd#RESPONSE_SUFFIX} | ||
| */ | ||
| public static String getResponseNameByClass(Class<?> clazz) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this being used?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As the PR is intended to clean up the repeated code (it will not change the APIs behavior), I would rather not touch those 88 APIs here. My proposal for those remaining 88 APIs is a later discussion on how we should handle them and if changing them would affect any other place.
Yes, it is used in class public static final Map<String, String> responseNameMap;
static {
Map<String, String> tempMap = new HashMap<String, String>();
tempMap.put(Type.ISO.toString(), BaseCmd.getResponseNameByClass(ExtractIsoCmd.class));
tempMap.put(Type.TEMPLATE.toString(), BaseCmd.getResponseNameByClass(ExtractTemplateCmd.class));
tempMap.put(Type.VOLUME.toString(), BaseCmd.getResponseNameByClass(ExtractVolumeCmd.class));
tempMap.put("DEFAULT", "extractresponse");
responseNameMap = Collections.unmodifiableMap(tempMap);
} |
||
| return getCommandNameByClass(clazz).toLowerCase() + BaseCmd.RESPONSE_SUFFIX; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.