Merge pull request #2759 from tchak/api-entreprise-check-available-data
Only reject api entreprise data if required fields are missing
This commit is contained in:
commit
af4a50d8a2
6 changed files with 42 additions and 16 deletions
|
@ -1,4 +1,6 @@
|
||||||
class ApiEntreprise::Adapter
|
class ApiEntreprise::Adapter
|
||||||
|
UNAVAILABLE = 'Donnée indisponible'
|
||||||
|
|
||||||
def initialize(siret, procedure_id)
|
def initialize(siret, procedure_id)
|
||||||
@siret = siret
|
@siret = siret
|
||||||
@procedure_id = procedure_id
|
@procedure_id = procedure_id
|
||||||
|
@ -17,4 +19,8 @@ class ApiEntreprise::Adapter
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def valid_params?(params)
|
||||||
|
!params.has_value?(UNAVAILABLE)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,10 +34,7 @@ class ApiEntreprise::API
|
||||||
params: params,
|
params: params,
|
||||||
timeout: TIMEOUT)
|
timeout: TIMEOUT)
|
||||||
|
|
||||||
# Responses with a 206 codes are sometimes not useable,
|
if response.success?
|
||||||
# as the RNA calls often return a 206 with an error message,
|
|
||||||
# not a partial response
|
|
||||||
if response.success? && response.code != 206
|
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
else
|
else
|
||||||
raise RestClient::ResourceNotFound
|
raise RestClient::ResourceNotFound
|
||||||
|
|
|
@ -8,8 +8,13 @@ class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter
|
||||||
|
|
||||||
def process_params
|
def process_params
|
||||||
params = data_source[:entreprise].slice(*attr_to_fetch)
|
params = data_source[:entreprise].slice(*attr_to_fetch)
|
||||||
|
|
||||||
|
if valid_params?(params)
|
||||||
params[:date_creation] = Time.at(params[:date_creation]).to_datetime
|
params[:date_creation] = Time.at(params[:date_creation]).to_datetime
|
||||||
params.transform_keys { |k| :"entreprise_#{k}" }
|
params.transform_keys { |k| :"entreprise_#{k}" }
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def attr_to_fetch
|
def attr_to_fetch
|
||||||
|
|
|
@ -7,10 +7,15 @@ class ApiEntreprise::EtablissementAdapter < ApiEntreprise::Adapter
|
||||||
|
|
||||||
def process_params
|
def process_params
|
||||||
params = data_source[:etablissement].slice(*attr_to_fetch)
|
params = data_source[:etablissement].slice(*attr_to_fetch)
|
||||||
|
|
||||||
|
if valid_params?(params)
|
||||||
adresse_line = params[:adresse].slice(*address_lines_to_fetch).values.compact.join("\r\n")
|
adresse_line = params[:adresse].slice(*address_lines_to_fetch).values.compact.join("\r\n")
|
||||||
params.merge!(params[:adresse].slice(*address_attr_to_fetch))
|
params.merge!(params[:adresse].slice(*address_attr_to_fetch))
|
||||||
params[:adresse] = adresse_line
|
params[:adresse] = adresse_line
|
||||||
params
|
params
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def attr_to_fetch
|
def attr_to_fetch
|
||||||
|
|
|
@ -10,7 +10,11 @@ class ApiEntreprise::ExercicesAdapter < ApiEntreprise::Adapter
|
||||||
exercice.slice(*attr_to_fetch)
|
exercice.slice(*attr_to_fetch)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if exercices_array == exercices_array.select { |params| valid_params?(params) }
|
||||||
{ exercices_attributes: exercices_array }
|
{ exercices_attributes: exercices_array }
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def attr_to_fetch
|
def attr_to_fetch
|
||||||
|
|
|
@ -6,17 +6,26 @@ class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_params
|
def process_params
|
||||||
if data_source[:association][:id].present?
|
# Responses with a 206 codes are sometimes not useable,
|
||||||
|
# as the RNA calls often return a 206 with an error message,
|
||||||
|
# not a partial response
|
||||||
|
if !data_source.key?(:association)
|
||||||
|
{}
|
||||||
|
else
|
||||||
params = data_source[:association].slice(*attr_to_fetch)
|
params = data_source[:association].slice(*attr_to_fetch)
|
||||||
params[:rna] = data_source[:association][:id]
|
|
||||||
params.transform_keys { |k| :"association_#{k}" }
|
if params[:id].present? && valid_params?(params)
|
||||||
|
params[:rna] = params[:id]
|
||||||
|
params.except(:id).transform_keys { |k| :"association_#{k}" }
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def attr_to_fetch
|
def attr_to_fetch
|
||||||
[
|
[
|
||||||
|
:id,
|
||||||
:titre,
|
:titre,
|
||||||
:objet,
|
:objet,
|
||||||
:date_creation,
|
:date_creation,
|
||||||
|
|
Loading…
Add table
Reference in a new issue