Background
When a CoreFile is updated in Rails (title, authors, contributors, visibility, collections), the MODS and TFE records stored in BaseX become stale. Neither POST .../mods nor POST .../tfe is called after initial upload.
Work required
app/jobs/sync_tapas_xq_metadata_job.rb
Create the job with a sync: keyword argument accepting :mods, :tfe, or :both.
- Skips if
TapasXq.configuration.disabled? or core_file.tapas_xq_doc_id is blank
- For
:mods or :both: POSTs to /#{project_id}/#{doc_id}/mods with title, authors, contributors; saves returned MODS XML to core_file.mods_xml via update_columns
- For
:tfe or :both: POSTs to /#{project_id}/#{doc_id}/tfe with collections (comma-separated IDs) and is-public
- Swallows
TapasXq::NotFoundError with a warning log
- Retries on
TimeoutError (3×, 5s) and ConnectionError (3×, 10s)
app/models/core_file.rb
Add after_update :enqueue_tapas_xq_metadata_sync, if: :tapas_xq_uploaded? and:
MODS_FIELDS = %w[title tei_authors tei_contributors].freeze
TFE_FIELDS = %w[is_public].freeze
def tapas_xq_uploaded?
tapas_xq_doc_id.present?
end
def enqueue_tapas_xq_metadata_sync
mods_changed = MODS_FIELDS.any? { |f| saved_change_to_attribute?(f) }
tfe_changed = TFE_FIELDS.any? { |f| saved_change_to_attribute?(f) }
sync = if mods_changed && tfe_changed then :both
elsif mods_changed then :mods
elsif tfe_changed then :tfe
end
SyncTapasXqMetadataJob.perform_later(id, sync: sync) if sync
end
app/models/collection_core_file.rb
Collection changes go through the join model and do not fire CoreFile#after_update. Add callbacks here:
after_create :sync_tfe_with_tapas_xq
after_destroy :sync_tfe_with_tapas_xq
private
def sync_tfe_with_tapas_xq
return unless core_file.tapas_xq_doc_id.present?
SyncTapasXqMetadataJob.perform_later(core_file_id, sync: :tfe)
end
Dependencies
- No new services required — uses
TapasXq::Client directly or can be extracted into a service later
Tests
See spec/jobs/sync_tapas_xq_metadata_job_spec.rb, additions to spec/models/core_file_spec.rb, and spec/requests/core_files_spec.rb in the testing plan doc.
Background
When a
CoreFileis updated in Rails (title, authors, contributors, visibility, collections), the MODS and TFE records stored in BaseX become stale. NeitherPOST .../modsnorPOST .../tfeis called after initial upload.Work required
app/jobs/sync_tapas_xq_metadata_job.rbCreate the job with a
sync:keyword argument accepting:mods,:tfe, or:both.TapasXq.configuration.disabled?orcore_file.tapas_xq_doc_idis blank:modsor:both: POSTs to/#{project_id}/#{doc_id}/modswithtitle,authors,contributors; saves returned MODS XML tocore_file.mods_xmlviaupdate_columns:tfeor:both: POSTs to/#{project_id}/#{doc_id}/tfewithcollections(comma-separated IDs) andis-publicTapasXq::NotFoundErrorwith a warning logTimeoutError(3×, 5s) andConnectionError(3×, 10s)app/models/core_file.rbAdd
after_update :enqueue_tapas_xq_metadata_sync, if: :tapas_xq_uploaded?and:app/models/collection_core_file.rbCollection changes go through the join model and do not fire
CoreFile#after_update. Add callbacks here:Dependencies
TapasXq::Clientdirectly or can be extracted into a service laterTests
See
spec/jobs/sync_tapas_xq_metadata_job_spec.rb, additions tospec/models/core_file_spec.rb, andspec/requests/core_files_spec.rbin the testing plan doc.