Skip to content

Commit

Permalink
Refactor the methods so that we use a Tuple<Guid,Guid> for the RunChe…
Browse files Browse the repository at this point in the history
…rryPick methods instead of a single specific parameter.
  • Loading branch information
Robbware committed Oct 20, 2023
1 parent 06d9139 commit fecfda7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public async Task VerifyProperties()
var engineeringModelId = Guid.NewGuid();
var iterationId = Guid.NewGuid();
propertyInfo?.SetValue(this.viewModel, true, null);
await this.viewModel.RunSingleCherryPickAsync(engineeringModelId, iterationId);
await this.viewModel.RunCherryPickAsync(new[] { (engineeringModelId, iterationId)});
this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny<IEnumerable<IEnumerable<Thing>>>()), Times.Never);

propertyInfo?.SetValue(this.viewModel, false, null);
await this.viewModel.RunSingleCherryPickAsync(engineeringModelId, iterationId);
await this.viewModel.RunCherryPickAsync(new[] { (engineeringModelId, iterationId)});
this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny<IEnumerable<IEnumerable<Thing>>>()), Times.Once);
}
}
Expand Down
100 changes: 39 additions & 61 deletions COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,95 +70,73 @@ public void InitializeProperties(IEnumerable<INeedCherryPickedData> needCherryPi
this.needCherryPicked.Clear();
this.needCherryPicked.AddRange(needCherryPickedData);
}

/// <summary>
/// Gets the defined category ids to be used as a filter
/// </summary>
/// <returns>A <see cref="IEnumerable{Guid}"/></returns> with the IDs of the categories to filter on
private IEnumerable<Guid> GetCategoryIdsForCherryPick()
{
var categoriesName = this.needCherryPicked.SelectMany(x => x.CategoriesOfInterest).Distinct();
var categories = new List<Category>();

foreach (var referenceDataLibrary in this.sessionService.Session.RetrieveSiteDirectory().AvailableReferenceDataLibraries())
{
categories.AddRange(referenceDataLibrary.DefinedCategory
.Where(x => categoriesName.Contains(x.Name))
.ToList());
}

var categoriesIds = categories.Select(x => x.Iid);
return categoriesIds;
}

/// <summary>
/// Gets the defined class kinds to be used as a filter
/// </summary>
/// <returns>A <see cref="IEnumerable{ClassKind}"/> with the <see cref="ClassKind"/> to filter on</returns>
private IEnumerable<ClassKind> GetClassKindsForCherryPick()
{
return this.needCherryPicked.SelectMany(x => x.ClassKindsOfInterest).Distinct();
}


/// <summary>
/// Processes the retrieved cherry picked data
/// Runs the cherrypick features based on data required from <see cref="needCherryPicked" />
/// </summary>
/// <param name="cherryPickedData">The cherry picked data</param>
private void ProcessCherryPickedData(IReadOnlyCollection<IEnumerable<Thing>> cherryPickedData)
/// <returns>A <see cref="Task" /></returns>
public async Task RunCherryPickAsync()
{
foreach (var needCherryPickedData in this.needCherryPicked)
{
needCherryPickedData.ProcessCherryPickedData(cherryPickedData);
}
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);
}

/// <summary>
/// Runs the cherrypick features based on data required from <see cref="needCherryPicked" />
/// Runs the cherrypick features based on data required from <see cref="NeedCherryPicked" />
/// </summary>
/// <returns>A <see cref="Task" /></returns>
public async Task RunCherryPickAsync()
public async Task RunCherryPickAsync(IEnumerable<(Guid engineeringModelId, Guid iterationId)> ids)
{
if (this.IsCherryPicking)
{
return;
}

this.IsCherryPicking = true;

var classKinds = this.GetClassKindsForCherryPick();
var categoriesIds = this.GetCategoryIdsForCherryPick();

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, categoriesIds)).ToList();
var categoryIds = this.GetCategoryIdsForCherryPick();

var cherryPicks = ids.Select(pair => this.sessionService.Session.CherryPick(pair.engineeringModelId, pair.iterationId, classKinds, categoryIds))
.ToList();

var results = (await Task.WhenAll(cherryPicks)).Where(x => x.Any()).ToList();

foreach (var needCherryPickedData in this.needCherryPicked)
{
needCherryPickedData.ProcessCherryPickedData(results);
}

this.ProcessCherryPickedData(results);
this.IsCherryPicking = false;
}

/// <summary>
/// Runs the cherrypick features for a specific Engineering Model and Iteration, based on data required from <see cref="needCherryPicked" />
/// Gets the defined category ids to be used as a filter
/// </summary>
/// <param name="engineeringModelId">The engineering model Id that we want to cherry pick from</param>
/// <param name="iterationId">The iteration Id that we want to cherry pick from</param>
/// <returns>A <see cref="Task" /></returns>
public async Task RunSingleCherryPickAsync(Guid engineeringModelId, Guid iterationId)
/// <returns>A <see cref="IEnumerable{Guid}"/></returns> with the IDs of the categories to filter on
private IEnumerable<Guid> GetCategoryIdsForCherryPick()
{
if (this.IsCherryPicking)
var categoriesName = this.needCherryPicked.SelectMany(x => x.CategoriesOfInterest).Distinct();
var categories = new List<Category>();

foreach (var referenceDataLibrary in this.sessionService.Session.RetrieveSiteDirectory().AvailableReferenceDataLibraries())
{
return;
categories.AddRange(referenceDataLibrary.DefinedCategory
.Where(x => categoriesName.Contains(x.Name))
.ToList());
}

this.IsCherryPicking = true;

var classKinds = this.GetClassKindsForCherryPick();
var categoriesIds = this.GetCategoryIdsForCherryPick();

var cherryPicks = await this.sessionService.Session.CherryPick(engineeringModelId, iterationId, classKinds, categoriesIds);

this.ProcessCherryPickedData(new []{ cherryPicks });
var categoriesIds = categories.Select(x => x.Iid);
return categoriesIds;
}

this.IsCherryPicking = false;
/// <summary>
/// Gets the defined class kinds to be used as a filter
/// </summary>
/// <returns>A <see cref="IEnumerable{ClassKind}"/> with the <see cref="ClassKind"/> to filter on</returns>
private IEnumerable<ClassKind> GetClassKindsForCherryPick()
{
return this.needCherryPicked.SelectMany(x => x.ClassKindsOfInterest).Distinct();
}
}
}
13 changes: 6 additions & 7 deletions COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,16 @@ public interface ICherryPickRunner
void InitializeProperties(IEnumerable<INeedCherryPickedData> needCherryPickedData);

/// <summary>
/// Runs the cherrypick features for a specific Engineering Model and Iteration, based on data required from <see cref="NeedCherryPicked" />
/// Runs the cherrypick features based on data required from &lt;see cref="CherryPickRunner.NeedCherryPicked" /&gt;
/// </summary>
/// <param name="engineeringModelId">The engineering model Id that we want to cherry pick from</param>
/// <param name="iterationId">The iteration Id that we want to cherry pick from</param>
/// <returns>A <see cref="Task" /></returns>
Task RunSingleCherryPickAsync(Guid engineeringModelId, Guid iterationId);
Task RunCherryPickAsync();

/// <summary>
/// Runs the cherrypick features based on data required from <see cref="CherryPickRunner.NeedCherryPicked" />
/// Runs the cherrypick features based on data required from <see cref="CherryPickRunner.NeedCherryPicked" /> and a particular set of EngineeringModelId and IterationId.
/// </summary>
/// <param name="ids">A <see cref="Tuple{Guid,Guid}"/> to run the cherry pick for a particular set of engineeringModelIds and iterationIds</param>
/// <returns>A <see cref="Task" /></returns>
Task RunCherryPickAsync();
Task RunCherryPickAsync(IEnumerable<(Guid engineeringModelId, Guid iterationId)> ids);
}
}

0 comments on commit fecfda7

Please sign in to comment.