-
Notifications
You must be signed in to change notification settings - Fork 61
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
Conversation
WalkthroughThe 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
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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 usingstring.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 ofx?.Name == AP.AppName
. This approach ensures that both null and empty string values are handled, preventing potential issues with emptyName
properties.Ginger/Ginger/AutomatePageLib/AddActionMenu/ActionsLibrary/ActionsLibraryNavPage.xaml.cs (1)
23-23
: Added import forAmdocs.Ginger.Common.WorkSpaceLib
.The addition of the
Amdocs.Ginger.Common.WorkSpaceLib
import is appropriate for the changes made in this file, enabling access toGingerCoreCommonWorkSpace
functionalities.
{ | ||
bool doesApplicationAgentAlreadyExist = mExecutionEngine.GingerRunner.ApplicationAgents.Any((aa) => aa.AppName.Equals(selectedTargetApplication.AppName)); | ||
// ApplicationAgent applicationAgent = new ApplicationAgent() { AppName = ((TargetApplication)actTargetApp).AppName }; |
There was a problem hiding this comment.
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.
// ApplicationAgent applicationAgent = new ApplicationAgent() { AppName = ((TargetApplication)actTargetApp).AppName }; |
|
||
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))); | ||
} |
There was a problem hiding this comment.
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.
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. | |
} | |
} |
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); | ||
}); | ||
|
||
} |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
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); | |
} | |
} | |
} |
Thank you for your contribution.
Before submitting this PR, please make sure: