Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/AssessmentSectionEntityReadExtensions.cs =================================================================== diff -u -rb5d7394714ada93dfff0349111dacc17c4030638 -r366957369348a28ea2c32c26678d57389560e69d --- Riskeer/Storage/src/Riskeer.Storage.Core/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision b5d7394714ada93dfff0349111dacc17c4030638) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/AssessmentSectionEntityReadExtensions.cs (.../AssessmentSectionEntityReadExtensions.cs) (revision 366957369348a28ea2c32c26678d57389560e69d) @@ -28,6 +28,7 @@ using Riskeer.Common.Data.Hydraulics; using Riskeer.Integration.Data; using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read.SpecificFailurePaths; using Riskeer.Storage.Core.Serializers; namespace Riskeer.Storage.Core.Read @@ -93,6 +94,8 @@ entity.ReadStabilityStoneCoverFailureMechanism(assessmentSection, collector); entity.ReadStabilityPointStructuresFailureMechanism(assessmentSection, collector); + entity.ReadSpecificFailurePaths(assessmentSection, collector); + return assessmentSection; } @@ -146,7 +149,6 @@ assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.AddRange(waterLevelHydraulicLocationCalculationForTargetProbabilityCollectionEntities.Select(e => e.Read(collector)) .ToArray()); - IEnumerable waveHeightHydraulicLocationCalculationForTargetProbabilityCollectionEntities = entity.HydraulicLocationCalculationForTargetProbabilityCollectionEntities .Where(e => e.HydraulicBoundaryLocationCalculationType == (short) HydraulicBoundaryLocationCalculationType.WaveHeight) @@ -276,5 +278,16 @@ { return entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (int) type); } + + private static void ReadSpecificFailurePaths(this AssessmentSectionEntity entity, + IAssessmentSection assessmentSection, + ReadConversionCollector collector) + { + IEnumerable specificFailurePathEntities = + entity.SpecificFailurePathEntities + .OrderBy(e => e.Order); + + assessmentSection.SpecificFailurePaths.AddRange(specificFailurePathEntities.Select(e => e.Read(collector)).ToArray()); + } } } \ No newline at end of file Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/ReadConversionCollector.cs =================================================================== diff -u -r6a11b3b59df43bbd1c924a9acac7f7600f1591ec -r366957369348a28ea2c32c26678d57389560e69d --- Riskeer/Storage/src/Riskeer.Storage.Core/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision 6a11b3b59df43bbd1c924a9acac7f7600f1591ec) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision 366957369348a28ea2c32c26678d57389560e69d) @@ -28,6 +28,7 @@ using Riskeer.Common.Data.Hydraulics; using Riskeer.DuneErosion.Data; using Riskeer.HeightStructures.Data; +using Riskeer.Integration.Data.FailurePath; using Riskeer.MacroStabilityInwards.Data.SoilProfile; using Riskeer.MacroStabilityInwards.Primitives; using Riskeer.Piping.Data.SoilProfile; @@ -72,10 +73,10 @@ private readonly Dictionary hydraulicBoundaryLocations = CreateDictionary(); - + private readonly Dictionary hydraulicLocationCalculationsForTargetProbabilities = - CreateDictionary(); + CreateDictionary(); private readonly Dictionary duneLocations = CreateDictionary(); @@ -98,6 +99,9 @@ private readonly Dictionary stabilityPointStructures = CreateDictionary(); + private readonly Dictionary specificFailurePaths = + CreateDictionary(); + private static Dictionary CreateDictionary() { return new Dictionary(new ReferenceEqualityComparer()); @@ -802,7 +806,7 @@ } #endregion - + #region HydraulicLocationCalculationForTargetProbabilityCollectionEntity: Read, Contains, Get /// @@ -812,7 +816,7 @@ /// The that was read. /// The that was constructed. /// Thrown when any of the input parameters is null. - internal void Read(HydraulicLocationCalculationForTargetProbabilityCollectionEntity entity, + internal void Read(HydraulicLocationCalculationForTargetProbabilityCollectionEntity entity, HydraulicBoundaryLocationCalculationsForTargetProbability model) { if (entity == null) @@ -1371,5 +1375,76 @@ } #endregion + + #region SpecificFailurePathEntity: Read, Contains, Get + + /// + /// Registers a read operation for and the + /// that was constructed with the information. + /// + /// The that was read. + /// The that was constructed. + /// Thrown when any of the input parameters is null. + internal void Read(SpecificFailurePathEntity entity, SpecificFailurePath model) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + specificFailurePaths[entity] = model; + } + + /// + /// Checks whether a read operation has been registered for a given . + /// + /// The to check for. + /// true if the was read before, false otherwise. + /// Thrown when is null. + internal bool Contains(SpecificFailurePathEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + return specificFailurePaths.ContainsKey(entity); + } + + /// + /// Obtains the which was read for the + /// given . + /// + /// The for which a read + /// operation has been registered. + /// The constructed . + /// Thrown when is null. + /// Thrown when no read operation has + /// been registered for . + /// Use to find out whether a + /// read operation has been registered for . + internal SpecificFailurePath Get(SpecificFailurePathEntity entity) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + try + { + return specificFailurePaths[entity]; + } + catch (KeyNotFoundException e) + { + throw new InvalidOperationException(e.Message, e); + } + } + + #endregion } } \ No newline at end of file Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensions.cs =================================================================== diff -u -r8c62999c079e94486138d3f1b69f952ba904fb18 -r366957369348a28ea2c32c26678d57389560e69d --- Riskeer/Storage/src/Riskeer.Storage.Core/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensions.cs (.../SpecificFailurePathEntityReadExtensions.cs) (revision 8c62999c079e94486138d3f1b69f952ba904fb18) +++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensions.cs (.../SpecificFailurePathEntityReadExtensions.cs) (revision 366957369348a28ea2c32c26678d57389560e69d) @@ -20,6 +20,9 @@ // All rights reserved. using System; +using System.Linq; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.FailureMechanism; using Riskeer.Integration.Data.FailurePath; using Riskeer.Storage.Core.DbContext; @@ -36,35 +39,59 @@ /// . /// /// The to create for. - /// The target of the read operation. /// The object keeping track of read operations. /// A new . /// Thrown when is null. internal static SpecificFailurePath Read(this SpecificFailurePathEntity entity, - SpecificFailurePath failurePath, ReadConversionCollector collector) { if (collector == null) { throw new ArgumentNullException(nameof(collector)); } - // if (collector.Contains(entity)) - // { - // return collector.Get(entity); - // } + if (collector.Contains(entity)) + { + return collector.Get(entity); + } - //failurePath.Name = entity.Name; - failurePath.IsRelevant = Convert.ToBoolean(entity.IsRelevant); - failurePath.InputComments.Body = entity.InputComments; - failurePath.OutputComments.Body = entity.OutputComments; - failurePath.NotRelevantComments.Body = entity.NotRelevantComments; + var specificFailurePath = new SpecificFailurePath + { + Name = entity.Name, + IsRelevant = Convert.ToBoolean(entity.IsRelevant), + InputComments = + { + Body = entity.InputComments + }, + OutputComments = + { + Body = entity.OutputComments + }, + NotRelevantComments = + { + Body = entity.NotRelevantComments + } + }; - //entity.ReadFailureMechanismSections(failureMechanism, collector); - - //collector.Read(entity, failurePath); + entity.ReadFailureMechanismSections(specificFailurePath, collector); - return failurePath; + collector.Read(entity, specificFailurePath); + + return specificFailurePath; } + + private static void ReadFailureMechanismSections(this SpecificFailurePathEntity entity, + IFailurePath specificFailurePath, + ReadConversionCollector collector) + { + FailureMechanismSection[] readFailureMechanismSections = entity.FailureMechanismSectionEntities + .Select(failureMechanismSectionEntity => + failureMechanismSectionEntity.Read(collector)) + .ToArray(); + if (readFailureMechanismSections.Any()) + { + specificFailurePath.SetSections(readFailureMechanismSections, entity.FailureMechanismSectionCollectionSourcePath); + } + } } } \ No newline at end of file Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/AssessmentSectionEntityReadExtensionsTest.cs =================================================================== diff -u -rcb44709200595ebe223867e21dc78d226ed1bdfa -r366957369348a28ea2c32c26678d57389560e69d --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/AssessmentSectionEntityReadExtensionsTest.cs (.../AssessmentSectionEntityReadExtensionsTest.cs) (revision cb44709200595ebe223867e21dc78d226ed1bdfa) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/AssessmentSectionEntityReadExtensionsTest.cs (.../AssessmentSectionEntityReadExtensionsTest.cs) (revision 366957369348a28ea2c32c26678d57389560e69d) @@ -1008,6 +1008,45 @@ section.TechnicalInnovation); } + [Test] + public void Read_WithSpecificFailurePathProperties_ReturnsNewAssessmentSectionWithPropertiesInSpecificFailurePath() + { + // Setup + AssessmentSectionEntity entity = CreateAssessmentSectionEntity(); + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + const string name = "Specific failure path name"; + const string inputComments = "Some input text"; + const string outputComments = "Some output text"; + const string notRelevantComments = "Some not relevant text"; + + var specificFailurePathEntity = new SpecificFailurePathEntity + { + Name = name, + IsRelevant = Convert.ToByte(isRelevant), + InputComments = inputComments, + OutputComments = outputComments, + NotRelevantComments = notRelevantComments + }; + + entity.SpecificFailurePathEntities.Add(specificFailurePathEntity); + entity.BackgroundDataEntities.Add(CreateBackgroundDataEntity()); + + var collector = new ReadConversionCollector(); + + // Call + AssessmentSection section = entity.Read(collector); + + // Assert + IFailurePath specificFailurePath = section.SpecificFailurePaths.Single(); + Assert.AreEqual(name, specificFailurePath.Name); + Assert.AreEqual(isRelevant, specificFailurePath.IsRelevant); + Assert.AreEqual(inputComments, specificFailurePath.InputComments.Body); + Assert.AreEqual(outputComments, specificFailurePath.OutputComments.Body); + Assert.AreEqual(notRelevantComments, specificFailurePath.NotRelevantComments.Body); + Assert.IsNull(specificFailurePath.FailureMechanismSectionSourcePath); + } + private static void AssertHydraulicBoundaryLocationCalculation(HydraulicLocationCalculationEntity expectedEntity, HydraulicBoundaryLocation expectedHydraulicBoundaryLocation, HydraulicBoundaryLocationCalculation actualCalculation) Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/ReadConversionCollectorTest.cs =================================================================== diff -u -r6a11b3b59df43bbd1c924a9acac7f7600f1591ec -r366957369348a28ea2c32c26678d57389560e69d --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/ReadConversionCollectorTest.cs (.../ReadConversionCollectorTest.cs) (revision 6a11b3b59df43bbd1c924a9acac7f7600f1591ec) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/ReadConversionCollectorTest.cs (.../ReadConversionCollectorTest.cs) (revision 366957369348a28ea2c32c26678d57389560e69d) @@ -34,6 +34,7 @@ using Riskeer.DuneErosion.Data.TestUtil; using Riskeer.HeightStructures.Data; using Riskeer.HeightStructures.Data.TestUtil; +using Riskeer.Integration.Data.FailurePath; using Riskeer.MacroStabilityInwards.Data.SoilProfile; using Riskeer.MacroStabilityInwards.Data.TestUtil; using Riskeer.MacroStabilityInwards.Data.TestUtil.SoilProfile; @@ -405,6 +406,24 @@ #endregion + #region SpecificFailurePath + + [TestFixture] + private class SpecificFailurePathCollectorTest : CollectorTest + { + public SpecificFailurePathCollectorTest() : base( + (c, e, m) => c.Read(e, m), + (c, e) => c.Contains(e), + (c, e) => c.Get(e)) {} + + protected override SpecificFailurePath CreateDataModel() + { + return new SpecificFailurePath(); + } + } + + #endregion + #region Piping [TestFixture] Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensionsTest.cs =================================================================== diff -u --- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensionsTest.cs (revision 0) +++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/SpecificFailurePaths/SpecificFailurePathEntityReadExtensionsTest.cs (revision 366957369348a28ea2c32c26678d57389560e69d) @@ -0,0 +1,118 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.Integration.Data.FailurePath; +using Riskeer.Storage.Core.DbContext; +using Riskeer.Storage.Core.Read; +using Riskeer.Storage.Core.Read.SpecificFailurePaths; + +namespace Riskeer.Storage.Core.Test.Read.SpecificFailurePaths +{ + [TestFixture] + public class SpecificFailurePathEntityReadExtensionsTest + { + [Test] + public void Read_ReadConversionCollectorNull_ThrowArgumentNullException() + { + // Setup + var entity = new SpecificFailurePathEntity(); + + // Call + void Call() => entity.Read(null); + + // Assert + string paramName = Assert.Throws(Call).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Read_EntityNotReadBefore_RegisterEntity() + { + // Setup + var entity = new SpecificFailurePathEntity + { + Name = "name" + }; + + var collector = new ReadConversionCollector(); + + // Precondition + Assert.IsFalse(collector.Contains(entity)); + + // Call + SpecificFailurePath specificFailurePath = entity.Read(collector); + + // Assert + Assert.IsTrue(collector.Contains(entity)); + Assert.AreSame(specificFailurePath, collector.Get(entity)); + } + + [Test] + public void Read_ValidEntity_ReturnSpecificFailurePath() + { + // Setup + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + var entity = new SpecificFailurePathEntity + { + Name = "Specific failure path name", + IsRelevant = Convert.ToByte(isRelevant), + InputComments = "Some input text", + OutputComments = "Some output text", + NotRelevantComments = "Some not relevant text" + }; + + var collector = new ReadConversionCollector(); + + // Call + SpecificFailurePath specificFailurePath = entity.Read(collector); + + // Assert + Assert.AreEqual(entity.Name, specificFailurePath.Name); + Assert.AreEqual(Convert.ToBoolean(entity.IsRelevant), specificFailurePath.IsRelevant); + Assert.AreEqual(entity.InputComments, specificFailurePath.InputComments.Body); + Assert.AreEqual(entity.OutputComments, specificFailurePath.OutputComments.Body); + Assert.AreEqual(entity.NotRelevantComments, specificFailurePath.NotRelevantComments.Body); + Assert.IsNull(specificFailurePath.FailureMechanismSectionSourcePath); + + Assert.IsTrue(collector.Contains(entity)); + } + + [Test] + public void Read_EntityRegistered_ReturnRegisteredSpecificFailurePath() + { + // Setup + var entity = new SpecificFailurePathEntity(); + var registeredSpecificFailurePath = new SpecificFailurePath(); + var collector = new ReadConversionCollector(); + collector.Read(entity, registeredSpecificFailurePath); + + // Call + SpecificFailurePath readSpecificFailurePath = entity.Read(collector); + + // Assert + Assert.AreSame(registeredSpecificFailurePath, readSpecificFailurePath); + } + } +} \ No newline at end of file