From 2522ec34616b5e9ee388eff506e18efecb9115db Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Mon, 5 Dec 2022 09:46:37 +0100 Subject: [PATCH] fixed validation for Canal transits (NOA_NOD) --- bsmd.database/NOA_NOD.cs | 63 ++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/bsmd.database/NOA_NOD.cs b/bsmd.database/NOA_NOD.cs index 1a348db2..5969dec3 100644 --- a/bsmd.database/NOA_NOD.cs +++ b/bsmd.database/NOA_NOD.cs @@ -256,34 +256,26 @@ namespace bsmd.database public override void Validate(List errors, List violations) { - if (this.GetValidationBlock() == ValidationBlock.BLOCK1) + if (this.GetValidationBlock() == ValidationBlock.BLOCK1) // VISIT { - if(this.ETDFromPortOfCall.HasValue && this.ETAToPortOfCall.HasValue && - (this.ETDFromPortOfCall < this.ETAToPortOfCall)) + if(this.ETDFromPortOfCall.HasValue && this.ETAToPortOfCall.HasValue && (this.ETDFromPortOfCall < this.ETAToPortOfCall)) errors.Add(RuleEngine.CreateError(ValidationCode.E121, "ETDFromPortOfCall implausible", this.ETDFromPortOfCall?.ToLocalTime().ToString(), this.Title, null, this.Tablename)); // 8.11.20 Validierung gegen ETA /ETD in der Vergangenheit if((this.ETAToPortOfCall < DateTime.Now) || (this.ETAToPortOfCall.HasValue && this.ETAToPortOfCall.Value.ToLocalTime().IsTimeEmpty())) { violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check ETAToPortOfCall: might be implausible", this.ETAToPortOfCall.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); - } - // NSW 7.1 ETDFromLastPort Pflichtfeld, wenn LastPort != ZZUKN - if(!this.LastPort.IsNullOrEmpty() && !this.LastPort.Equals("ZZUKN") && !this.ETDFromLastPort.HasValue) - { - errors.Add(RuleEngine.CreateError(ValidationCode.E125, "ETDFromLastPort must be provided for a given last port", "", this.Title, null, this.Tablename)); } - if((this.ETDFromLastPort < DateTime.Now.AddDays(-14)) || (this.ETDFromLastPort.HasValue && this.ETDFromLastPort.Value.ToLocalTime().IsTimeEmpty())) - { - violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check ETDFromLastPort: might be implausible", this.ETDFromLastPort.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); - } if ((this.ETDFromPortOfCall < DateTime.Now.AddDays(-14)) || (this.ETDFromPortOfCall > DateTime.Now.AddDays(14)) || (this.ETDFromPortOfCall.HasValue && this.ETDFromPortOfCall.Value.ToLocalTime().IsTimeEmpty())) { violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check ETDFromPortOfCall: might be implausible", this.ETDFromPortOfCall.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); } - if ((this.ETAToNextPort < DateTime.Now) || (this.ETAToNextPort > DateTime.Now.AddDays(14)) || (this.ETAToNextPort.HasValue && this.ETAToNextPort.Value.ToLocalTime().IsTimeEmpty())) - { - violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check ETAToNextPort: might be implausible", this.ETAToNextPort.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); - } + + if (this.ETDFromPortOfCall.HasValue && this.ETAToNextPort.HasValue && (this.NextPort?.Equals("ZZUKN") == false) && (this.ETAToNextPort <= ETDFromPortOfCall)) + errors.Add(RuleEngine.CreateError(ValidationCode.E122, "ETAToNextPort", null, this.Title, null, this.Tablename)); + + if (this.ETDFromLastPort.HasValue && this.ETAToPortOfCall.HasValue && (this.ETDFromLastPort >= this.ETAToPortOfCall)) + errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "ETDFromLastPort", null, this.Title, null, this.Tablename)); if (this.CallPurposes.IsNullOrEmpty()) { @@ -300,34 +292,47 @@ namespace bsmd.database } } } - else + else // TRANSIT { if (this.ETDFromKielCanal.HasValue && this.ETAToKielCanal.HasValue && (this.ETDFromKielCanal < this.ETAToKielCanal)) errors.Add(RuleEngine.CreateError(ValidationCode.E121, "ETDFromKielCanal implausible", this.ETDFromKielCanal.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); - if(this.ETDFromKielCanal.HasValue && this.ETDFromKielCanal.Value.ToLocalTime().IsTimeEmpty()) + if ((this.ETAToKielCanal < DateTime.Now) || (this.ETAToKielCanal.HasValue && this.ETAToKielCanal.Value.ToLocalTime().IsTimeEmpty())) + violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check ETAToKielCanal: might be implausible", this.ETAToKielCanal.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); + + if ((this.ETDFromKielCanal < DateTime.Now.AddDays(-14)) || (this.ETDFromKielCanal > DateTime.Now.AddDays(14)) || (this.ETDFromKielCanal.HasValue && this.ETDFromKielCanal.Value.ToLocalTime().IsTimeEmpty())) violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check ETDFromKielCanal: might be implausible", this.ETDFromKielCanal.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); - if(this.ETAToKielCanal.HasValue && this.ETAToKielCanal.Value.ToLocalTime().IsTimeEmpty()) - violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check ETAToKielCanal: might be implausible", this.ETAToKielCanal.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); + if (this.ETDFromKielCanal.HasValue && this.ETAToNextPort.HasValue && (this.NextPort?.Equals("ZZUKN") == false) && (this.ETAToNextPort <= ETDFromKielCanal)) + errors.Add(RuleEngine.CreateError(ValidationCode.E122, "ETAToNextPort", null, this.Title, null, this.Tablename)); + + if (this.ETDFromLastPort.HasValue && this.ETAToKielCanal.HasValue && (this.ETDFromLastPort >= this.ETAToKielCanal)) + errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "ETDFromLastPort", null, this.Title, null, this.Tablename)); } - if((this.LastPort?.Equals("ZZUKN") == true) && this.ETDFromLastPort.HasValue) - errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE_ZZUKN, "ETDFromLastPort cannot be set if ZZUKN", null, this.Title, null, this.Tablename)); + // NSW 7.1 ETDFromLastPort Pflichtfeld, wenn LastPort != ZZUKN + if (!this.LastPort.IsNullOrEmpty() && !this.LastPort.Equals("ZZUKN") && !this.ETDFromLastPort.HasValue) + { + errors.Add(RuleEngine.CreateError(ValidationCode.E125, "ETDFromLastPort must be provided for a given last port", "", this.Title, null, this.Tablename)); + } + if ((this.ETDFromLastPort < DateTime.Now.AddDays(-14)) || (this.ETDFromLastPort.HasValue && this.ETDFromLastPort.Value.ToLocalTime().IsTimeEmpty())) + { + violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check ETDFromLastPort: might be implausible", this.ETDFromLastPort.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); + } + if ((this.ETAToNextPort < DateTime.Now) || (this.ETAToNextPort > DateTime.Now.AddDays(14)) || (this.ETAToNextPort.HasValue && this.ETAToNextPort.Value.ToLocalTime().IsTimeEmpty())) + { + violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Check ETAToNextPort: might be implausible", this.ETAToNextPort.Value.ToLocalTime().ToString(), this.Title, null, this.Tablename)); + } - if (this.ETDFromPortOfCall.HasValue && this.ETAToNextPort.HasValue && (this.NextPort?.Equals("ZZUKN") == false) && - (this.ETAToNextPort <= ETDFromPortOfCall)) - errors.Add(RuleEngine.CreateError(ValidationCode.E122, "ETAToNextPort", null, this.Title, null, this.Tablename)); + if ((this.LastPort?.Equals("ZZUKN") == true) && this.ETDFromLastPort.HasValue) + errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE_ZZUKN, "ETDFromLastPort cannot be set if ZZUKN", null, this.Title, null, this.Tablename)); if ((this.NextPort?.Equals("ZZUKN") == false) && !this.ETAToNextPort.HasValue) errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, "ETAToNextPort missing", null, this.Title, null, this.Tablename)); if((this.NextPort?.Equals("ZZUKN") == true) && this.ETAToNextPort.HasValue) errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE_ZZUKN, "ETAToNextPort cannot be set if ZZUKN", null, this.Title, null, this.Tablename)); - - if (this.ETDFromLastPort.HasValue && this.ETAToPortOfCall.HasValue && (this.ETDFromLastPort >= this.ETAToPortOfCall)) - errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "ETDFromLastPort", null, this.Title, null, this.Tablename)); - + } public override DatabaseEntity.ValidationBlock GetValidationBlock()