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

Defect/target application fix #3594

Merged
merged 3 commits into from
Apr 8, 2024

Conversation

Maheshkale447
Copy link
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

Copy link
Contributor

coderabbitai bot commented Apr 8, 2024

Walkthrough

The latest updates across various Ginger modules focus on refining and simplifying the logic for handling application agents, target applications, and error management. Efforts were made to enhance readability and maintainability of the code by adjusting spacing, improving conditions for adding or updating elements, and ensuring consistent error handling. These changes collectively aim to streamline operations, making the system more efficient and user-friendly.

Changes

Files Summary
.../ApplicationAgentsMapPage.xaml.cs
.../EditBusinessFlowAppsPage.xaml.cs
.../BusinessFlowLib/BusinessFlow.cs
Simplified logic for initializing and updating ApplicationAgents and TargetApplications, including checks for null values and ensuring necessary objects are present in lists.
.../ActionsLibrary/ActionsLibraryNavPage.xaml.cs Improved handling of TargetApplication including import addition, missing TA handling, and application platform retrieval.
.../NewAutomatePage.xaml.cs Enhanced readability, error handling, and target application management. Adjusted timeline report generation and minor formatting.

🐇✨
In the den of code, under digital skies,
A rabbit hopped, with bright, keen eyes.
Through lines and loops, it danced with glee,
Weaving a spell, for you and me.
"Behold!" it cried, with a joyful tweak,
"A smoother path for all who seek."
🎉🐾

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b8a1f65 and c53e84e.
Files selected for processing (5)
  • Ginger/Ginger/Agents/ApplicationAgentsMapPage.xaml.cs (1 hunks)
  • Ginger/Ginger/AutomatePageLib/AddActionMenu/ActionsLibrary/ActionsLibraryNavPage.xaml.cs (3 hunks)
  • Ginger/Ginger/AutomatePageLib/NewAutomatePage.xaml.cs (9 hunks)
  • Ginger/Ginger/BusinessFlowWindows/EditBusinessFlowAppsPage.xaml.cs (1 hunks)
  • Ginger/GingerCoreCommon/Repository/BusinessFlowLib/BusinessFlow.cs (2 hunks)
Additional Context Used
GitHub Check Runs (1)
Codacy Static Code Analysis action_required (1)

Ginger/Ginger/AutomatePageLib/NewAutomatePage.xaml.cs: [warning] 634-634: Ginger/Ginger/AutomatePageLib/NewAutomatePage.xaml.cs#L634
Remove this commented out code.

Learnings (1)
Ginger/Ginger/AutomatePageLib/NewAutomatePage.xaml.cs (4)
User: prashelke"
PR: Ginger-Automation/Ginger#3429
File: Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs:1123-1126
Timestamp: 2024-01-05T14:01:37.634Z
Learning: The user has removed an unnecessary empty line at 1123 in `WindowExplorerPage.xaml.cs` for better code compactness.
User: prashelke"
PR: Ginger-Automation/Ginger#3429
File: Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs:1123-1126
Timestamp: 2024-01-05T14:01:37.634Z
Learning: The user has removed an unnecessary empty line at 1123 in `WindowExplorerPage.xaml.cs` for better code compactness.
User: prashelke"
PR: Ginger-Automation/Ginger#3429
File: Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs:1139-1142
Timestamp: 2024-01-05T14:03:05.043Z
Learning: The user has updated the code by removing or addressing the commented code as suggested in the review.
User: prashelke"
PR: Ginger-Automation/Ginger#3429
File: Ginger/Ginger/AutomatePageLib/AddActionMenu/WindowExplorer/Common/WindowExplorerPage.xaml.cs:1139-1142
Timestamp: 2024-01-05T14:03:05.043Z
Learning: The user has updated the code by removing or addressing the commented code as suggested in the review.
Additional comments not posted (2)
Ginger/Ginger/BusinessFlowWindows/EditBusinessFlowAppsPage.xaml.cs (1)

77-77: Consider using string.IsNullOrEmpty(x?.Name) for null or empty string checks.

To enhance the robustness of the null check, you might want to consider using string.IsNullOrEmpty(x?.Name) instead of x?.Name == AP.AppName. This approach ensures that both null and empty string values are handled, preventing potential issues with empty Name properties.

Ginger/Ginger/AutomatePageLib/AddActionMenu/ActionsLibrary/ActionsLibraryNavPage.xaml.cs (1)

23-23: Added import for Amdocs.Ginger.Common.WorkSpaceLib.

The addition of the Amdocs.Ginger.Common.WorkSpaceLib import is appropriate for the changes made in this file, enabling access to GingerCoreCommonWorkSpace functionalities.

{
bool doesApplicationAgentAlreadyExist = mExecutionEngine.GingerRunner.ApplicationAgents.Any((aa) => aa.AppName.Equals(selectedTargetApplication.AppName));
// ApplicationAgent applicationAgent = new ApplicationAgent() { AppName = ((TargetApplication)actTargetApp).AppName };
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this commented out code.

-                //    ApplicationAgent applicationAgent = new ApplicationAgent() { AppName = ((TargetApplication)actTargetApp).AppName };
-                //    applicationAgent.ApplicationAgentOperations = new ApplicationAgentOperations(applicationAgent);
-                //    applicationAgent.Agent = applicationAgent.PossibleAgents?.FirstOrDefault((agent) => agent.Name.Equals(actTargetApp.LastExecutingAgentName)) as Agent;
-                //    if (applicationAgent.Agent == null && applicationAgent.PossibleAgents?.Count >= 1)
-                //    {
-                //        applicationAgent.Agent = applicationAgent.PossibleAgents[0] as Agent;
-                //    }

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.

Suggested change
// ApplicationAgent applicationAgent = new ApplicationAgent() { AppName = ((TargetApplication)actTargetApp).AppName };

Comment on lines +832 to +836

if (!string.IsNullOrEmpty(activity.TargetApplication) && !TargetApplications.Any(bfTA => ((TargetApplication)bfTA).AppName.Equals(activity.TargetApplication)))
{
TargetApplications.Add(GingerCoreCommonWorkSpace.Instance.Solution.GetSolutionTargetApplications().FirstOrDefault(f=>f.Name.Equals(activity.TargetApplication)));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the case where GingerCoreCommonWorkSpace.Instance.Solution.GetSolutionTargetApplications().FirstOrDefault(f=>f.Name.Equals(activity.TargetApplication)) returns null.

if (!string.IsNullOrEmpty(activity.TargetApplication) && !TargetApplications.Any(bfTA => ((TargetApplication)bfTA).AppName.Equals(activity.TargetApplication)))
{
+   var targetAppToAdd = GingerCoreCommonWorkSpace.Instance.Solution.GetSolutionTargetApplications().FirstOrDefault(f=>f.Name.Equals(activity.TargetApplication));
+   if(targetAppToAdd != null)
+   {
    TargetApplications.Add(targetAppToAdd);
+   }
+   else
+   {
+       // Consider logging or handling the case where the target application is not found in the solution's target applications.
+   }
}

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.

Suggested change
if (!string.IsNullOrEmpty(activity.TargetApplication) && !TargetApplications.Any(bfTA => ((TargetApplication)bfTA).AppName.Equals(activity.TargetApplication)))
{
TargetApplications.Add(GingerCoreCommonWorkSpace.Instance.Solution.GetSolutionTargetApplications().FirstOrDefault(f=>f.Name.Equals(activity.TargetApplication)));
}
if (!string.IsNullOrEmpty(activity.TargetApplication) && !TargetApplications.Any(bfTA => ((TargetApplication)bfTA).AppName.Equals(activity.TargetApplication)))
{
var targetAppToAdd = GingerCoreCommonWorkSpace.Instance.Solution.GetSolutionTargetApplications().FirstOrDefault(f=>f.Name.Equals(activity.TargetApplication));
if(targetAppToAdd != null)
{
TargetApplications.Add(targetAppToAdd);
}
else
{
// Consider logging or handling the case where the target application is not found in the solution's target applications.
}
}

Comment on lines +92 to +102
foreach (ApplicationAgent Apag in mRunner.GingerRunner.ApplicationAgents)
{
return;
}

var allTargetApplications = WorkSpace.Instance.Solution.GetSolutionTargetApplications();

var TargetApplicationsInBusinessFlow = allTargetApplications.Where((App) =>
{
return AllTargetApplicationNames.Contains(App.Name);
});


mContext.BusinessFlow.TargetApplications = new ObservableList<TargetBase>(TargetApplicationsInBusinessFlow.ToList());

if (BusinessFlowTargetApplicationChanged != null)
if (Apag.ApplicationAgentOperations == null)
{
BusinessFlowTargetApplicationChanged();
Apag.ApplicationAgentOperations = new ApplicationAgentOperations(Apag);
}

TargetApplicationsInBusinessFlow.ForEach((FilteredTargetApp) =>
{
ApplicationAgent applicationAgent = new ApplicationAgent() { AppName = ((TargetApplication)FilteredTargetApp).AppName };
applicationAgent.ApplicationAgentOperations = new ApplicationAgentOperations(applicationAgent);
applicationAgent.Agent = applicationAgent.PossibleAgents?.FirstOrDefault((agent) => agent.Name.Equals(FilteredTargetApp.LastExecutingAgentName)) as Agent;


if (applicationAgent.Agent == null && applicationAgent.PossibleAgents?.Count >= 1)
if (mRunner.SolutionApplications.FirstOrDefault(x => x.AppName == Apag.AppName && x.Platform == ePlatformType.NA) == null)
{
applicationAgent.Agent = applicationAgent.PossibleAgents[0] as Agent;
ApplicationAgents.Add(Apag);
}

ApplicationAgents.Add(applicationAgent);
});

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the null check and addition logic for ApplicationAgents.

The logic for checking if ApplicationAgentOperations is null and then initializing it, followed by the condition to add Apag to ApplicationAgents, can be simplified. Consider using LINQ's Where method to filter ApplicationAgents first and then iterate over the filtered list to initialize ApplicationAgentOperations if null. This approach reduces the complexity and improves readability.

- foreach (ApplicationAgent Apag in mRunner.GingerRunner.ApplicationAgents)
- {
-     if (Apag.ApplicationAgentOperations == null)
-     {
-         Apag.ApplicationAgentOperations = new ApplicationAgentOperations(Apag);
-     }
-     if (mRunner.SolutionApplications.FirstOrDefault(x => x.AppName == Apag.AppName && x.Platform == ePlatformType.NA) == null)
-     {
-         ApplicationAgents.Add(Apag);
-     }
- }
+ var relevantAgents = mRunner.GingerRunner.ApplicationAgents
+     .Where(Apag => mRunner.SolutionApplications.Any(x => x.AppName != Apag.AppName || x.Platform != ePlatformType.NA))
+     .ToList();
+ foreach (var Apag in relevantAgents)
+ {
+     Apag.ApplicationAgentOperations ??= new ApplicationAgentOperations(Apag);
+     ApplicationAgents.Add(Apag);
+ }

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.

Suggested change
foreach (ApplicationAgent Apag in mRunner.GingerRunner.ApplicationAgents)
{
return;
}
var allTargetApplications = WorkSpace.Instance.Solution.GetSolutionTargetApplications();
var TargetApplicationsInBusinessFlow = allTargetApplications.Where((App) =>
{
return AllTargetApplicationNames.Contains(App.Name);
});
mContext.BusinessFlow.TargetApplications = new ObservableList<TargetBase>(TargetApplicationsInBusinessFlow.ToList());
if (BusinessFlowTargetApplicationChanged != null)
if (Apag.ApplicationAgentOperations == null)
{
BusinessFlowTargetApplicationChanged();
Apag.ApplicationAgentOperations = new ApplicationAgentOperations(Apag);
}
TargetApplicationsInBusinessFlow.ForEach((FilteredTargetApp) =>
{
ApplicationAgent applicationAgent = new ApplicationAgent() { AppName = ((TargetApplication)FilteredTargetApp).AppName };
applicationAgent.ApplicationAgentOperations = new ApplicationAgentOperations(applicationAgent);
applicationAgent.Agent = applicationAgent.PossibleAgents?.FirstOrDefault((agent) => agent.Name.Equals(FilteredTargetApp.LastExecutingAgentName)) as Agent;
if (applicationAgent.Agent == null && applicationAgent.PossibleAgents?.Count >= 1)
if (mRunner.SolutionApplications.FirstOrDefault(x => x.AppName == Apag.AppName && x.Platform == ePlatformType.NA) == null)
{
applicationAgent.Agent = applicationAgent.PossibleAgents[0] as Agent;
ApplicationAgents.Add(Apag);
}
ApplicationAgents.Add(applicationAgent);
});
}
var relevantAgents = mRunner.GingerRunner.ApplicationAgents
.Where(Apag => mRunner.SolutionApplications.Any(x => x.AppName != Apag.AppName || x.Platform != ePlatformType.NA))
.ToList();
foreach (var Apag in relevantAgents)
{
Apag.ApplicationAgentOperations ??= new ApplicationAgentOperations(Apag);
ApplicationAgents.Add(Apag);
}

@@ -183,7 +184,7 @@ private void LoadGridData()
}
else
{
platformActions.Add(cA);
platformActions.Add(cA);
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor the logic for handling missing TargetApplication.

The logic for checking and adding a missing TargetApplication can be streamlined to improve readability and efficiency. Consider encapsulating this logic into a separate method to reduce duplication and enhance maintainability.

- TargetApplication TA = (TargetApplication)mContext.BusinessFlow.TargetApplications.FirstOrDefault(x => x.Name == mContext.BusinessFlow.CurrentActivity.TargetApplication);
- if (TA == null)
- {
-     mContext.BusinessFlow.TargetApplications.Add(GingerCoreCommonWorkSpace.Instance.Solution.GetSolutionTargetApplications().FirstOrDefault(f => f.Name.Equals(mContext.BusinessFlow.CurrentActivity.TargetApplication)));
-     TA = (TargetApplication)mContext.BusinessFlow.TargetApplications.FirstOrDefault(x => x.Name == mContext.BusinessFlow.CurrentActivity.TargetApplication);
- }
+ EnsureTargetApplicationExists(mContext.BusinessFlow.CurrentActivity.TargetApplication);

+ private void EnsureTargetApplicationExists(string targetApplicationName)
+ {
+     if (!mContext.BusinessFlow.TargetApplications.Any(x => x.Name == targetApplicationName))
+     {
+         var targetApplication = GingerCoreCommonWorkSpace.Instance.Solution.GetSolutionTargetApplications().FirstOrDefault(f => f.Name.Equals(targetApplicationName));
+         if (targetApplication != null)
+         {
+             mContext.BusinessFlow.TargetApplications.Add(targetApplication);
+         }
+     }
+ }

This refactor not only simplifies the current logic but also encapsulates the functionality for reusability and clarity.

Also applies to: 243-247


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.

Suggested change
platformActions.Add(cA);
EnsureTargetApplicationExists(mContext.BusinessFlow.CurrentActivity.TargetApplication);
private void EnsureTargetApplicationExists(string targetApplicationName)
{
if (!mContext.BusinessFlow.TargetApplications.Any(x => x.Name == targetApplicationName))
{
var targetApplication = GingerCoreCommonWorkSpace.Instance.Solution.GetSolutionTargetApplications().FirstOrDefault(f => f.Name.Equals(targetApplicationName));
if (targetApplication != null)
{
mContext.BusinessFlow.TargetApplications.Add(targetApplication);
}
}
}

@Maheshkale447 Maheshkale447 merged commit c115a34 into Releases/Beta Apr 8, 2024
1 check passed
@Maheshkale447 Maheshkale447 deleted the Defect/TargetApplicationFix branch April 8, 2024 22:09
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.

1 participant