From afc1523e9e020efae6a699954b11aa24486b2b13 Mon Sep 17 00:00:00 2001 From: antoineatrhea Date: Fri, 15 Mar 2024 13:00:26 +0100 Subject: [PATCH] Header update and readme --- DEH-CSV.Tests/CsvReaderTestFixture.cs | 14 +++++++------- DEH-CSV.sln.DotSettings | 2 +- DEH-CSV/CsvReader.cs | 2 +- DEH-CSV/DEH-CSV.csproj | 2 +- DEH-CSV/Helpers/PropertyPath.cs | 6 +++--- DEH-CSV/Mapping/PropertyMap.cs | 6 +++--- README.md | 22 ++++++++++++++++++++++ 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/DEH-CSV.Tests/CsvReaderTestFixture.cs b/DEH-CSV.Tests/CsvReaderTestFixture.cs index 6833cd3..918001e 100644 --- a/DEH-CSV.Tests/CsvReaderTestFixture.cs +++ b/DEH-CSV.Tests/CsvReaderTestFixture.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// Copyright 2023 RHEA System S.A. +// Copyright 2023-2024 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. @@ -50,14 +50,14 @@ namespace RHEAGROUP.DEHCSV.Tests [TestFixture] public class CsvReaderTestFixture { - private readonly Uri uri = new ("https://cdp4services-public.cdp4.org"); + 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() { @@ -86,7 +86,7 @@ public void Teardown() 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"); @@ -139,7 +139,7 @@ public async Task VerifyCsvReaderImplementation() 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{elementDefinition.Owner})); + Assert.That(elementDefinition.Parameter.Select(x => x.Owner).Distinct(), Is.EquivalentTo(new List { elementDefinition.Owner })); }); foreach (var parameter in elementDefinition.Parameter) @@ -149,8 +149,8 @@ public async Task VerifyCsvReaderImplementation() 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)); + 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++; } diff --git a/DEH-CSV.sln.DotSettings b/DEH-CSV.sln.DotSettings index 28b89ba..9662113 100644 --- a/DEH-CSV.sln.DotSettings +++ b/DEH-CSV.sln.DotSettings @@ -5,7 +5,7 @@ ------------------------------------------------------------------------------------------------- <copyright file="${File.FileName}" company="RHEA System S.A."> - Copyright 2023 RHEA System S.A. + Copyright 2023-${CurrentDate.Year} 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. diff --git a/DEH-CSV/CsvReader.cs b/DEH-CSV/CsvReader.cs index 0b4b21d..0d9a343 100644 --- a/DEH-CSV/CsvReader.cs +++ b/DEH-CSV/CsvReader.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// Copyright 2023 RHEA System S.A. +// Copyright 2023-2024 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. diff --git a/DEH-CSV/DEH-CSV.csproj b/DEH-CSV/DEH-CSV.csproj index 5e9c2be..06bdf17 100644 --- a/DEH-CSV/DEH-CSV.csproj +++ b/DEH-CSV/DEH-CSV.csproj @@ -20,7 +20,7 @@ RHEA System S.A. - Copyright 2023 RHEA System S.A. + Copyright 2023-2024 RHEA System S.A. Sam Gerené Apache-2.0 diff --git a/DEH-CSV/Helpers/PropertyPath.cs b/DEH-CSV/Helpers/PropertyPath.cs index e20f27d..248416e 100644 --- a/DEH-CSV/Helpers/PropertyPath.cs +++ b/DEH-CSV/Helpers/PropertyPath.cs @@ -1,7 +1,7 @@ // ------------------------------------------------------------------------------------------------- // // -// Copyright 2023 RHEA System S.A. +// Copyright 2023-2024 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. @@ -111,12 +111,12 @@ private void ComputeChildren(IReadOnlyCollection<(PropertyDescriptor Descriptor, if (nextProperties.Count == 1) { var (descriptor, map) = nextProperties[0]; - this.Children = new List { new (descriptor, map, allProperties) }; + this.Children = new List { new(descriptor, map, allProperties) }; } else { var propertiesWithSameSource = nextProperties.Where(x => x.Map.Source == this.PropertyMap.Source).ToList(); - var collectionToUseForChildren = propertiesWithSameSource.Count == 0 ? nextProperties : propertiesWithSameSource; + var collectionToUseForChildren = propertiesWithSameSource.Count == 0 ? nextProperties : propertiesWithSameSource; this.Children = new List(collectionToUseForChildren.Select(x => new PropertyPath(x.Descriptor, x.Map, allProperties))); } } diff --git a/DEH-CSV/Mapping/PropertyMap.cs b/DEH-CSV/Mapping/PropertyMap.cs index d3817a4..7839b81 100644 --- a/DEH-CSV/Mapping/PropertyMap.cs +++ b/DEH-CSV/Mapping/PropertyMap.cs @@ -1,7 +1,7 @@ -// ------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // // -// Copyright 2023 RHEA System S.A. +// Copyright 2023-2024 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. @@ -58,7 +58,7 @@ public class PropertyMap /// for a thing to be created /// public bool IsIdentifierProperty { get; set; } - + /// /// Gets or sets the path to find Thing(s) /// diff --git a/README.md b/README.md index f002979..ebdcb2e 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ The packages are available on Nuget at https://www.nuget.org/packages/DEH-CSV/ ## Quickstart 1. Install the nuget package into your project or solution. + +### Write + 1. Add a mapping file that states how the properties of an ECSS-E-TM-10-25 [Thing](https://comet-dev-docs.mbsehub.org/) needs to be mapped to fields in a CSV file. 1. Use the [ICsvWriter](https://github.com/RHEAGROUP/DEH-CSV/blob/master/DEH-CSV/ICsvWriter.cs) interface and/or the [CsvWriter](https://github.com/RHEAGROUP/DEH-CSV/blob/master/DEH-CSV/CsvWriter.cs) class. @@ -37,6 +40,25 @@ The `ICsvWriter` interface exposes only one method: **write**. - target: the target directory where the CSV files are to be generated. - options: any kind of `object` that can contain configuration information (this is igonred by the standard implementation but can be used when a derived CsvWriter is created where the `Write` method is overriden). +### Read + + 1. Add a mapping file that states of a CSV file needs to be mapped to the properties of an ECSS-E-TM-10-25 [Thing](https://comet-dev-docs.mbsehub.org/) + 1. Add the corresponding CSV file that needs to be processed + 1. Use the [ICsvReader](https://github.com/RHEAGROUP/DEH-CSV/blob/development/DEH-CSV/ICsvReader.cs) interface and/or the [CsvReader](https://github.com/RHEAGROUP/DEH-CSV/blob/development/DEH-CSV/CsvReader.cs) class. + + The `ICsvReader` interface exposes only one method: **read**. + +``` + public Task> Read(Stream stream, IReadOnlyCollection typeMaps, ISession session); +``` + + - stream: The `Stream` that contains CSV content + - typeMaps: The collection of `TypeMap`s + - session: The `ISession` that helps to retrieve `Thing` + - returns: A `Task` that contains a collection of mapped `Thing`s + + After the read is done, all mapped `Thing`s can be written to the `Isession` by adding them to the correct TopContainer. A manual action will need to be done there, unless a `TypeMap` is created to perform that action. + ## Build Status GitHub actions are used to build and test the libraries