Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening outside the inception year #421

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ifrs17-template/Test/ReimportTest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,40 @@
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Check that Import into Data Source Fails "
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"var activity = await Import.FromString(openings)",
"\n .WithFormat(ImportFormats.Opening)",
"\n .WithTarget(DataSource)",
"\n .ExecuteAsync();",
"\nactivity"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": [
"var expectedMessage = Error.OpeningOutsideOfInceptionYear.GetMessage(\"DT1.1\", \"2021\", \"2020\");",
"\nactivity.Status.Should().Be(ActivityLogStatus.Failed);",
"\nactivity.Errors.Count().Should().Be(1);",
"\nactivity.Errors.FirstOrDefault().ToString().Contains(expectedMessage).Should().Be(true);"
],
"metadata": {},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
Expand Down
2 changes: 2 additions & 0 deletions ifrs17/Constants/Validations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
"\n public static readonly Error InvalidInterpolationMethod = new Error(nameof(InvalidInterpolationMethod));",
"\n public static readonly Error InvalidEconomicBasisDriver = new Error(nameof(InvalidEconomicBasisDriver));",
"\n public static readonly Error InvalidReleasePattern = new Error(nameof(InvalidReleasePattern));",
"\n public static readonly Error OpeningOutsideOfInceptionYear = new Error(nameof(OpeningOutsideOfInceptionYear));",
"\n",
"\n // Storage Errors",
"\n public static readonly Error DataNodeNotFound = new Error(nameof(DataNodeNotFound));",
Expand Down Expand Up @@ -257,6 +258,7 @@
"\n (nameof(InvalidInterpolationMethod), 1) => $\"Invalid InterpolationMethod parameter for Data Node {s[0]}.\",",
"\n (nameof(InvalidEconomicBasisDriver), 1) => $\"Invalid EconomicBasisDriver parameter for Data Node {s[0]}.\",",
"\n (nameof(InvalidReleasePattern), 1) => $\"Invalid ReleasePattern parameters for Data Node {s[0]}.\",",
"\n (nameof(OpeningOutsideOfInceptionYear), 3) => $\"Provided opening for data node {s[0]} in year {s[1]}, however this data node was incepted in {s[2]}.\", ",
"\n ",
"\n // Storage",
"\n (nameof(DataNodeNotFound), 1) => $\"DataNode {s[0]} not found.\",",
Expand Down
10 changes: 8 additions & 2 deletions ifrs17/Import/Importers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,15 @@
"\n ",
"\n var dataNodesImported = table.Rows.Select(x => x.Field<string>(nameof(RawVariable.DataNode))).ToHashSet();",
"\n var dataNodesDefined = await targetDataSource.Query<GroupOfContract>().Where(x => dataNodesImported.Contains(x.SystemName)).ToArrayAsync();",
"\n var dataNodeStatesDefined = await targetDataSource.Query<DataNodeState>().Select(x => x.DataNode).ToArrayAsync();",
"\n var dataNodeStatesDefined = await targetDataSource.Query<DataNodeState>().Select(x => new {DataNode = x.DataNode, InceptionYear = x.Year}).ToArrayAsync();",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add (in the PR or in the issue) a description of what is wrong in the code, and how this implementation fixes it?
Currently, I fail to see it... thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, let me maybe explain right here. If you carefully examine the code, you will discover that until now we never did this check in the first place, so not surprisingly this import succeeded.

So to fix I chose this place, where we query the data note state anyway. Data node state carries the information about the the inception year, which is a year, so I just expand here the query, to keep the information about the data node and the inception year. Note that the year of the args, that arrive here, carry the information about the opening year, as it comes to us from the opening file. So at the next step, if the import format is opening, I generate an enumerable with all the data nodes that have the opening outside the inception year, and if this enumerable is not empty, log an error for each entry. The data DataNodeFactoryAsync is called by the opening importer at the very early stage (line 9), at line 10 it discovers that the that the activity has errors and exists. Does it make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this validation into the parser and exploit the storage data.

"\n if (tableName == ImportFormats.Opening){",
"\n var dataNodesWithWrongOpeningYear = dataNodeStatesDefined.Where(x => dataNodesImported.Contains(x.DataNode) && x.InceptionYear != args.Year);",
"\n if (dataNodesWithWrongOpeningYear.Any()) ",
"\n foreach(var element in dataNodesWithWrongOpeningYear) ",
"\n ApplicationMessage.Log(Error.OpeningOutsideOfInceptionYear, element.DataNode, args.Year.ToString(), element.InceptionYear.ToString());",
"\n }",
"\n var dataNodeParametersDefined = await targetDataSource.Query<SingleDataNodeParameter>().Select(x => x.DataNode).ToArrayAsync(); ",
"\n var dataNodeStatesUndefined = dataNodesImported.Where(x => x != null && !dataNodeStatesDefined.Contains(x)).ToHashSet();",
"\n var dataNodeStatesUndefined = dataNodesImported.Where(x => x != null && !dataNodeStatesDefined.Select(x => x.DataNode).Contains(x)).ToHashSet();",
"\n var dataNodeSingleParametersUndefined = dataNodesImported.Where(x => x != null &&",
"\n !dataNodeParametersDefined.Contains(x) && ",
"\n dataNodesDefined.SingleOrDefault(y => y.SystemName == x) is GroupOfInsuranceContract).ToHashSet();",
Expand Down