Skip to content
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

Feat/SessionServiceImprovements. Fix #489 #490

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SessionServiceExtensionsTestFixture.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.Extensions
{
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;

using CDP4Dal;
using CDP4Dal.Operations;

using COMET.Web.Common.Extensions;
using COMET.Web.Common.Services.SessionManagement;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;

[TestFixture]
public class SessionServiceExtensionsTestFixture
{
private Mock<ISession> session;
private ISessionService sessionService;

[SetUp]
public void Setup()
{
var logger = new Mock<ILogger<SessionService>>();

this.session = new Mock<ISession>();
this.sessionService = new SessionService(logger.Object)
{
Session = this.session.Object
};
}

[Test]
public void VerifyAddParameter()
{
var model = new EngineeringModel();
var iterationSetup = new IterationSetup();
var iteration = new Iteration()
{
IterationSetup = iterationSetup,
Container = model
};
model.Iteration.Add(iteration);

var elementDefinition = new ElementDefinition();
iteration.Element.Add(elementDefinition);

var textParameterType = new TextParameterType();

var doe = new DomainOfExpertise()
{
Name = "doe",
ShortName = "doe"
};

Assert.Multiple(() =>
{
Assert.That(() => this.sessionService.AddParameter(null, null, null, null, null), Throws.ArgumentNullException);
Assert.That(() => this.sessionService.AddParameter(elementDefinition, null, null, null, null), Throws.ArgumentNullException);
Assert.That(() => this.sessionService.AddParameter(elementDefinition, null, textParameterType, null, null), Throws.ArgumentNullException);
Assert.That(() => this.sessionService.AddParameter(elementDefinition, null, textParameterType, null, doe), Throws.Nothing);
});

this.session.Verify(x => x.Write(It.IsAny<OperationContainer>()), Times.Once);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace COMET.Web.Common.Tests.Services.SessionManagement

using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Services.SessionManagement;

using Microsoft.Extensions.Logging;

using Moq;

using NUnit.Framework;
Expand All @@ -59,8 +62,13 @@ public class SessionServiceTestFixture
[SetUp]
public void Setup()
{
var logger = new Mock<ILogger<SessionService>>();

this.session = new Mock<ISession>();
this.sessionService = new SessionService { Session = this.session.Object };
this.sessionService = new SessionService(logger.Object)
{
Session = this.session.Object
};
this.assembler = new Assembler(this.uri);
this.domain = new DomainOfExpertise(Guid.NewGuid(), this.assembler.Cache, this.uri);

Expand Down
3 changes: 2 additions & 1 deletion COMET.Web.Common/COMET.Web.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>Latest</LangVersion>
<Version>1.0.39</Version>
<Version>1.0.40</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>
<Title>CDP4 WEB Common</Title>
Expand All @@ -27,6 +27,7 @@
<ItemGroup>
<PackageReference Include="CDP4ServicesDal-CE" Version="24.2.0" />
<PackageReference Include="DevExpress.Blazor" Version="23.1.4" />
<PackageReference Include="FluentResults" Version="3.15.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.4" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
Expand Down
87 changes: 87 additions & 0 deletions COMET.Web.Common/Extensions/SessionServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SessionServiceExtensions.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.Extensions
{
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Services.SessionManagement;

using FluentResults;

/// <summary>
/// Static class with extension methods for the <see cref="ISessionService"/>
/// </summary>
public static class SessionServiceExtensions
{
/// <summary>
/// Adds a new parameter for a given element definition
/// </summary>
/// <param name="sessionService">The <see cref="ISessionService"/> in which data will be updated</param>
/// <param name="elementDefinition">The <see cref="ElementDefinition"/> in which a new parameter will be added</param>
/// <param name="group">The <see cref="ParameterGroup"/> of the new parameter</param>
/// <param name="parameterType">The <see cref="ParameterType"/> of the new parameter</param>
/// <param name="measurementScale">The <see cref="MeasurementScale"/> of the new parameter</param>
/// <param name="owner">The <see cref="DomainOfExpertise"/> of the owner</param>
/// <returns>A <see cref="Task"/></returns>
/// <exception cref="ArgumentNullException">Throws an <see cref="ArgumentNullException"/></exception>
public static async Task<Result> AddParameter(this ISessionService sessionService, ElementDefinition elementDefinition, ParameterGroup group, ParameterType parameterType, MeasurementScale measurementScale, DomainOfExpertise owner)

Check warning on line 50 in COMET.Web.Common/Extensions/SessionServiceExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Split this method into two, one handling parameters check and the other handling the asynchronous code. (https://rules.sonarsource.com/csharp/RSPEC-4457)

Check warning on line 50 in COMET.Web.Common/Extensions/SessionServiceExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Split this method into two, one handling parameters check and the other handling the asynchronous code. (https://rules.sonarsource.com/csharp/RSPEC-4457)
{
if (elementDefinition == null)
{
throw new ArgumentNullException(nameof(elementDefinition), "The container ElementDefinition may not be null");
}

if (parameterType == null)
{
throw new ArgumentNullException(nameof(parameterType), "The ParameterType may not be null");
}

if (owner == null)
{
throw new ArgumentNullException(nameof(owner), "The owner DomainOfExpertise may not be null");
}

if (sessionService.Session == null)
{
throw new ArgumentNullException(nameof(sessionService.Session), "The session may not be null");

Check warning on line 69 in COMET.Web.Common/Extensions/SessionServiceExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The parameter name 'Session' is not declared in the argument list. (https://rules.sonarsource.com/csharp/RSPEC-3928)

Check warning on line 69 in COMET.Web.Common/Extensions/SessionServiceExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The parameter name 'Session' is not declared in the argument list. (https://rules.sonarsource.com/csharp/RSPEC-3928)
}

var parameter = new Parameter(Guid.NewGuid(), null, null)
{
Owner = owner,
ParameterType = parameterType,
Scale = measurementScale,
Group = group,
ValueSet = { new ParameterValueSet() }
};

var clone = elementDefinition.Clone(false);
clone.Parameter.Add(parameter);

return await sessionService.CreateThing(clone, parameter);
}
}
}
42 changes: 22 additions & 20 deletions COMET.Web.Common/Services/SessionManagement/ISessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace COMET.Web.Common.Services.SessionManagement

using DynamicData;

using FluentResults;

/// <summary>
/// The <see cref="ISessionService" /> interface provides access to an <see cref="ISession" />
/// </summary>
Expand Down Expand Up @@ -75,8 +77,8 @@ public interface ISessionService
/// </summary>
/// <param name="iterationSetup">The selected <see cref="IterationSetup" /></param>
/// <param name="domain">The <see cref="DomainOfExpertise" /></param>
/// <returns>An asynchronous operation</returns>
Task ReadIteration(IterationSetup iterationSetup, DomainOfExpertise domain);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> ReadIteration(IterationSetup iterationSetup, DomainOfExpertise domain);

/// <summary>
/// Close all the opened <see cref="Iteration" />
Expand Down Expand Up @@ -125,72 +127,72 @@ public interface ISessionService
/// </summary>
/// <param name="container">the <see cref="Thing"/> container where the <param name="thingToCreate"></param> should be created</param>
/// <param name="thingToCreate">the thing to create in the session</param>
/// <returns>An asynchronous operation</returns>
Task CreateThing(Thing container, Thing thingToCreate);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> CreateThing(Thing container, Thing thingToCreate);

/// <summary>
/// Write new Things in an <see cref="Iteration"/>
/// </summary>
/// <param name="container">the <see cref="Thing"/> container where the <param name="thingsToCreate"></param> should be created</param>
/// <param name="thingsToCreate">the things to create in the session</param>
/// <returns>An asynchronous operation</returns>
Task CreateThings(Thing container, params Thing[] thingsToCreate);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> CreateThings(Thing container, params Thing[] thingsToCreate);

/// <summary>
/// Write new Things in an <see cref="Iteration" />
/// </summary>
/// <param name="container">The <see cref="Thing" /> where the <see cref="Thing" />s should be created</param>
/// <param name="thingsToCreate">List of Things to create in the session</param>
/// <returns>An asynchronous operation</returns>
Task CreateThings(Thing container, IEnumerable<Thing> thingsToCreate);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> CreateThings(Thing container, IEnumerable<Thing> thingsToCreate);

/// <summary>
/// Write updated Thing in an <see cref="Iteration" />
/// </summary>
/// <param name="container">The <see cref="Thing" /> where the <see cref="Thing" />s should be updated</param>
/// <param name="thingToUpdate">the thing to update in the session</param>
/// <returns>An asynchronous operation</returns>
Task UpdateThing(Thing container, Thing thingToUpdate);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> UpdateThing(Thing container, Thing thingToUpdate);

/// <summary>
/// Write updated Things in an <see cref="Iteration" />
/// </summary>
/// <param name="container">The <see cref="Thing" /> where the <see cref="Thing" />s should be updated</param>
/// <param name="thingsToUpdate">List of Things to update in the session</param>
/// <returns>An asynchronous operation</returns>
Task UpdateThings(Thing container, params Thing[] thingsToUpdate);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> UpdateThings(Thing container, params Thing[] thingsToUpdate);

/// <summary>
/// Write updated Things in an <see cref="Iteration" />
/// </summary>
/// <param name="container">The <see cref="Thing" /> where the <see cref="Thing" />s should be updated</param>
/// <param name="thingsToUpdate">List of Things to update in the session</param>
/// <returns>An asynchronous operation</returns>
Task UpdateThings(Thing container, IEnumerable<Thing> thingsToUpdate);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> UpdateThings(Thing container, IEnumerable<Thing> thingsToUpdate);

/// <summary>
/// Deletes a <see cref="Thing"/> from it's container
/// </summary>
/// <param name="containerClone">the container clone of the thing to delete</param>
/// <param name="thingToDelete">the thing to delete in the session</param>
/// <returns>An asynchronous operation</returns>
Task DeleteThing(Thing containerClone, Thing thingToDelete);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> DeleteThing(Thing containerClone, Thing thingToDelete);

/// <summary>
/// Deletes a collection of <see cref="Thing"/> from it's container
/// </summary>
/// <param name="containerClone">the container clone of the thing to delete</param>
/// <param name="thingsToDelete">the things to delete in the session</param>
/// <returns>An asynchronous operation</returns>
Task DeleteThings(Thing containerClone, params Thing[] thingsToDelete);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> DeleteThings(Thing containerClone, params Thing[] thingsToDelete);

/// <summary>
/// Deletes a collection <see cref="Thing"/> from it's container
/// </summary>
/// <param name="containerClone">the container clone of the thing to delete</param>
/// <param name="thingsToDelete">the things to delete in the session</param>
/// <returns>An asynchronous operation</returns>
Task DeleteThings(Thing containerClone, IEnumerable<Thing> thingsToDelete);
/// <returns>An asynchronous operation with a <see cref="Result"/></returns>
Task<Result> DeleteThings(Thing containerClone, IEnumerable<Thing> thingsToDelete);

/// <summary>
/// Gets the <see cref="ParticipantRole" /> inside an iteration
Expand Down
Loading
Loading