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
Remove use of java.util.Properties for URL query parsing utility #6403
Comments
Hi, how do you recommend we change ImportingUtilities to accommodate the new changes? If we are unable to modify the existing methods through refactoring, we could potentially face significant code duplication issues. For instance, in the case of the retrieveContentFromPostRequest method, it appears that only a single line of code needs to be modified within a method spanning 227 lines. Any suggestions? |
A standard mechanism for dealing with code duplication is to extract a
common method which can be called in the multiple places where it's needed.
Would that work here? If you are using an IDE, it should have an "Extract
Method" refactoring function that can help with this.
… Message ID: ***@***.***>
|
Okay, I think the problem is that the code that needs to be changed is nested very deep inside retrieveContentFromPostRequest, so I don't think that a refactoring of it would help that much to avoid code duplication. Is it acceptable to modify the public method retrieveContentFromPostRequest as long as it doesn't change the signature and functionality of the method? If so, my solution would be create a new method that takes Map<String,String> and from the original method simply convert Properties parameters to a Map<String, String> and call the new method. Like this:
Is that a viable solution? |
Yes, exactly. I suspect you'll need to do that for multiple methods, so you might want to extract your property remapping code into a separate utility method that you can reuse. Pleased also add an |
p.s. you can use Java 8 Streams to make your remapping a little more concise:
|
Great, thanks for your tips, will do that! |
As part of the epic #6391 to minimize our use of
java.util.Properties
we want our URL parameter parsing to not use this as a return type.Proposed solution
ParsingUtilities
which return java.util.Properties`static public Properties parseUrlParameters(HttpServletRequest request)
with the signaturestatic public Map<String, String> parseParameters(HttpServletRequest request)
which uses available functionality for its implementation likerequest.getParameterMap()
parseUrlParameters
to use the new method and adjust all necessary code to accommodate the new return type. This primarily affects our bundled importers.ImportingUtilities
has public APIs which are affected, but double check.Alternatives considered
We could use
request.getParameterMap
directly, but since it returnsMap<String, String[]>
instead of Map<String, String> it would require more extensive modifications to the existing code and none of our current parameters can be repeated, so the array support is unnecessary.The text was updated successfully, but these errors were encountered: