Skip to content

Commit

Permalink
Header update and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineatrhea committed Mar 15, 2024
1 parent 0d9f4af commit afc1523
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
14 changes: 7 additions & 7 deletions DEH-CSV.Tests/CsvReaderTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="CsvReaderTestFixture.cs" company="RHEA System S.A.">
//
// 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.
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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<DomainOfExpertise>{elementDefinition.Owner}));
Assert.That(elementDefinition.Parameter.Select(x => x.Owner).Distinct(), Is.EquivalentTo(new List<DomainOfExpertise> { elementDefinition.Owner }));
});

foreach (var parameter in elementDefinition.Parameter)
Expand All @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion DEH-CSV.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue"> -------------------------------------------------------------------------------------------------
&lt;copyright file="${File.FileName}" company="RHEA System S.A."&gt;

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.
Expand Down
2 changes: 1 addition & 1 deletion DEH-CSV/CsvReader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="CsvReader.cs" company="RHEA System S.A.">
//
// 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.
Expand Down
2 changes: 1 addition & 1 deletion DEH-CSV/DEH-CSV.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>
<PropertyGroup Label="Copyright">
<Company>RHEA System S.A.</Company>
<Copyright>Copyright 2023 RHEA System S.A.</Copyright>
<Copyright>Copyright 2023-2024 RHEA System S.A.</Copyright>
<Authors>Sam Gerené</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions DEH-CSV/Helpers/PropertyPath.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="PropertyPath.cs" company="RHEA System S.A.">
//
// 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.
Expand Down Expand Up @@ -111,12 +111,12 @@ private void ComputeChildren(IReadOnlyCollection<(PropertyDescriptor Descriptor,
if (nextProperties.Count == 1)
{
var (descriptor, map) = nextProperties[0];
this.Children = new List<PropertyPath> { new (descriptor, map, allProperties) };
this.Children = new List<PropertyPath> { 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<PropertyPath>(collectionToUseForChildren.Select(x => new PropertyPath(x.Descriptor, x.Map, allProperties)));
}
}
Expand Down
6 changes: 3 additions & 3 deletions DEH-CSV/Mapping/PropertyMap.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// <copyright file="PropertyMap.cs" company="RHEA System S.A.">
//
// 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.
Expand Down Expand Up @@ -58,7 +58,7 @@ public class PropertyMap
/// for a thing to be created
/// </summary>
public bool IsIdentifierProperty { get; set; }

/// <summary>
/// Gets or sets the path to find Thing(s)
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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<IEnumerable<Thing>> Read(Stream stream, IReadOnlyCollection<TypeMap> 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
Expand Down

0 comments on commit afc1523

Please sign in to comment.