Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs
===================================================================
diff -u -r56a1b0ad79756583461f17301d0edcd79a1d0de4 -r250f2f821d2540a5c562d5fa9ccaab669dacb24b
--- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (.../StructuresImporter.cs) (revision 56a1b0ad79756583461f17301d0edcd79a1d0de4)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/StructuresImporter.cs (.../StructuresImporter.cs) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b)
@@ -41,6 +41,7 @@
/// Abstract class for structure importers, providing an implementation of importing point shapefiles
/// containing structure locations and csv files containing structure schematizations.
///
+ /// Object type that is the target for this importer.
public abstract class StructuresImporter : FileImporterBase
{
private readonly ILog log = LogManager.GetLogger(typeof(StructuresImporter));
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs
===================================================================
diff -u -r58c471864c590aff4b609e7c2df36a220bf390b1 -r250f2f821d2540a5c562d5fa9ccaab669dacb24b
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision 58c471864c590aff4b609e7c2df36a220bf390b1)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/HeightStructuresImporter.cs (.../HeightStructuresImporter.cs) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b)
@@ -37,24 +37,37 @@
///
public class HeightStructuresImporter : StructuresImporter>
{
+ private readonly IStructureUpdateStrategy structureUpdateStrategy;
+
///
/// Creates a new instance of .
///
/// The height structures to import on.
/// The reference line used to check if the
/// objects found in the file are intersecting it.
+ /// The strategy to update the structures with imported data.
/// The path to the file to import from.
- /// Thrown when ,
- /// or is null.
- public HeightStructuresImporter(StructureCollection importTarget,
- ReferenceLine referenceLine, string filePath)
- : base(importTarget, referenceLine, filePath) {}
+ /// Thrown when any of the input parameters is null.
+ public HeightStructuresImporter(StructureCollection importTarget, ReferenceLine referenceLine,
+ IStructureUpdateStrategy structureUpdateStrategy,
+ string filePath)
+ : base(importTarget, referenceLine, filePath)
+ {
+ if (structureUpdateStrategy == null)
+ {
+ throw new ArgumentNullException(nameof(structureUpdateStrategy));
+ }
+ this.structureUpdateStrategy = structureUpdateStrategy;
+ }
+
protected override void CreateSpecificStructures(ICollection structureLocations,
Dictionary> groupedStructureParameterRows)
{
- ImportTarget.AddRange(CreateHeightStructures(structureLocations.ToList(), groupedStructureParameterRows).ToArray(),
- FilePath);
+ structureUpdateStrategy.UpdateStructuresWithImportedData(ImportTarget,
+ CreateHeightStructures(structureLocations.ToList(),
+ groupedStructureParameterRows).ToArray(),
+ FilePath);
}
private IEnumerable CreateHeightStructures(IEnumerable structureLocations,
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs
===================================================================
diff -u -rc10213be206d81cd8618603d9e526f18f070211b -r250f2f821d2540a5c562d5fa9ccaab669dacb24b
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision c10213be206d81cd8618603d9e526f18f070211b)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b)
@@ -51,6 +51,7 @@
using Ringtoets.HeightStructures.Forms.Views;
using Ringtoets.HeightStructures.IO;
using Ringtoets.HeightStructures.IO.Configurations;
+using Ringtoets.HeightStructures.Plugin.FileImporters;
using Ringtoets.HeightStructures.Service;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources;
@@ -90,6 +91,7 @@
{
CreateFileImporter = (context, filePath) => new HeightStructuresImporter(context.WrappedData,
context.AssessmentSection.ReferenceLine,
+ new HeightStructureReplaceDataStrategy(context.FailureMechanism),
filePath),
Name = RingtoetsCommonFormsResources.StructuresImporter_DisplayName,
Category = RingtoetsCommonFormsResources.Ringtoets_Category,
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresImporterTest.cs
===================================================================
diff -u -r58c471864c590aff4b609e7c2df36a220bf390b1 -r250f2f821d2540a5c562d5fa9ccaab669dacb24b
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresImporterTest.cs (.../HeightStructuresImporterTest.cs) (revision 58c471864c590aff4b609e7c2df36a220bf390b1)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/HeightStructuresImporterTest.cs (.../HeightStructuresImporterTest.cs) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b)
@@ -31,6 +31,7 @@
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.IO.FileImporters;
using Ringtoets.HeightStructures.Data;
+using Ringtoets.HeightStructures.Plugin.FileImporters;
namespace Ringtoets.HeightStructures.IO.Test
{
@@ -42,10 +43,26 @@
private readonly string testFilePath = string.Empty;
[Test]
+ public void Constructor_StructureUpdateStrategyNull_ThrowsArgumentNullException()
+ {
+ // Call
+ TestDelegate call = () => new HeightStructuresImporter(testImportTarget, testReferenceLine,
+ null, testFilePath);
+
+ // Assert
+ string paramName = Assert.Throws(call).ParamName;
+ Assert.AreEqual("structureUpdateStrategy", paramName);
+ }
+
+ [Test]
public void Constructor_Always_ExpectedValues()
{
+ // Setup
+ var replaceDataStrategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism());
+
// Call
- var importer = new HeightStructuresImporter(testImportTarget, testReferenceLine, testFilePath);
+ var importer = new HeightStructuresImporter(testImportTarget, testReferenceLine,
+ replaceDataStrategy, testFilePath);
// Assert
Assert.IsInstanceOf>>(importer);
@@ -56,12 +73,15 @@
{
// Setup
string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
- Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp"));
+ Path.Combine("Structures", "CorrectFiles",
+ "Kunstwerken.shp"));
ReferenceLine referenceLine = CreateReferenceLine();
+ var failureMechanism = new HeightStructuresFailureMechanism();
+ var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism);
- var importTarget = new StructureCollection();
- var structuresImporter = new HeightStructuresImporter(importTarget, referenceLine, filePath);
+ var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures,
+ referenceLine, replaceDataStrategy, filePath);
// Call
var importResult = false;
@@ -83,22 +103,26 @@
};
TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages);
Assert.IsTrue(importResult);
- Assert.AreEqual(1, importTarget.Count);
- Assert.AreEqual(filePath, importTarget.SourcePath);
+ Assert.AreEqual(1, failureMechanism.HeightStructures.Count);
+ Assert.AreEqual(filePath, failureMechanism.HeightStructures.SourcePath);
}
[Test]
public void Import_ValidFileWithConversionsBetweenVarianceTypes_WarnUserAboutConversion()
{
// Setup
string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HeightStructures.IO,
- Path.Combine("HeightStructuresVarianceConvert", "StructureNeedVarianceValueConversion.shp"));
+ Path.Combine("HeightStructuresVarianceConvert",
+ "StructureNeedVarianceValueConversion.shp"));
ReferenceLine referenceLine = CreateReferenceLine();
- var importTarget = new StructureCollection();
- var structuresImporter = new HeightStructuresImporter(importTarget, referenceLine, filePath);
+ var failureMechanism = new HeightStructuresFailureMechanism();
+ var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism);
+ var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures,
+ referenceLine, replaceDataStrategy, filePath);
+
// Call
var importResult = false;
Action call = () => importResult = structuresImporter.Import();
@@ -115,15 +139,15 @@
};
TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages);
Assert.IsTrue(importResult);
- Assert.AreEqual(1, importTarget.Count);
- HeightStructure structure = importTarget[0];
+ Assert.AreEqual(1, failureMechanism.HeightStructures.Count);
+ HeightStructure structure = failureMechanism.HeightStructures[0];
Assert.AreEqual(0.12, structure.LevelCrestStructure.StandardDeviation.Value);
Assert.AreEqual(0.24, structure.FlowWidthAtBottomProtection.StandardDeviation.Value);
Assert.AreEqual(1.0, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value);
Assert.AreEqual(0.97, structure.WidthFlowApertures.StandardDeviation.Value);
Assert.AreEqual(1.84, structure.StorageStructureArea.CoefficientOfVariation.Value);
Assert.AreEqual(2.18, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value);
- Assert.AreEqual(filePath, importTarget.SourcePath);
+ Assert.AreEqual(filePath, failureMechanism.HeightStructures.SourcePath);
}
[Test]
@@ -132,13 +156,15 @@
{
// Setup
string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
- Path.Combine("Structures", "CorrectShpIncompleteCsv", "Kunstwerken.shp"));
+ Path.Combine("Structures", "CorrectShpIncompleteCsv",
+ "Kunstwerken.shp"));
ReferenceLine referenceLine = CreateReferenceLine();
+ var failureMechanism = new HeightStructuresFailureMechanism();
+ var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism);
+ var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures,
+ referenceLine, replaceDataStrategy, filePath);
- var importTarget = new StructureCollection();
- var structuresImporter = new HeightStructuresImporter(importTarget, referenceLine, filePath);
-
// Call
var importResult = false;
Action call = () => importResult = structuresImporter.Import();
@@ -165,21 +191,24 @@
};
TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages);
Assert.IsTrue(importResult);
- Assert.AreEqual(0, importTarget.Count);
- Assert.AreEqual(filePath, importTarget.SourcePath);
+ Assert.AreEqual(0, failureMechanism.HeightStructures.Count);
+ Assert.AreEqual(filePath, failureMechanism.HeightStructures.SourcePath);
}
[Test]
public void Import_MissingParameters_LogWarningAndContinueImportWithDefaultValues()
{
// Setup
string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HeightStructures.IO,
- Path.Combine(nameof(HeightStructuresImporter), "Kunstwerken.shp"));
+ Path.Combine(nameof(HeightStructuresImporter),
+ "Kunstwerken.shp"));
ReferenceLine referenceLine = CreateReferenceLine();
- var importTarget = new StructureCollection();
- var structuresImporter = new HeightStructuresImporter(importTarget, referenceLine, filePath);
+ var failureMechanism = new HeightStructuresFailureMechanism();
+ var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism);
+ var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures,
+ referenceLine, replaceDataStrategy, filePath);
// Call
var importResult = false;
@@ -199,8 +228,8 @@
// Don't care about the other message.
});
Assert.IsTrue(importResult);
- Assert.AreEqual(1, importTarget.Count);
- HeightStructure importedStructure = importTarget.First();
+ Assert.AreEqual(1, failureMechanism.HeightStructures.Count);
+ HeightStructure importedStructure = failureMechanism.HeightStructures.First();
var defaultStructure = new HeightStructure(new HeightStructure.ConstructionProperties
{
Name = "test",
@@ -210,15 +239,16 @@
Assert.AreEqual(defaultStructure.StructureNormalOrientation, importedStructure.StructureNormalOrientation);
DistributionAssert.AreEqual(defaultStructure.FlowWidthAtBottomProtection, importedStructure.FlowWidthAtBottomProtection);
Assert.AreEqual(defaultStructure.FailureProbabilityStructureWithErosion, importedStructure.FailureProbabilityStructureWithErosion);
- Assert.AreEqual(filePath, importTarget.SourcePath);
+ Assert.AreEqual(filePath, failureMechanism.HeightStructures.SourcePath);
}
[Test]
public void Import_ParameterIdsWithVaryingCase_TrueAndImportTargetUpdated()
{
// Setup
string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO,
- Path.Combine("Structures", "CorrectShpRandomCaseHeaderCsv", "Kunstwerken.shp"));
+ Path.Combine("Structures", "CorrectShpRandomCaseHeaderCsv",
+ "Kunstwerken.shp"));
var referencePoints = new List
{
@@ -229,16 +259,19 @@
};
var referenceLine = new ReferenceLine();
referenceLine.SetGeometry(referencePoints);
- var importTarget = new StructureCollection();
- var structuresImporter = new HeightStructuresImporter(importTarget, referenceLine, filePath);
+ var failureMechanism = new HeightStructuresFailureMechanism();
+ var replaceDataStrategy = new HeightStructureReplaceDataStrategy(failureMechanism);
+ var structuresImporter = new HeightStructuresImporter(failureMechanism.HeightStructures,
+ referenceLine, replaceDataStrategy, filePath);
+
// Call
bool importResult = structuresImporter.Import();
// Assert
Assert.IsTrue(importResult);
- Assert.AreEqual(4, importTarget.Count);
- Assert.AreEqual(filePath, importTarget.SourcePath);
+ Assert.AreEqual(4, failureMechanism.HeightStructures.Count);
+ Assert.AreEqual(filePath, failureMechanism.HeightStructures.SourcePath);
}
private static ReferenceLine CreateReferenceLine()
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Ringtoets.HeightStructures.IO.Test.csproj
===================================================================
diff -u -r8aeff3f1153aaac2b2980ca207e298b6d764947b -r250f2f821d2540a5c562d5fa9ccaab669dacb24b
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Ringtoets.HeightStructures.IO.Test.csproj (.../Ringtoets.HeightStructures.IO.Test.csproj) (revision 8aeff3f1153aaac2b2980ca207e298b6d764947b)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Ringtoets.HeightStructures.IO.Test.csproj (.../Ringtoets.HeightStructures.IO.Test.csproj) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b)
@@ -98,6 +98,10 @@
{D63FCFEC-34E8-4C68-8B4F-99338D2447AC}
Ringtoets.HeightStructures.IO
+
+ {9AF85B2B-8D78-43C5-9542-FBB3A14EAB36}
+ Ringtoets.HeightStructures.Plugin
+
{F67E8AE8-1FF0-4680-9817-99E025CD9FF6}
Ringtoets.HeightStructures.Data.TestUtil
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresScenariosViewIntegrationTest.cs
===================================================================
diff -u -r20e9bfea15dfe132ee137283a9f24bc4c413ce4a -r250f2f821d2540a5c562d5fa9ccaab669dacb24b
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresScenariosViewIntegrationTest.cs (.../HeightStructuresScenariosViewIntegrationTest.cs) (revision 20e9bfea15dfe132ee137283a9f24bc4c413ce4a)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/HeightStructuresScenariosViewIntegrationTest.cs (.../HeightStructuresScenariosViewIntegrationTest.cs) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b)
@@ -34,6 +34,7 @@
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Forms.Views;
using Ringtoets.HeightStructures.IO;
+using Ringtoets.HeightStructures.Plugin.FileImporters;
using Ringtoets.Integration.Data;
using Ringtoets.Integration.TestUtils;
@@ -93,10 +94,11 @@
{
var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
DataImportHelper.ImportReferenceLine(assessmentSection);
- IFailureMechanism failureMechanism = assessmentSection.HeightStructures;
+ HeightStructuresFailureMechanism failureMechanism = assessmentSection.HeightStructures;
DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);
new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures,
assessmentSection.ReferenceLine,
+ new HeightStructureReplaceDataStrategy(failureMechanism),
filePath)
.Import();
@@ -141,10 +143,11 @@
{
var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
DataImportHelper.ImportReferenceLine(assessmentSection);
- IFailureMechanism failureMechanism = assessmentSection.HeightStructures;
+ HeightStructuresFailureMechanism failureMechanism = assessmentSection.HeightStructures;
DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);
new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures,
assessmentSection.ReferenceLine,
+ new HeightStructureReplaceDataStrategy(failureMechanism),
filePath)
.Import();
@@ -195,10 +198,11 @@
{
var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike);
DataImportHelper.ImportReferenceLine(assessmentSection);
- IFailureMechanism failureMechanism = assessmentSection.HeightStructures;
+ HeightStructuresFailureMechanism failureMechanism = assessmentSection.HeightStructures;
DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);
new HeightStructuresImporter(assessmentSection.HeightStructures.HeightStructures,
assessmentSection.ReferenceLine,
+ new HeightStructureReplaceDataStrategy(failureMechanism),
filePath)
.Import();
Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/Ringtoets.HeightStructures.Integration.Test.csproj
===================================================================
diff -u -r08b3bcba439831d547684b194ecdf903f2519700 -r250f2f821d2540a5c562d5fa9ccaab669dacb24b
--- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/Ringtoets.HeightStructures.Integration.Test.csproj (.../Ringtoets.HeightStructures.Integration.Test.csproj) (revision 08b3bcba439831d547684b194ecdf903f2519700)
+++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Integration.Test/Ringtoets.HeightStructures.Integration.Test.csproj (.../Ringtoets.HeightStructures.Integration.Test.csproj) (revision 250f2f821d2540a5c562d5fa9ccaab669dacb24b)
@@ -119,6 +119,10 @@
{D63FCFEC-34E8-4C68-8B4F-99338D2447AC}
Ringtoets.HeightStructures.IO
+
+ {9AF85B2B-8D78-43C5-9542-FBB3A14EAB36}
+ Ringtoets.HeightStructures.Plugin
+
{20DD96D3-001E-407A-AE2E-432887088F1F}
Ringtoets.HeightStructures.Service