Skip to content
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

D44105_D44104_D44103 RQM BugFix related to dynamic filed mapping #3987

Merged
merged 5 commits into from
Nov 8, 2024

Conversation

prashelke
Copy link
Contributor

@prashelke prashelke commented Nov 8, 2024

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 export functionality to ensure mandatory fields are validated before exporting to RQM.
    • Improved retrieval and handling of custom attributes and external fields during import and export processes.
    • Introduced a method to retrieve external item fields based on ALM configuration.
  • Bug Fixes

    • Enhanced error handling and logging for mandatory fields in the export process.
  • Refactor

    • Simplified code structure by encapsulating logic for retrieving external fields into dedicated methods, improving maintainability.

Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

Warning

Rate limit exceeded

@prashelke has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 44 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 708cfa0 and 77d1dad.

Walkthrough

The pull request introduces significant refactoring in the RQMRepository, ExportToRQM, and ImportFromRQM classes, focusing on the management of external item fields and the export process to RQM. A new private method, GetExternalFields(), is created to streamline the retrieval of external fields, enhancing the readability and maintainability of the ExportBusinessFlowToALM method. The ExportToRQM class is updated to improve error handling and ensure that mandatory fields are validated before exporting execution details. Additionally, the ImportFromRQM class sees changes to enhance the handling of custom attributes.

Changes

File Path Change Summary
Ginger/Ginger/ALM/Repository/RQMRepository.cs - Added method GetExternalFields() to retrieve external item fields.
- Refactored ExportBusinessFlowToALM to call GetExternalFields().
- Added checks for mandatory fields in export process.
Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs - Added method GetExternalFields() for external fields retrieval.
- Updated CreateExecutionRecord to include external fields parameter.
- Enhanced error handling for mandatory fields.
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs - Updated GetCustomAttributes to return an ObservableList<ExternalItemFieldBase>.
- Improved error handling and logging in custom attributes retrieval.
Ginger/GingerCoreNET/GeneralLib/General.cs - Added method GetExternalFields() for retrieving external item fields from ALM configuration.

Possibly related PRs

Suggested reviewers

  • Maheshkale447

Poem

🐰 In the garden where fields do grow,
A method sprouted, with a gentle glow.
GetExternalFields() hops with grace,
Simplifying exports, it finds its place.
With checks in hand, we leap with cheer,
For every field, the path is clear! 🌼


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (4)
Ginger/Ginger/ALM/Repository/RQMRepository.cs (1)

Line range hint 244-293: Enhance error handling and validation in ExportBusinessFlowToALM.

While the validation for mandatory fields is a good addition, consider these improvements:

  1. Provide more specific error messages about which mandatory fields are missing
  2. Restructure the method to use early returns for better readability

Here's the suggested implementation for the validation part:

 var originalExternalFields = GetExternalFields();
 
-if (!originalExternalFields.Any(x => x.ItemType == "TestCase"))
+var mandatoryFields = originalExternalFields.Where(x => x.ItemType == "TestCase").ToList();
+if (!mandatoryFields.Any())
 {
-    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. " +
+        "Please configure the required fields before exporting. " +
+        "Navigate to 'ALM' -> 'ALM Items Fields Configuration' to set these values.");
     return false;
 }
+
+var missingMandatoryFields = mandatoryFields.Where(f => string.IsNullOrEmpty(f.SelectedValue)).ToList();
+if (missingMandatoryFields.Any())
+{
+    Reporter.ToUser(eUserMsgKey.StaticInfoMessage, 
+        $"The following mandatory fields are missing values: {string.Join(", ", missingMandatoryFields.Select(f => f.Name))}. " +
+        "Please configure these fields before exporting.");
+    return false;
+}
Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (1)

663-663: Correct grammatical error in user message

The message should use 'has' instead of 'have' for proper grammar.

Apply the following change:

-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 fields. Please configure before doing export. ('ALM'-'ALM Items Fields Configuration')");
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (2)

1517-1525: Handle 'SelectedValue' assignment for non-string custom attributes

In the else block starting at line 1517, when the field.Type is neither "MEDIUM_STRING" nor "SMALL_STRING", the SelectedValue is set to null. This could cause issues if SelectedValue is expected to be non-null elsewhere in the code. Consider initializing SelectedValue appropriately or adding checks where SelectedValue is used.

You might want to ensure that SelectedValue is properly handled for all custom attribute types to prevent potential NullReferenceException.


1532-1536: Avoid swallowing exceptions without proper handling

In the catch block starting at line 1532, the exception is logged but not rethrown or handled further. If this method silently fails without informing the caller, it might lead to unexpected behavior. Consider rethrowing the exception or handling it in a way that the caller can respond appropriately.

Modify the catch block to either rethrow the exception or return an appropriate result indicating failure.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 608a69b and 3a8e4cc.

⛔ 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/Ginger/ALM/Repository/RQMRepository.cs (2 hunks)
  • Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (3 hunks)
  • Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (3 hunks)
🧰 Additional context used
🪛 GitHub Check: Codacy Static Code Analysis
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs

[warning] 1251-1251: Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs#L1251
Remove this useless assignment to local variable 'Customfields'.

🪛 GitHub Check: Build Stage / build
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs

[failure] 1253-1253:
'ObservableList' does not contain a definition for 'AddRange' and no accessible extension method 'AddRange' accepting a first argument of type 'ObservableList' could be found (are you missing a using directive or an assembly reference?)

🔇 Additional comments (2)
Ginger/Ginger/ALM/Repository/RQMRepository.cs (1)

Line range hint 244-332: Verify the usage of external fields across the RQM integration.

Let's verify that the external fields handling is consistent across the RQM integration codebase.

✅ Verification successful

Let me gather more specific information about the RQM export implementation.


Based on the verification results, I can now provide the final response:

External fields handling is consistent across RQM integration

The implementation of external fields handling is properly synchronized between RQMRepository.cs and ExportToRQM.cs. Both components:

  • Perform identical validation for TestCase mandatory fields
  • Use the same pattern for external fields retrieval
  • Share consistent error handling and reporting

The changes in the reviewed code maintain the existing validation patterns and don't introduce any inconsistencies in the RQM integration flow.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for external fields handling in RQM-related code
echo "Searching for external fields usage in RQM integration..."
rg -l "ExternalItemsFields|GetExternalFields" --type cs

# Search for potential places where mandatory fields are validated
echo "Searching for mandatory fields validation..."
rg "ItemType.*TestCase" --type cs

# Search for other RQM export methods that might need similar validation
echo "Searching for RQM export methods..."
ast-grep --pattern 'ExportBusinessFlow.*RQM'

Length of output: 8486


Script:

#!/bin/bash
# Check the implementation of ExportBusinessFlowToRQM in RQMCore
echo "Checking RQMCore implementation..."
rg -A 5 "ExportBusinessFlowToRQM" --type cs

# Check for other usages of GetExternalFields in RQM related files
echo "Checking GetExternalFields usage in RQM..."
rg -A 5 "GetExternalFields" Ginger/GingerCoreNET/ALMLib/RQM/

# Check for similar validation patterns in RQM
echo "Checking similar validation patterns..."
rg "originalExternalFields.*Any.*ItemType" --type cs

Length of output: 4308

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

705-705: Verify that 'GetOnlineFields' method can handle null parameters

Passing null to ImportFromRQM.GetOnlineFields(null) may lead to exceptions if the method does not handle null values appropriately. Please verify that GetOnlineFields can accept null parameters without causing errors.

Ginger/Ginger/ALM/Repository/RQMRepository.cs Outdated Show resolved Hide resolved
Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs Outdated Show resolved Hide resolved
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs Outdated Show resolved Hide resolved
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

659-665: LGTM: Good validation of external fields.

The validation of external fields before creating the execution record is a good practice. However, consider enhancing the error message to specify which mandatory fields are missing.

Consider modifying the error message to include the list of missing mandatory 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 is missing predefined values for RQM's mandatory fields: {string.Join(", ", GetRequiredFields())}. Please configure these fields before exporting. ('ALM'-'ALM Items Fields Configuration')");

666-668: Consider proper disposal of external fields list.

The external fields list should be properly disposed after use to prevent memory leaks.

Consider wrapping the external fields usage in a using block:

-List<ACL_Data_Contract.ExternalItemFieldBase> ExternalFields = ConvertExternalFieldsToACLDataContractfields(originalExternalFields);
-var resultInfo = RQMConnect.Instance.RQMRep.CreateExecutionRecordPerActivity(loginData, RQMCore.ALMProjectGuid, ALMCore.DefaultAlmConfig.ALMProjectName, RQMCore.ALMProjectGroupName, currentActivity, bfExportedID, testPlan.Name, ExternalFields);
+using (var ExternalFields = ConvertExternalFieldsToACLDataContractfields(originalExternalFields))
+{
+    var resultInfo = RQMConnect.Instance.RQMRep.CreateExecutionRecordPerActivity(loginData, RQMCore.ALMProjectGuid, ALMCore.DefaultAlmConfig.ALMProjectName, RQMCore.ALMProjectGroupName, currentActivity, bfExportedID, testPlan.Name, ExternalFields);
+}
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (1)

1520-1528: Use StringComparison.OrdinalIgnoreCase for consistent string comparisons

When comparing strings for equality, it's recommended to use StringComparison.OrdinalIgnoreCase to ensure consistent behavior regardless of the system's culture settings. This avoids potential bugs due to culture-specific casing rules.

Apply this diff to update the string comparisons:

-if(field.Type != null && (field.Type.Equals("MEDIUM_STRING",StringComparison.CurrentCultureIgnoreCase) || field.Type.Equals("SMALL_STRING", StringComparison.CurrentCultureIgnoreCase)))
+if(field.Type != null && (field.Type.Equals("MEDIUM_STRING", StringComparison.OrdinalIgnoreCase) || field.Type.Equals("SMALL_STRING", StringComparison.OrdinalIgnoreCase)))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3a8e4cc and 708cfa0.

📒 Files selected for processing (4)
  • Ginger/Ginger/ALM/Repository/RQMRepository.cs (2 hunks)
  • Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs (2 hunks)
  • Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (3 hunks)
  • Ginger/GingerCoreNET/GeneralLib/General.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Ginger/Ginger/ALM/Repository/RQMRepository.cs
🧰 Additional context used
📓 Learnings (1)
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs (1)
Learnt from: prashelke
PR: Ginger-Automation/Ginger#3987
File: Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs:1436-1449
Timestamp: 2024-11-08T10:39:57.748Z
Learning: In `Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs`, when processing custom attributes, do not set `itemfield.IsMultiple` based on `CustomAttributefieldType`.
🔇 Additional comments (5)
Ginger/GingerCoreNET/GeneralLib/General.cs (2)

27-27: LGTM!

The new using directive is properly placed and necessary for RQM integration.


708-746: Verify integration with RQM repository.

Since this method is part of the RQM integration changes, let's verify:

  1. Usage in RQM repository
  2. Potential breaking changes for existing consumers
✅ Verification successful

Let me generate another script to better understand the RQM integration:


Let me generate one final script to check the usage of GetOnlineFields in ImportFromRQM:


Integration with RQM repository is properly implemented

The verification shows that:

  1. GetExternalFields() is correctly used in both ExportToRQM and RQMRepository classes for field validation before export
  2. The method integrates with ImportFromRQM.GetOnlineFields() to fetch online fields when project GUID changes
  3. No breaking changes were introduced in the method signature
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for GetExternalFields usage
echo "Searching for GetExternalFields usage..."
rg -A 5 "GetExternalFields"

# Search for RQM repository implementation
echo "Searching for RQM repository implementation..."
ast-grep --pattern 'class $_ {
  $$$
  ExportBusinessFlowToALM($$$) {
    $$$
  }
  $$$
}'

Length of output: 8373


Script:

#!/bin/bash
# Search for RQM repository class and its implementation
echo "Searching for RQM repository class..."
rg -A 10 "class.*RQMRepository"

# Search for ExportToRQM class implementation
echo "Searching for ExportToRQM class..."
rg -A 10 "class.*ExportToRQM"

# Search for ImportFromRQM class since it's used in GetExternalFields
echo "Searching for ImportFromRQM class..."
rg -A 10 "class.*ImportFromRQM"

Length of output: 3179


Script:

#!/bin/bash
# Search for GetOnlineFields implementation and usage
echo "Searching for GetOnlineFields implementation..."
rg -A 15 "GetOnlineFields" "Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs"

# Search for any breaking changes in the method signature
echo "Searching for previous versions of GetExternalFields..."
git log -p -- "Ginger/GingerCoreNET/GeneralLib/General.cs" | rg -A 10 "GetExternalFields"

Length of output: 1898

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

22-22: LGTM: Import statements are appropriate.

The added imports for GingerCoreNET and GeneralLib are correctly placed and necessary for the functionality.

Also applies to: 28-28

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

1520-1528: Confirm handling of SelectedValue being set to null

In the else block, field.SelectedValue is set to null. Ensure that downstream code can handle SelectedValue being null without causing exceptions or unexpected behavior.

Run the following script to search for usages of SelectedValue that might not handle null values:

#!/bin/bash
# Description: Find where 'SelectedValue' is used without null checks.

# Test: Search for accesses to 'SelectedValue' without null checks. Expect: All usages handle null appropriately.

rg -U --pcre2 '(?<!if\s*\(.*)\bSelectedValue\b'

1480-1518: Verify that field.IsMultiple is correctly initialized

The condition if(field.IsMultiple) relies on field.IsMultiple being properly set. However, there is no assignment to IsMultiple within the GetCustomAttributes method. Ensure that IsMultiple is initialized correctly elsewhere to prevent logic errors in this conditional block.

Run the following script to search for assignments to IsMultiple in the codebase:

✅ Verification successful

Based on the search results, I found that IsMultiple is properly defined in the ExternalItemFieldBase class with a default value:

public bool IsMultiple { get; set; } = false;

Additionally, in OctaneCore.cs, there's evidence that IsMultiple is being set based on field type data:

itemfield.IsMultiple = temp.GetBooleanValue("multiple").Value;

This shows that IsMultiple is properly initialized and managed within the codebase. The conditional check if(field.IsMultiple) in ImportFromRQM.cs is valid as the property is properly initialized with a default value of false and can be set through the ALM integration code.

The IsMultiple property is correctly initialized and managed

The property has a default value of false and is properly set through ALM integration code, making the conditional check in ImportFromRQM.cs safe to use.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for assignments to 'IsMultiple' in the codebase.

# Test: Find assignments to 'IsMultiple'. Expect: Assignments exist outside 'GetCustomAttributes'.

ast-grep --pattern '$_.IsMultiple = $_'

Length of output: 134


Script:

#!/bin/bash
# Let's try different approaches to find IsMultiple initialization

# Search for class/struct definitions containing IsMultiple property
ast-grep --pattern 'class $_ {
  $$$
  IsMultiple $_
  $$$
}'

# Search for IsMultiple using ripgrep for broader context
rg "IsMultiple" -B 5 -A 5

# Search for files containing IsMultiple
fd -t f . | xargs rg "IsMultiple" -l

Length of output: 54185

Ginger/GingerCoreNET/GeneralLib/General.cs Outdated Show resolved Hide resolved
Ginger/GingerCoreNET/ALMLib/RQM/ImportFromRQM.cs Outdated Show resolved Hide resolved
@Maheshkale447 Maheshkale447 merged commit a77e2f2 into Releases/Beta Nov 8, 2024
2 checks passed
@Maheshkale447 Maheshkale447 deleted the Beta/BugFix/RQMChanges branch November 8, 2024 11:31
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