-
Notifications
You must be signed in to change notification settings - Fork 36
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
Added a new parse util method to avoid repetition / refactored code with new method #721
Added a new parse util method to avoid repetition / refactored code with new method #721
Conversation
8d3f42c
to
0e4071e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! This looks great!
Note there's 2 more changes upcoming in #718, so if that gets merged first you can update, or if your PR gets merged first than @owaiskazi19 can update. :)
Can you make a few naming changes to make the method more generic? Also we need to add a CHANGELOG entry and add a unit test in ParseUtilsTest
?
src/main/java/org/opensearch/flowframework/util/ParseUtils.java
Outdated
Show resolved
Hide resolved
Yes, i will get on it !
…On Thu, 30 May 2024 at 18:50, Daniel Widdis ***@***.***> wrote:
***@***.**** commented on this pull request.
Thanks for your contribution! This looks great!
Note there's 2 more changes upcoming in #718
<#718>, so if
that gets merged first you can update, or if your PR gets merged first than
@owaiskazi19 <https://github.com/owaiskazi19> can update. :)
Can you make a few naming changes to make the method more generic? Also we
need to add a CHANGELOG entry and add a unit test in ParseUtilsTest?
------------------------------
In src/main/java/org/opensearch/flowframework/util/ParseUtils.java
<#721 (comment)>
:
> @@ -472,4 +473,8 @@ public static Map<String, String> convertStringToObjectMapToStringToStringMap(Ma
return stringToStringMap;
}
}
+
+ public static Boolean checkIfInputsContainsKey(Map<String, Object> inputs, String enumKey){
This method is good but the naming implies we're just checking whether the
key exists. How about parseBooleanIfExists or something similar?
Also as a more generic util method it may not be "inputsso just a more
generic map variable name; and the key may be a string constant, not
necessarily an enum so justkey` probably works there.
This needs a Javadoc added explaining what the method does.
—
Reply to this email directly, view it on GitHub
<#721 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AU52WT3KIH4TJ2IVMRBZPBDZE5DD3AVCNFSM6AAAAABIQ4AWA6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDAOBYG4YDCMBSHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
02413df
to
215710f
Compare
src/main/java/org/opensearch/flowframework/util/ParseUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/flowframework/util/ParseUtils.java
Outdated
Show resolved
Hide resolved
this is a good suggestion! But to be right instead of
+ return Float.parseFloat(value.toString());
it should be
+ return type.cast(Float.parseFloat(value.toString()));
i will push the changes now!
…On Sat, Jun 1, 2024 at 1:49 AM Owais Kazi ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/main/java/org/opensearch/flowframework/util/ParseUtils.java
<#721 (comment)>
:
> + /**
+ * Checks if the inputs map contains the specified key and parses the associated value to a generic class.
+ *
+ * @param inputs the map containing the input data
+ * @param key the key to check in the map
+ * @param type the class to parse the value to
+ * @return the generic type value associated with the key if present, or null if the key is not found
+ */
+ public static <T> T parseIfExists(Map<String, Object> inputs, String key, Class<T> type) {
+ if (!inputs.containsKey(key)) {
+ return null;
+ }
+
+ Object value = inputs.get(key);
+ if (type == Boolean.class) {
+ return type.cast(Boolean.valueOf(value.toString()));
⬇️ Suggested change
- return type.cast(Boolean.valueOf(value.toString()));
+ return Booleans.parseBoolean(value.toString())
------------------------------
In src/main/java/org/opensearch/flowframework/util/ParseUtils.java
<#721 (comment)>
:
> + *
+ * @param inputs the map containing the input data
+ * @param key the key to check in the map
+ * @param type the class to parse the value to
+ * @return the generic type value associated with the key if present, or null if the key is not found
+ */
+ public static <T> T parseIfExists(Map<String, Object> inputs, String key, Class<T> type) {
+ if (!inputs.containsKey(key)) {
+ return null;
+ }
+
+ Object value = inputs.get(key);
+ if (type == Boolean.class) {
+ return type.cast(Boolean.valueOf(value.toString()));
+ } else if (type == Float.class) {
+ return type.cast(Float.valueOf(value.toString()));
⬇️ Suggested change
- return type.cast(Float.valueOf(value.toString()));
+ return Float.parseFloat(value.toString());
—
Reply to this email directly, view it on GitHub
<#721 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AU52WT2W4Z2DM4BKW7PNHMLZFD46RAVCNFSM6AAAAABIQ4AWA6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDAOJRHAYDCOJWGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@martinpkr you also need to amend your changes with |
@martinpkr thanks for your patience working through code review! one note: you do need to sign your commits with DCO (Signed-off-by: Your Name [email protected]). If committing on git command line just use Also be sure to run |
@dbwiddis since this PR just adds a util method, we can ignore the CHANGELOG. Wdyt?
|
4c847fc
to
5f20442
Compare
Signed off my commits and did an changelog entry for the issue,also fixed the javadoc to include info about , tell me if there is anything else . |
Just |
just done that , see if everything is okay now... first time using gradle, so i'm sorry for the confusion. |
fca8b56
to
9f92614
Compare
* Add user mapping to Workflow State index Signed-off-by: Daniel Widdis <[email protected]> * Increment schema version Signed-off-by: Daniel Widdis <[email protected]> --------- Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: martinpkr <[email protected]>
…ith new method Signed-off-by: martinpkr <[email protected]>
Signed-off-by: martinpkr <[email protected]>
Signed-off-by: martinpkr <[email protected]>
adb1660
to
e4e62ee
Compare
Signed-off-by: martinpkr <[email protected]>
* Initial commit for reindex workflow step with extra params Signed-off-by: owaiskazi19 <[email protected]> * Addressed PR comments Signed-off-by: owaiskazi19 <[email protected]> * Changed request per second to Float Signed-off-by: owaiskazi19 <[email protected]> * Addressed string array for source indices and removed state index entry Signed-off-by: owaiskazi19 <[email protected]> * Minor comments Signed-off-by: owaiskazi19 <[email protected]> --------- Signed-off-by: owaiskazi19 <[email protected]> Signed-off-by: martinpkr <[email protected]>
Signed-off-by: martinpkr <[email protected]>
…ist (opensearch-project#719) Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: martinpkr <[email protected]>
Signed-off-by: martinpkr <[email protected]>
Signed-off-by: martinpkr <[email protected]>
* Initial commit for reindex workflow step with extra params Signed-off-by: owaiskazi19 <[email protected]> * Addressed PR comments Signed-off-by: owaiskazi19 <[email protected]> * Changed request per second to Float Signed-off-by: owaiskazi19 <[email protected]> * Addressed string array for source indices and removed state index entry Signed-off-by: owaiskazi19 <[email protected]> * Minor comments Signed-off-by: owaiskazi19 <[email protected]> --------- Signed-off-by: owaiskazi19 <[email protected]> Signed-off-by: martinpkr <[email protected]>
…ist (opensearch-project#719) Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: martinpkr <[email protected]>
Signed-off-by: martinpkr <[email protected]>
Signed-off-by: martinpkr <[email protected]>
* Initial commit for reindex workflow step with extra params Signed-off-by: owaiskazi19 <[email protected]> * Addressed PR comments Signed-off-by: owaiskazi19 <[email protected]> * Changed request per second to Float Signed-off-by: owaiskazi19 <[email protected]> * Addressed string array for source indices and removed state index entry Signed-off-by: owaiskazi19 <[email protected]> * Minor comments Signed-off-by: owaiskazi19 <[email protected]> --------- Signed-off-by: owaiskazi19 <[email protected]> Signed-off-by: martinpkr <[email protected]>
…method Signed-off-by: martinpkr <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #721 +/- ##
============================================
+ Coverage 74.33% 74.41% +0.07%
- Complexity 742 744 +2
============================================
Files 84 84
Lines 3807 3811 +4
Branches 332 330 -2
============================================
+ Hits 2830 2836 +6
Misses 823 823
+ Partials 154 152 -2 ☔ View full report in Codecov by Sentry. |
cec9081
to
ee6b0a0
Compare
Signed-off-by: martinpkr <[email protected]>
19bf570
to
ec25f91
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the checks passed. Thanks @martinpkr for addressing the comments patiently. Welcome to the club and feel free to pick up other good first issues as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks @martinpkr for your patience here and expanding this PR to be much more useful than we originally envisioned!
…ith new method (#721) * Add user mapping to Workflow State index (#705) * Add user mapping to Workflow State index Signed-off-by: Daniel Widdis <[email protected]> * Increment schema version Signed-off-by: Daniel Widdis <[email protected]> --------- Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: martinpkr <[email protected]> * Added a new parse util method to avoid repetition / refactored code with new method Signed-off-by: martinpkr <[email protected]> * refactored method name and added unit test Signed-off-by: martinpkr <[email protected]> * made method use generics + added test Signed-off-by: martinpkr <[email protected]> * fixed javadoc Signed-off-by: martinpkr <[email protected]> * Added workflow step for ReIndex Step (#718) * Initial commit for reindex workflow step with extra params Signed-off-by: owaiskazi19 <[email protected]> * Addressed PR comments Signed-off-by: owaiskazi19 <[email protected]> * Changed request per second to Float Signed-off-by: owaiskazi19 <[email protected]> * Addressed string array for source indices and removed state index entry Signed-off-by: owaiskazi19 <[email protected]> * Minor comments Signed-off-by: owaiskazi19 <[email protected]> --------- Signed-off-by: owaiskazi19 <[email protected]> Signed-off-by: martinpkr <[email protected]> * Incorporating parseIfExist method into ReindexStep class Signed-off-by: martinpkr <[email protected]> * Add param to delete workflow API to clear status even if resources exist (#719) Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: martinpkr <[email protected]> * refactored method to use parseBoolean and parseFloat methods Signed-off-by: martinpkr <[email protected]> * Adding a missing param in javaDoc Signed-off-by: martinpkr <[email protected]> * Added workflow step for ReIndex Step (#718) * Initial commit for reindex workflow step with extra params Signed-off-by: owaiskazi19 <[email protected]> * Addressed PR comments Signed-off-by: owaiskazi19 <[email protected]> * Changed request per second to Float Signed-off-by: owaiskazi19 <[email protected]> * Addressed string array for source indices and removed state index entry Signed-off-by: owaiskazi19 <[email protected]> * Minor comments Signed-off-by: owaiskazi19 <[email protected]> --------- Signed-off-by: owaiskazi19 <[email protected]> Signed-off-by: martinpkr <[email protected]> * Add param to delete workflow API to clear status even if resources exist (#719) Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: martinpkr <[email protected]> * Added a chagelog entry Signed-off-by: martinpkr <[email protected]> * fixed failing spotless check Signed-off-by: martinpkr <[email protected]> * Added workflow step for ReIndex Step (#718) * Initial commit for reindex workflow step with extra params Signed-off-by: owaiskazi19 <[email protected]> * Addressed PR comments Signed-off-by: owaiskazi19 <[email protected]> * Changed request per second to Float Signed-off-by: owaiskazi19 <[email protected]> * Addressed string array for source indices and removed state index entry Signed-off-by: owaiskazi19 <[email protected]> * Minor comments Signed-off-by: owaiskazi19 <[email protected]> --------- Signed-off-by: owaiskazi19 <[email protected]> Signed-off-by: martinpkr <[email protected]> * removed unnecessary changelog info Signed-off-by: martinpkr <[email protected]> --------- Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: martinpkr <[email protected]> Signed-off-by: owaiskazi19 <[email protected]> Co-authored-by: Daniel Widdis <[email protected]> Co-authored-by: Owais Kazi <[email protected]> (cherry picked from commit 13b32f1) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…factored code with new method (#728) Added a new parse util method to avoid repetition / refactored code with new method (#721) * Add user mapping to Workflow State index (#705) * Add user mapping to Workflow State index * Increment schema version --------- * Added a new parse util method to avoid repetition / refactored code with new method * refactored method name and added unit test * made method use generics + added test * fixed javadoc * Added workflow step for ReIndex Step (#718) * Initial commit for reindex workflow step with extra params * Addressed PR comments * Changed request per second to Float * Addressed string array for source indices and removed state index entry * Minor comments --------- * Incorporating parseIfExist method into ReindexStep class * Add param to delete workflow API to clear status even if resources exist (#719) * refactored method to use parseBoolean and parseFloat methods * Adding a missing param in javaDoc * Added workflow step for ReIndex Step (#718) * Initial commit for reindex workflow step with extra params * Addressed PR comments * Changed request per second to Float * Addressed string array for source indices and removed state index entry * Minor comments --------- * Add param to delete workflow API to clear status even if resources exist (#719) * Added a chagelog entry * fixed failing spotless check * Added workflow step for ReIndex Step (#718) * Initial commit for reindex workflow step with extra params * Addressed PR comments * Changed request per second to Float * Addressed string array for source indices and removed state index entry * Minor comments --------- * removed unnecessary changelog info --------- (cherry picked from commit 13b32f1) Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: martinpkr <[email protected]> Signed-off-by: owaiskazi19 <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Daniel Widdis <[email protected]> Co-authored-by: Owais Kazi <[email protected]>
Description
This change adds a static util method that helps with reusing a piece of code and avoids repetition for the future
Issues Resolved
Will resolve [FEATURE] Create a new Util method for a common pattern -> #720
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.