lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 7aaa73e 6/9: Validate external input more str


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 7aaa73e 6/9: Validate external input more stringently
Date: Thu, 12 Jul 2018 13:12:58 -0400 (EDT)

branch: master
commit 7aaa73e38e5fce3d306a74f29d6520611c991cb9
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Validate external input more stringently
    
    Throw an exception when invalid dates are diagnosed while reading an
    input file from an external system. This change restores the behavior
    prior to commit 5286b9ea of 20180702T1258Z. The old <InforceDataSource>
    element righteously having been expunged, this behavior must now be
    conditioned on the "data_source" attribute instead. It had earlier been
    assumed that external systems generated only valid input files, but it
    turns out that they inappropriately permit off-monthiversary extracts,
    which are invalid prima facie and cannot possibly be corrected by lmi.
---
 input.hpp                  |  5 ++++-
 input_harmonization.cpp    | 24 +++++++++++++++++++-----
 multiple_cell_document.cpp |  1 +
 single_cell_document.cpp   |  1 +
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/input.hpp b/input.hpp
index 0d4de6d..f58b65c 100644
--- a/input.hpp
+++ b/input.hpp
@@ -40,6 +40,7 @@
 
 class product_database;
 
+#include <iosfwd>                       // ostream
 #include <map>
 #include <memory>                       // unique_ptr
 #include <string>
@@ -143,6 +144,8 @@ class LMI_SO Input final
 
     static Input consummate(Input const&);
 
+    void validate_external_data();
+
   private:
     void AscribeMembers();
 
@@ -178,7 +181,7 @@ class LMI_SO Input final
     void DoTransmogrify() override;
 
     void set_solve_durations();
-    void set_inforce_durations_from_dates();
+    void set_inforce_durations_from_dates(std::ostream& os);
 
     std::map<std::string,std::string> const 
permissible_specified_amount_strategy_keywords(); // Obsolete.
 
diff --git a/input_harmonization.cpp b/input_harmonization.cpp
index 6aa8f6a..32228e2 100644
--- a/input_harmonization.cpp
+++ b/input_harmonization.cpp
@@ -119,7 +119,7 @@ void Input::DoCustomizeInitialValues()
     InforceContractYear              = 0;
     InforceMonth                     = 0;
     InforceYear                      = 0;
-    set_inforce_durations_from_dates();
+    set_inforce_durations_from_dates(warning());
 
     if(mce_yes == UseCurrentDeclaredRate)
         {
@@ -906,7 +906,7 @@ void Input::DoTransmogrify()
         return;
         }
 
-    set_inforce_durations_from_dates();
+    set_inforce_durations_from_dates(warning());
 
     // USER !! This is the credited rate as of the database date,
     // regardless of the date of illustration, because the database
@@ -1089,7 +1089,7 @@ void Input::set_solve_durations()
 /// must be taken into account for inforce, but disregarded (or
 /// asserted to be zero) for new business).
 
-void Input::set_inforce_durations_from_dates()
+void Input::set_inforce_durations_from_dates(std::ostream& os)
 {
     std::pair<int,int> ym0 = years_and_months_since
         (EffectiveDate  .value()
@@ -1115,7 +1115,7 @@ void Input::set_inforce_durations_from_dates()
         );
     if(expected != InforceAsOfDate.value())
         {
-        warning()
+        os
             << "Input inforce-as-of date, "
             << InforceAsOfDate.value().str()
             << ", is not an exact monthiversary date."
@@ -1140,10 +1140,24 @@ void Input::set_inforce_durations_from_dates()
         && (0 == InforceYear && 0 == InforceMonth)
         )
         {
-        warning()
+        os
             << "Inforce illustrations not permitted during month of issue."
             << LMI_FLUSH
             ;
         }
 }
 
+/// Validate an input cell from an external source.
+///
+/// External input files are often defective. They're tested with an
+/// xml schema, but a schema can't find all the flaws; in particular,
+/// it can't test relationships among the values of various elements,
+/// so some crucial invariants are tested here.
+
+void Input::validate_external_data()
+{
+    global_settings::instance().ash_nazg()
+        ? set_inforce_durations_from_dates(warning())
+        : set_inforce_durations_from_dates(alarum())
+        ;
+}
diff --git a/multiple_cell_document.cpp b/multiple_cell_document.cpp
index 69aa068..07e719d 100644
--- a/multiple_cell_document.cpp
+++ b/multiple_cell_document.cpp
@@ -175,6 +175,7 @@ void multiple_cell_document::parse(xml_lmi::dom_parser 
const& parser)
             j >> cell;
             if(data_source_is_external(parser.document()))
                 {
+                cell.validate_external_data();
                 cell.Reconcile();
                 }
             v.push_back(cell);
diff --git a/single_cell_document.cpp b/single_cell_document.cpp
index 5944617..c7361a6 100644
--- a/single_cell_document.cpp
+++ b/single_cell_document.cpp
@@ -126,6 +126,7 @@ void single_cell_document::parse(xml_lmi::dom_parser const& 
parser)
     *elements.begin() >> input_data_;
     if(data_source_is_external(parser.document()))
         {
+        input_data_.validate_external_data();
         input_data_.Reconcile();
         }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]