Remove skip_fetch_data mechanism

This commit is contained in:
Damien Le Thiec 2022-10-11 11:52:59 +02:00
parent 927edb5809
commit bcdc9c18ae
4 changed files with 12 additions and 16 deletions

View file

@ -7,10 +7,10 @@ class Champs::RNAController < ApplicationController
@network_error = false @network_error = false
begin begin
data = APIEntreprise::RNAAdapter.new(@rna, @champ.procedure_id).to_params data = APIEntreprise::RNAAdapter.new(@rna, @champ.procedure_id).to_params
@champ.update!(data: data, value: @rna, skip_cleanup: true, skip_fetch: true) @champ.update!(data: data, value: @rna, skip_cleanup: true)
rescue APIEntreprise::API::Error, ActiveRecord::RecordInvalid => error rescue APIEntreprise::API::Error, ActiveRecord::RecordInvalid => error
@network_error = true if error.try(:network_error?) && !APIEntrepriseService.api_up? @network_error = true if error.try(:network_error?) && !APIEntrepriseService.api_up?
@champ.update(data: nil, value: nil, skip_cleanup: true, skip_fetch: true) @champ.update(data: nil, value: nil, skip_cleanup: true)
end end
end end
end end

View file

@ -26,7 +26,6 @@ class Champ < ApplicationRecord
has_one_attached :piece_justificative_file has_one_attached :piece_justificative_file
attr_accessor :skip_cleanup attr_accessor :skip_cleanup
attr_accessor :skip_fetch
# We declare champ specific relationships (Champs::CarteChamp, Champs::SiretChamp and Champs::RepetitionChamp) # We declare champ specific relationships (Champs::CarteChamp, Champs::SiretChamp and Champs::RepetitionChamp)
# here because otherwise we can't easily use includes in our queries. # here because otherwise we can't easily use includes in our queries.
@ -82,7 +81,7 @@ class Champ < ApplicationRecord
before_validation :set_dossier_id, if: :needs_dossier_id? before_validation :set_dossier_id, if: :needs_dossier_id?
before_save :cleanup_if_empty, unless: :skip_cleanup before_save :cleanup_if_empty, unless: :skip_cleanup
before_save :normalize before_save :normalize
after_update_commit :fetch_external_data_later, unless: :skip_fetch after_update_commit :fetch_external_data_later
def public? def public?
!private? !private?

View file

@ -43,14 +43,6 @@ class Champs::RNAChamp < Champ
etablissement.present? ? etablissement.search_terms : [value] etablissement.present? ? etablissement.search_terms : [value]
end end
def fetch_external_data?
true
end
def fetch_external_data
APIEntreprise::RNAAdapter.new(external_id, procedure_id).to_params
end
def update_external_id def update_external_id
self.external_id = self.value self.external_id = self.value
end end

View file

@ -185,7 +185,7 @@ ActiveRecord::Schema.define(version: 2022_09_11_134914) do
create_table "champs", id: :serial, force: :cascade do |t| create_table "champs", id: :serial, force: :cascade do |t|
t.datetime "created_at" t.datetime "created_at"
t.jsonb "data" t.jsonb "data"
t.integer "dossier_id" t.integer "dossier_id", null: false
t.integer "etablissement_id" t.integer "etablissement_id"
t.string "external_id" t.string "external_id"
t.string "fetch_external_data_exceptions", array: true t.string "fetch_external_data_exceptions", array: true
@ -194,7 +194,7 @@ ActiveRecord::Schema.define(version: 2022_09_11_134914) do
t.datetime "rebased_at" t.datetime "rebased_at"
t.integer "row" t.integer "row"
t.string "type" t.string "type"
t.integer "type_de_champ_id" t.integer "type_de_champ_id", null: false
t.datetime "updated_at" t.datetime "updated_at"
t.string "value" t.string "value"
t.jsonb "value_json" t.jsonb "value_json"
@ -862,11 +862,11 @@ ActiveRecord::Schema.define(version: 2022_09_11_134914) do
end end
create_table "zone_labels", force: :cascade do |t| create_table "zone_labels", force: :cascade do |t|
t.datetime "created_at", precision: 6, null: false t.bigint "zone_id", null: false
t.date "designated_on", null: false t.date "designated_on", null: false
t.string "name", null: false t.string "name", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.bigint "zone_id", null: false
t.index ["zone_id"], name: "index_zone_labels_on_zone_id" t.index ["zone_id"], name: "index_zone_labels_on_zone_id"
end end
@ -878,6 +878,7 @@ ActiveRecord::Schema.define(version: 2022_09_11_134914) do
t.index ["acronym"], name: "index_zones_on_acronym", unique: true t.index ["acronym"], name: "index_zones_on_acronym", unique: true
end end
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "administrateurs", "users" add_foreign_key "administrateurs", "users"
add_foreign_key "administrateurs_instructeurs", "administrateurs" add_foreign_key "administrateurs_instructeurs", "administrateurs"
@ -894,6 +895,9 @@ ActiveRecord::Schema.define(version: 2022_09_11_134914) do
add_foreign_key "bulk_messages_groupe_instructeurs", "bulk_messages" add_foreign_key "bulk_messages_groupe_instructeurs", "bulk_messages"
add_foreign_key "bulk_messages_groupe_instructeurs", "groupe_instructeurs" add_foreign_key "bulk_messages_groupe_instructeurs", "groupe_instructeurs"
add_foreign_key "champs", "champs", column: "parent_id" add_foreign_key "champs", "champs", column: "parent_id"
add_foreign_key "champs", "dossiers"
add_foreign_key "champs", "etablissements"
add_foreign_key "champs", "types_de_champ"
add_foreign_key "closed_mails", "procedures" add_foreign_key "closed_mails", "procedures"
add_foreign_key "commentaires", "dossiers" add_foreign_key "commentaires", "dossiers"
add_foreign_key "commentaires", "experts" add_foreign_key "commentaires", "experts"
@ -903,6 +907,7 @@ ActiveRecord::Schema.define(version: 2022_09_11_134914) do
add_foreign_key "dossiers", "groupe_instructeurs" add_foreign_key "dossiers", "groupe_instructeurs"
add_foreign_key "dossiers", "procedure_revisions", column: "revision_id" add_foreign_key "dossiers", "procedure_revisions", column: "revision_id"
add_foreign_key "dossiers", "users" add_foreign_key "dossiers", "users"
add_foreign_key "etablissements", "dossiers"
add_foreign_key "experts", "users" add_foreign_key "experts", "users"
add_foreign_key "experts_procedures", "experts" add_foreign_key "experts_procedures", "experts"
add_foreign_key "experts_procedures", "procedures" add_foreign_key "experts_procedures", "procedures"