From c9064f03d5b50a7b3bd2a5351fbb7cdc7c056798 Mon Sep 17 00:00:00 2001 From: Alexander van Delft <56023674+lxatrhea@users.noreply.github.com> Date: Mon, 23 Nov 2020 11:58:41 +0100 Subject: [PATCH] Fixes #151 DomainOfExpertise from session (#152) * Implement * Version bump * Review changes * Docs changed --- CDP4Dal.Tests/SessionTestFixture.cs | 70 ++------------------------ CDP4Dal/CDP4Dal.csproj | 4 +- CDP4Dal/ISession.cs | 25 ++++----- CDP4Dal/Session.cs | 57 ++++++++------------- CDP4JsonFileDal/CDP4JsonFileDal.csproj | 4 +- CDP4ServicesDal/CDP4ServicesDal.csproj | 5 +- CDP4WspDal/CDP4WspDal.csproj | 5 +- 7 files changed, 40 insertions(+), 130 deletions(-) diff --git a/CDP4Dal.Tests/SessionTestFixture.cs b/CDP4Dal.Tests/SessionTestFixture.cs index 6d5025f0d..b47cba2d4 100644 --- a/CDP4Dal.Tests/SessionTestFixture.cs +++ b/CDP4Dal.Tests/SessionTestFixture.cs @@ -622,69 +622,6 @@ public void VerifyThatIsVersionSupportedReturnsExpectedResult() Assert.IsFalse(this.session.IsVersionSupported(notSupportedVersion)); } - [Test] - public async Task VerifyThatQueryCurrentDomainOfExpertiseWorks() - { - var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); - var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; - var modelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); - var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { IterationIid = Guid.NewGuid() }; - var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); - var srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); - var activeDomain = new DomainOfExpertise(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); - mrdl.RequiredRdl = srdl; - modelSetup.RequiredRdl.Add(mrdl); - modelSetup.IterationSetup.Add(iterationSetup); - siteDir.Model.Add(modelSetup); - siteDir.SiteReferenceDataLibrary.Add(srdl); - siteDir.Domain.Add(activeDomain); - siteDir.Person.Add(JohnDoe); - - this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy(() => siteDir)); - this.session.Assembler.Cache.TryAdd(new CacheKey(JohnDoe.Iid, null), new Lazy(() => JohnDoe)); - this.session.Assembler.Cache.TryAdd(new CacheKey(modelSetup.Iid, null), new Lazy(() => modelSetup)); - this.session.Assembler.Cache.TryAdd(new CacheKey(mrdl.Iid, null), new Lazy(() => mrdl)); - this.session.Assembler.Cache.TryAdd(new CacheKey(srdl.Iid, null), new Lazy(() => srdl)); - this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy(() => siteDir)); - this.session.Assembler.Cache.TryAdd(new CacheKey(iterationSetup.Iid, null), new Lazy(() => iterationSetup)); - - this.session.GetType().GetProperty("ActivePerson").SetValue(this.session, JohnDoe, null); - - var participant = new CDP4Common.SiteDirectoryData.Participant(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { Person = this.session.ActivePerson }; - participant.Domain.Add(activeDomain); - modelSetup.Participant.Add(participant); - - var model = new EngineeringModel(Guid.NewGuid(), 1); - var iteration = new Iteration(iterationSetup.IterationIid, 10) { IterationSetup = iterationSetup.Iid }; - model.Iteration.Add(iteration.Iid); - model.EngineeringModelSetup = modelSetup.Iid; - - var readOutput = new List - { - model, - iteration - }; - - var readTaskCompletionSource = new TaskCompletionSource>(); - readTaskCompletionSource.SetResult(readOutput); - this.mockedDal.Setup(x => x.Read(It.IsAny(), It.IsAny(), It.IsAny())).Returns(readTaskCompletionSource.Task); - - var iterationToOpen = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); - var modelToOpen = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null); - iterationToOpen.Container = modelToOpen; - - await this.session.Read(iterationToOpen, activeDomain); - - var resultDomain = this.session.QueryCurrentDomainOfExpertise(); - - Assert.AreEqual(activeDomain, resultDomain); - - iterationSetup.FrozenOn = DateTime.UtcNow; - - resultDomain = this.session.QueryCurrentDomainOfExpertise(); - - Assert.IsNull(resultDomain); - } [Test] public async Task VerifyThatQueryDomainOfExpertiseWorks() @@ -739,13 +676,12 @@ public async Task VerifyThatQueryDomainOfExpertiseWorks() await this.session.Read(iterationToOpen, activeDomain); - var resultDomains = this.session.QueryDomainOfExpertise(); + var resultDomains = this.session.QueryDomainOfExpertise(iterationToOpen); CollectionAssert.AreEqual(new [] {activeDomain}, resultDomains); - iterationSetup.FrozenOn = DateTime.UtcNow; - - resultDomains = this.session.QueryDomainOfExpertise(); + var unknownIteration = new CDP4Common.EngineeringModelData.Iteration(Guid.NewGuid(), null, null); + resultDomains = this.session.QueryDomainOfExpertise(unknownIteration); CollectionAssert.IsEmpty(resultDomains); } diff --git a/CDP4Dal/CDP4Dal.csproj b/CDP4Dal/CDP4Dal.csproj index c5adde8f2..f183a0c6f 100644 --- a/CDP4Dal/CDP4Dal.csproj +++ b/CDP4Dal/CDP4Dal.csproj @@ -4,7 +4,7 @@ net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1 RHEA System S.A. CDP4Dal Community Edition - 6.3.0 + 7.0.0 CDP4 Data Access Layer library, a consumer of an ECSS-E-TM-10-25 Annex C API Copyright © RHEA System S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathaniel, Kamil @@ -19,7 +19,7 @@ CDP CDP4 ECSS-E-TM-10-25 LGPL-3.0-only - [Update] Uri handling + [Fix] Query DomainOfExpertise methods on ISession diff --git a/CDP4Dal/ISession.cs b/CDP4Dal/ISession.cs index 5f77c2e74..e045888ac 100644 --- a/CDP4Dal/ISession.cs +++ b/CDP4Dal/ISession.cs @@ -128,6 +128,15 @@ public interface ISession /// A if has been selected for the , null otherwise. /// DomainOfExpertise QuerySelectedDomainOfExpertise(Iteration iteration); + + /// + /// Queries the 's 's from the session for the provided + /// + /// The + /// + /// The s for the that belongs to the for this . + /// + IEnumerable QueryDomainOfExpertise(Iteration iteration); /// /// Switches the current domain for an iteration @@ -311,21 +320,5 @@ public interface ISession /// The . /// Task CloseModelRdl(ModelReferenceDataLibrary modelRdl); - - /// - /// Queries the current from the session for the current - /// - /// - /// The if selected, null otherwise. - /// - DomainOfExpertise QueryCurrentDomainOfExpertise(); - - /// - /// Queries the 's 's from the session for the current - /// - /// - /// The if selected, null otherwise. - /// - IEnumerable QueryDomainOfExpertise(); } } diff --git a/CDP4Dal/Session.cs b/CDP4Dal/Session.cs index e6b7d4d40..e71334342 100644 --- a/CDP4Dal/Session.cs +++ b/CDP4Dal/Session.cs @@ -225,6 +225,26 @@ public DomainOfExpertise QuerySelectedDomainOfExpertise(Iteration iteration) return iterationDomainPair.Value == null || iterationDomainPair.Value.Item1 == null ? null : iterationDomainPair.Value.Item1; } + + /// + /// Queries the 's 's from the session for the provided + /// + /// + /// The + /// The s for the that belongs to the for this . + /// + public IEnumerable QueryDomainOfExpertise(Iteration iteration) + { + var iterationDomainPair = this.OpenIterations.SingleOrDefault(x => x.Key.Iid == iteration.Iid); + var domainOfExpertise = new List(); + + if (iterationDomainPair.Value?.Item2 != null) + { + domainOfExpertise.AddRange(iterationDomainPair.Value.Item2.Domain); + } + + return domainOfExpertise; + } /// /// Convenience function to get the required reference data library chain for the passed in engineeringModel. @@ -947,42 +967,5 @@ private void AddIterationToOpenList(Guid iterationId, DomainOfExpertise activeDo var modelRdl = ((EngineeringModel) iteration.Container).EngineeringModelSetup.RequiredRdl.Single(); this.AddRdlToOpenList(modelRdl); } - - /// - /// Queries the current from the session for the current - /// - /// - /// The if selected, null otherwise. - /// - public DomainOfExpertise QueryCurrentDomainOfExpertise() - { - var iterationDomainPair = this.OpenIterations.SingleOrDefault(x => !x.Key.IterationSetup.FrozenOn.HasValue); - - if (iterationDomainPair.Equals(default(KeyValuePair>))) - { - return null; - } - - return (iterationDomainPair.Value == null) || (iterationDomainPair.Value.Item1 == null) ? null : iterationDomainPair.Value.Item1; - } - - /// - /// Queries the 's 's from the session for the current - /// - /// - /// The if selected, null otherwise. - /// - public IEnumerable QueryDomainOfExpertise() - { - var iterationDomainPair = this.OpenIterations.SingleOrDefault(x => !x.Key.IterationSetup.FrozenOn.HasValue); - var domainOfExpertise = new List(); - - if (iterationDomainPair.Value?.Item2 != null) - { - domainOfExpertise.AddRange(iterationDomainPair.Value.Item2.Domain); - } - - return domainOfExpertise; - } } } diff --git a/CDP4JsonFileDal/CDP4JsonFileDal.csproj b/CDP4JsonFileDal/CDP4JsonFileDal.csproj index 5ce2f52eb..e01ce61d3 100644 --- a/CDP4JsonFileDal/CDP4JsonFileDal.csproj +++ b/CDP4JsonFileDal/CDP4JsonFileDal.csproj @@ -4,7 +4,7 @@ net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1 RHEA System S.A. CDP4JsonFileDal Community Edition - 6.3.0 + 7.0.0 CDP4 Json File Dal Plugin Copyright © RHEA System S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathaniel, Kamil @@ -19,7 +19,7 @@ CDP CDP4 ECSS-E-TM-10-25 LGPL-3.0-only - [Update] to CDP4Dal 6.3.0 + [Update] to CDP4Dal 7.0.0 diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj index 4cb5f24dc..0a55a2589 100644 --- a/CDP4ServicesDal/CDP4ServicesDal.csproj +++ b/CDP4ServicesDal/CDP4ServicesDal.csproj @@ -4,7 +4,7 @@ net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1 RHEA System S.A. CDP4ServicesDal Community Edition - 6.3.0 + 7.0.0 CDP4ServicesDal Dal Plugin Copyright © RHEA System S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathaniel, Kamil @@ -19,8 +19,7 @@ CDP CDP4 ECSS-E-TM-10-25 LGPL-3.0-only - [Update] to CDP4Dal 6.3.0 - [Fix] Uri handling + [Update] to CDP4Dal 7.0.0 diff --git a/CDP4WspDal/CDP4WspDal.csproj b/CDP4WspDal/CDP4WspDal.csproj index 6db918b67..1fe772188 100644 --- a/CDP4WspDal/CDP4WspDal.csproj +++ b/CDP4WspDal/CDP4WspDal.csproj @@ -4,7 +4,7 @@ net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1 RHEA System S.A. CDP4WspDal Community Edition - 6.3.0 + 7.0.0 CDP4 WSP Dal Plugin Copyright © RHEA System S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathaniel, Kamil @@ -19,8 +19,7 @@ CDP CDP4 ECSS-E-TM-10-25 LGPL-3.0-only - [Update] to CDP4Dal 6.3.0 - [Fix] Uri handling + [Update] to CDP4Dal 7.0.0