-
Notifications
You must be signed in to change notification settings - Fork 6
[#835] Create BRP client #886
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
Draft
stefanvi
wants to merge
33
commits into
main
Choose a base branch
from
create-brp-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 21 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
f37bbb6
Create BrpClient, query and response structs
stefanvi b99fca5
Add correct path to brp client
stefanvi 4a60acf
Brp deserializing (WIP)
stefanvi 6e66433
Add verify function to brp client
stefanvi b7803a2
Add brp mock to docker compose
stefanvi ab2a922
Translate struct name and fields to English
stefanvi ea3b837
improve handling of international addresses
stefanvi dca72e9
Use structstruck for nested BRP struct definitions
stefanvi 5c879a5
Remove first name from BrpPersonRaw
stefanvi 99bf14d
Add basic brp check when csb importing political group
stefanvi d24618c
Move BrpValidation event to CsbEvent enum
stefanvi 40edbe8
Create BrpField enum (WIP: address implementation broken)
stefanvi 0afddb0
Fix address verification
stefanvi f01b70b
Refactor brp module
stefanvi 3e34520
Run BRP import on tokio task
stefanvi fdf2917
Make brp verify function return a vec of Omissions
stefanvi 3b9e896
Add test to check if ommissions are added when a person is not succes…
stefanvi d9669f9
Add more tracing to do_brp_verification
stefanvi 994fef2
Fix clippy issues
stefanvi a975389
Merge branch 'main' into create-brp-client
stefanvi 1be31e6
Refactor brp files into its own directory and delete orphaned files
stefanvi c332fc5
Add test for brp verification upon csb import
stefanvi 594d49c
Add timeout to brp_veriy and several other small improvements
stefanvi 5f87f99
Add BrpValidationInProgress event to CsbStore
stefanvi b0e90ac
Make omission test more explicit and remove typo
stefanvi 06f11b3
Add BrpClient to the AppState
stefanvi 2edd27b
Skip persons that have already been validated against the brp
stefanvi 3387452
Add candidate lists to omission category for brp validation
stefanvi e791d4e
Add new_for_test constructor for BrpClient
stefanvi fcfed8a
Convert brp_validation_status from a boolean into an enum
stefanvi 69000a8
Run BRP checks in a separate background task, that monitors completion
stefanvi 04ec323
Use 'korteStraatnaam' instead of 'officieleStraatnaam'
stefanvi 22036d3
Improve code structure
stefanvi 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| use std::time::Duration; | ||
|
|
||
| use askama::Template; | ||
| use axum::{ | ||
| extract::State, | ||
|
|
@@ -6,15 +8,20 @@ use axum::{ | |
| use serde::Deserialize; | ||
|
|
||
| use crate::{ | ||
| AppError, AppState, Context, CsbContext, CsbEvent, Form, HtmlTemplate, Locale, PgStoreData, | ||
| StreamId, | ||
| AppError, AppState, Context, CsbContext, CsbEvent, CsbStoreData, Form, HtmlTemplate, Locale, | ||
| PgStoreData, StreamId, | ||
| csb::examination::{CsbExaminationOverviewPath, CsbPoliticalGroupPath}, | ||
| filters, redirect_success, trans, | ||
| filters, redirect_success, | ||
| store::Store, | ||
| structs::brp::BrpClient, | ||
| trans, | ||
| utils::parse_hash_prefix, | ||
| }; | ||
|
|
||
| use super::{CsbCreateEmptyPath, CsbImportPath}; | ||
|
|
||
| const BRP_COURTESY_TIMEOUT: Duration = Duration::from_secs(1); | ||
|
|
||
| #[derive(Template)] | ||
| #[template(path = "csb/import/pages/import.html")] | ||
| struct CsbImportTemplate { | ||
|
|
@@ -121,6 +128,10 @@ async fn do_import( | |
| }) | ||
| .await?; | ||
|
|
||
| // TODO: get from env at higher level probably | ||
| let brp_client = BrpClient::new("http://localhost:5010", "", "haalcentraal/api/brp/personen"); | ||
| do_brp_verification(&csb_store, &brp_client).await?; | ||
|
|
||
| Ok(redirect_success(CsbPoliticalGroupPath { | ||
| stream_id: csb_store.stream_id, | ||
| })) | ||
|
|
@@ -141,6 +152,48 @@ pub async fn create_empty( | |
| })) | ||
| } | ||
|
|
||
| pub async fn do_brp_verification( | ||
| store: &Store<CsbStoreData>, | ||
| brp_client: &BrpClient, | ||
| ) -> Result<(), AppError> { | ||
| let store = store.clone(); | ||
| let brp_client = brp_client.clone(); | ||
|
|
||
| tokio::task::spawn(async move { | ||
|
Contributor
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. You should await this task somewhere. If the task panics, any remaining candidates will silently be unverified. |
||
| store.data.write().brp_verification_in_progress = true; | ||
|
stefanvi marked this conversation as resolved.
Outdated
|
||
|
|
||
| let mut ticker = tokio::time::interval(BRP_COURTESY_TIMEOUT); | ||
| for person in store.get_persons() { | ||
| tracing::info!("Checking person {} against the brp", person.id); | ||
| ticker.tick().await; | ||
|
|
||
| match brp_client.verify(&person).await { | ||
| Ok(omissions) => { | ||
| for omission in omissions { | ||
| if let Err(err) = omission.create(&store).await { | ||
| tracing::error!( | ||
| "failed to record BRP omission for {}: {err}", | ||
| person.id | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| Err(err) => { | ||
| tracing::error!("BRP verification failed for {}: {err}", person.id); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tracing::info!( | ||
| "Finished checking candidates on list {:?}", | ||
| store.data.read().imported_data.political_group | ||
| ); | ||
| store.data.write().brp_verification_in_progress = false; | ||
|
stefanvi marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.