erikbocks opened a new pull request, #12502:
URL: https://github.com/apache/cloudstack/pull/12502

   ### Description
   
   Currently, API parameters that have `UUID` as their type either accept the 
resource's UUID, or their internal ID directly. If the resource UUID was 
provided, a workflow responsible for processing the parameters of the APIs 
automatically translates it to the resource's internal ID before it reaches the 
API level. However, some APIs events descriptions are created after the 
translation process. If the command wishes to present which resource is being 
interacted with, the translation process causes API events descriptions to 
expose the resource's internal ID to the final user.
   
   As a workaround, it is possible to use the `UuidMgr.getUuid(Class<T> 
entityType, Long customId)` method to get the resource's UUID. Even though this 
method can be used, it is very verbose and makes an additional call to the 
database. Thus, in order to solve this issue, the `getResourceUuid(String 
parameterName)` method was created.
   
   This method belongs to the `BaseCmd` class, allowing all current and future 
API classes to inherit it. To store the resources UUIDs, the 
`apiResourcesUuids` HashMap was added to the `CallContext` class. This map is 
populated during the parameter processing, that occurs at the 
`ParamProcessWorker#translateUuidToInternalId(final String uuid, final 
Parameter annotation)` method, leveraging the UUID translation process to 
eliminate the additional database call. For each UUID type parameter sent, the 
map is populated with the parameter's name as the map key, and the resource's 
UUID as its value. If the provided key is not found in the map, or the value 
found is not a UUID, the method returns a `null` value.
   
   This PR also refactors events descriptions, aiming to enhance them to be 
more descriptive or only to implement the new `getResourceUuid()` method. The 
method calling was standardized by using the `ApiConstants` attributes as the 
`parameterName` value.
   
   Fixes: #11859
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [X] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] Build/CI
   - [ ] Test (unit or integration test code)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Feature/Enhancement Scale
   
   - [ ] Major
   - [X] Minor
   
   ### Screenshots (if appropriate):
   
   ### How Has This Been Tested?
   
   After applying the updated packages to my local environment, I called the 
`disable account` API, informing the `id` parameter as the account's UUID, and 
validated that the created event contained the resource UUID instead of the 
database ID. The same process was repeated informing the resource's database ID 
as the parameter value, and the correct behavior was observed. By using a 
debugger, I also validated that the parameter processing flow as executing the 
correct validations and storing the values correctly in the HashMap.
   
   The codebase tests were also successfully executed. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to