diff --git a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj index 1c357f38..0a277a13 100644 --- a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj +++ b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj @@ -35,8 +35,11 @@ true PreserveNewest - - + + Always + + + Always diff --git a/COMET.Web.Common.Tests/Resources/configuration/naming_convention.json b/COMET.Web.Common.Tests/Resources/configuration/naming_convention.json new file mode 100644 index 00000000..5ee08a20 --- /dev/null +++ b/COMET.Web.Common.Tests/Resources/configuration/naming_convention.json @@ -0,0 +1,4 @@ +{ + "TestValue1": "TestValue1", + "TestValue2": "TestValue2" +} \ No newline at end of file diff --git a/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs new file mode 100644 index 00000000..772f1b48 --- /dev/null +++ b/COMET.Web.Common.Tests/Services/NamingConventionService/NamingConventionServiceTestFixture.cs @@ -0,0 +1,73 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace COMET.Web.Common.Tests.Services.NamingConventionService +{ + using COMET.Web.Common.Server.Services.NamingConventionService; + using COMET.Web.Common.Services.NamingConventionService; + + using Microsoft.Extensions.Logging; + + using Moq; + + using NUnit.Framework; + + [TestFixture] + public class NamingConventionServiceTestFixture + { + private NamingConventionService service; + private Mock>> logger; + + [SetUp] + public void Setup() + { + this.logger = new Mock>>(); + this.service = new NamingConventionService(this.logger.Object); + } + + [Test] + public async Task VerifyInitializationAndGetNamingConvention() + { + await this.service.InitializeService(); + var enumValues = Enum.GetValues(); + + Assert.Multiple(() => + { + foreach (var namingConventionKind in enumValues) + { + Assert.That(this.service.GetNamingConventionValue(namingConventionKind), Is.Not.Empty); + } + }); + } + + /// To be used for testing purposes only + public enum NamingConventionKindTestEnum + { + TestValue1, + TestValue2 + } + } +} diff --git a/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs new file mode 100644 index 00000000..1b460b8f --- /dev/null +++ b/COMET.Web.Common.Tests/Utilities/CherryPick/CherryPickRunnerTestFixture.cs @@ -0,0 +1,72 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace COMET.Web.Common.Tests.Utilities.CherryPick +{ + using NUnit.Framework; + + using CDP4Common.SiteDirectoryData; + + using COMET.Web.Common.Services.SessionManagement; + using COMET.Web.Common.Utilities.CherryPick; + + using Moq; + + [TestFixture] + public class CherryPickRunnerTestFixture + { + private CherryPickRunner viewModel; + private Mock sessionService; + private Mock needCherryPickedData; + + [SetUp] + public void Setup() + { + this.sessionService = new Mock(); + this.needCherryPickedData = new Mock(); + this.viewModel = new CherryPickRunner(this.sessionService.Object); + } + + [Test] + public async Task VerifyProperties() + { + Assert.That(this.viewModel.IsCherryPicking, Is.False); + this.viewModel.InitializeProperties(new List { this.needCherryPickedData.Object }); + + this.sessionService.Setup(x => x.Session.RetrieveSiteDirectory()).Returns(new SiteDirectory()); + + 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); + + propertyInfo?.SetValue(this.viewModel, false, null); + await this.viewModel.RunCherryPick(); + this.needCherryPickedData.Verify(x => x.ProcessCherryPickedData(Moq.It.IsAny>>()), Times.Once); + } + } +} diff --git a/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs b/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs new file mode 100644 index 00000000..344cf3fe --- /dev/null +++ b/COMET.Web.Common.Tests/WebAssembly/Services/NamingConventionService/NamingConventionServiceTestFixture.cs @@ -0,0 +1,116 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Tests.WebAssembly.Services.NamingConventionService +{ + using System.Net; + + using COMET.Web.Common.Services.NamingConventionService; + using COMET.Web.Common.Test.Helpers; + using COMET.Web.Common.WebAssembly.Services.NamingConventionService; + + using Microsoft.Extensions.Logging; + + using Moq; + + using NUnit.Framework; + + using RichardSzalay.MockHttp; + + [TestFixture] + public class NamingConventionServiceTestFixture + { + private NamingConventionService service; + private MockHttpMessageHandler mockHttpMessageHandler; + private Mock>> logger; + + [SetUp] + public void Setup() + { + this.mockHttpMessageHandler = new MockHttpMessageHandler(); + var httpClient = this.mockHttpMessageHandler.ToHttpClient(); + httpClient.BaseAddress = new Uri("http://localhost/"); + this.logger = new Mock>>(); + this.service = new NamingConventionService(this.logger.Object, httpClient); + } + + [Test] + public async Task VerifyService() + { + this.mockHttpMessageHandler.When(HttpMethod.Get, "/_content/CDP4.WEB.Common/naming_convention.json") + .Throw(new Exception()); + + await this.service.InitializeService(); + this.logger.Verify(LogLevel.Critical, o => o!.ToString()!.Contains("Exception has been raised"), Times.Once()); + + this.mockHttpMessageHandler.ResetBackendDefinitions(); + + var httpResponse = new HttpResponseMessage() + { + StatusCode = HttpStatusCode.InternalServerError + }; + + this.mockHttpMessageHandler.When(HttpMethod.Get, "/_content/CDP4.WEB.Common/naming_convention.json") + .Respond(_ => httpResponse); + + await this.service.InitializeService(); + this.logger.Verify(LogLevel.Error, o => o!.ToString()!.Contains("Error fetching naming conventions. Status code:"), Times.Once()); + + httpResponse.StatusCode = HttpStatusCode.NotFound; + + await this.service.InitializeService(); + this.logger.Verify(LogLevel.Error, o => o!.ToString()!.Contains("Naming conventions file not found at "), Times.Once()); + + httpResponse.StatusCode = HttpStatusCode.OK; + + var json = """ + { + "TestValue1": "TestValue1", + "TestValue2": "TestValue2" + } + """; + + httpResponse.Content = new StringContent(json); + await this.service.InitializeService(); + + var enumValues = Enum.GetValues(); + + Assert.Multiple(() => + { + foreach (var namingConventionKind in enumValues) + { + Assert.That(this.service.GetNamingConventionValue(namingConventionKind), Is.Not.Empty); + } + }); + } + + /// To be used for testing purposes only + public enum NamingConventionKindTestEnum + { + TestValue1, + TestValue2 + } + } +} diff --git a/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs new file mode 100644 index 00000000..576f2837 --- /dev/null +++ b/COMET.Web.Common/Server/Services/NamingConventionService/NamingConventionService.cs @@ -0,0 +1,68 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Server.Services.NamingConventionService +{ + using System.Text.Json; + + using COMET.Web.Common.Services.NamingConventionService; + + using Microsoft.Extensions.Logging; + + /// + /// The provides static information based on defined naming convention, like for names of + /// to use for example + /// + public class NamingConventionService : BaseNamingConventionService where TEnum : Enum + { + /// + /// The + /// + private readonly ILogger> logger; + + public NamingConventionService(ILogger> logger) : base(logger) + { + this.logger = logger; + } + + /// + /// Gets the naming convention configuration + /// + /// A of the naming convention configuration + protected override async Task> GetNamingConventionConfiguration() + { + try + { + var namingConvention = JsonSerializer.Deserialize>(await File.ReadAllTextAsync(Path.Combine("Resources", "configuration", "naming_convention.json")))!; + return new Dictionary(namingConvention, StringComparer.OrdinalIgnoreCase); + } + catch (Exception e) + { + this.logger.LogError(e, "Error while getting the naming convention configuration file."); + throw; + } + } + } +} diff --git a/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs new file mode 100644 index 00000000..aedf4fed --- /dev/null +++ b/COMET.Web.Common/Services/NamingConventionService/BaseNamingConventionService.cs @@ -0,0 +1,104 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Services.NamingConventionService +{ + using Microsoft.Extensions.Logging; + + /// + /// The provides static information based on defined naming convention, like for names of + /// to use for example + /// + /// Any type of enumeration that will contain the different types of naming conventions + public abstract class BaseNamingConventionService : INamingConventionService where TEnum : Enum + { + /// + /// that holds the defined naming convention + /// + private readonly Dictionary definedNaming = new(StringComparer.OrdinalIgnoreCase); + + /// + /// The + /// + protected readonly ILogger> Logger; + + /// + /// Initializes a new instance of the class. + /// + /// The + protected BaseNamingConventionService(ILogger> logger) + { + this.Logger = logger; + } + + /// + /// Initializes this service + /// + /// A + public async Task InitializeService() + { + var namingConvention = await this.GetNamingConventionConfiguration(); + + foreach (var namingConventionKind in Enum.GetValues(typeof(TEnum))) + { + if (namingConvention.TryGetValue(namingConventionKind.ToString(), out var namingConventionValue)) + { + this.definedNaming[namingConventionKind.ToString()] = namingConventionValue; + } + else + { + this.Logger.LogWarning("{namingConventionKind} is missing from the Naming Convention configuration file", namingConventionKind.ToString()); + } + } + } + + /// + /// Gets the value for naming convention + /// + /// The naming convention key + /// The defined naming convention, if exists + public string GetNamingConventionValue(string namingConventionKey) + { + return this.definedNaming.TryGetValue(namingConventionKey, out var namingConventionValue) ? namingConventionValue : string.Empty; + } + + /// + /// Gets the value for naming convention + /// + /// The enum that is used by the service + /// The defined naming convention, if exists + public string GetNamingConventionValue(TEnum namingConventionKind) + { + return this.GetNamingConventionValue(namingConventionKind.ToString()); + } + + /// + /// Gets the naming convention configuration + /// + /// A of the naming convention configuration + /// + protected abstract Task> GetNamingConventionConfiguration(); + } +} diff --git a/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs new file mode 100644 index 00000000..dd14eb1e --- /dev/null +++ b/COMET.Web.Common/Services/NamingConventionService/INamingConventionService.cs @@ -0,0 +1,54 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Services.NamingConventionService +{ + /// + /// The provides static information based on defined naming convention, like for names of to use for example + /// + /// Any type of enumeration that will contain the different types of naming conventions + public interface INamingConventionService where TEnum : Enum + { + /// + /// Initializes this service + /// + /// A + Task InitializeService(); + + /// + /// Gets the value for naming convention + /// + /// The naming convention key + /// The defined naming convention, if exists + string GetNamingConventionValue(string namingConventionKey); + + /// + /// Gets the value for naming convention + /// + /// The + /// The defined naming convention, if exists + string GetNamingConventionValue(TEnum namingConventionKind); + } +} diff --git a/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs b/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs new file mode 100644 index 00000000..c9bc990c --- /dev/null +++ b/COMET.Web.Common/Utilities/CherryPick/CherryPickRunner.cs @@ -0,0 +1,110 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Utilities.CherryPick +{ + using CDP4Common.SiteDirectoryData; + + using COMET.Web.Common.Services.SessionManagement; + + /// + /// Utility class that could run CherryPick query for + /// + public class CherryPickRunner : ICherryPickRunner + { + /// + /// Gets the collection of + /// + private readonly List NeedCherryPicked = new(); + + /// + /// Gets the + /// + protected readonly ISessionService SessionService; + + /// + /// Initializes a new + /// + /// The + public CherryPickRunner(ISessionService sessionService) + { + this.SessionService = sessionService; + } + + /// + /// Asserts that the cherrypick feature is on going + /// + public bool IsCherryPicking { get; private set; } + + /// + /// Initializes the internal properties + /// + /// A collection of + public void InitializeProperties(IEnumerable needCherryPicked) + { + this.NeedCherryPicked.Clear(); + this.NeedCherryPicked.AddRange(needCherryPicked); + } + + /// + /// Runs the cherrypick features based on data required from + /// + /// A + 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(); + + 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; + } + } +} diff --git a/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs b/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs new file mode 100644 index 00000000..aa8c4e32 --- /dev/null +++ b/COMET.Web.Common/Utilities/CherryPick/ICherryPickRunner.cs @@ -0,0 +1,50 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Utilities.CherryPick +{ + /// + /// Utility class that could run CherryPick query for + /// + public interface ICherryPickRunner + { + /// + /// Asserts that the cherrypick feature is on going + /// + bool IsCherryPicking { get; } + + /// + /// Initializes the internal properties + /// + /// A collection of + void InitializeProperties(IEnumerable needCherryPicked); + + /// + /// Runs the cherrypick features based on data required from + /// + /// A + Task RunCherryPick(); + } +} diff --git a/COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs b/COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs new file mode 100644 index 00000000..44d012ef --- /dev/null +++ b/COMET.Web.Common/Utilities/CherryPick/INeedCherryPickedData.cs @@ -0,0 +1,54 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Utilities.CherryPick +{ + using CDP4Common.CommonData; + using CDP4Common.SiteDirectoryData; + + using Thing = CDP4Common.DTO.Thing; + + /// + /// Interface that define that an object needs data that comes from CherryPick feature + /// + public interface INeedCherryPickedData + { + /// + /// Gets the collection of name that this object is interested on + /// + public IReadOnlyCollection CategoriesOfInterest { get; } + + /// + /// Gets the collection of that this object is interested on + /// + public IReadOnlyCollection ClassKindsOfInterest { get; } + + /// + /// Process Cherry picked data + /// + /// A collection of collection of + public void ProcessCherryPickedData(IEnumerable> cherryPickedData); + } +} diff --git a/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs b/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs new file mode 100644 index 00000000..6a8bbc0e --- /dev/null +++ b/COMET.Web.Common/WebAssembly/Services/NamingConventionService/NamingConventionService.cs @@ -0,0 +1,92 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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. +// +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.WebAssembly.Services.NamingConventionService +{ + using System.Collections.Immutable; + using System.Net; + using System.Text.Json; + + using COMET.Web.Common.Services.NamingConventionService; + using COMET.Web.Common.Utilities; + + using Microsoft.Extensions.Logging; + + /// + /// The provides static information based on defined naming convention, like for names of + /// to use for example + /// + public class NamingConventionService : BaseNamingConventionService where TEnum : Enum + { + /// + /// The + /// + private readonly HttpClient httpClient; + + /// + /// Creates a new instance of type + /// + /// the + /// the + public NamingConventionService(ILogger> logger, HttpClient httpClient) : base(logger) + { + this.httpClient = httpClient; + } + + /// + /// Gets the naming convention configuration + /// + /// A of the naming convention configuration + protected override async Task> GetNamingConventionConfiguration() + { + try + { + var path = ContentPathBuilder.BuildPath("naming_convention.json"); + var response = await this.httpClient.GetAsync(path); + + if (response.IsSuccessStatusCode) + { + var jsonContent = await response.Content.ReadAsStreamAsync(); + var namingConvention = JsonSerializer.Deserialize>(jsonContent); + return new Dictionary(namingConvention, StringComparer.OrdinalIgnoreCase); + } + + if (response.StatusCode == HttpStatusCode.NotFound) + { + this.Logger.LogError("Naming conventions file not found at {path}", path); + return ImmutableDictionary.Empty; + } + + this.Logger.LogError("Error fetching naming conventions. Status code: {response}", response.StatusCode); + return ImmutableDictionary.Empty; + } + catch (Exception e) + { + this.Logger.LogCritical("Exception has been raised : {message}", e.Message); + return ImmutableDictionary.Empty; + } + } + } +}