Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs =================================================================== diff -u -re50b6ad32d33acb630c391bce2a6d359cc7e2b28 -r82af27f82c4dc2248e03c0e22bbe46b5e01e88bb --- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision e50b6ad32d33acb630c391bce2a6d359cc7e2b28) +++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision 82af27f82c4dc2248e03c0e22bbe46b5e01e88bb) @@ -25,7 +25,10 @@ using Core.Common.Base.IO; using Core.Common.IO.Readers; using log4net; +using Ringtoets.Common.Data; using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.DikeProfiles; +using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.IO.Configurations; using Ringtoets.Common.IO.Properties; using Ringtoets.Common.IO.Readers; @@ -127,6 +130,185 @@ message, calculationName); } + /// + /// Validate the defined wave reduction parameters in combination with a given foreshore profile. + /// + /// Configuration possibly containing wave reduction parameters. + /// The foreshore profile currently assigned to the calculation. + /// The name of the calculation which is being validated. + /// false when there is an invalid wave reduction parameter defined, true otherwise. + /// Thrown when is null. + protected bool ValidateWaveReduction(WaveReductionConfiguration waveReduction, ForeshoreProfile foreshoreProfile, string calculationName) + { + if (calculationName == null) + { + throw new ArgumentNullException(nameof(calculationName)); + } + + if (foreshoreProfile == null) + { + if (HasParametersDefined(waveReduction)) + { + LogReadCalculationConversionError( + Resources.CalculationConfigurationImporter_ValidateWaveReduction_No_foreshore_profile_provided, + calculationName); + + return false; + } + } + else if (!foreshoreProfile.Geometry.Any() && waveReduction.UseForeshoreProfile == true) + { + LogReadCalculationConversionError( + string.Format( + Resources.ReadForeshoreProfile_ForeshoreProfile_0_has_no_geometry_and_cannot_be_used, + foreshoreProfile.Name), + calculationName); + + return false; + } + return true; + } + + /// + /// Tries to find the hydraulic boundary location with the given + /// in the . + /// + /// The name of the location to find. + /// Name of the calculation to assign the location to. + /// The collection of + /// to search in. + /// The location with the name equal to + /// if there was any. + /// true if no is given, or when a location with + /// the name was found, false otherwise. + /// Thrown when + /// or is null. + protected bool TryReadHydraulicBoundaryLocation(string locationName, string calculationName, IEnumerable hydraulicBoundaryLocations, out HydraulicBoundaryLocation foundLocation) + { + if (calculationName == null) + { + throw new ArgumentNullException(nameof(calculationName)); + } + if (hydraulicBoundaryLocations == null) + { + throw new ArgumentNullException(nameof(hydraulicBoundaryLocations)); + } + + foundLocation = null; + + if (locationName != null) + { + var location = hydraulicBoundaryLocations.FirstOrDefault(l => l.Name == locationName); + + if (location == null) + { + LogReadCalculationConversionError( + string.Format( + Resources.CalculationConfigurationImporter_ReadHydraulicBoundaryLocation_HydraulicBoundaryLocation_0_does_not_exist, + locationName), + calculationName); + + return false; + } + + foundLocation = location; + } + return true; + } + + /// + /// Tries to find the structure with the given + /// in the . + /// + /// The name of the structure to find. + /// Name of the calculation to assign the structure to. + /// The collection of to search in. + /// The structure with the name equal to + /// if there was any. + /// true if no is given, or when a structure with + /// the name was found, false otherwise. + /// Thrown when + /// or is null. + protected bool TryReadStructure(string structureName, string calculationName, IEnumerable structures, out T foundStructure) + where T : StructureBase + { + if (calculationName == null) + { + throw new ArgumentNullException(nameof(calculationName)); + } + if (structures == null) + { + throw new ArgumentNullException(nameof(structures)); + } + foundStructure = null; + if (structureName != null) + { + T structure = structures.FirstOrDefault(l => l.Name == structureName); + + if (structure == null) + { + LogReadCalculationConversionError( + string.Format( + Resources.CalculationConfigurationImporter_ReadStructure_Structure_0_does_not_exist, + structureName), + calculationName); + + return false; + } + + foundStructure = structure; + } + + return true; + } + + /// + /// Tries to find the foreshore profile with the given + /// in the . + /// + /// The name of the foreshore profile to find. + /// Name of the calculation to assign the foreshore profile to. + /// The collection of to search in. + /// The foreshore profile with the name equal to + /// if there was any. + /// true if no is given, or when a foreshore profile with + /// the name was found, false otherwise. + /// Thrown when + /// or is null. + protected bool TryReadForeshoreProfile(string foreshoreProfileName, string calculationName, IEnumerable foreshoreProfiles, out ForeshoreProfile foundForeshoreProfile) + { + if (calculationName == null) + { + throw new ArgumentNullException(nameof(calculationName)); + } + if (foreshoreProfiles == null) + { + throw new ArgumentNullException(nameof(foreshoreProfiles)); + } + + foundForeshoreProfile = null; + + if (foreshoreProfileName != null) + { + var foreshoreProfile = foreshoreProfiles.FirstOrDefault(fp => fp.Name == foreshoreProfileName); + + if (foreshoreProfile == null) + { + LogReadCalculationConversionError( + string.Format( + Resources.CalculationConfigurationImporter_ReadForeshoreProfile_ForeshoreProfile_0_does_not_exist, + foreshoreProfileName), + calculationName); + + return false; + } + + foundForeshoreProfile = foreshoreProfile; + } + + return true; + } + private ReadResult ReadConfiguration() { try @@ -199,5 +381,14 @@ ImportTarget.Children.Add(parsedCalculationItem); } } + + private static bool HasParametersDefined(WaveReductionConfiguration waveReduction) + { + return waveReduction != null + && (waveReduction.UseBreakWater.HasValue + || waveReduction.UseForeshoreProfile.HasValue + || waveReduction.BreakWaterHeight.HasValue + || waveReduction.BreakWaterType.HasValue); + } } } \ No newline at end of file