-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10690 from mfo/US/normalize-addresses-for-rnf-rna…
…-siret ETQ Tech, les adresses des champs siret / rna / rnf sont normalisées pour une recherche homogène via les filtres
- Loading branch information
Showing
13 changed files
with
345 additions
and
4 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
# Dans le cadre de la story pour pouvoir rechercher un dossier en fonction des valeurs des champs branchées sur une API, voici une première pièce qui cible les champs RNA/RNF/SIRET (notamment les adresses pour de la recherche). Cette PR intègre : | ||
# la normalisation des adresses des champs RNA/RNF/SIRET | ||
# le fait de stocker ces données normalisées dans le champs.value_json (un jsonb) | ||
# le backfill les anciens champs RNA/RNF/SIRET | ||
module Maintenance | ||
class PopulateRNAJSONValueTask < MaintenanceTasks::Task | ||
def collection | ||
Champs::RNAChamp.where.not(value: nil) | ||
end | ||
|
||
def process(champ) | ||
return if champ&.dossier&.procedure&.id.blank? | ||
data = APIEntreprise::RNAAdapter.new(champ.value, champ&.dossier&.procedure&.id).to_params | ||
return if data.blank? | ||
champ.update(value_json: APIGeoService.parse_rna_address(data['adresse'])) | ||
end | ||
|
||
def count | ||
# not really interested in counting because it raises PG Statement timeout | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
# Dans le cadre de la story pour pouvoir rechercher un dossier en fonction des valeurs des champs branchées sur une API, voici une première pièce qui cible les champs RNA/RNF/SIRET (notamment les adresses pour de la recherche). Cette PR intègre : | ||
# la normalisation des adresses des champs RNA/RNF/SIRET | ||
# le fait de stocker ces données normalisées dans le champs.value_json (un jsonb) | ||
# le backfill les anciens champs RNA/RNF/SIRET | ||
module Maintenance | ||
class PopulateRNFJSONValueTask < MaintenanceTasks::Task | ||
include Dry::Monads[:result] | ||
|
||
def collection | ||
Champs::RNFChamp.where(value_json: nil) | ||
# Collection to be iterated over | ||
# Must be Active Record Relation or Array | ||
end | ||
|
||
def process(champ) | ||
result = champ.fetch_external_data | ||
case result | ||
in Success(data) | ||
begin | ||
champ.update_with_external_data!(data:) | ||
rescue ActiveRecord::RecordInvalid | ||
# some champ might have dossier nil | ||
end | ||
else | ||
# not found | ||
end | ||
end | ||
|
||
def count | ||
# not really interested in counting because it raises PG Statement timeout | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
# Dans le cadre de la story pour pouvoir rechercher un dossier en fonction des valeurs des champs branchées sur une API, voici une première pièce qui cible les champs RNA/RNF/SIRET (notamment les adresses pour de la recherche). Cette PR intègre : | ||
# la normalisation des adresses des champs RNA/RNF/SIRET | ||
# le fait de stocker ces données normalisées dans le champs.value_json (un jsonb) | ||
# le backfill les anciens champs RNA/RNF/SIRET | ||
module Maintenance | ||
class PopulateSiretValueJSONTask < MaintenanceTasks::Task | ||
def collection | ||
Champs::SiretChamp.where.not(value: nil) | ||
end | ||
|
||
def process(champ) | ||
return if champ.etablissement.blank? | ||
champ.update!(value_json: APIGeoService.parse_etablissement_address(champ.etablissement)) | ||
end | ||
|
||
def count | ||
# not really interested in counting because it raises PG Statement timeout | ||
end | ||
end | ||
end |
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
39 changes: 39 additions & 0 deletions
39
spec/tasks/maintenance/populate_rna_json_value_task_spec.rb
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
module Maintenance | ||
RSpec.describe PopulateRNAJSONValueTask do | ||
describe "#process" do | ||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :rna }]) } | ||
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) } | ||
let(:element) { dossier.champs.first } | ||
subject(:process) { described_class.process(element) } | ||
|
||
let(:body) { File.read('spec/fixtures/files/api_entreprise/associations.json') } | ||
let(:status) { 200 } | ||
|
||
before do | ||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v4\/djepva\/api-association\/associations\/open_data\/#{element.value}/) | ||
.to_return(body: body, status: status) | ||
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false) | ||
end | ||
it 'updates value_json' do | ||
expect { subject }.to change { element.reload.value_json } | ||
.from(nil) | ||
.to({ | ||
"street_number" => "33", | ||
"street_name" => "de Modagor", | ||
"street_address" => "33 rue de Modagor", | ||
"postal_code" => "75009", | ||
"city_name" => "Paris", | ||
"city_code" => "75108", | ||
"departement_code" => nil, | ||
"departement_name" => nil, | ||
"region_code" => nil, | ||
"region_name" => nil | ||
}) | ||
end | ||
end | ||
end | ||
end |
71 changes: 71 additions & 0 deletions
71
spec/tasks/maintenance/populate_rnf_json_value_task_spec.rb
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
module Maintenance | ||
RSpec.describe PopulateRNFJSONValueTask do | ||
describe "#process" do | ||
include Dry::Monads[:result] | ||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :rnf }]) } | ||
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) } | ||
let(:element) { dossier.champs.first } | ||
let(:data) do | ||
{ | ||
id: 3, | ||
rnfId: '075-FDD-00003-01', | ||
type: 'FDD', | ||
department: '75', | ||
title: 'Fondation SFR', | ||
dissolvedAt: nil, | ||
phone: '+33185060000', | ||
email: '[email protected]', | ||
addressId: 3, | ||
createdAt: "2023-09-07T13:26:10.358Z", | ||
updatedAt: "2023-09-07T13:26:10.358Z", | ||
address: { | ||
id: 3, | ||
createdAt: "2023-09-07T13:26:10.358Z", | ||
updatedAt: "2023-09-07T13:26:10.358Z", | ||
label: "16 Rue du Général de Boissieu 75015 Paris", | ||
type: "housenumber", | ||
streetAddress: "16 Rue du Général de Boissieu", | ||
streetNumber: "16", | ||
streetName: "Rue du Général de Boissieu", | ||
postalCode: "75015", | ||
cityName: "Paris", | ||
cityCode: "75115", | ||
departmentName: "Paris", | ||
departmentCode: "75", | ||
regionName: "Île-de-France", | ||
regionCode: "11" | ||
}, | ||
status: nil, | ||
persons: [] | ||
} | ||
end | ||
|
||
subject(:process) { described_class.process(element) } | ||
|
||
before do | ||
allow_any_instance_of(Champs::RNFChamp).to receive(:fetch_external_data).and_return(Success(data)) | ||
end | ||
|
||
it 'updates value_json' do | ||
expect { subject }.to change { element.reload.value_json } | ||
.from(nil) | ||
.to({ | ||
"street_number" => "16", | ||
"street_name" => "Rue du Général de Boissieu", | ||
"street_address" => "16 Rue du Général de Boissieu", | ||
"postal_code" => "75015", | ||
"city_name" => "Paris 15e Arrondissement", | ||
"city_code" => "75115", | ||
"departement_code" => "75", | ||
"departement_name" => "Paris", | ||
"region_code" => "11", | ||
"region_name" => "Île-de-France" | ||
}) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.