feat/CUS-11393-Update JSON actions to handle nested key matches#358
Conversation
📝 WalkthroughWalkthroughThe PR updates the Maven artifact version from 1.0.2 to 1.0.3 and refactors JSON traversal logic in two UpdateSingleValueBasedOnKey implementations by adding Lombok's Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java (1)
23-28: Missing@EqualsAndHashCodeannotation for consistency with web version.The web variant of this class has
@EqualsAndHashCode(callSuper = false)added, but this windows version does not. For consistency and to suppress Lombok warnings about extending a class without explicit equals/hashCode handling, consider adding the same annotation here.Proposed fix
Add the import:
import lombok.EqualsAndHashCode;Then add the annotation:
`@Data` +@EqualsAndHashCode(callSuper = false) `@Action`(actionText = "JSON: Update the JSON file at File-Path by finding Key-Name with Key-Value, updating Key-To-Update to New-Value, and storing the file path in variable-name",🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java` around lines 23 - 28, The class UpdateSingleValueBasedOnKey is missing the Lombok `@EqualsAndHashCode` annotation that the web variant uses; add import lombok.EqualsAndHashCode and annotate the class with `@EqualsAndHashCode`(callSuper = false) above the class declaration (alongside `@Data` and `@Action`) to match the web version and suppress equals/hashCode warnings when extending WebAction.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@update_json_file/src/main/java/com/testsigma/addons/web/UpdateSingleValueBasedOnKey.java`:
- Around line 141-146: The current findAndUpdate logic calls
updateNestedKey(jsonObject, keyToUpdate, newValue) then immediately returns
true, ignoring updateNestedKey's boolean result; change findAndUpdate so it
captures the boolean result from updateNestedKey and only returns true when that
result is true (otherwise continue searching and ultimately return false if no
update occurred). Update any related logging in findAndUpdate/execute to reflect
success only when updateNestedKey returned true so execute() doesn't report
false successes.
In
`@update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java`:
- Around line 141-145: The method findAndUpdate currently calls
updateNestedKey(jsonObject, keyToUpdate, newValue) but ignores its boolean
return; change findAndUpdate to capture the result (e.g., boolean updated =
updateNestedKey(...)) and only return true when updated is true, otherwise
continue searching (or return false if fully finished without updates). Ensure
execute() uses the boolean returned by findAndUpdate to decide success/failure
so that a missing key leads to a false/failed result instead of a false success;
reference updateNestedKey, findAndUpdate, and execute to locate and propagate
the boolean properly.
---
Nitpick comments:
In
`@update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java`:
- Around line 23-28: The class UpdateSingleValueBasedOnKey is missing the Lombok
`@EqualsAndHashCode` annotation that the web variant uses; add import
lombok.EqualsAndHashCode and annotate the class with
`@EqualsAndHashCode`(callSuper = false) above the class declaration (alongside
`@Data` and `@Action`) to match the web version and suppress equals/hashCode
warnings when extending WebAction.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b75e53fb-6d20-42d0-b8dc-aa6e01692eed
📒 Files selected for processing (3)
update_json_file/pom.xmlupdate_json_file/src/main/java/com/testsigma/addons/web/UpdateSingleValueBasedOnKey.javaupdate_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java
| if (key.equals(attributeName)) { | ||
| if (value != null && value.asText().equals(attributeValue)) { | ||
| if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) { | ||
| logger.info(" Found attribute: " + attributeName + " with value " + attributeValue); | ||
| updateNestedKey(jsonObject, keyToUpdate, newValue); | ||
| return true; // Stop after finding and updating | ||
| } |
There was a problem hiding this comment.
Return value of updateNestedKey is ignored, causing false success reports.
Same issue as the windows variant: when the matching object is found but keyToUpdate doesn't exist within it, updateNestedKey returns false, but findAndUpdate returns true regardless. This leads to execute() reporting success when no update occurred.
Proposed fix
if (key.equals(attributeName)) {
if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) {
logger.info(" Found attribute: " + attributeName + " with value " + attributeValue);
- updateNestedKey(jsonObject, keyToUpdate, newValue);
- return true; // Stop after finding and updating
+ if (updateNestedKey(jsonObject, keyToUpdate, newValue)) {
+ return true; // Stop after finding and updating
+ }
+ // Continue searching if key wasn't found in this object
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (key.equals(attributeName)) { | |
| if (value != null && value.asText().equals(attributeValue)) { | |
| if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) { | |
| logger.info(" Found attribute: " + attributeName + " with value " + attributeValue); | |
| updateNestedKey(jsonObject, keyToUpdate, newValue); | |
| return true; // Stop after finding and updating | |
| } | |
| if (key.equals(attributeName)) { | |
| if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) { | |
| logger.info(" Found attribute: " + attributeName + " with value " + attributeValue); | |
| if (updateNestedKey(jsonObject, keyToUpdate, newValue)) { | |
| return true; // Stop after finding and updating | |
| } | |
| // Continue searching if key wasn't found in this object | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@update_json_file/src/main/java/com/testsigma/addons/web/UpdateSingleValueBasedOnKey.java`
around lines 141 - 146, The current findAndUpdate logic calls
updateNestedKey(jsonObject, keyToUpdate, newValue) then immediately returns
true, ignoring updateNestedKey's boolean result; change findAndUpdate so it
captures the boolean result from updateNestedKey and only returns true when that
result is true (otherwise continue searching and ultimately return false if no
update occurred). Update any related logging in findAndUpdate/execute to reflect
success only when updateNestedKey returned true so execute() doesn't report
false successes.
| logger.info(" Found attribute: " + attributeName + " with value " + attributeValue); | ||
| updateNestedKey(jsonObject, keyToUpdate, newValue); | ||
| return true; // Stop after finding and updating | ||
| } | ||
| } else { | ||
| } |
There was a problem hiding this comment.
Return value of updateNestedKey is ignored, causing false success reports.
When the matching object is found but keyToUpdate doesn't exist within it, updateNestedKey returns false. However, findAndUpdate returns true regardless, causing execute() to report success even when no update occurred.
Proposed fix
if (key.equals(attributeName)) {
if (value != null && value.isValueNode() && value.asText().equals(attributeValue)) {
logger.info(" Found attribute: " + attributeName + " with value " + attributeValue);
- updateNestedKey(jsonObject, keyToUpdate, newValue);
- return true; // Stop after finding and updating
+ if (updateNestedKey(jsonObject, keyToUpdate, newValue)) {
+ return true; // Stop after finding and updating
+ }
+ // Continue searching if key wasn't found in this object
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| logger.info(" Found attribute: " + attributeName + " with value " + attributeValue); | |
| updateNestedKey(jsonObject, keyToUpdate, newValue); | |
| return true; // Stop after finding and updating | |
| } | |
| } else { | |
| } | |
| logger.info(" Found attribute: " + attributeName + " with value " + attributeValue); | |
| if (updateNestedKey(jsonObject, keyToUpdate, newValue)) { | |
| return true; // Stop after finding and updating | |
| } | |
| // Continue searching if key wasn't found in this object | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@update_json_file/src/main/java/com/testsigma/addons/windows/UpdateSingleValueBasedOnKey.java`
around lines 141 - 145, The method findAndUpdate currently calls
updateNestedKey(jsonObject, keyToUpdate, newValue) but ignores its boolean
return; change findAndUpdate to capture the result (e.g., boolean updated =
updateNestedKey(...)) and only return true when updated is true, otherwise
continue searching (or return false if fully finished without updates). Ensure
execute() uses the boolean returned by findAndUpdate to decide success/failure
so that a missing key leads to a false/failed result instead of a false success;
reference updateNestedKey, findAndUpdate, and execute to locate and propagate
the boolean properly.
Publish this addon as PUBLIC
Addon Name: Update JSON File
Jarvis Link: https://jarvis.testsigma.com/ui/tenants/2817/addons
Jira : https://testsigma.atlassian.net/browse/CUS-11393
Update JSON actions to handle nested key matches
Summary by CodeRabbit