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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ module RNAChampAssociationFetchableConcern
return clear_association!(:invalid) unless valid_champ_value?
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
if APIEntrepriseService.service_unavailable_error?(error, target: :djepva)
clear_association!(:network_error)

View file

@ -10,4 +10,20 @@ class TypesDeChamp::RNATypeDeChamp < TypesDeChamp::TypeDeChampBase
def champ_value_for_export(champ, path = :value)
champ.identifier
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

View file

@ -35,6 +35,22 @@ class TypesDeChamp::RNFTypeDeChamp < TypesDeChamp::TextTypeDeChamp
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
def paths

View file

@ -8,4 +8,8 @@ class TypesDeChamp::SiretTypeDeChamp < TypesDeChamp::TypeDeChampBase
end
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

View file

@ -14,7 +14,7 @@ module Maintenance
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']))
champ.update_with_external_data!(data:)
rescue URI::InvalidURIError
# some Champs::RNAChamp contain spaces which raise this error
rescue ActiveRecord::RecordNotFound

View file

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

View file

@ -170,7 +170,7 @@ FactoryBot.define do
factory :champ_do_not_use_rna, class: 'Champs::RNAChamp' do
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
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
value { '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
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
it 'works' do
value_json = {
: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",
:department_code => "75",
:departement_name => "Paris",
:department_name => "Paris",
:region_code => "11",
:region_name => "Île-de-France"
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",
department_code: "75",
departement_name: "Paris",
department_name: "Paris",
region_code: "11",
region_name: "Île-de-France",
title: "Fondation SFR"
}
expect(champ).to receive(:update!).with(data: anything, value_json:)
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('cojo', 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

View file

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

View file

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