diff --git a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs index 1b460b8f..e931ccfc 100644 --- a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs +++ b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs @@ -28,7 +28,8 @@ namespace COMET.Web.Common.Tests.Utilities.CherryPick { using NUnit.Framework; - using CDP4Common.SiteDirectoryData; + using SiteDirectory = CDP4Common.SiteDirectoryData.SiteDirectory; + using CDP4Common.DTO; using COMET.Web.Common.Services.SessionManagement; using COMET.Web.Common.Utilities.CherryPick; @@ -61,12 +62,24 @@ public async Task VerifyProperties() var propertyInfo = typeof(CherryPickRunner).GetProperty("IsCherryPicking", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); propertyInfo?.SetValue(this.viewModel, true, null); - await this.viewModel.RunCherryPick(); - this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Never); + await this.viewModel.RunCherryPickAsync(); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Never); propertyInfo?.SetValue(this.viewModel, false, null); - await this.viewModel.RunCherryPick(); - this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); + await this.viewModel.RunCherryPickAsync(); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); + + this.needCherryPickedData.Invocations.Clear(); + + var engineeringModelId = Guid.NewGuid(); + var iterationId = Guid.NewGuid(); + propertyInfo?.SetValue(this.viewModel, true, null); + await this.viewModel.RunCherryPickAsync(new[] { (engineeringModelId, iterationId)}); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Never); + + propertyInfo?.SetValue(this.viewModel, false, null); + await this.viewModel.RunCherryPickAsync(new[] { (engineeringModelId, iterationId)}); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); } } } diff --git a/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs b/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs index c9bc990c..4a392a96 100644 --- a/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs +++ b/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs @@ -25,6 +25,7 @@ namespace COMET.Web.Common.Utilities.CherryPick { + using CDP4Common.CommonData; using CDP4Common.SiteDirectoryData; using COMET.Web.Common.Services.SessionManagement; @@ -37,12 +38,12 @@ public class CherryPickRunner : ICherryPickRunner /// /// Gets the collection of /// - private readonly List NeedCherryPicked = new(); + private readonly List needCherryPicked = new(); /// /// Gets the /// - protected readonly ISessionService SessionService; + private readonly ISessionService sessionService; /// /// Initializes a new @@ -50,7 +51,7 @@ public class CherryPickRunner : ICherryPickRunner /// The public CherryPickRunner(ISessionService sessionService) { - this.SessionService = sessionService; + this.sessionService = sessionService; } /// @@ -61,18 +62,30 @@ public CherryPickRunner(ISessionService sessionService) /// /// Initializes the internal properties /// - /// A collection of - public void InitializeProperties(IEnumerable needCherryPicked) + /// A collection of + public void InitializeProperties(IEnumerable needCherryPickedData) { - this.NeedCherryPicked.Clear(); - this.NeedCherryPicked.AddRange(needCherryPicked); + this.needCherryPicked.Clear(); + this.needCherryPicked.AddRange(needCherryPickedData); } - + + /// + /// Runs the cherrypick features based on data required from for all the Engineering Models the user is participating on + /// + /// A + public async Task RunCherryPickAsync() + { + var availableEngineeringModelSetups = this.sessionService.GetParticipantModels().ToList(); + var engineeringModelAndIterationIdTuple = availableEngineeringModelSetups.Select(x => (x.Iid, x.IterationSetup.Single(c => c.FrozenOn == null).Iid)); + await this.RunCherryPickAsync(engineeringModelAndIterationIdTuple); + } + /// - /// Runs the cherrypick features based on data required from + /// Runs the cherrypick features based on data required from and a particular set of EngineeringModelId and IterationId. /// + /// A to run the cherry pick for a particular set of engineeringModelIds and iterationIds /// A - public async Task RunCherryPick() + public async Task RunCherryPickAsync(IEnumerable<(Guid engineeringModelId, Guid iterationId)> ids) { if (this.IsCherryPicking) { @@ -80,31 +93,49 @@ public async Task RunCherryPick() } this.IsCherryPicking = true; - var classKinds = this.NeedCherryPicked.SelectMany(x => x.ClassKindsOfInterest).Distinct(); - var categoriesName = this.NeedCherryPicked.SelectMany(x => x.CategoriesOfInterest).Distinct(); + var classKinds = this.GetClassKindsForCherryPick(); + var categoryIds = this.GetCategoryIdsForCherryPick(); - var categories = new List(); + var cherryPicks = ids.Select(pair => this.sessionService.Session.CherryPick(pair.engineeringModelId, pair.iterationId, classKinds, categoryIds)) + .ToList(); - foreach (var referenceDataLibrary in this.SessionService.Session.RetrieveSiteDirectory().AvailableReferenceDataLibraries()) + var results = (await Task.WhenAll(cherryPicks)).Where(x => x.Any()).ToList(); + + foreach (var needCherryPickedData in this.needCherryPicked) { - categories.AddRange(referenceDataLibrary.DefinedCategory - .Where(x => categoriesName.Contains(x.Name)) - .ToList()); + needCherryPickedData.ProcessCherryPickedData(results); } - var availableEngineeringModelSetups = this.SessionService.GetParticipantModels().ToList(); - - var cherryPicks = availableEngineeringModelSetups.Select(engineeringModelSetup => this.SessionService.Session.CherryPick(engineeringModelSetup.EngineeringModelIid, engineeringModelSetup.IterationSetup.Single(x => x.FrozenOn == null).IterationIid, classKinds, categories.Select(x => x.Iid))) - .ToList(); + this.IsCherryPicking = false; + } - var results = (await Task.WhenAll(cherryPicks)).Where(x => x.Any()).ToList(); + /// + /// Gets the defined category ids to be used as a filter + /// + /// A with the IDs of the categories to filter on + private IEnumerable GetCategoryIdsForCherryPick() + { + var categoriesName = this.needCherryPicked.SelectMany(x => x.CategoriesOfInterest).Distinct(); + var categories = new List(); - foreach (var needCherryPickedData in this.NeedCherryPicked) + foreach (var referenceDataLibrary in this.sessionService.Session.RetrieveSiteDirectory().AvailableReferenceDataLibraries()) { - needCherryPickedData.ProcessCherryPickedData(results); + categories.AddRange(referenceDataLibrary.DefinedCategory + .Where(x => categoriesName.Contains(x.Name)) + .ToList()); } - this.IsCherryPicking = false; + var categoriesIds = categories.Select(x => x.Iid); + return categoriesIds; + } + + /// + /// Gets the defined class kinds to be used as a filter + /// + /// A with the to filter on + private IEnumerable GetClassKindsForCherryPick() + { + return this.needCherryPicked.SelectMany(x => x.ClassKindsOfInterest).Distinct(); } } } diff --git a/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs b/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs index aa8c4e32..21436a30 100644 --- a/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs +++ b/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs @@ -38,13 +38,20 @@ public interface ICherryPickRunner /// /// Initializes the internal properties /// - /// A collection of - void InitializeProperties(IEnumerable needCherryPicked); + /// A collection of + void InitializeProperties(IEnumerable needCherryPickedData); /// - /// Runs the cherrypick features based on data required from + /// Runs the cherrypick features based on data required from ; /// /// A - Task RunCherryPick(); + Task RunCherryPickAsync(); + + /// + /// Runs the cherrypick features based on data required from and a particular set of EngineeringModelId and IterationId. + /// + /// A to run the cherry pick for a particular set of engineeringModelIds and iterationIds + /// A + Task RunCherryPickAsync(IEnumerable<(Guid engineeringModelId, Guid iterationId)> ids); } }