Skip to content

Commit

Permalink
Fix SampledFunctionParameterType value array (#166)
Browse files Browse the repository at this point in the history
* Fix SampledFunctionParameterType value array

* Valueset validation for SampledFunctionParameterType

* Better handling og Canceled event in Write Session

* Fix unit tests

* Fix NestedParameter to support SampledFunctionParameterType

Co-authored-by: lxatrhea <[email protected]>
  • Loading branch information
Alex Vorobiev and lxatrhea authored Feb 3, 2021
1 parent 40fdcc1 commit ec2d263
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 48 deletions.
12 changes: 6 additions & 6 deletions CDP4Common/AutoGenDto/SampledFunctionParameterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SampledFunctionParameterType()
{
this.DependentParameterType = new List<OrderedItem>();
this.IndependentParameterType = new List<OrderedItem>();
this.InterpolationPeriod = new List<string>();
this.InterpolationPeriod = new ValueArray<string>();
}

/// <summary>
Expand All @@ -67,7 +67,7 @@ public SampledFunctionParameterType(Guid iid, int rev) : base(iid: iid, rev: rev
{
this.DependentParameterType = new List<OrderedItem>();
this.IndependentParameterType = new List<OrderedItem>();
this.InterpolationPeriod = new List<string>();
this.InterpolationPeriod = new ValueArray<string>();
}

/// <summary>
Expand All @@ -92,11 +92,11 @@ public SampledFunctionParameterType(Guid iid, int rev) : base(iid: iid, rev: rev
public List<OrderedItem> IndependentParameterType { get; set; }

/// <summary>
/// Gets or sets a list of String.
/// Gets or sets a list of ordered String.
/// </summary>
[UmlInformation(aggregation: AggregationKind.None, isDerived: false, isOrdered: false, isNullable: false, isPersistent: true)]
[UmlInformation(aggregation: AggregationKind.None, isDerived: false, isOrdered: true, isNullable: false, isPersistent: true)]
[DataMember]
public List<string> InterpolationPeriod { get; set; }
public ValueArray<string> InterpolationPeriod { get; set; }

/// <summary>
/// Gets the route for the current <see ref="SampledFunctionParameterType"/>.
Expand Down Expand Up @@ -217,7 +217,7 @@ public override void ResolveCopy(Thing originalThing, IReadOnlyDictionary<Thing,
this.IndependentParameterType.Add(new OrderedItem { K = orderedItem.K, V = copy.Value.Iid });
}

this.InterpolationPeriod.AddRange(original.InterpolationPeriod);
this.InterpolationPeriod = original.InterpolationPeriod;

this.IsDeprecated = original.IsDeprecated;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public IEnumerable<PropertyMetaInfo> Properties
{ "ExcludedDomain", new PropertyMetaInfo("ExcludedDomain", "DomainOfExpertise", PropertyKind.List, AggregationKind.None, false, false, true, 0, "*", true) },
{ "ExcludedPerson", new PropertyMetaInfo("ExcludedPerson", "Person", PropertyKind.List, AggregationKind.None, false, false, true, 0, "*", true) },
{ "Iid", new PropertyMetaInfo("Iid", "Guid", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "InterpolationPeriod", new PropertyMetaInfo("InterpolationPeriod", "string", PropertyKind.List, AggregationKind.None, false, false, true, 1, "*", true) },
{ "InterpolationPeriod", new PropertyMetaInfo("InterpolationPeriod", "string", PropertyKind.ValueArray, AggregationKind.None, false, true, true, 1, "*", true) },
{ "IsDeprecated", new PropertyMetaInfo("IsDeprecated", "bool", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "ModifiedOn", new PropertyMetaInfo("ModifiedOn", "DateTime", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "Name", new PropertyMetaInfo("Name", "string", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
Expand All @@ -309,7 +309,6 @@ public IEnumerable<PropertyMetaInfo> Properties
{ "ExcludedPerson", (value) => (Guid)value },
{ "HyperLink", (value) => (Guid)value },
{ "IndependentParameterType", (value) => (Guid)value },
{ "InterpolationPeriod", (value) => (string)value },
};

/// <summary>
Expand All @@ -319,6 +318,7 @@ public IEnumerable<PropertyMetaInfo> Properties
{
{ "DegreeOfInterpolation", (sampledFunctionParameterType, value) => sampledFunctionParameterType.DegreeOfInterpolation = value == null ? (int?)null : (int)value },
{ "Iid", (sampledFunctionParameterType, value) => sampledFunctionParameterType.Iid = (Guid)value },
{ "InterpolationPeriod", (sampledFunctionParameterType, value) => sampledFunctionParameterType.InterpolationPeriod = (ValueArray<string>)value },
{ "IsDeprecated", (sampledFunctionParameterType, value) => sampledFunctionParameterType.IsDeprecated = (bool)value },
{ "ModifiedOn", (sampledFunctionParameterType, value) => sampledFunctionParameterType.ModifiedOn = (DateTime)value },
{ "Name", (sampledFunctionParameterType, value) => sampledFunctionParameterType.Name = value.ToString() },
Expand Down
16 changes: 8 additions & 8 deletions CDP4Common/AutoGenPoco/SampledFunctionParameterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public SampledFunctionParameterType()
{
this.DependentParameterType = new OrderedItemList<DependentParameterTypeAssignment>(this, true);
this.IndependentParameterType = new OrderedItemList<IndependentParameterTypeAssignment>(this, true);
this.InterpolationPeriod = new List<string>();
this.InterpolationPeriod = new ValueArray<string>(this);
}

/// <summary>
Expand All @@ -92,7 +92,7 @@ public SampledFunctionParameterType(Guid iid, ConcurrentDictionary<CacheKey, Laz
{
this.DependentParameterType = new OrderedItemList<DependentParameterTypeAssignment>(this, true);
this.IndependentParameterType = new OrderedItemList<IndependentParameterTypeAssignment>(this, true);
this.InterpolationPeriod = new List<string>();
this.InterpolationPeriod = new ValueArray<string>(this);
}

/// <summary>
Expand Down Expand Up @@ -124,15 +124,15 @@ public SampledFunctionParameterType(Guid iid, ConcurrentDictionary<CacheKey, Laz
public OrderedItemList<IndependentParameterTypeAssignment> IndependentParameterType { get; protected set; }

/// <summary>
/// Gets or sets a list of String.
/// Gets or sets a list of ordered String.
/// </summary>
/// <remarks>
/// optional representation of a period in case of a cyclic function to be taken into account for interpolation
/// Note: The number of values shall be equal to the number of parameter types in the <i>independentParameterType</i> property. An empty value means no cyclic interpolation for the corresponding <i>independentParameterType</i>.
/// Example: The function could represent the incident albedo flux as a function of mission elapsed time for a spacecraft in a circular orbit.
/// </remarks>
[UmlInformation(aggregation: AggregationKind.None, isDerived: false, isOrdered: false, isNullable: false, isPersistent: true)]
public List<string> InterpolationPeriod { get; set; }
[UmlInformation(aggregation: AggregationKind.None, isDerived: false, isOrdered: true, isNullable: false, isPersistent: true)]
public ValueArray<string> InterpolationPeriod { get; set; }

/// <summary>
/// Gets an <see cref="IEnumerable{IEnumerable}"/> that references the composite properties of the current <see cref="SampledFunctionParameterType"/>.
Expand Down Expand Up @@ -166,7 +166,7 @@ protected override Thing GenericClone(bool cloneContainedThings)
clone.ExcludedPerson = new List<Person>(this.ExcludedPerson);
clone.HyperLink = cloneContainedThings ? new ContainerList<HyperLink>(clone) : new ContainerList<HyperLink>(this.HyperLink, clone);
clone.IndependentParameterType = cloneContainedThings ? null : new OrderedItemList<IndependentParameterTypeAssignment>(this.IndependentParameterType, clone);
clone.InterpolationPeriod = new List<string>(this.InterpolationPeriod);
clone.InterpolationPeriod = new ValueArray<string>(this.InterpolationPeriod, this);

if (cloneContainedThings)
{
Expand Down Expand Up @@ -252,7 +252,7 @@ internal override void ResolveProperties(DTO.Thing dtoThing)
this.ExcludedPerson.ResolveList(dto.ExcludedPerson, dto.IterationContainerId, this.Cache);
this.HyperLink.ResolveList(dto.HyperLink, dto.IterationContainerId, this.Cache);
this.IndependentParameterType.ResolveList(dto.IndependentParameterType, dto.IterationContainerId, this.Cache);
this.InterpolationPeriod.ClearAndAddRange(dto.InterpolationPeriod);
this.InterpolationPeriod = new ValueArray<string>(dto.InterpolationPeriod, this);
this.IsDeprecated = dto.IsDeprecated;
this.ModifiedOn = dto.ModifiedOn;
this.Name = dto.Name;
Expand Down Expand Up @@ -280,7 +280,7 @@ public override DTO.Thing ToDto()
dto.ExcludedPerson.AddRange(this.ExcludedPerson.Select(x => x.Iid));
dto.HyperLink.AddRange(this.HyperLink.Select(x => x.Iid));
dto.IndependentParameterType.AddRange(this.IndependentParameterType.ToDtoOrderedItemList());
dto.InterpolationPeriod.AddRange(this.InterpolationPeriod);
dto.InterpolationPeriod = new ValueArray<string>(this.InterpolationPeriod, this);
dto.IsDeprecated = this.IsDeprecated;
dto.ModifiedOn = this.ModifiedOn;
dto.Name = this.Name;
Expand Down
2 changes: 1 addition & 1 deletion CDP4Common/CDP4Common.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;netstandard1.6;netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4Common Community Edition</Title>
<VersionPrefix>7.2.0</VersionPrefix>
<VersionPrefix>7.3.0</VersionPrefix>
<Description>CDP4 Common Class Library that contains DTOs, POCOs</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Kamil</Authors>
Expand Down
2 changes: 1 addition & 1 deletion CDP4Common/Poco/NestedParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected string GetDerivedPath()
private string QueryParameterShortName()
{
string parameterShortName;
if (this.AssociatedParameter.ParameterType is ScalarParameterType)
if (this.AssociatedParameter.ParameterType is ScalarParameterType || this.AssociatedParameter.ParameterType is SampledFunctionParameterType)
{
parameterShortName = this.AssociatedParameter.ParameterType.ShortName;
}
Expand Down
22 changes: 22 additions & 0 deletions CDP4Common/Poco/ParameterSubscriptionValueSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ protected override IEnumerable<string> ValidatePocoProperties()
}

var numberOfComponent = container.ParameterType.NumberOfValues;

// validate number of values for sampled funtion parameter type
if (container.ParameterType is SampledFunctionParameterType sampledFunctionParameterType)
{
if (this.Manual.Count % numberOfComponent != 0)
{
errorList.Add($"Wrong number of values in the Manual set for the option: {((this.ActualOption == null) ? "-" : this.ActualOption.Name)}, state: {((this.ActualState == null) ? "-" : this.ActualState.Name)}");
}

if (this.Computed.Count % numberOfComponent != 0)
{
errorList.Add($"Wrong number of values in the Computed set for the option: {((this.ActualOption == null) ? "-" : this.ActualOption.Name)}, state: {((this.ActualState == null) ? "-" : this.ActualState.Name)}");
}

if (this.Reference.Count % numberOfComponent != 0)
{
errorList.Add($"Wrong number of values in the Reference set for the option: {((this.ActualOption == null) ? "-" : this.ActualOption.Name)}, state: {((this.ActualState == null) ? "-" : this.ActualState.Name)}");
}

return errorList;
}

if (this.Manual.Count != numberOfComponent)
{
errorList.Add($"Wrong number of values in the Manual set for the option: {((this.ActualOption == null) ? "-" : this.ActualOption.Name)}, state: {((this.ActualState == null) ? "-" : this.ActualState.Name)}");
Expand Down
27 changes: 27 additions & 0 deletions CDP4Common/Poco/ParameterValueSetBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ protected override IEnumerable<string> ValidatePocoProperties()
}

var numberOfComponent = container.ParameterType.NumberOfValues;

// validate number of values for sampled funtion parameter type
if(container.ParameterType is SampledFunctionParameterType sampledFunctionParameterType)
{
if (this.Manual.Count % numberOfComponent != 0)
{
errorList.Add($"Wrong number of values in the Manual set for the option: {((this.ActualOption == null) ? "-" : this.ActualOption.Name)}, state: {((this.ActualState == null) ? "-" : this.ActualState.Name)}");
}

if (this.Computed.Count % numberOfComponent != 0)
{
errorList.Add($"Wrong number of values in the Computed set for the option: {((this.ActualOption == null) ? "-" : this.ActualOption.Name)}, state: {((this.ActualState == null) ? "-" : this.ActualState.Name)}");
}

if (this.Reference.Count % numberOfComponent != 0)
{
errorList.Add($"Wrong number of values in the Reference set for the option: {((this.ActualOption == null) ? "-" : this.ActualOption.Name)}, state: {((this.ActualState == null) ? "-" : this.ActualState.Name)}");
}

if (this.Published.Count % numberOfComponent != 0)
{
errorList.Add($"Wrong number of values in the Published set for the option: {((this.ActualOption == null) ? "-" : this.ActualOption.Name)}, state: {((this.ActualState == null) ? "-" : this.ActualState.Name)}");
}

return errorList;
}

if (this.Manual.Count != numberOfComponent)
{
errorList.Add($"Wrong number of values in the Manual set for the option: {((this.ActualOption == null) ? "-" : this.ActualOption.Name)}, state: {((this.ActualState == null) ? "-" : this.ActualState.Name)}");
Expand Down
43 changes: 43 additions & 0 deletions CDP4Common/Poco/SampledFunctionParameterType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SampledFunctionParameterType.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2020 RHEA System S.A.
//
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou
//
// This file is part of CDP4-SDK Community Edition
//
// The CDP4-SDK Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4-SDK 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4Common.SiteDirectoryData
{
using System.Linq;

/// <summary>
/// Extended part for the auto-generated <see cref="SampledFunctionParameterType"/>
/// </summary>
public partial class SampledFunctionParameterType
{
/// <summary>
/// Gets the number of values for this <see cref="SampledFunctionParameterType"/>
/// </summary>
/// <returns>The Number of Values of a <see cref="SampledFunctionParameterType"/> is the sum of number of independet and dependent values, but should be used as a multiple as real value set size is variable.</returns>
protected override int GetDerivedNumberOfValues()
{
return this.IndependentParameterType.Sum(pta => pta.ParameterType.NumberOfValues) + this.DependentParameterType.Sum(pta => pta.ParameterType.NumberOfValues);
}
}
}
6 changes: 3 additions & 3 deletions CDP4Dal.NetCore.Tests/SessionTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SessionTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2020 RHEA System S.A.
// Copyright (c) 2015-2021 RHEA System S.A.
//
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski
//
Expand Down Expand Up @@ -621,7 +621,7 @@ public async Task VerifyThatWriteWorksWithEventHandler()
}

[Test]
public async Task VerifyThatCancelWriteWorks()
public void VerifyThatCancelWriteWorks()
{
var context = $"/SiteDirectory/{Guid.NewGuid()}";
var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" };
Expand All @@ -632,7 +632,7 @@ public async Task VerifyThatCancelWriteWorks()
args.Cancelled = true;
};

await this.session.Write(new OperationContainer(context));
Assert.ThrowsAsync<OperationCanceledException>(async () => await this.session.Write(new OperationContainer(context)));

this.mockedDal.Verify(x => x.Write(It.IsAny<OperationContainer>(), It.IsAny<IEnumerable<string>>()), Times.Exactly(0));
}
Expand Down
6 changes: 3 additions & 3 deletions CDP4Dal.Tests/SessionTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SessionTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2020 RHEA System S.A.
// Copyright (c) 2015-2021 RHEA System S.A.
//
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski
//
Expand Down Expand Up @@ -621,7 +621,7 @@ public async Task VerifyThatWriteWorksWithEventHandler()
}

[Test]
public async Task VerifyThatCancelWriteWorks()
public void VerifyThatCancelWriteWorks()
{
var context = $"/SiteDirectory/{Guid.NewGuid()}";
var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" };
Expand All @@ -632,7 +632,7 @@ public async Task VerifyThatCancelWriteWorks()
args.Cancelled = true;
};

await this.session.Write(new OperationContainer(context));
Assert.ThrowsAsync<OperationCanceledException>(async () => await this.session.Write(new OperationContainer(context)));

this.mockedDal.Verify(x => x.Write(It.IsAny<OperationContainer>(), It.IsAny<IEnumerable<string>>()), Times.Exactly(0));
}
Expand Down
2 changes: 1 addition & 1 deletion 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>7.2.0</VersionPrefix>
<VersionPrefix>7.3.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, Nathanael</Authors>
Expand Down
4 changes: 3 additions & 1 deletion CDP4Dal/DAL/Dal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public abstract class Dal : IDal
/// </summary>
protected Dal()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
#if NET45 || NET451 || NET452 || NET46 || NET461 || NET462
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
#endif

this.MetaDataProvider = StaticMetadataProvider.GetMetaDataProvider;
this.SetCdpVersion();
Expand Down
Loading

0 comments on commit ec2d263

Please sign in to comment.