-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix #1: Generic CSV import supported #2
Merged
antoineatstariongroup
merged 2 commits into
development
from
feat/gh1-generic-csv-import
Mar 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,3 +396,5 @@ FodyWeavers.xsd | |
|
||
# JetBrains Rider | ||
*.sln.iml | ||
|
||
switcher.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// <copyright file="CsvReaderTestFixture.cs" company="RHEA System S.A."> | ||
// | ||
// Copyright 2023 RHEA System S.A. | ||
// | ||
// 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. | ||
// | ||
// </copyright> | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
namespace RHEAGROUP.DEHCSV.Tests | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
|
||
using CDP4Common.CommonData; | ||
using CDP4Common.EngineeringModelData; | ||
using CDP4Common.SiteDirectoryData; | ||
|
||
using CDP4Dal; | ||
using CDP4Dal.DAL; | ||
|
||
using CDP4ServicesDal; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using NUnit.Framework; | ||
|
||
using RHEAGROUP.DEHCSV.Mapping; | ||
|
||
using File = System.IO.File; | ||
|
||
[TestFixture] | ||
public class CsvReaderTestFixture | ||
{ | ||
private readonly Uri uri = new ("https://cdp4services-public.cdp4.org"); | ||
private Credentials credentials; | ||
private CdpServicesDal dal; | ||
private CDPMessageBus messageBus; | ||
private Session session; | ||
private CsvReader csvReader; | ||
private JsonSerializerOptions options; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
this.credentials = new Credentials("admin", "pass", this.uri); | ||
this.dal = new CdpServicesDal(); | ||
this.messageBus = new CDPMessageBus(); | ||
this.session = new Session(this.dal, this.credentials, this.messageBus); | ||
var loggerFactory = LoggerFactory.Create(x => x.AddConsole()); | ||
|
||
this.csvReader = new CsvReader(loggerFactory.CreateLogger<CsvReader>()); | ||
|
||
this.options = new JsonSerializerOptions() | ||
{ | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
Converters = { new JsonStringEnumConverter<ClassKind>() } | ||
}; | ||
} | ||
|
||
[TearDown] | ||
public void Teardown() | ||
{ | ||
this.messageBus.Dispose(); | ||
} | ||
|
||
[Test] | ||
public async Task VerifyCsvReaderImplementation() | ||
{ | ||
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; | ||
|
||
var csvPath = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Data", "import-data.csv"); | ||
var mappingFunctionPath = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Data", "import-mapping.json"); | ||
|
||
var typeMaps = JsonSerializer.Deserialize<IEnumerable<TypeMap>>(await File.ReadAllTextAsync(mappingFunctionPath), this.options); | ||
|
||
var csvStream = File.OpenRead(csvPath); | ||
await this.session.Open(); | ||
var loftModel = this.session.RetrieveSiteDirectory().Model.Find(x => x.Name == "LOFT")!; | ||
var iterationSetup = loftModel.IterationSetup.Single(x => x.FrozenOn == null); | ||
|
||
var iteration = new Iteration() | ||
{ | ||
Iid = iterationSetup.IterationIid, | ||
IterationSetup = iterationSetup | ||
}; | ||
|
||
var engineeringModel = new EngineeringModel() | ||
{ | ||
Iid = loftModel.EngineeringModelIid, | ||
EngineeringModelSetup = loftModel | ||
}; | ||
|
||
engineeringModel.Iteration.Add(iteration); | ||
|
||
var domain = loftModel.Participant.Single(x => x.Person == this.session.ActivePerson).SelectedDomain; | ||
await this.session.Read(iteration, domain); | ||
var mappedThings = (await this.csvReader.Read(csvStream, typeMaps.ToList(), this.session)).ToList(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(mappedThings, Is.Not.Empty); | ||
Assert.That(mappedThings, Has.Count.EqualTo(315)); | ||
Assert.That(mappedThings.OfType<ElementDefinition>().ToImmutableList(), Has.Count.EqualTo(35)); | ||
Assert.That(mappedThings.OfType<Parameter>().ToImmutableList(), Has.Count.EqualTo(140)); | ||
Assert.That(mappedThings.OfType<ParameterValueSet>().ToImmutableList(), Has.Count.EqualTo(140)); | ||
}); | ||
|
||
var count = 0; | ||
|
||
foreach (var elementDefinition in mappedThings.OfType<ElementDefinition>()) | ||
{ | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(elementDefinition.ShortName, Is.EqualTo($"shortName{count:0000}")); | ||
Assert.That(elementDefinition.Name, Is.EqualTo($"Name {count:0000}")); | ||
Assert.That(elementDefinition.Category[0].Name, Is.EqualTo("Subsystem")); | ||
Assert.That(elementDefinition.Owner.Name, Is.EqualTo("System Engineering")); | ||
Assert.That(elementDefinition.Parameter, Has.Count.EqualTo(4)); | ||
Assert.That(elementDefinition.Parameter[0].ParameterType.Name, Is.EqualTo("area")); | ||
Assert.That(elementDefinition.Parameter[1].ParameterType.Name, Is.EqualTo("mass")); | ||
Assert.That(elementDefinition.Parameter[2].ParameterType.Name, Is.EqualTo("dry mass")); | ||
Assert.That(elementDefinition.Parameter[3].ParameterType.Name, Is.EqualTo("radius")); | ||
Assert.That(elementDefinition.Parameter.Select(x => x.Owner).Distinct(), Is.EquivalentTo(new List<DomainOfExpertise>{elementDefinition.Owner})); | ||
}); | ||
|
||
foreach (var parameter in elementDefinition.Parameter) | ||
{ | ||
Assert.That(parameter.ValueSet, Has.Count.EqualTo(1)); | ||
} | ||
|
||
Assert.That(int.Parse(elementDefinition.Parameter[0].ValueSet[0].Manual[0]), Is.EqualTo(count)); | ||
Assert.That(int.Parse(elementDefinition.Parameter[1].ValueSet[0].Manual[0]), Is.EqualTo(-count)); | ||
Assert.That(int.Parse(elementDefinition.Parameter[2].ValueSet[0].Manual[0]), Is.EqualTo(count+10)); | ||
Assert.That(int.Parse(elementDefinition.Parameter[3].ValueSet[0].Manual[0]), Is.EqualTo(count+100)); | ||
|
||
count++; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Category;Short name;Name;area;mass;dry mass;radius;Ownership | ||
Subsystem;shortName0000;Name 0000;0;0;10;100;System Engineering | ||
Subsystem;shortName0001;Name 0001;1;-1;11;101;System Engineering | ||
Subsystem;shortName0002;Name 0002;2;-2;12;102;System Engineering | ||
Subsystem;shortName0003;Name 0003;3;-3;13;103;System Engineering | ||
Subsystem;shortName0004;Name 0004;4;-4;14;104;System Engineering | ||
Subsystem;shortName0005;Name 0005;5;-5;15;105;System Engineering | ||
Subsystem;shortName0006;Name 0006;6;-6;16;106;System Engineering | ||
Subsystem;shortName0007;Name 0007;7;-7;17;107;System Engineering | ||
Subsystem;shortName0008;Name 0008;8;-8;18;108;System Engineering | ||
Subsystem;shortName0009;Name 0009;9;-9;19;109;System Engineering | ||
Subsystem;shortName0010;Name 0010;10;-10;20;110;System Engineering | ||
Subsystem;shortName0011;Name 0011;11;-11;21;111;System Engineering | ||
Subsystem;shortName0012;Name 0012;12;-12;22;112;System Engineering | ||
Subsystem;shortName0013;Name 0013;13;-13;23;113;System Engineering | ||
Subsystem;shortName0014;Name 0014;14;-14;24;114;System Engineering | ||
Subsystem;shortName0015;Name 0015;15;-15;25;115;System Engineering | ||
Subsystem;shortName0016;Name 0016;16;-16;26;116;System Engineering | ||
Subsystem;shortName0017;Name 0017;17;-17;27;117;System Engineering | ||
Subsystem;shortName0018;Name 0018;18;-18;28;118;System Engineering | ||
Subsystem;shortName0019;Name 0019;19;-19;29;119;System Engineering | ||
Subsystem;shortName0020;Name 0020;20;-20;30;120;System Engineering | ||
Subsystem;shortName0021;Name 0021;21;-21;31;121;System Engineering | ||
Subsystem;shortName0022;Name 0022;22;-22;32;122;System Engineering | ||
Subsystem;shortName0023;Name 0023;23;-23;33;123;System Engineering | ||
Subsystem;shortName0024;Name 0024;24;-24;34;124;System Engineering | ||
Subsystem;shortName0025;Name 0025;25;-25;35;125;System Engineering | ||
Subsystem;shortName0026;Name 0026;26;-26;36;126;System Engineering | ||
Subsystem;shortName0027;Name 0027;27;-27;37;127;System Engineering | ||
Subsystem;shortName0028;Name 0028;28;-28;38;128;System Engineering | ||
Subsystem;shortName0029;Name 0029;29;-29;39;129;System Engineering | ||
Subsystem;shortName0030;Name 0030;30;-30;40;130;System Engineering | ||
Subsystem;shortName0031;Name 0031;31;-31;41;131;System Engineering | ||
Subsystem;shortName0032;Name 0032;32;-32;42;132;System Engineering | ||
Subsystem;shortName0033;Name 0033;33;-33;43;133;System Engineering | ||
Subsystem;shortName0034;Name 0034;34;-34;44;134;System Engineering |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2023-2024