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

1429 metaData with empty values imported #1507

Merged
merged 3 commits into from
Feb 22, 2022
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 @@ -7,6 +7,7 @@
using OSPSuite.Core.Domain.Services;
using OSPSuite.Core.Domain.UnitSystem;
using OSPSuite.Infrastructure.Import.Extensions;
using OSPSuite.Utility.Extensions;

namespace OSPSuite.Infrastructure.Import.Core.Mappers
{
Expand Down Expand Up @@ -39,7 +40,8 @@ public DataSetToDataRepositoryMappingResult ConvertImportDataSet(ImportedDataSet

foreach (var metaDataDescription in dataSet.MetaDataDescription)
{
dataRepository.ExtendedProperties.Add(new ExtendedProperty<string>() { Name = metaDataDescription.Name, Value = metaDataDescription.Value });
if (!metaDataDescription.Value.IsNullOrEmpty())
dataRepository.ExtendedProperties.Add(new ExtendedProperty<string>() { Name = metaDataDescription.Name, Value = metaDataDescription.Value });
}

var warningFlag = false;
Expand Down
Binary file modified tests/OSPSuite.Presentation.Tests/Data/IntegrationSample1.xlsx
Binary file not shown.
138 changes: 40 additions & 98 deletions tests/OSPSuite.Presentation.Tests/Services/DataImporterSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ protected override void Context()
_metaDataCategories.First(md => md.Name == _dataImporterSettings.NameOfMetaDataHoldingMoleculeInformation).ListOfValues.Add("TestInputMolecule", "233");
}

protected List<DataFormatParameter> createTestParameters(string moleculeColumnName, UnitDescription timeUnitDescription, UnitDescription concentrationUnitDescription, IDimension _timeConcentrationDimension)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ah yes!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe not sure if you are agreeing on the refactoring or disagreeing somehow on the number of parameters of the function...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this .. I was just waiting for the build to finish sorry. Merging

{
var parameterList = new List<DataFormatParameter>
{
new MappingDataFormatParameter("time [h]",
new Column() { Name = "Time", Dimension = _dimensionFactory.Dimension("Time"), Unit = timeUnitDescription }),
new MappingDataFormatParameter("conc [mg/l]",
new Column()
{
Name = "Concentration", Dimension = _timeConcentrationDimension, Unit = concentrationUnitDescription
}),
new MappingDataFormatParameter("SD [mg/l]",
new Column()
{
Name = "Error", ErrorStdDev = "Arithmetic Standard Deviation", Dimension = _massConcentrationDimension,
Unit = new UnitDescription("mg/l")
}),
new MetaDataFormatParameter("VenousBlood", "Organ", false),
new MetaDataFormatParameter(moleculeColumnName, "Molecule", false)
};
return parameterList;
}
protected string getFileFullName(string fileName) => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", fileName);

private IReadOnlyList<ColumnInfo> getDefaultColumnInfos()
Expand Down Expand Up @@ -145,24 +167,7 @@ public class When_importing_data_from_correct_configuration : concern_for_DataIm
{
protected override void Because()
{
var parameterList = new List<DataFormatParameter>
{
new MappingDataFormatParameter("time [h]",
new Column() {Name = "Time", Dimension = _dimensionFactory.Dimension("Time"), Unit = new UnitDescription("h")}),
new MappingDataFormatParameter("conc [mg/l]",
new Column()
{
Name = "Concentration", Dimension = _massConcentrationDimension, Unit = new UnitDescription("mg/l")
}),
new MappingDataFormatParameter("SD [mg/l]",
new Column()
{
Name = "Error", ErrorStdDev = "Arithmetic Standard Deviation", Dimension = _massConcentrationDimension,
Unit = new UnitDescription("mg/l")
}),
new MetaDataFormatParameter("VenousBlood", "Organ", false),
new MetaDataFormatParameter("TestInputMolecule", "Molecule", false)
};
var parameterList = createTestParameters("TestInputMolecule", new UnitDescription("h"), new UnitDescription("mg/l"), _massConcentrationDimension);
var parameterListMolecularWeight = new List<DataFormatParameter>(parameterList);
parameterListMolecularWeight.Add(new MetaDataFormatParameter("Molecular Weight", "Molecular Weight", true));
_importerConfiguration.CloneParametersFrom(parameterList);
Expand Down Expand Up @@ -281,24 +286,7 @@ public class When_importing_data_with_missing_columns : concern_for_DataImporter
{
protected override void Because()
{
var parameterList = new List<DataFormatParameter>
{
new MappingDataFormatParameter("time [h]",
new Column() {Name = "Time", Dimension = _dimensionFactory.Dimension("Time"), Unit = new UnitDescription("h")}),
new MappingDataFormatParameter("conc [mg/l]",
new Column()
{
Name = "Concentration", Dimension = _massConcentrationDimension, Unit = new UnitDescription("mg/l")
}),
new MappingDataFormatParameter("SD [mg/l]",
new Column()
{
Name = "Error", ErrorStdDev = "Arithmetic Standard Deviation", Dimension = _massConcentrationDimension,
Unit = new UnitDescription("mg/l")
}),
new MetaDataFormatParameter("VenousBlood", "Organ", false),
new MetaDataFormatParameter(null, "Molecule", false)
};
var parameterList = createTestParameters(null, new UnitDescription("h"), new UnitDescription("mg/l"), _massConcentrationDimension);
_importerConfiguration.CloneParametersFrom(parameterList);
}

Expand All @@ -323,24 +311,7 @@ public class When_importing_data_with_missing_unit_columns : concern_for_DataImp
{
protected override void Because()
{
var parameterList = new List<DataFormatParameter>
{
new MappingDataFormatParameter("time [h]",
new Column() {Name = "Time", Dimension = _dimensionFactory.Dimension("Time"), Unit = new UnitDescription("h", "timeUnitColumn")}),
new MappingDataFormatParameter("conc [mg/l]",
new Column()
{
Name = "Concentration", Dimension = _massConcentrationDimension, Unit = new UnitDescription("mg/l")
}),
new MappingDataFormatParameter("SD [mg/l]",
new Column()
{
Name = "Error", ErrorStdDev = "Arithmetic Standard Deviation", Dimension = _massConcentrationDimension,
Unit = new UnitDescription("mg/l")
}),
new MetaDataFormatParameter("VenousBlood", "Organ", false),
new MetaDataFormatParameter(null, "Molecule", false)
};
var parameterList = createTestParameters(null, new UnitDescription("h", "timeUnitColumn"), new UnitDescription("mg/l"), _massConcentrationDimension);
_importerConfiguration.CloneParametersFrom(parameterList);
}

Expand All @@ -353,33 +324,17 @@ public void should_set_unit_of_missing_column_to_undefined()
}
}

public class When_importing_data_from_incorrect_configuration : concern_for_DataImporter
public class When_importing_with_inconsistent_units_in_column : concern_for_DataImporter
{
protected override void Because()
{
var parameterList = new List<DataFormatParameter>
{
new MappingDataFormatParameter("time [h]",
new Column() {Name = "Time", Dimension = _dimensionFactory.Dimension("Time"), Unit = new UnitDescription("h")}),
new MappingDataFormatParameter("conc [mg/l]",
new Column()
{
Name = "Concentration", Dimension = _timeConcentrationDimension, Unit = new UnitDescription("s")
}),
new MappingDataFormatParameter("SD [mg/l]",
new Column()
{
Name = "Error", ErrorStdDev = "Arithmetic Standard Deviation", Dimension = _massConcentrationDimension,
Unit = new UnitDescription("mg/l")
}),
new MetaDataFormatParameter("VenousBlood", "Organ", false),
new MetaDataFormatParameter("TestInputMolecule", "Molecule", false)
};
var parameterList =
createTestParameters("TestInputMolecule", new UnitDescription("h"), new UnitDescription("s"), _timeConcentrationDimension);
_importerConfiguration.CloneParametersFrom(parameterList);
}

[Observation]
public void should_throw_exception_when_trying_to_import()
public void should_throw_exception()
{
The.Action(() =>
sut.ImportFromConfiguration(_importerConfiguration, _metaDataCategories, _columnInfos, _dataImporterSettings,
Expand All @@ -388,38 +343,25 @@ public void should_throw_exception_when_trying_to_import()
}
}

public class When_importing_with_inconsistent_units_in_column : concern_for_DataImporter
public class When_importing_empty_metadata_columns : concern_for_DataImporter
{
protected override void Because()
{
var parameterList = new List<DataFormatParameter>
{
new MappingDataFormatParameter("time [h]",
new Column() {Name = "Time", Dimension = _dimensionFactory.Dimension("Time"), Unit = new UnitDescription("h")}),
new MappingDataFormatParameter("conc [mg/l]",
new Column()
{
Name = "Concentration", Dimension = _timeConcentrationDimension, Unit = new UnitDescription("s")
}),
new MappingDataFormatParameter("SD [mg/l]",
new Column()
{
Name = "Error", ErrorStdDev = "Arithmetic Standard Deviation", Dimension = _massConcentrationDimension,
Unit = new UnitDescription("mg/l")
}),
new MetaDataFormatParameter("VenousBlood", "Organ", false),
new MetaDataFormatParameter("TestInputMolecule", "Molecule", false)
};
var parameterList = createTestParameters("TestInputMolecule", new UnitDescription("h"), new UnitDescription("mg/l"),
_massConcentrationDimension);
parameterList.Add(new MetaDataFormatParameter("Dose", "Dose", true));
_importerConfiguration.CloneParametersFrom(parameterList);
}

[Observation]
public void should_throw_exception()
public void should_not_import_empty_metadata()
{
The.Action(() =>
sut.ImportFromConfiguration(_importerConfiguration, _metaDataCategories, _columnInfos, _dataImporterSettings,
getFileFullName(
"IntegrationSample1.xlsx"))).ShouldThrowAn<OSPSuiteException>();
var result = sut.ImportFromConfiguration(_importerConfiguration, _metaDataCategories, _columnInfos, _dataImporterSettings,
getFileFullName(
"IntegrationSample1.xlsx"));
result.First().ExtendedProperties.Contains("Dose").ShouldBeFalse();


}
}
}