D43121_ RQM Category and Custom attributes update fix#4019
Conversation
WalkthroughThe changes involve modifications to the Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
Ginger/GingerCoreNET/External/JsonExternalItemField.cs (1)
30-32: LGTM! Consider adding documentation.The new properties
PossibleValueKeysandSelectedKeyalign well with the existing structure. Consider adding XML documentation comments to explain their purpose and relationship withPossibleValuesandSelectedproperties.public class JsonExternalItemField { public string ID { get; set; } public string Name { get; set; } public string ItemType { get; set; } public bool Mandatory { get; set; } public ObservableList<string> PossibleValues { get; set; } + /// <summary> + /// Gets or sets the keys corresponding to each possible value in PossibleValues. + /// </summary> public ObservableList<string> PossibleValueKeys { get; set; } public string Selected { get; set; } + /// <summary> + /// Gets or sets the key corresponding to the Selected value. + /// </summary> public string SelectedKey { get; set; }Ginger/GingerCoreNET/ALMLib/Generic/ALMCore.cs (1)
374-375: Consider improving the robustness of field synchronization.The synchronization of value keys is implemented correctly, but the code could be more maintainable:
- The logic for updating selected values and keys is spread across multiple conditions
- Similar code is repeated in multiple branches
Consider extracting the synchronization logic into a separate method:
+private void SyncFieldValues(ExternalItemFieldBase currentField, ExternalItemFieldBase latestField) +{ + int selectedElementIndex = latestField.PossibleValues.IndexOf(currentField.SelectedValue); + if (selectedElementIndex != -1) + { + currentField.SelectedValue = latestField.PossibleValues[selectedElementIndex]; + currentField.SelectedValueKey = latestField.PossibleValueKeys[selectedElementIndex]; + } + else + { + currentField.SelectedValue = latestField.SelectedValue; + currentField.SelectedValueKey = latestField.SelectedValueKey; + } +}Then use it in the refresh method:
if ((latestField.PossibleValues.Count == 0 && currentField.SelectedValue != latestField.SelectedValue) || (latestField.PossibleValues.Count > 0 && latestField.PossibleValues.Contains(currentField.SelectedValue) && currentField.SelectedValue != latestField.PossibleValues[0])) { currentField.ToUpdate = true; - int SelectedElementIndex = latestField.PossibleValues.IndexOf(currentField.SelectedValue); - if(SelectedElementIndex != -1) - { - currentField.SelectedValue = latestField.PossibleValues[SelectedElementIndex]; - currentField.SelectedValueKey = latestField.PossibleValueKeys[SelectedElementIndex]; - } - else - { - currentField.SelectedValue = latestField.SelectedValue; - currentField.SelectedValueKey = latestField.SelectedValueKey; - } + SyncFieldValues(currentField, latestField); }Also applies to: 382-392, 397-397, 404-404
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (3)
Ginger/GingerCoreNET/DLLS/ACL_Data_Contract.dllis excluded by!**/*.dll,!**/*.dllGinger/GingerCoreNET/DLLS/RQMExportStd.dllis excluded by!**/*.dll,!**/*.dllGinger/GingerCoreNET/DLLS/RQM_RepositoryStd.dllis excluded by!**/*.dll,!**/*.dll
📒 Files selected for processing (6)
Ginger/GingerCoreCommon/Repository/ALMLib/ExternalItemFieldBase.cs(5 hunks)Ginger/GingerCoreNET/ALMLib/Generic/ALMCore.cs(1 hunks)Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs(1 hunks)Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs(4 hunks)Ginger/GingerCoreNET/External/JsonExternalItemField.cs(1 hunks)Ginger/GingerCoreNET/GeneralLib/General.cs(4 hunks)
👮 Files not reviewed due to content moderation or server errors (3)
- Ginger/GingerCoreNET/GeneralLib/General.cs
- Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs
- Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs
🔇 Additional comments (1)
Ginger/GingerCoreCommon/Repository/ALMLib/ExternalItemFieldBase.cs (1)
85-97: LGTM! Properties are well-implemented.
The new properties PossibleValueKeys and SelectedValueKey are properly implemented with:
- Private backing fields
- Property change notifications
- Serialization attributes where needed
Also applies to: 118-134
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (3)
Line range hint
1224-1252: Add null check and optimize the code.The code has several potential improvements:
- Add null check before accessing index at line 1251
- Use LINQ for more efficient and cleaner code
- Use consistent string comparison
Consider this refactor:
- var titles = doc.Descendants(ns + "entry") - .Select(entry => entry) - .Where(title => title != null); + var entries = doc.Descendants(ns + "entry") + .Where(entry => entry != null); - foreach (var title in titles) - { - field.PossibleValues.Add(title.Element(ns + "title")?.Value); - string PossibleValueKey = title.Element(ns + "id")?.Value; - string PossibleValueKeyID = PossibleValueKey[(PossibleValueKey.LastIndexOf(':') + 1)..]; - field.PossibleValueKeys.Add(PossibleValueKeyID); - } + foreach (var entry in entries) + { + var titleValue = entry.Element(ns + "title")?.Value; + var idValue = entry.Element(ns + "id")?.Value; + + if (titleValue != null && idValue != null) + { + field.PossibleValues.Add(titleValue); + field.PossibleValueKeys.Add(idValue[(idValue.LastIndexOf(':') + 1)..]); + } + } - if (field.SelectedValue.Equals("Unassigned",StringComparison.CurrentCultureIgnoreCase) && field.PossibleValues.Count > 0) + if (string.Equals(field.SelectedValue, "Unassigned", StringComparison.CurrentCultureIgnoreCase) && field.PossibleValues.Count > 0) { field.SelectedValue = field.PossibleValues[0]; field.SelectedValueKey = field.PossibleValueKeys[0]; } else { - int SelectedElementIndex = field.PossibleValues.IndexOf(field.SelectedValue); - field.SelectedValueKey = field.PossibleValueKeys[SelectedElementIndex]; + int selectedElementIndex = field.PossibleValues.IndexOf(field.SelectedValue); + if (selectedElementIndex >= 0 && selectedElementIndex < field.PossibleValueKeys.Count) + { + field.SelectedValueKey = field.PossibleValueKeys[selectedElementIndex]; + } }
Line range hint
4-4: Address TODO comment for test coverage.The TODO comment indicates missing tests. This should be addressed to ensure proper test coverage.
Would you like me to help create unit tests for this functionality?
Line range hint
1-1600: Consider reducing code duplication in error handling.There are several instances of duplicated error handling code throughout the file. Consider extracting common error handling logic into a reusable method.
Consider creating a helper method:
+ private static void HandleRQMError(string methodName, Exception ex, string customMessage = null) + { + string message = customMessage ?? $"Method - {methodName}, Error - {ex.Message}"; + Reporter.ToLog(eLogLevel.ERROR, message, ex); + }Then use it consistently throughout the code:
- catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } + catch (Exception ex) { HandleRQMError(MethodBase.GetCurrentMethod().Name, ex); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
Ginger/GingerCoreCommon/Repository/ALMLib/ExternalItemFieldBase.cs(5 hunks)Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- Ginger/GingerCoreCommon/Repository/ALMLib/ExternalItemFieldBase.cs
🔇 Additional comments (2)
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (2)
952-954: LGTM! Properties are correctly serialized.
The new properties PossibleValueKeys and SelectedValueKey are properly included in the JSON serialization process, maintaining consistency with the existing property serialization pattern.
915-929: LGTM! Verify data consistency between values and keys.
The addition of PossibleValueKeys and SelectedValueKey properties is implemented correctly, with proper initialization and default value handling. The implementation maintains consistency with the existing PossibleValues property.
✅ Verification successful
Based on the search results, I can now generate the final response since I have enough information to verify the data consistency between PossibleValues and PossibleValueKeys:
Data consistency between values and keys is properly maintained
The codebase shows consistent handling of PossibleValues and PossibleValueKeys arrays:
- Both arrays are initialized together in
ExternalItemFieldBase.cswith empty lists - The arrays are always modified in pairs:
- In
ImportFromRQM.cswhen populating from JSON - In
ALMCore.cswhen updating fields - In RQM integration code when adding new values
- In
- The code includes validation to ensure array lengths match before accessing indices
- Default/fallback values are handled consistently for both arrays
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that PossibleValueKeys and PossibleValues are always in sync
# Search for any instances where these properties might be modified independently
rg -A 5 "PossibleValueKeys|PossibleValues" --type cs
Length of output: 65914
Thank you for your contribution.
Before submitting this PR, please make sure:
Summary by CodeRabbit
New Features
PossibleValueKeysandSelectedValueKeyfor enhanced management of external item fields.Bug Fixes
Documentation