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

1409 importer handling of imvalid files #1437

Merged
merged 21 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 23 additions & 4 deletions src/OSPSuite.Infrastructure.Import/Core/DataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using OSPSuite.Core.Domain;
using OSPSuite.Core.Import;
using OSPSuite.Infrastructure.Import.Core.Exceptions;
using OSPSuite.Infrastructure.Import.Core.Helpers;
using OSPSuite.Infrastructure.Import.Extensions;
using OSPSuite.Infrastructure.Import.Services;
using OSPSuite.Utility.Collections;
Expand Down Expand Up @@ -58,7 +57,8 @@ public interface IDataSource
Cache<string, IDataSet> DataSets { get; }
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this as a cache exposed. DataSet are added outside of the DataSource as it stands

IEnumerable<string> NamesFromConvention();
NanSettings NanSettings { get; set; }
ImportedDataSet DataSetAt(int index);
ImportedDataSet ImportedDataSetAt(int index);
IDataSet DataSetAt(int index);
ParseErrors ValidateDataSourceUnits(IReadOnlyList<ColumnInfo> columnInfos);
}

Expand Down Expand Up @@ -155,7 +155,26 @@ public IEnumerable<string> NamesFromConvention()
return _importer.NamesFromConvention(_configuration.NamingConventions, _configuration.FileName, DataSets, _mappings);
}

public ImportedDataSet DataSetAt(int index)
public IDataSet DataSetAt(int index)
Copy link
Member

Choose a reason for hiding this comment

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

Let's talk about this in the meeting. I don't understand what this is doing.

{
var sheetIndex = 0;
var sheet = DataSets.GetEnumerator();
var accumulatedIndexes = 0;
while (sheet.MoveNext() && index >= 0)
{
if (sheet.Current.Data.Count() > index)
Copy link
Member

Choose a reason for hiding this comment

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

(sheet.Current.Data.Count() 3 times in the same while loop. Maybe cache it?

{
return sheet.Current;
}

index -= sheet.Current.Data.Count();
sheetIndex++;
accumulatedIndexes += sheet.Current.Data.Count();
}
return null;
}

public ImportedDataSet ImportedDataSetAt(int index)
{
var sheetIndex = 0;
var sheet = DataSets.GetEnumerator();
Expand Down Expand Up @@ -296,7 +315,7 @@ private ParseErrors validateUnitsSupportedAndSameDimension(IReadOnlyList<ColumnI
return errors;
}

ParseErrors IDataSource.ValidateDataSourceUnits(IReadOnlyList<ColumnInfo> columnInfos)
public ParseErrors ValidateDataSourceUnits(IReadOnlyList<ColumnInfo> columnInfos)
{
var errors = validateUnitsSupportedAndSameDimension(columnInfos);
errors.Add(validateErrorAgainstMeasurement(columnInfos));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ public EmptyDataSetsParseErrorDescription(IEnumerable<string> dataSetNames)
Message = Error.EmptyDataSet($"{dataSetNames.ToString(", ")}");
}
}

public class NonMonotonicalTimeParseErrorDescription : ParseErrorDescription
{
public NonMonotonicalTimeParseErrorDescription(string message)
{
Message = message;
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion src/OSPSuite.Infrastructure.Import/Services/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public IReadOnlyList<DataSetToDataRepositoryMappingResult> DataSourceToDataSets(

for (var i = 0; i < dataSource.DataSets.SelectMany(ds => ds.Data).Count(); i++)
{
var dataRepoMapping = _dataRepositoryMapper.ConvertImportDataSet(dataSource.DataSetAt(i));
var dataRepoMapping = _dataRepositoryMapper.ConvertImportDataSet(dataSource.ImportedDataSetAt(i));
var dataRepo = dataRepoMapping.DataRepository;
dataRepo.ConfigurationId = id;
determineMolecularWeight(metaDataCategories, dataImporterSettings, dataRepo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ IReadOnlyList<ColumnInfo> columnInfos
void GetFormatBasedOnCurrentSheet();
void ResetLoadedSheets();
void SetTabMarks(ParseErrors errors, Cache<string, IDataSet> loadedDataSets);
void SetTabMarks(ParseErrors errors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,10 @@ public void SetTabMarks(ParseErrors errors, Cache<string, IDataSet> loadedDataSe
{
View.SetTabMarks(errors, loadedDataSets);
}

public void SetTabMarks(ParseErrors errors)
{
View.SetTabMarks(errors);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using OSPSuite.Utility.Collections;
using OSPSuite.Utility.Extensions;
using ImporterConfiguration = OSPSuite.Core.Import.ImporterConfiguration;
using OSPSuite.Infrastructure.Import.Core.Helpers;

namespace OSPSuite.Presentation.Presenters.Importer
{
Expand Down Expand Up @@ -100,14 +99,15 @@ private void plotDataSet(object sender, DataSetSelectedEventArgs e)
{
try
{
_view.HideExtraErrors();
var dataRepository = _dataRepositoryMapper.ConvertImportDataSet(_dataSource.DataSetAt(e.Index));
var dataRepository = _dataRepositoryMapper.ConvertImportDataSet(_dataSource.ImportedDataSetAt(e.Index));
_confirmationPresenter.PlotDataRepository(dataRepository.DataRepository);
}
catch (InvalidArgumentException invalidException)
{
_view.ShowExtraErrors(Error.ErrorWhenPlottingDataRepository(e.Index, invalidException.Message));
_view.DisableConfirmationView();
var errors = new ParseErrors();
errors.Add(_dataSource.DataSetAt(e.Index), new NonMonotonicalTimeParseErrorDescription(Error.ErrorWhenPlottingDataRepository(e.Index, invalidException.Message)));
_importerDataPresenter.SetTabMarks(errors);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public interface IImporterDataView : IView<IImporterDataPresenter>
string SelectedTab { get; set; }
string GetFilter();
void SetTabMarks(ParseErrors errors, Cache<string, IDataSet> loadedDataSets);
void SetTabMarks(ParseErrors errors);
}
}
2 changes: 0 additions & 2 deletions src/OSPSuite.Presentation/Views/Importer/IImporterView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ public interface IImporterView : IView<IImporterPresenter>
void EnableConfirmationView();
void DisableConfirmationView();
void AddNanView(INanView nanView);
void ShowExtraErrors(string errorMessage);
void HideExtraErrors();
}
}
3 changes: 0 additions & 3 deletions src/OSPSuite.UI/Properties/licenses.licx

This file was deleted.

34 changes: 12 additions & 22 deletions src/OSPSuite.UI/Views/Importer/ImporterDataView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions src/OSPSuite.UI/Views/Importer/ImporterDataView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
using DevExpress.XtraTab.ViewInfo;
using OSPSuite.Assets;
using OSPSuite.Infrastructure.Import.Core;
using OSPSuite.Infrastructure.Import.Core.Exceptions;
using OSPSuite.Presentation.Presenters.Importer;
using OSPSuite.Presentation.Views.Importer;
using OSPSuite.UI.Controls;
using OSPSuite.UI.Extensions;
using OSPSuite.UI.Services;
using OSPSuite.Utility.Collections;
using OSPSuite.Utility.Extensions;

Expand All @@ -23,6 +23,7 @@ namespace OSPSuite.UI.Views.Importer
public partial class ImporterDataView : BaseUserControl, IImporterDataView
{
private IImporterDataPresenter _dataPresenter;
private readonly IImageListRetriever _imageListRetriever;

private string _contextMenuSelectedTab;
private bool sheetImportedFlag;
Expand All @@ -31,7 +32,7 @@ public partial class ImporterDataView : BaseUserControl, IImporterDataView
private ParseErrors _lastErrors = new ParseErrors();
private Cache<string, IDataSet> _lastLoadedDataSets = new Cache<string, IDataSet>();

public ImporterDataView()
public ImporterDataView(IImageListRetriever imageListRetriever)
{
InitializeComponent();
btnImport.Click += (s, a) => OnEvent(onButtonImportClicked, s, a);
Expand All @@ -50,6 +51,7 @@ public ImporterDataView()
btnImport.Text = Captions.Importer.LoadCurrentSheet;
allImportButtonsDisabledFlag = false;
dataViewingGridView.OptionsBehavior.Editable = false;
_imageListRetriever = imageListRetriever;
}

public override void InitializeResources()
Expand Down Expand Up @@ -228,7 +230,7 @@ public string GetActiveFilterCriteria()

public void AddTabs(List<string> sheetNames)
{
importerTabControl.Images = imageCollection1;
importerTabControl.Images = _imageListRetriever.AllImages16x16;
foreach (var sheetName in sheetNames)
importerTabControl.TabPages.Add(sheetName);

Expand Down Expand Up @@ -311,12 +313,12 @@ private void refreshErrorMessage()
if (_lastLoadedDataSets.Contains(SelectedTab) && _lastErrors.Contains(_lastLoadedDataSets[SelectedTab]))
Copy link
Member

Choose a reason for hiding this comment

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

somehow this feels like this code belongs in the presenter.

{
labelControlError.Text = Error.ParseErrorMessage(_lastErrors.ErrorsFor(_lastLoadedDataSets[SelectedTab]).Select(x => x.Message));
layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
layoutControlItemError.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
}
else
{
labelControlError.Text = "";
layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
layoutControlItemError.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
}
}

Expand All @@ -326,14 +328,19 @@ private void refreshErrorMarks()
{
if (_lastLoadedDataSets.Contains(x.Text))
Copy link
Member

Choose a reason for hiding this comment

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

this codes for which image to show also belongs in the presenter
And hopefully, we won't have those magin number anymore 1 and 0 once we use ApplicationIcons

{
x.ImageIndex = _lastErrors.Contains(_lastLoadedDataSets[x.Text]) ? 1 : 0;
x.ImageIndex = _lastErrors.Contains(_lastLoadedDataSets[x.Text]) ? _imageListRetriever.ImageIndex(ApplicationIcons.Cancel) : _imageListRetriever.ImageIndex(ApplicationIcons.OK);
return;
}

x.ImageIndex = -1;
});
}

public void SetTabMarks(ParseErrors errors)
{
SetTabMarks(errors, _lastLoadedDataSets);
}

public void SetTabMarks(ParseErrors errors, Cache<string, IDataSet> loadedDataSets)
{
_lastErrors = errors;
Expand Down
43 changes: 0 additions & 43 deletions src/OSPSuite.UI/Views/Importer/ImporterDataView.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,47 +120,4 @@
<metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="useForImportCheckEdit.ToolTip" xml:space="preserve">
<value>When selected, the filter will apply to the data during the import process. When deselected, the filter only affects this view. Check documentation for more information on defining filters: &lt;href=https://docs.open-systems-pharmacology.org/shared-tools-and-example-workflows/features-of-tables#filtering&gt;https://docs.open-systems-pharmacology.org/shared-tools-and-example-workflows/features-of-tables#filtering&lt;/href&gt;</value>
</data>
<metadata name="imageCollection1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>163, 17</value>
</metadata>
<assembly alias="DevExpress.Utils.v21.2" name="DevExpress.Utils.v21.2, Version=21.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<data name="imageCollection1.ImageStream" type="DevExpress.Utils.ImageCollectionStreamer, DevExpress.Utils.v21.2" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFpEZXZFeHByZXNzLlV0aWxzLnYyMS4yLCBWZXJzaW9uPTIxLjIu
My4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI4OGQxNzU0ZDcwMGU0OWEMAwAAAFFT
eXN0ZW0uRHJhd2luZywgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRv
a2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAAChEZXZFeHByZXNzLlV0aWxzLkltYWdlQ29sbGVjdGlvblN0
cmVhbWVyAgAAAAlJbWFnZVNpemUERGF0YQQHE1N5c3RlbS5EcmF3aW5nLlNpem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f9jMEi9l/WVRTGAeehLmKOvj0MtPUSWNXpA7FtvMASoaIOL1udVTNJdXVIrCbWqaZYLkgA1xw0uc4jG
LHNB5NpbpsnVRTVVk1xWpwsZLui3rXpxI39mTXYnmeQl5sx8+XyuolYS83XEgNGf9y6MwivIM5t3ossJ
wY9iAAvtmjZfry9EyLwwPeT55Dj1OoTMiAGcmDhH44V/5eN9Vc3oueiwNGwoIWhPVYpQjGcjFz2VFZmL
Hug2TKnoCIAfQmzsw53qs4QAAAAASUVORK5CYIIL
</value>
</data>
<metadata name="dpiAwareImageCollection1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>338, 17</value>
</metadata>
<data name="dpiAwareImageCollection1.Stream" type="DevExpress.Utils.DPIAwareImageCollectionStreamer, DevExpress.Utils.v21.2" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFpEZXZFeHByZXNzLlV0aWxzLnYyMS4yLCBWZXJzaW9uPTIxLjIu
My4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI4OGQxNzU0ZDcwMGU0OWEFAQAAADBE
ZXZFeHByZXNzLlV0aWxzLkRQSUF3YXJlSW1hZ2VDb2xsZWN0aW9uU3RyZWFtZXIAAAAAAgAAAAs=
</value>
</data>
</root>
Loading