-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the CherryPickRunner on the common lib
- Loading branch information
Showing
4 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="CherryPickRunnerTestFixture.cs" company="RHEA System S.A."> | ||
// Copyright (c) 2023 RHEA System S.A. | ||
// | ||
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine | ||
// | ||
// This file is part of COMET WEB Community Edition | ||
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. | ||
// | ||
// The COMET WEB Community Edition is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Affero General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 3 of the License, or (at your option) any later version. | ||
// | ||
// The COMET WEB Community Edition is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace COMET.Web.Common.Tests.Utilities.CherryPick; | ||
|
||
using NUnit.Framework; | ||
|
||
using CDP4Common.SiteDirectoryData; | ||
|
||
using Moq; | ||
|
||
[TestFixture] | ||
public class CherryPickRunnerTestFixture | ||
{ | ||
private Common.Utilities.CherryPick.CherryPickRunner viewModel; | ||
private Mock<Common.Services.SessionManagement.ISessionService> sessionService; | ||
private Mock<Common.Utilities.CherryPick.INeedCherryPickedData> needCherryPickedData; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
this.sessionService = new Mock<Common.Services.SessionManagement.ISessionService>(); | ||
this.needCherryPickedData = new Mock<Common.Utilities.CherryPick.INeedCherryPickedData>(); | ||
this.viewModel = new Common.Utilities.CherryPick.CherryPickRunner(this.sessionService.Object); | ||
} | ||
|
||
[Test] | ||
public async Task VerifyProperties() | ||
{ | ||
Assert.That(this.viewModel.IsCherryPicking, Is.False); | ||
this.viewModel.InitializeProperties(new List<Common.Utilities.CherryPick.INeedCherryPickedData> { this.needCherryPickedData.Object }); | ||
|
||
this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); | ||
|
||
var propertyInfo = typeof(Common.Utilities.CherryPick.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<IEnumerable<IEnumerable<CDP4Common.DTO.Thing>>>()), Times.Never); | ||
|
||
propertyInfo?.SetValue(this.viewModel, false, null); | ||
await this.viewModel.RunCherryPick(); | ||
this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny<IEnumerable<IEnumerable<CDP4Common.DTO.Thing>>>()), Times.Once); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="CherryPickRunner.cs" company="RHEA System S.A."> | ||
// Copyright (c) 2023 RHEA System S.A. | ||
// | ||
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar | ||
// | ||
// This file is part of COMET WEB Community Edition | ||
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 | ||
// Annex A and Annex C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace COMET.Web.Common.Utilities.CherryPick | ||
{ | ||
using CDP4Common.SiteDirectoryData; | ||
|
||
using COMET.Web.Common.Services.SessionManagement; | ||
|
||
/// <summary> | ||
/// Utility class that could run CherryPick query for <see cref="INeedCherryPickedData" /> | ||
/// </summary> | ||
public class CherryPickRunner : ICherryPickRunner | ||
{ | ||
/// <summary> | ||
/// Gets the collection of <see cref="INeedCherryPickedData" /> | ||
/// </summary> | ||
private readonly List<INeedCherryPickedData> NeedCherryPicked = new(); | ||
|
||
/// <summary> | ||
/// Gets the <see cref="ISessionService"/> | ||
/// </summary> | ||
protected readonly ISessionService SessionService; | ||
|
||
/// <summary> | ||
/// Initializes a new <see cref="CherryPickRunner" /> | ||
/// </summary> | ||
/// <param name="sessionService">The <see cref="ISessionService" /></param> | ||
public CherryPickRunner(ISessionService sessionService) | ||
{ | ||
this.SessionService = sessionService; | ||
} | ||
|
||
/// <summary> | ||
/// Asserts that the cherrypick feature is on going | ||
/// </summary> | ||
public bool IsCherryPicking { get; private set; } | ||
|
||
/// <summary> | ||
/// Initializes the internal properties | ||
/// </summary> | ||
/// <param name="needCherryPicked">A collection of <see cref="INeedCherryPickedData"/></param> | ||
public void InitializeProperties(IEnumerable<INeedCherryPickedData> needCherryPicked) | ||
{ | ||
this.NeedCherryPicked.Clear(); | ||
this.NeedCherryPicked.AddRange(needCherryPicked); | ||
} | ||
|
||
/// <summary> | ||
/// Runs the cherrypick features based on data required from <see cref="NeedCherryPicked" /> | ||
/// </summary> | ||
/// <returns>A <see cref="Task" /></returns> | ||
public async Task RunCherryPick() | ||
{ | ||
if (this.IsCherryPicking) | ||
{ | ||
return; | ||
} | ||
|
||
this.IsCherryPicking = true; | ||
var classKinds = this.NeedCherryPicked.SelectMany(x => x.ClassKindsOfInterest).Distinct(); | ||
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 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(); | ||
|
||
var results = (await Task.WhenAll(cherryPicks)).Where(x => x.Any()).ToList(); | ||
|
||
foreach (var needCherryPickedData in this.NeedCherryPicked) | ||
{ | ||
needCherryPickedData.ProcessCherryPickedData(results); | ||
} | ||
|
||
this.IsCherryPicking = false; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="ICherryPickRunner.cs" company="RHEA System S.A."> | ||
// Copyright (c) 2023 RHEA System S.A. | ||
// | ||
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar | ||
// | ||
// This file is part of COMET WEB Community Edition | ||
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 | ||
// Annex A and Annex C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace COMET.Web.Common.Utilities.CherryPick | ||
{ | ||
/// <summary> | ||
/// Utility class that could run CherryPick query for <see cref="INeedCherryPickedData" /> | ||
/// </summary> | ||
public interface ICherryPickRunner | ||
{ | ||
/// <summary> | ||
/// Asserts that the cherrypick feature is on going | ||
/// </summary> | ||
bool IsCherryPicking { get; } | ||
|
||
/// <summary> | ||
/// Initializes the internal properties | ||
/// </summary> | ||
/// <param name="needCherryPicked">A collection of <see cref="INeedCherryPickedData"/></param> | ||
void InitializeProperties(IEnumerable<INeedCherryPickedData> needCherryPicked); | ||
|
||
/// <summary> | ||
/// Runs the cherrypick features based on data required from <see cref="CherryPickRunner.NeedCherryPicked" /> | ||
/// </summary> | ||
/// <returns>A <see cref="Task" /></returns> | ||
Task RunCherryPick(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="INeedCherryPickedData.cs" company="RHEA System S.A."> | ||
// Copyright (c) 2023 RHEA System S.A. | ||
// | ||
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar | ||
// | ||
// This file is part of COMET WEB Community Edition | ||
// The COMET WEB Community Edition is the RHEA Web Application implementation of ECSS-E-TM-10-25 | ||
// Annex A and Annex C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace COMET.Web.Common.Utilities.CherryPick | ||
{ | ||
using CDP4Common.CommonData; | ||
using CDP4Common.SiteDirectoryData; | ||
|
||
using Thing = CDP4Common.DTO.Thing; | ||
|
||
/// <summary> | ||
/// Interface that define that an object needs data that comes from CherryPick feature | ||
/// </summary> | ||
public interface INeedCherryPickedData | ||
{ | ||
/// <summary> | ||
/// Gets the collection of <see cref="Category" /> name that this object is interested on | ||
/// </summary> | ||
public IReadOnlyCollection<string> CategoriesOfInterest { get; } | ||
|
||
/// <summary> | ||
/// Gets the collection of <see cref="ClassKind" /> that this object is interested on | ||
/// </summary> | ||
public IReadOnlyCollection<ClassKind> ClassKindsOfInterest { get; } | ||
|
||
/// <summary> | ||
/// Process Cherry picked data | ||
/// </summary> | ||
/// <param name="cherryPickedData">A collection of collection of <see cref="Thing" /></param> | ||
public void ProcessCherryPickedData(IEnumerable<IEnumerable<Thing>> cherryPickedData); | ||
} | ||
} |