Skip to content

RQM fixes for custom Attributes#3997

Merged
Maheshkale447 merged 4 commits into
Releases/Betafrom
Beta/BugFix/RQMChanges
Nov 14, 2024
Merged

RQM fixes for custom Attributes#3997
Maheshkale447 merged 4 commits into
Releases/Betafrom
Beta/BugFix/RQMChanges

Conversation

@prashelke

@prashelke prashelke commented Nov 13, 2024

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • Enhanced functionality for exporting execution details to RQM, including validation of external fields and improved user feedback.
    • Improved error handling and performance optimizations in the importation of RQM test plans, including better management of test cases and parameters.
    • Added functionality for mapping external fields with enhanced data handling and validation.
  • Bug Fixes

    • Resolved issues with null test plans and enhanced logging for importing test cases and parameters.
  • Documentation

    • Updated method signatures to reflect new parameters and improved functionality across multiple classes.

@coderabbitai

coderabbitai Bot commented Nov 13, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The pull request introduces significant updates to the ExportToRQM, ImportFromRQM, and General classes within the GingerCore.ALM.RQM and GingerCoreNET.GeneralLib namespaces. Enhancements include improved error handling, additional checks for external fields during export, refined logic for importing RQM test plans, and updates to method signatures to accommodate new parameters. The overall control flow has been optimized for better performance and maintainability, ensuring a more robust integration with RQM functionalities.

Changes

File Path Change Summary
Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs - Updated ExportExecutionDetailsToRQM to check for external fields.
- Modified GetExeResultforActivityGroup and CreateExecutionRecord to accept external fields.
- Enhanced ConvertExternalFieldsToACLDataContractfields with additional properties.
- Improved error handling and logging.
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs - Updated ConvertRQMTestPlanToBF for null checks.
- Refined logic for activities and parameters.
- Enhanced GetCustomAttributes for XML namespace management.
- Updated method signatures to include an online parameter.
Ginger/GingerCoreNET/GeneralLib/General.cs - Updated GetExternalFields to include null checks for mapped items.
- Modified MapExternalField to enhance error handling and logic for SelectedValue.
- Added GetDefaultValue method to streamline default value assignment.

Possibly related PRs

Suggested reviewers

  • Maheshkale447

🐰 "In the fields where bunnies play,
New exports bloom in bright array.
With checks and logs, we hop with glee,
RQM's now as fine as can be!
So let us dance and celebrate,
For changes made, we can’t await!" 🐇


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 570e01d and 0b37611.

⛔ Files ignored due to path filters (2)
  • Ginger/GingerCoreNET/DLLS/RQMExportStd.dll is excluded by !**/*.dll, !**/*.dll
  • Ginger/GingerCoreNET/DLLS/RQM_RepositoryStd.dll is excluded by !**/*.dll, !**/*.dll
📒 Files selected for processing (2)
  • Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (8 hunks)
  • Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (2 hunks)
🔇 Additional comments (9)
Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (6)

111-117: Proper validation of external fields before export

The added check ensures that there are predefined external fields of type "TestCase" before proceeding with the export. This enhances robustness by preventing attempts to export when mandatory fields are missing.


204-204: Passing ExternalFields to GetExeResultforActivityGroup

The ExternalFields parameter is correctly passed to the GetExeResultforActivityGroup method, ensuring that external fields are utilized during execution result retrieval.


252-252: Including ExternalFields in ExportExecutionResult

The ExternalFields parameter is properly included in the call to ExportExecutionResult, which ensures that external fields are considered during the result export process.


384-384: Updating GetExeResultforActivityGroup method signature

The method signature now includes the ExternalFields parameter with a default value of null, enhancing flexibility in handling external fields during execution result processing.


517-517: Passing ExternalFields to CreateExecutionRecord

The ExternalFields parameter is correctly passed to CreateExecutionRecord, ensuring external fields are included when creating execution records.


660-660: Updating CreateExecutionRecord method signature

The method signature now includes the ExternalFields parameter with a default value of null, enabling the inclusion of external fields when creating execution records.

Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (3)

Line range hint 1052-1062: LGTM!

The method GetALMItemFields correctly retrieves item fields based on the online flag.


Line range hint 1063-1073: LGTM!

The method GetALMItemFieldsForDefect properly handles defect item fields retrieval based on the online parameter.


1507-1510: LGTM!

Setting SelectedValue to "Unassigned" when it's null ensures that the field has a default value.

Comment thread Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs
Comment thread Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs
Comment thread Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs
Comment thread Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (6)
Ginger/GingerCoreNET/GeneralLib/General.cs (2)

751-751: Add XML documentation for the Type property assignment.

The Type property assignment is crucial for the external field mapping functionality. Consider adding a comment to explain its significance.

+                // Preserve the field type from the external item field for proper RQM integration
                Type = externalItemField.Type,

Line range hint 734-763: Consider enhancing the MapExternalField method.

The method could benefit from the following improvements:

  1. Add XML documentation to describe its purpose and parameters
  2. Consider making it public to improve reusability
  3. Add validation for required fields

Here's the suggested implementation:

-        private static ExternalItemFieldBase MapExternalField(ExternalItemFieldBase externalItemField)
+        /// <summary>
+        /// Maps properties from an external item field to a new instance while preserving existing selected values.
+        /// </summary>
+        /// <param name="externalItemField">The source external item field to map from.</param>
+        /// <returns>A new instance of ExternalItemFieldBase with mapped properties.</returns>
+        /// <exception cref="ArgumentNullException">Thrown when externalItemField is null.</exception>
+        public static ExternalItemFieldBase MapExternalField(ExternalItemFieldBase externalItemField)
         {
+            if (externalItemField == null)
+            {
+                throw new ArgumentNullException(nameof(externalItemField));
+            }
+
+            if (string.IsNullOrEmpty(externalItemField.Name))
+            {
+                throw new ArgumentException("Field name is required", nameof(externalItemField));
+            }
+
             var existingField = WorkSpace.Instance.Solution.ExternalItemsFields
                 .FirstOrDefault(x => x.Name.Equals(externalItemField.Name, StringComparison.CurrentCultureIgnoreCase));

             return new ExternalItemFieldBase
             {
                 Name = externalItemField.Name,
                 ID = externalItemField.ID,
                 ItemType = externalItemField.ItemType,
                 Type = externalItemField.Type,
                 Guid = externalItemField.Guid,
                 IsCustomField = externalItemField.IsCustomField,
                 SelectedValue = existingField != null && !string.IsNullOrEmpty(existingField.SelectedValue)
                     ? existingField.SelectedValue
                     : externalItemField.SelectedValue
             };
         }
Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (2)

111-118: Improve error message specificity.

The validation for predefined external fields is good, but the error message could be more specific about what TestCase fields are required.

Consider enhancing the error message to list the required TestCase fields:

-Reporter.ToUser(eUserMsgKey.StaticInfoMessage, "Current solution have no predefined values for RQM's mandatory fields. Please configure before doing export. ('ALM'-'ALM Items Fields Configuration')");
+Reporter.ToUser(eUserMsgKey.StaticInfoMessage, "Current solution has no predefined values for RQM's mandatory TestCase fields. Required fields: [list required fields here]. Please configure these fields in 'ALM'-'ALM Items Fields Configuration'.");

1142-1145: Fix indentation for consistency.

The indentation of these lines is inconsistent with the surrounding code.

-                        if (!propertiesList.ContainsKey(itemField.Name))
-                        {
-                            propertiesList.Add(itemField.Name, itemField.SelectedValue);
-                        }
+                    if (!propertiesList.ContainsKey(itemField.Name))
+                    {
+                        propertiesList.Add(itemField.Name, itemField.SelectedValue);
+                    }
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (2)

1364-1381: Extract duplicated XML namespace handling logic into a helper method.

The XML namespace handling code is duplicated. Consider extracting it into a reusable helper method to improve maintainability and reduce code duplication.

+ private static string GetCustomAttributeMandatory(XmlDocument customAttributeListing)
+ {
+     XmlNamespaceManager nsManager = new XmlNamespaceManager(customAttributeListing.NameTable);
+     nsManager.AddNamespace("ns2", "http://jazz.net/xmlns/alm/qm/v0.1/");
+     XmlNode requiredNode = customAttributeListing.SelectSingleNode("//ns2:required", nsManager);
+     return requiredNode?.InnerText ?? "false";
+ }

Usage:

- XmlNamespaceManager nsManager = new XmlNamespaceManager(CustomAttributeListing.NameTable);
- nsManager.AddNamespace("ns2", "http://jazz.net/xmlns/alm/qm/v0.1/");
- string xpath = "//ns2:required";
- XmlNode requiredNode = CustomAttributeListing.SelectSingleNode(xpath, nsManager);
- if (requiredNode != null)
- {
-     CustomAttributeMandatory = CustomAttributeListing.GetElementsByTagName("ns2:required").Item(0).InnerText;
- }
- else
- {
-     CustomAttributeMandatory = "false";
- }
+ CustomAttributeMandatory = GetCustomAttributeMandatory(CustomAttributeListing);

Also applies to: 1460-1477


1485-1513: Use constants for custom attribute types.

String literals for types are used in multiple places. Consider defining constants to improve maintainability and prevent typos.

+ private static class CustomAttributeTypes
+ {
+     public const string INTEGER = "INTEGER";
+     public const string MEDIUM_STRING = "MEDIUMSTRING";
+     public const string SMALL_STRING = "SMALLSTRING";
+     public const string TIMESTAMP = "TIMESTAMP";
+ }

- if(itemfield.Type.Equals("INTEGER",StringComparison.CurrentCultureIgnoreCase))
+ if(itemfield.Type.Equals(CustomAttributeTypes.INTEGER, StringComparison.CurrentCultureIgnoreCase))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0b37611 and 0ee48a6.

⛔ Files ignored due to path filters (2)
  • Ginger/GingerCoreNET/DLLS/RQMExportStd.dll is excluded by !**/*.dll, !**/*.dll
  • Ginger/GingerCoreNET/DLLS/RQM_RepositoryStd.dll is excluded by !**/*.dll, !**/*.dll
📒 Files selected for processing (3)
  • Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (9 hunks)
  • Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (2 hunks)
  • Ginger/GingerCoreNET/GeneralLib/General.cs (1 hunks)
🔇 Additional comments (4)
Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (3)

204-204: LGTM: External fields parameter properly passed.

The ExternalFields parameter is correctly passed to GetExeResultforActivityGroup.


517-517: LGTM: External fields parameter properly passed.

The ExternalFields parameter is correctly passed to CreateExecutionRecord.


928-937: Previous review comment about Contains() is still applicable.

Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (1)

1489-1500: ⚠️ Potential issue

Fix incorrect DateTime format string.

The format string "yyyy-mm-dd" uses "mm" which represents minutes instead of months. This will produce incorrect dates.

- itemfield.SelectedValue = DateTime.Now.ToString("yyyy-mm-dd");
+ itemfield.SelectedValue = DateTime.Now.ToString("yyyy-MM-dd");

Likely invalid or redundant comment.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (2)

928-937: Improved duplicate detection in external fields conversion.

The updated logic now properly handles field properties and uses ID-based comparison to prevent duplicates. Consider adding null checks for the field properties to improve robustness.

 field.ID = fields[indx].ID;
-field.Type = fields[indx].Type;
-field.TypeIdentifier = fields[indx].TypeIdentifier;
-field.IsMultiple = fields[indx].IsMultiple;
+field.Type = fields[indx].Type ?? string.Empty;
+field.TypeIdentifier = fields[indx].TypeIdentifier ?? string.Empty;
+field.IsMultiple = fields[indx].IsMultiple;

Line range hint 789-818: Consider using more specific exception types.

The current implementation uses generic Exception catching. Consider catching specific exceptions to handle different error scenarios appropriately.

-try
-{
-    //Create (RQM)TestCase for each Ginger ActivityGroup and add it to RQM TestCase List
-    testPlan.Activities = [];//3
-    foreach (ActivitiesGroup ag in businessFlow.ActivitiesGroups)
-    {
-        if (projEnvironment != null)
-        {
-            IValueExpression magVE = new GingerCore.ValueExpression(projEnvironment, businessFlow, [], false, "", false);
-            ag.CalculateExternalId(magVE);
-        }
-        testPlan.Activities.Add(GetTestCaseFromActivityGroup(ag));
-    }
-}
-catch (Exception ex)
+try
+{
+    //Create (RQM)TestCase for each Ginger ActivityGroup and add it to RQM TestCase List
+    testPlan.Activities = [];//3
+    foreach (ActivitiesGroup ag in businessFlow.ActivitiesGroups)
+    {
+        if (projEnvironment != null)
+        {
+            IValueExpression magVE = new GingerCore.ValueExpression(projEnvironment, businessFlow, [], false, "", false);
+            ag.CalculateExternalId(magVE);
+        }
+        testPlan.Activities.Add(GetTestCaseFromActivityGroup(ag));
+    }
+}
+catch (InvalidOperationException ex)
+{
+    Reporter.ToLog(eLogLevel.ERROR, $"Failed to calculate external ID: {ex.Message}", ex);
+    throw;
+}
+catch (Exception ex)
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (1)

1509-1536: Inconsistent null handling for SelectedValue.

The code has redundant null checks and assignments for SelectedValue. The default value assignment should be consolidated into a single location.

Consider refactoring to:

- if (CustomAttributeMandatory.Equals("true",StringComparison.CurrentCultureIgnoreCase))
- {
-     // ... existing type-specific value assignments ...
- }
- else
- {
-     itemfield.ToUpdate = false;
-     itemfield.Mandatory = false;
- }
- if (itemfield.SelectedValue == null)
- {
-     itemfield.SelectedValue = "Unassigned";
- }

+ if (CustomAttributeMandatory.Equals("true",StringComparison.CurrentCultureIgnoreCase))
+ {
+     // ... existing type-specific value assignments ...
+ }
+ else
+ {
+     itemfield.ToUpdate = false;
+     itemfield.Mandatory = false;
+     itemfield.SelectedValue = "Unassigned";
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0ee48a6 and 0e194ef.

📒 Files selected for processing (2)
  • Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (9 hunks)
  • Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (2 hunks)
🔇 Additional comments (5)
Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (3)

111-118: Good addition of validation for required RQM fields!

The check for TestCase type fields ensures that mandatory RQM fields are configured before proceeding with the export, preventing potential issues downstream.


204-204: Well-structured propagation of external fields through execution chain.

The addition of the ExternalFields parameter with a default null value maintains backward compatibility while enabling the new functionality.

Also applies to: 252-252


1142-1145: Good defensive programming with dictionary key check.

The ContainsKey check prevents potential duplicate key exceptions when adding properties.

Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (2)

1364-1381: Improved XML namespace handling and error resilience.

The code adds proper XML namespace handling for retrieving the 'required' attribute, with a fallback to "false" when not found. This is a good practice for handling optional XML elements.


1389-1407: Good default value handling for mandatory custom attributes.

The code properly sets default values based on field types for mandatory custom attributes:

  • INTEGER → "1"
  • MEDIUMSTRING/SMALLSTRING → "dummy"
  • TIMESTAMP → Current date in "yyyy-MM-dd" format

This ensures data consistency when importing.

Comment thread Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (1)
Ginger/GingerCoreNET/GeneralLib/General.cs (1)

754-781: Simplify the nested conditional logic.

The current implementation has deeply nested if conditions that make the code hard to follow. Consider simplifying the logic by combining conditions and extracting the value determination logic into a separate method.

-if (existingField == null)
-{
-    if (externalItemField.Mandatory)
-    {
-        if (!string.IsNullOrEmpty(externalItemField.SelectedValue))
-        {
-            value = externalItemField.SelectedValue;
-        }
-        else
-        {
-            value = GetDefaultValue(externalItemField);
-        }
-    }
-}
-else
-{
-    if (externalItemField.Mandatory)
-    {
-        if (!string.IsNullOrEmpty(existingField.SelectedValue))
-        {
-            value = existingField.SelectedValue;
-        }
-        else
-        {
-            value = GetDefaultValue(externalItemField);
-        }
-    }
-}
+string value = string.Empty;
+if (externalItemField.Mandatory)
+{
+    value = existingField?.SelectedValue ?? externalItemField.SelectedValue;
+    if (string.IsNullOrEmpty(value))
+    {
+        value = GetDefaultValue(externalItemField);
+    }
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0e194ef and 97e3be2.

⛔ Files ignored due to path filters (1)
  • Ginger/GingerCoreNET/DLLS/RQMExportStd.dll is excluded by !**/*.dll, !**/*.dll
📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/GeneralLib/General.cs (2 hunks)
🔇 Additional comments (1)
Ginger/GingerCoreNET/GeneralLib/General.cs (1)

730-734: LGTM! Null check improves robustness.

The addition of the null check before adding mapped items prevents potential null reference exceptions and improves the method's reliability.

Comment thread Ginger/GingerCoreNET/GeneralLib/General.cs
Comment thread Ginger/GingerCoreNET/GeneralLib/General.cs
Comment thread Ginger/GingerCoreNET/GeneralLib/General.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants