Merge pull request #11049 from mfo/US/more-rna-rnf-data

ETQ instructeur, je souhaite pouvoir chercher par nom d'association/fondation
This commit is contained in:
mfo 2024-11-18 09:00:50 +00:00 committed by GitHub
commit 92639be88b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 84 additions and 25 deletions

View file

@ -13,6 +13,10 @@ class Champs::RNAChamp < Champ
data&.dig("association_titre") data&.dig("association_titre")
end end
def update_with_external_data!(data:)
update!(data:, value_json: extract_value_json(data:))
end
def identifier def identifier
title.present? ? "#{value} (#{title})" : value title.present? ? "#{value} (#{title})" : value
end end
@ -41,4 +45,11 @@ class Champs::RNAChamp < Champ
city_code: address["code_insee"] city_code: address["code_insee"]
}.with_indifferent_access }.with_indifferent_access
end end
private
def extract_value_json(data:)
h = APIGeoService.parse_rna_address(data['adresse'])
h.merge(title: data['association_titre'])
end
end end

View file

@ -16,7 +16,7 @@ class Champs::RNFChamp < Champ
end end
def update_with_external_data!(data:) def update_with_external_data!(data:)
update!(data:, value_json: APIGeoService.parse_rnf_address(data[:address])) update!(data:, value_json: extract_value_json(data:))
end end
def fetch_external_data? def fetch_external_data?
@ -109,4 +109,11 @@ class Champs::RNFChamp < Champ
address['label'] address['label']
end end
end end
private
def extract_value_json(data:)
h = APIGeoService.parse_rnf_address(data[:address])
h.merge(title: data[:title])
end
end end

View file

@ -4,8 +4,8 @@ module AddressableColumnConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
def columns(procedure:, displayable: true, prefix: nil) def addressable_columns(procedure:, displayable: true, prefix: nil)
addressable_columns = [ [
["code postal (5 chiffres)", '$.postal_code', :text, []], ["code postal (5 chiffres)", '$.postal_code', :text, []],
["commune", '$.city_name', :text, []], ["commune", '$.city_name', :text, []],
["département", '$.departement_code', :enum, APIGeoService.departement_options], ["département", '$.departement_code', :enum, APIGeoService.departement_options],
@ -22,8 +22,6 @@ module AddressableColumnConcern
type: type:
) )
end end
super.concat(addressable_columns)
end end
end end
end end

View file

@ -12,7 +12,7 @@ module RNAChampAssociationFetchableConcern
return clear_association!(:invalid) unless valid_champ_value? return clear_association!(:invalid) unless valid_champ_value?
return clear_association!(:not_found) if (data = APIEntreprise::RNAAdapter.new(rna, procedure_id).to_params).blank? return clear_association!(:not_found) if (data = APIEntreprise::RNAAdapter.new(rna, procedure_id).to_params).blank?
update!(data:, value_json: APIGeoService.parse_rna_address(data['adresse'])) update_with_external_data!(data:)
rescue APIEntreprise::API::Error, APIEntrepriseToken::TokenError => error rescue APIEntreprise::API::Error, APIEntrepriseToken::TokenError => error
if APIEntrepriseService.service_unavailable_error?(error, target: :djepva) if APIEntrepriseService.service_unavailable_error?(error, target: :djepva)
clear_association!(:network_error) clear_association!(:network_error)

View file

@ -10,4 +10,20 @@ class TypesDeChamp::RNATypeDeChamp < TypesDeChamp::TypeDeChampBase
def champ_value_for_export(champ, path = :value) def champ_value_for_export(champ, path = :value)
champ.identifier champ.identifier
end end
def columns(procedure:, displayable: true, prefix: nil)
super
.concat(addressable_columns(procedure:, displayable:, prefix:))
.concat([
Columns::JSONPathColumn.new(
procedure_id: procedure.id,
stable_id:,
tdc_type: type_champ,
label: "#{libelle_with_prefix(prefix)} Titre au répertoire national des associations",
type: :text,
jsonpath: '$.title',
displayable:
)
])
end
end end

View file

@ -35,6 +35,22 @@ class TypesDeChamp::RNFTypeDeChamp < TypesDeChamp::TextTypeDeChamp
def champ_blank?(champ) = champ.external_id.blank? def champ_blank?(champ) = champ.external_id.blank?
def columns(procedure:, displayable: true, prefix: nil)
super
.concat(addressable_columns(procedure:, displayable:, prefix:))
.concat([
Columns::JSONPathColumn.new(
procedure_id: procedure.id,
stable_id:,
tdc_type: type_champ,
label: "#{libelle_with_prefix(prefix)} Titre au répertoire national des fondations ",
type: :text,
jsonpath: '$.title',
displayable:
)
])
end
private private
def paths def paths

View file

@ -8,4 +8,8 @@ class TypesDeChamp::SiretTypeDeChamp < TypesDeChamp::TypeDeChampBase
end end
def champ_blank_or_invalid?(champ) = Siret.new(siret: champ.value).invalid? def champ_blank_or_invalid?(champ) = Siret.new(siret: champ.value).invalid?
def columns(procedure:, displayable: true, prefix: nil)
super.concat(addressable_columns(procedure:, displayable:, prefix:))
end
end end

View file

@ -14,7 +14,7 @@ module Maintenance
return if champ&.dossier&.procedure&.id.blank? return if champ&.dossier&.procedure&.id.blank?
data = APIEntreprise::RNAAdapter.new(champ.value, champ&.dossier&.procedure&.id).to_params data = APIEntreprise::RNAAdapter.new(champ.value, champ&.dossier&.procedure&.id).to_params
return if data.blank? return if data.blank?
champ.update(value_json: APIGeoService.parse_rna_address(data['adresse'])) champ.update_with_external_data!(data:)
rescue URI::InvalidURIError rescue URI::InvalidURIError
# some Champs::RNAChamp contain spaces which raise this error # some Champs::RNAChamp contain spaces which raise this error
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound

View file

@ -134,7 +134,8 @@ describe Champs::RNAController, type: :controller do
"region_name" => nil, "region_name" => nil,
"street_address" => "33 rue de Modagor", "street_address" => "33 rue de Modagor",
"street_name" => "de Modagor", "street_name" => "de Modagor",
"street_number" => "33" "street_number" => "33",
"title" => "LA PRÉVENTION ROUTIERE"
}) })
end end
end end

View file

@ -170,7 +170,7 @@ FactoryBot.define do
factory :champ_do_not_use_rna, class: 'Champs::RNAChamp' do factory :champ_do_not_use_rna, class: 'Champs::RNAChamp' do
value { 'W173847273' } value { 'W173847273' }
value_json { AddressProxy::ADDRESS_PARTS.index_by(&:itself) } value_json { AddressProxy::ADDRESS_PARTS.index_by(&:itself).merge(title: "LA PRÉVENTION ROUTIERE") }
end end
factory :champ_do_not_use_engagement_juridique, class: 'Champs::EngagementJuridiqueChamp' do factory :champ_do_not_use_engagement_juridique, class: 'Champs::EngagementJuridiqueChamp' do
@ -183,7 +183,7 @@ FactoryBot.define do
factory :champ_do_not_use_rnf, class: 'Champs::RNFChamp' do factory :champ_do_not_use_rnf, class: 'Champs::RNFChamp' do
value { '075-FDD-00003-01' } value { '075-FDD-00003-01' }
external_id { '075-FDD-00003-01' } external_id { '075-FDD-00003-01' }
value_json { AddressProxy::ADDRESS_PARTS.index_by(&:itself) } value_json { AddressProxy::ADDRESS_PARTS.index_by(&:itself).merge(title: "Fondation SFR") }
end end
factory :champ_do_not_use_expression_reguliere, class: 'Champs::ExpressionReguliereChamp' do factory :champ_do_not_use_expression_reguliere, class: 'Champs::ExpressionReguliereChamp' do

View file

@ -102,18 +102,19 @@ describe Champs::RNFChamp, type: :model do
describe 'update_with_external_data!' do describe 'update_with_external_data!' do
it 'works' do it 'works' do
value_json = { value_json = {
:street_number => "16", street_number: "16",
:street_name => "Rue du Général de Boissieu", street_name: "Rue du Général de Boissieu",
:street_address => "16 Rue du Général de Boissieu", street_address: "16 Rue du Général de Boissieu",
:postal_code => "75015", postal_code: "75015",
:city_name => "Paris 15e Arrondissement", city_name: "Paris 15e Arrondissement",
:city_code => "75115", city_code: "75115",
:departement_code => "75", departement_code: "75",
:department_code => "75", department_code: "75",
:departement_name => "Paris", departement_name: "Paris",
:department_name => "Paris", department_name: "Paris",
:region_code => "11", region_code: "11",
:region_name => "Île-de-France" region_name: "Île-de-France",
title: "Fondation SFR"
} }
expect(champ).to receive(:update!).with(data: anything, value_json:) expect(champ).to receive(:update!).with(data: anything, value_json:)
champ.update_with_external_data!(data: subject.value!) champ.update_with_external_data!(data: subject.value!)

View file

@ -41,6 +41,8 @@ describe Columns::ChampColumn do
expect_type_de_champ_values('mesri', eq([nil])) expect_type_de_champ_values('mesri', eq([nil]))
expect_type_de_champ_values('cojo', eq([nil])) expect_type_de_champ_values('cojo', eq([nil]))
expect_type_de_champ_values('expression_reguliere', eq([nil])) expect_type_de_champ_values('expression_reguliere', eq([nil]))
expect_type_de_champ_values('rna', eq(["W173847273", "postal_code", "city_name", "departement_code", "region_name", "LA PRÉVENTION ROUTIERE"]))
expect_type_de_champ_values('rnf', eq(["075-FDD-00003-01", "postal_code", "city_name", "departement_code", "region_name", "Fondation SFR"]))
end end
end end

View file

@ -33,7 +33,8 @@ module Maintenance
"departement_name" => nil, "departement_name" => nil,
"department_name" => nil, "department_name" => nil,
"region_code" => nil, "region_code" => nil,
"region_name" => nil "region_name" => nil,
"title" => "LA PRÉVENTION ROUTIERE"
}) })
end end
end end

View file

@ -66,7 +66,8 @@ module Maintenance
"departement_name" => "Paris", "departement_name" => "Paris",
"department_name" => "Paris", "department_name" => "Paris",
"region_code" => "11", "region_code" => "11",
"region_name" => "Île-de-France" "region_name" => "Île-de-France",
"title" => "Fondation SFR"
}) })
end end
end end
@ -92,7 +93,8 @@ module Maintenance
"departement_name" => "Paris", "departement_name" => "Paris",
"department_name" => "Paris", "department_name" => "Paris",
"region_code" => "11", "region_code" => "11",
"region_name" => "Île-de-France" "region_name" => "Île-de-France",
"title" => "Fondation SFR"
}) })
end end
end end