Index: Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/GeneralResultConverter.cs =================================================================== diff -u -r2e5f2b59e81cda48f3d7ee03afa4db88abc7b1a8 -rbe44404797296f09605f5fc861c87f5766c14478 --- Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/GeneralResultConverter.cs (.../GeneralResultConverter.cs) (revision 2e5f2b59e81cda48f3d7ee03afa4db88abc7b1a8) +++ Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/GeneralResultConverter.cs (.../GeneralResultConverter.cs) (revision be44404797296f09605f5fc861c87f5766c14478) @@ -22,12 +22,14 @@ using System; using System.Collections.Generic; using System.Linq; +using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.IllustrationPoints; using HydraRingWindDirectionClosingSituation = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.WindDirectionClosingSituation; using HydraRingIllustrationPointTreeNode = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.IllustrationPointTreeNode; using HydraRingGeneralResult = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.GeneralResult; using IHydraRingIllustrationPoint = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.IIllustrationPoint; using HydraRingSubMechanismIllustrationPoint = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.SubMechanismIllustrationPoint; +using HydraRingFaultTreeIllustrationPoint = Ringtoets.HydraRing.Calculation.Data.Output.IllustrationPoints.FaultTreeIllustrationPoint; namespace Ringtoets.Common.Service.IllustrationPoints { @@ -36,6 +38,13 @@ /// public static class GeneralResultConverter { + private static IEnumerable GetStochasts(HydraRingGeneralResult hydraGeneralResult) + { + return hydraGeneralResult.Stochasts.Select(StochastConverter.CreateStochast); + } + + #region SubMechanismIllustrationPoint + /// /// Creates a new instance of for top level sub /// mechanism illustration points based on the information of . @@ -44,6 +53,8 @@ /// to create on. /// The newly created . /// Thrown when is null. + /// Thrown when the + /// cannot be converted to a with top level sub mechanism illustration points. public static GeneralResult CreateGeneralResultTopLevelSubMechanismIllustrationPoint( HydraRingGeneralResult hydraRingGeneralResult) { @@ -52,37 +63,128 @@ throw new ArgumentNullException(nameof(hydraRingGeneralResult)); } - WindDirection windDirection = WindDirectionConverter.Create(hydraRingGeneralResult.GoverningWindDirection); + WindDirection governingWindDirection = WindDirectionConverter.Create(hydraRingGeneralResult.GoverningWindDirection); IEnumerable stochasts = GetStochasts(hydraRingGeneralResult); IEnumerable windDirectionClosingScenarioIllustrationPoints = - GetWindDirectionClosingSituationIllustrationPoint(hydraRingGeneralResult); + GetTopLevelSubMechanismIllustrationPoints(hydraRingGeneralResult.IllustrationPoints); - return new GeneralResult(windDirection, stochasts, windDirectionClosingScenarioIllustrationPoints); + return new GeneralResult(governingWindDirection, + stochasts, + windDirectionClosingScenarioIllustrationPoints); } - private static IEnumerable GetStochasts(HydraRingGeneralResult hydraGeneralResult) + /// + /// Creates all the top level fault tree illustration points based on the + /// combinations of and + /// . + /// + /// The collection of + /// and + /// combinations to base the on. + /// An of . + /// Thrown when the combination of + /// and + /// cannot be converted to . + private static IEnumerable GetTopLevelSubMechanismIllustrationPoints( + IDictionary hydraRingTopLevelIllustrationPoints) { - return hydraGeneralResult.Stochasts.Select(StochastConverter.CreateStochast); + var topLevelIlustrationPoints = new List(); + foreach (KeyValuePair topLevelIllustrationPointTreeNode in hydraRingTopLevelIllustrationPoints) + { + IHydraRingIllustrationPoint hydraIllustrationPointData = topLevelIllustrationPointTreeNode.Value.Data; + HydraRingWindDirectionClosingSituation hydraWindDirectionClosingSituation = topLevelIllustrationPointTreeNode.Key; + + var subMechanismIllustrationPoint = hydraIllustrationPointData as HydraRingSubMechanismIllustrationPoint; + if (subMechanismIllustrationPoint != null) + { + topLevelIlustrationPoints.Add(TopLevelSubMechanismIllustrationPointConverter.Create( + hydraWindDirectionClosingSituation, subMechanismIllustrationPoint)); + } + else + { + string exceptionMessage = $"Expected a fault tree node with data of type {typeof(HydraRingSubMechanismIllustrationPoint)} as root, " + + $"but got {hydraIllustrationPointData.GetType()}"; + throw new IllustrationPointConversionException(exceptionMessage); + } + } + + return topLevelIlustrationPoints; } - private static IEnumerable GetWindDirectionClosingSituationIllustrationPoint( - HydraRingGeneralResult hydraGeneralResult) + #endregion + + #region FaultTreeIllustrationPoint + + /// + /// Creates a new instance of for fault tree illustration points + /// based on the information of . + /// + /// The + /// to base the to create on. + /// The newly created . + /// Thrown when + /// is null. + /// Thrown when the + /// cannot be converted to a with top level fault tree illustration points. + public static GeneralResult CreateGeneralResultTopLevelFaultTreeIllustrationPoint( + HydraRingGeneralResult hydraRingGeneralResult) { - var combinations = new List(); - foreach (KeyValuePair illustrationPointTreeNode in hydraGeneralResult.IllustrationPoints) + if (hydraRingGeneralResult == null) { - IHydraRingIllustrationPoint hydraIllustrationPoint = illustrationPointTreeNode.Value.Data; + throw new ArgumentNullException(nameof(hydraRingGeneralResult)); + } + + WindDirection governingWindDirection = WindDirectionConverter.Create(hydraRingGeneralResult.GoverningWindDirection); + IEnumerable stochasts = GetStochasts(hydraRingGeneralResult); + IEnumerable topLevelIllustrationPoints = + GetTopLevelFaultTreeIllustrationPoints(hydraRingGeneralResult.IllustrationPoints); + + return new GeneralResult(governingWindDirection, + stochasts, + topLevelIllustrationPoints); + } + + /// + /// Creates all the top level fault tree illustration points based on the + /// combinations of and + /// . + /// + /// The collection of + /// and + /// combinations to base the on. + /// An of . + /// Thrown when the combination of + /// and + /// cannot be converted to . + private static IEnumerable GetTopLevelFaultTreeIllustrationPoints( + IDictionary hydraRingTopLevelIllustrationPoints) + { + var topLevelIllustrationPoints = new List(); + foreach (KeyValuePair illustrationPointTreeNode in hydraRingTopLevelIllustrationPoints) + { + HydraRingIllustrationPointTreeNode hydraRingIllustrationPointTreeNode = illustrationPointTreeNode.Value; + IHydraRingIllustrationPoint hydraIllustrationPointData = hydraRingIllustrationPointTreeNode.Data; HydraRingWindDirectionClosingSituation hydraWindDirectionClosingSituation = illustrationPointTreeNode.Key; - var subMechanismIllustrationPoint = hydraIllustrationPoint as HydraRingSubMechanismIllustrationPoint; - if (subMechanismIllustrationPoint != null) + var faultTreeIllustrationPoint = hydraIllustrationPointData as HydraRingFaultTreeIllustrationPoint; + if (faultTreeIllustrationPoint != null) { - combinations.Add(TopLevelSubMechanismIllustrationPointConverter.Create( - hydraWindDirectionClosingSituation, subMechanismIllustrationPoint)); + topLevelIllustrationPoints.Add(TopLevelFaultTreeIllustrationPointConverter.Create( + hydraWindDirectionClosingSituation, hydraRingIllustrationPointTreeNode)); } + else + { + string exceptionMessage = $"Expected a fault tree node with data of type {typeof(HydraRingFaultTreeIllustrationPoint)} as root, " + + $"but got {hydraIllustrationPointData.GetType()}"; + throw new IllustrationPointConversionException(exceptionMessage); + } } - return combinations; + return topLevelIllustrationPoints; } + + #endregion } } \ No newline at end of file