Skip to content
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

1872 importer metaData messed up fixed #1873

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,18 @@ public IEnumerable<ParsedDataSet> Parse(DataSheet dataSheet, ColumnInfoCache col
if (missingColumns.Any())
throw new MissingColumnException(dataSheet.SheetName, missingColumns);

var groupingCriteria =
//we first isolate the mapping parameters
var mappingCriteria =
Parameters
.Where(p => p.IsGroupingCriterion())
.Where(p => p.IsGroupingCriterion() && !p.IsAnImplementationOf<GroupByDataFormatParameter>())
.Select(p => p.ColumnName);

//and then add the grouping criteria, in order to have exactly the same order in the ParsedDataSet
//that will be created as in the mappings in the dataSource
var groupingCriteria = mappingCriteria.Union(Parameters
.Where(p => p.IsGroupingCriterion() && p.IsAnImplementationOf<GroupByDataFormatParameter>())
.Select(p => p.ColumnName));

return buildDataSets(dataSheet, groupingCriteria.ToList(), columnInfos);
}

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
<None Update="Data\IntegrationSampleMissingMapping.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\IntegrationSampleWithGroupBy.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\invalid.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -88,6 +91,9 @@
<None Update="Data\simple.pkml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\~%24IntegrationSampleWithGroupBy.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 32 additions & 0 deletions tests/OSPSuite.Presentation.Tests/Services/DataImporterSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OSPSuite.BDDHelper.Extensions;
using OSPSuite.Core;
using OSPSuite.Core.Domain;
using OSPSuite.Core.Domain.Data;
using OSPSuite.Core.Domain.UnitSystem;
using OSPSuite.Core.Extensions;
using OSPSuite.Core.Import;
Expand Down Expand Up @@ -132,6 +133,18 @@ protected List<DataFormatParameter> createTestParametersWithLLOQ(string molecule
return parameterList;
}

protected List<DataFormatParameter> createTestParametersWithGroupByColumn(string moleculeColumnName, UnitDescription timeUnitDescription,
UnitDescription concentrationUnitDescription, IDimension _timeConcentrationDimension)
{
var parameterList = createBaseParameters("TestInputMolecule", new UnitDescription("h"));

parameterList.Add(new GroupByDataFormatParameter("GroupBy"));

parameterList.Add(new MetaDataFormatParameter("Gender", "Gender", true));

return parameterList;
}


protected string getFileFullName(string fileName) => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", fileName);

Expand Down Expand Up @@ -447,6 +460,25 @@ public void should_throw_exception()
}
}

public class When_importing_excel_with_goupBy_defined_before_mapping : concern_for_DataImporter
{
protected override void Because()
{
var parameterList = createTestParametersWithGroupByColumn("TestInputMolecule", new UnitDescription("h"), new UnitDescription("mg/l"),
_massConcentrationDimension);
_importerConfiguration.CloneParametersFrom(parameterList);
}

[Observation]
public void should_import_values_correctly()
{
var result = sut.ImportFromConfiguration(_importerConfiguration, _metaDataCategories, _columnInfos, _dataImporterSettings,
getFileFullName(
"IntegrationSampleWithGroupBy.xlsx"));
result.First().ExtendedProperties["Gender"].ValueAsObject.ToString().ShouldBeEqualTo("F");
}
}

public class When_trying_to_import_file_with_duplicate_headers : concern_for_DataImporter
{
protected override void Because()
Expand Down