Skip to content

Commit

Permalink
Fixes #151 DomainOfExpertise from session (#152)
Browse files Browse the repository at this point in the history
* Implement
* Version bump
* Review changes
* Docs changed
  • Loading branch information
lxatstariongroup authored Nov 23, 2020
1 parent 8f6197a commit c9064f0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 130 deletions.
70 changes: 3 additions & 67 deletions CDP4Dal.Tests/SessionTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CDP4Common.CommonData.Thing>(() => siteDir));
this.session.Assembler.Cache.TryAdd(new CacheKey(JohnDoe.Iid, null), new Lazy<CDP4Common.CommonData.Thing>(() => JohnDoe));
this.session.Assembler.Cache.TryAdd(new CacheKey(modelSetup.Iid, null), new Lazy<CDP4Common.CommonData.Thing>(() => modelSetup));
this.session.Assembler.Cache.TryAdd(new CacheKey(mrdl.Iid, null), new Lazy<CDP4Common.CommonData.Thing>(() => mrdl));
this.session.Assembler.Cache.TryAdd(new CacheKey(srdl.Iid, null), new Lazy<CDP4Common.CommonData.Thing>(() => srdl));
this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy<CDP4Common.CommonData.Thing>(() => siteDir));
this.session.Assembler.Cache.TryAdd(new CacheKey(iterationSetup.Iid, null), new Lazy<CDP4Common.CommonData.Thing>(() => 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<Thing>
{
model,
iteration
};

var readTaskCompletionSource = new TaskCompletionSource<IEnumerable<Thing>>();
readTaskCompletionSource.SetResult(readOutput);
this.mockedDal.Setup(x => x.Read(It.IsAny<Iteration>(), It.IsAny<CancellationToken>(), It.IsAny<IQueryAttributes>())).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()
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions CDP4Dal/CDP4Dal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4Dal Community Edition</Title>
<VersionPrefix>6.3.0</VersionPrefix>
<VersionPrefix>7.0.0</VersionPrefix>
<Description>CDP4 Data Access Layer library, a consumer of an ECSS-E-TM-10-25 Annex C API</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathaniel, Kamil</Authors>
Expand All @@ -19,7 +19,7 @@
<PackageTags>CDP CDP4 ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[Update] Uri handling
[Fix] Query DomainOfExpertise methods on ISession
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
25 changes: 9 additions & 16 deletions CDP4Dal/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ public interface ISession
/// A <see cref="DomainOfExpertise"/> if has been selected for the <see cref="Iteration"/>, null otherwise.
/// </returns>
DomainOfExpertise QuerySelectedDomainOfExpertise(Iteration iteration);

/// <summary>
/// Queries the <see cref="Participant"/>'s <see cref="DomainOfExpertise"/>'s from the session for the provided <see cref="Iteration"/>
/// </summary>
/// <param name="iteration">The <see cref="Iteration"/></param>
/// <returns>
/// The <see cref="DomainOfExpertise"/>s for the <see cref="Participant"/> that belongs to the <see cref="Iteration"/> for this <see cref="Session"/>.
/// </returns>
IEnumerable<DomainOfExpertise> QueryDomainOfExpertise(Iteration iteration);

/// <summary>
/// Switches the current domain for an iteration
Expand Down Expand Up @@ -311,21 +320,5 @@ public interface ISession
/// The <see cref="Task"/>.
/// </returns>
Task CloseModelRdl(ModelReferenceDataLibrary modelRdl);

/// <summary>
/// Queries the current <see cref="DomainOfExpertise"/> from the session for the current <see cref="Iteration"/>
/// </summary>
/// <returns>
/// The <see cref="DomainOfExpertise"/> if selected, null otherwise.
/// </returns>
DomainOfExpertise QueryCurrentDomainOfExpertise();

/// <summary>
/// Queries the <see cref="Participant"/>'s <see cref="DomainOfExpertise"/>'s from the session for the current <see cref="Iteration"/>
/// </summary>
/// <returns>
/// The <see cref="DomainOfExpertise"/> if selected, null otherwise.
/// </returns>
IEnumerable<DomainOfExpertise> QueryDomainOfExpertise();
}
}
57 changes: 20 additions & 37 deletions CDP4Dal/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,26 @@ public DomainOfExpertise QuerySelectedDomainOfExpertise(Iteration iteration)

return iterationDomainPair.Value == null || iterationDomainPair.Value.Item1 == null ? null : iterationDomainPair.Value.Item1;
}

/// <summary>
/// Queries the <see cref="Participant"/>'s <see cref="DomainOfExpertise"/>'s from the session for the provided <see cref="Iteration"/>
/// </summary>
/// <returns>
/// <param name="iteration">The <see cref="Iteration"/></param>
/// The <see cref="DomainOfExpertise"/>s for the <see cref="Participant"/> that belongs to the <see cref="Iteration"/> for this <see cref="Session"/>.
/// </returns>
public IEnumerable<DomainOfExpertise> QueryDomainOfExpertise(Iteration iteration)
{
var iterationDomainPair = this.OpenIterations.SingleOrDefault(x => x.Key.Iid == iteration.Iid);
var domainOfExpertise = new List<DomainOfExpertise>();

if (iterationDomainPair.Value?.Item2 != null)
{
domainOfExpertise.AddRange(iterationDomainPair.Value.Item2.Domain);
}

return domainOfExpertise;
}

/// <summary>
/// Convenience function to get the required reference data library chain for the passed in engineeringModel.
Expand Down Expand Up @@ -947,42 +967,5 @@ private void AddIterationToOpenList(Guid iterationId, DomainOfExpertise activeDo
var modelRdl = ((EngineeringModel) iteration.Container).EngineeringModelSetup.RequiredRdl.Single();
this.AddRdlToOpenList(modelRdl);
}

/// <summary>
/// Queries the current <see cref="DomainOfExpertise"/> from the session for the current <see cref="Iteration"/>
/// </summary>
/// <returns>
/// The <see cref="DomainOfExpertise"/> if selected, null otherwise.
/// </returns>
public DomainOfExpertise QueryCurrentDomainOfExpertise()
{
var iterationDomainPair = this.OpenIterations.SingleOrDefault(x => !x.Key.IterationSetup.FrozenOn.HasValue);

if (iterationDomainPair.Equals(default(KeyValuePair<Iteration, Tuple<DomainOfExpertise, Participant>>)))
{
return null;
}

return (iterationDomainPair.Value == null) || (iterationDomainPair.Value.Item1 == null) ? null : iterationDomainPair.Value.Item1;
}

/// <summary>
/// Queries the <see cref="Participant"/>'s <see cref="DomainOfExpertise"/>'s from the session for the current <see cref="Iteration"/>
/// </summary>
/// <returns>
/// The <see cref="DomainOfExpertise"/> if selected, null otherwise.
/// </returns>
public IEnumerable<DomainOfExpertise> QueryDomainOfExpertise()
{
var iterationDomainPair = this.OpenIterations.SingleOrDefault(x => !x.Key.IterationSetup.FrozenOn.HasValue);
var domainOfExpertise = new List<DomainOfExpertise>();

if (iterationDomainPair.Value?.Item2 != null)
{
domainOfExpertise.AddRange(iterationDomainPair.Value.Item2.Domain);
}

return domainOfExpertise;
}
}
}
4 changes: 2 additions & 2 deletions CDP4JsonFileDal/CDP4JsonFileDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4JsonFileDal Community Edition</Title>
<VersionPrefix>6.3.0</VersionPrefix>
<VersionPrefix>7.0.0</VersionPrefix>
<Description>CDP4 Json File Dal Plugin</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathaniel, Kamil</Authors>
Expand All @@ -19,7 +19,7 @@
<PackageTags>CDP CDP4 ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[Update] to CDP4Dal 6.3.0
[Update] to CDP4Dal 7.0.0
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
5 changes: 2 additions & 3 deletions CDP4ServicesDal/CDP4ServicesDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4ServicesDal Community Edition</Title>
<VersionPrefix>6.3.0</VersionPrefix>
<VersionPrefix>7.0.0</VersionPrefix>
<Description>CDP4ServicesDal Dal Plugin</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathaniel, Kamil</Authors>
Expand All @@ -19,8 +19,7 @@
<PackageTags>CDP CDP4 ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[Update] to CDP4Dal 6.3.0
[Fix] Uri handling
[Update] to CDP4Dal 7.0.0
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
5 changes: 2 additions & 3 deletions CDP4WspDal/CDP4WspDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4WspDal Community Edition</Title>
<VersionPrefix>6.3.0</VersionPrefix>
<VersionPrefix>7.0.0</VersionPrefix>
<Description>CDP4 WSP Dal Plugin</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathaniel, Kamil</Authors>
Expand All @@ -19,8 +19,7 @@
<PackageTags>CDP CDP4 ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[Update] to CDP4Dal 6.3.0
[Fix] Uri handling
[Update] to CDP4Dal 7.0.0
</PackageReleaseNotes>
</PropertyGroup>

Expand Down

0 comments on commit c9064f0

Please sign in to comment.