Skip to content

Commit

Permalink
1872 fixed (#1873)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeDaskalakis authored Jan 25, 2023
1 parent 2529fd7 commit 6ef98c4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
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

0 comments on commit 6ef98c4

Please sign in to comment.