-
Notifications
You must be signed in to change notification settings - Fork 9
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
proposed changes on empty value handling for opensanctions search #863
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import ( | |
) | ||
|
||
const ( | ||
ErrSanctionCheckAllFieldsNull = "all_fields_null" | ||
ErrSanctionCheckAllFieldsNullOrEmpty = "all_fields_null_or_empty" | ||
) | ||
|
||
func (e ScenarioEvaluator) evaluateSanctionCheck( | ||
|
@@ -48,37 +48,35 @@ func (e ScenarioEvaluator) evaluateSanctionCheck( | |
} | ||
|
||
queries := []models.OpenSanctionsCheckQuery{} | ||
nullFieldRead := 0 | ||
emptyFieldRead := 0 | ||
nbEvaluatedFields := 0 | ||
emptyInput := false | ||
|
||
if iteration.SanctionCheckConfig.Query.Name != nil { | ||
queries, err = e.evaluateSanctionCheckName(ctx, queries, iteration, dataAccessor) | ||
nbEvaluatedFields += 1 | ||
queries, emptyInput, err = e.evaluateSanctionCheckName(ctx, queries, iteration, dataAccessor) | ||
if err != nil { | ||
switch { | ||
case errors.Is(err, ast.ErrNullFieldRead): | ||
nullFieldRead += 1 | ||
default: | ||
return nil, true, err | ||
} | ||
return nil, true, errors.Wrap(err, "could not evaluate sanction check name") | ||
} else if emptyInput { | ||
emptyFieldRead += 1 | ||
} | ||
} | ||
|
||
if iteration.SanctionCheckConfig.Query.Label != nil { | ||
queries, err = e.evaluateSanctionCheckLabel(ctx, queries, iteration, dataAccessor) | ||
nbEvaluatedFields += 1 | ||
queries, emptyInput, err = e.evaluateSanctionCheckLabel(ctx, queries, iteration, dataAccessor) | ||
if err != nil { | ||
switch { | ||
case errors.Is(err, ast.ErrNullFieldRead): | ||
nullFieldRead += 1 | ||
default: | ||
return nil, true, err | ||
} | ||
return nil, true, errors.Wrap(err, "could not evaluate sanction check label") | ||
} else if emptyInput { | ||
emptyFieldRead += 1 | ||
} | ||
} | ||
|
||
if nullFieldRead >= 2 { | ||
if emptyFieldRead == nbEvaluatedFields { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this condition was incorrect if one of the two inputs was left empty |
||
sanctionCheck = &models.SanctionCheckWithMatches{ | ||
SanctionCheck: models.SanctionCheck{ | ||
Status: models.SanctionStatusError, | ||
ErrorCodes: []string{ErrSanctionCheckAllFieldsNull}, | ||
ErrorCodes: []string{ErrSanctionCheckAllFieldsNullOrEmpty}, | ||
}, | ||
} | ||
|
||
|
@@ -150,69 +148,90 @@ func (e ScenarioEvaluator) evaluateSanctionCheck( | |
return | ||
} | ||
|
||
func (e ScenarioEvaluator) evaluateSanctionCheckName(ctx context.Context, queries []models.OpenSanctionsCheckQuery, | ||
iteration models.ScenarioIteration, dataAccessor DataAccessor, | ||
) ([]models.OpenSanctionsCheckQuery, error) { | ||
func (e ScenarioEvaluator) evaluateSanctionCheckName( | ||
ctx context.Context, | ||
queries []models.OpenSanctionsCheckQuery, | ||
iteration models.ScenarioIteration, | ||
dataAccessor DataAccessor, | ||
) (queriesOut []models.OpenSanctionsCheckQuery, emptyInput bool, err error) { | ||
queriesOut = queries | ||
nameFilterAny, err := e.evaluateAstExpression.EvaluateAstExpression(ctx, nil, | ||
*iteration.SanctionCheckConfig.Query.Name, iteration.OrganizationId, | ||
dataAccessor.ClientObject, dataAccessor.DataModel) | ||
if err != nil { | ||
return queries, err | ||
return | ||
} | ||
if nameFilterAny.ReturnValue == nil { | ||
emptyInput = true | ||
return | ||
} | ||
|
||
nameFilter, ok := nameFilterAny.ReturnValue.(string) | ||
if !ok { | ||
return queries, errors.New("name filter name query did not return a string") | ||
return nil, false, errors.New("name filter name query did not return a string") | ||
} | ||
if nameFilter == "" { | ||
emptyInput = true | ||
return | ||
} | ||
|
||
queries = append(queries, models.OpenSanctionsCheckQuery{ | ||
queriesOut = append(queriesOut, models.OpenSanctionsCheckQuery{ | ||
Type: "Thing", | ||
Filters: models.OpenSanctionCheckFilter{ | ||
"name": []string{nameFilter}, | ||
}, | ||
}) | ||
|
||
return queries, nil | ||
return queriesOut, false, nil | ||
} | ||
|
||
func (e ScenarioEvaluator) evaluateSanctionCheckLabel(ctx context.Context, queries []models.OpenSanctionsCheckQuery, | ||
iteration models.ScenarioIteration, dataAccessor DataAccessor, | ||
) ([]models.OpenSanctionsCheckQuery, error) { | ||
func (e ScenarioEvaluator) evaluateSanctionCheckLabel( | ||
ctx context.Context, | ||
queries []models.OpenSanctionsCheckQuery, | ||
iteration models.ScenarioIteration, | ||
dataAccessor DataAccessor, | ||
) (queriesOut []models.OpenSanctionsCheckQuery, emptyInput bool, err error) { | ||
queriesOut = queries | ||
labelFilterAny, err := e.evaluateAstExpression.EvaluateAstExpression(ctx, nil, | ||
*iteration.SanctionCheckConfig.Query.Label, iteration.OrganizationId, | ||
dataAccessor.ClientObject, dataAccessor.DataModel) | ||
if err != nil { | ||
return queries, err | ||
return | ||
} | ||
if labelFilterAny.ReturnValue == nil { | ||
return queries, ast.ErrNullFieldRead | ||
emptyInput = true | ||
return | ||
} | ||
|
||
labelFilter, ok := labelFilterAny.ReturnValue.(string) | ||
if !ok { | ||
return queries, errors.New("label filter name query did not return a string") | ||
return nil, false, errors.New("label filter name query did not return a string") | ||
} | ||
if labelFilter == "" { | ||
emptyInput = true | ||
return | ||
} | ||
|
||
if e.nameRecognizer == nil || !e.nameRecognizer.IsConfigured() { | ||
switch len(queries) { | ||
switch len(queriesOut) { | ||
case 0: | ||
queries = append(queries, models.OpenSanctionsCheckQuery{ | ||
queriesOut = append(queriesOut, models.OpenSanctionsCheckQuery{ | ||
Type: "Thing", | ||
Filters: models.OpenSanctionCheckFilter{ | ||
"name": []string{labelFilter}, | ||
}, | ||
}) | ||
|
||
default: | ||
queries[0].Filters["name"] = append(queries[0].Filters["name"], labelFilter) | ||
queriesOut[0].Filters["name"] = append(queriesOut[0].Filters["name"], labelFilter) | ||
} | ||
|
||
return queries, nil | ||
return queriesOut, false, nil | ||
} | ||
|
||
matches, err := e.nameRecognizer.PerformNameRecognition(ctx, labelFilter) | ||
if err != nil { | ||
return queries, errors.New("could not perform name recognition on label") | ||
return queriesOut, false, errors.New("could not perform name recognition on label") | ||
} | ||
|
||
var personQuery *models.OpenSanctionsCheckQuery = nil | ||
|
@@ -244,11 +263,11 @@ func (e ScenarioEvaluator) evaluateSanctionCheckLabel(ctx context.Context, queri | |
} | ||
|
||
if personQuery != nil { | ||
queries = append(queries, *personQuery) | ||
queriesOut = append(queriesOut, *personQuery) | ||
} | ||
if companyQuery != nil { | ||
queries = append(queries, *companyQuery) | ||
queriesOut = append(queriesOut, *companyQuery) | ||
} | ||
|
||
return queries, nil | ||
return queriesOut, false, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we actually used to have a lot of those, they have been rather deprecated in favor of "cleanly" returning nil in Evaluate if a nil value is "read" (AKA some nil received in a required input or actual nil value read in the logic of the function)