From 7e7143d25711ae1df4e118453ba33dd8c889c90f Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 20 Nov 2024 16:11:11 -0600 Subject: [PATCH 1/5] Refactor: DocumentDistributions instead of DocumentReferences This change moves the application business logic towards DCAT distributions instead of GBL's DC-based references. --- .../document_distributions_controller.rb | 172 ++++++++++++++++++ .../admin/document_references_controller.rb | 172 ------------------ app/controllers/admin/documents_controller.rb | 8 +- .../controllers/results_controller.js | 8 +- app/jobs/export_job.rb | 14 +- app/models/document.rb | 78 ++++---- ..._reference.rb => document_distribution.rb} | 50 ++--- app/models/reference_type.rb | 2 +- ...ort_csv_document_distributions_service.rb} | 18 +- .../geoblacklight_admin/image_service.rb | 2 +- .../geoblacklight_admin/item_viewer.rb | 8 +- .../_document_distribution.html.erb | 39 ++++ .../_document_distribution.json.jbuilder | 2 + .../_form.html.erb | 10 +- .../destroy_all.html.erb | 22 +-- .../document_distributions/edit.html.erb | 12 ++ .../import.html.erb | 20 +- .../index.html.erb | 40 ++-- .../index.json.jbuilder | 1 + .../admin/document_distributions/new.html.erb | 11 ++ .../document_distributions/show.html.erb | 10 + .../document_distributions/show.json.jbuilder | 1 + .../_document_reference.html.erb | 39 ---- .../_document_reference.json.jbuilder | 2 - .../admin/document_references/edit.html.erb | 12 -- .../document_references/index.json.jbuilder | 1 - .../admin/document_references/new.html.erb | 11 -- .../admin/document_references/show.html.erb | 10 - .../document_references/show.json.jbuilder | 1 - app/views/admin/documents/_form_nav.html.erb | 6 +- .../admin/documents/_json_aardvark.jbuilder | 2 +- .../admin/documents/_json_gbl_v1.jbuilder | 2 +- app/views/admin/ids/fetch.json.jbuilder | 2 - app/views/admin/ids/index.json.jbuilder | 2 - app/views/admin/shared/_navbar.html.erb | 2 +- ...8823_rename_references_to_distributions.rb | 5 + db/seeds_elements.csv | 2 +- db/seeds_elements.numbers | Bin 214421 -> 214579 bytes docs/upgrading.md | 9 +- .../geoblacklight_admin/config_generator.rb | 6 +- .../config/initializers/mime_types.rb | 2 +- .../{references.rake => distributions.rake} | 38 ++-- .../document_distributions_controller_test.rb | 79 ++++++++ .../document_references_controller_test.rb | 79 -------- ...erences.yml => document_distributions.yml} | 0 ...eferences.csv => import_distributions.csv} | 2 +- test/models/document_distribution_test.rb | 81 +++++++++ test/models/document_reference_test.rb | 81 --------- ...csv_document_distributions_service_test.rb | 40 ++++ ...rt_csv_document_references_service_test.rb | 40 ---- .../geoblacklight_admin/image_service_test.rb | 8 +- .../geoblacklight_admin/item_viewer_test.rb | 8 +- 52 files changed, 640 insertions(+), 632 deletions(-) create mode 100644 app/controllers/admin/document_distributions_controller.rb delete mode 100644 app/controllers/admin/document_references_controller.rb rename app/models/{document_reference.rb => document_distribution.rb} (68%) rename app/services/{export_csv_document_references_service.rb => export_csv_document_distributions_service.rb} (72%) create mode 100644 app/views/admin/document_distributions/_document_distribution.html.erb create mode 100644 app/views/admin/document_distributions/_document_distribution.json.jbuilder rename app/views/admin/{document_references => document_distributions}/_form.html.erb (70%) rename app/views/admin/{document_references => document_distributions}/destroy_all.html.erb (70%) create mode 100644 app/views/admin/document_distributions/edit.html.erb rename app/views/admin/{document_references => document_distributions}/import.html.erb (69%) rename app/views/admin/{document_references => document_distributions}/index.html.erb (69%) create mode 100644 app/views/admin/document_distributions/index.json.jbuilder create mode 100644 app/views/admin/document_distributions/new.html.erb create mode 100644 app/views/admin/document_distributions/show.html.erb create mode 100644 app/views/admin/document_distributions/show.json.jbuilder delete mode 100644 app/views/admin/document_references/_document_reference.html.erb delete mode 100644 app/views/admin/document_references/_document_reference.json.jbuilder delete mode 100644 app/views/admin/document_references/edit.html.erb delete mode 100644 app/views/admin/document_references/index.json.jbuilder delete mode 100644 app/views/admin/document_references/new.html.erb delete mode 100644 app/views/admin/document_references/show.html.erb delete mode 100644 app/views/admin/document_references/show.json.jbuilder create mode 100644 db/migrate/20241120238823_rename_references_to_distributions.rb rename lib/geoblacklight_admin/tasks/{references.rake => distributions.rake} (59%) create mode 100644 test/controllers/document_distributions_controller_test.rb delete mode 100644 test/controllers/document_references_controller_test.rb rename test/fixtures/{document_references.yml => document_distributions.yml} (100%) rename test/fixtures/files/{import_references.csv => import_distributions.csv} (73%) create mode 100644 test/models/document_distribution_test.rb delete mode 100644 test/models/document_reference_test.rb create mode 100644 test/services/export_csv_document_distributions_service_test.rb delete mode 100644 test/services/export_csv_document_references_service_test.rb diff --git a/app/controllers/admin/document_distributions_controller.rb b/app/controllers/admin/document_distributions_controller.rb new file mode 100644 index 00000000..6a3ae88a --- /dev/null +++ b/app/controllers/admin/document_distributions_controller.rb @@ -0,0 +1,172 @@ +# frozen_string_literal: true + +# Admin::DocumentDistributionsController +# +# This controller manages the CRUD operations for Document Distributions within the Admin namespace. +# It includes actions for listing, showing, creating, updating, and deleting document distributions. +# Additionally, it provides functionality for importing and destroying all distributions. +module Admin + class DocumentDistributionsController < Admin::AdminController + before_action :set_document + before_action :set_document_distribution, only: %i[show edit update destroy] + + # GET /admin/document_distributions or /admin/document_distributions.json + # + # Lists all document distributions. If a document_id is provided, it lists distributions + # associated with that document, ordered by position. Otherwise, it paginates all + # document distributions. + def index + @document_distributions = DocumentDistribution.all + if params[:document_id] + @document_distributions = DocumentDistribution.where(friendlier_id: @document.friendlier_id).order(position: :asc) + else + @pagy, @document_distributions = pagy(DocumentDistribution.all.order(friendlier_id: :asc, updated_at: :desc), items: 20) + end + end + + # GET /admin/document_distributions/1 or /admin/document_distributions/1.json + # + # Shows a specific document distribution. + def show + end + + # GET /admin/document_references/new + # + # Initializes a new document distribution. + def new + @document_distribution = DocumentDistribution.new + end + + # GET /admin/document_distributions/1/edit + # + # Edits an existing document distribution. + def edit + end + + # POST /admin/document_distributions or /admin/document_distributions.json + # + # Creates a new document distribution. If successful, redirects to the document distributions + # list with a success notice. Otherwise, renders the new form with errors. + def create + @document_distribution = DocumentDistribution.new(document_distribution_params) + + respond_to do |format| + if @document_distribution.save + format.html { redirect_to admin_document_document_distributions_path(@document), notice: "Document distribution was successfully created." } + format.json { render :show, status: :created, location: @document_distribution } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @document_distribution.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /admin/document_distributions/1 or /admin/document_distributions/1.json + # + # Updates an existing document distribution. If successful, redirects to the document distribution + # with a success notice. Otherwise, renders the edit form with errors. + def update + respond_to do |format| + if @document_distribution.update(document_distribution_params) + format.html { redirect_to admin_document_document_distributions_path(@document), notice: "Document distribution was successfully updated." } + format.json { render :show, status: :ok, location: @document_distribution } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @document_distribution.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /admin/document_distributions/1 or /admin/document_distributions/1.json + # + # Deletes a document distribution. Redirects to the document distributions list with a success notice. + def destroy + @document_distribution.destroy! + + respond_to do |format| + format.html { redirect_to admin_document_document_distributions_path(@document), status: :see_other, notice: "Document distribution was successfully destroyed." } + format.json { head :no_content } + end + end + + # DELETE /admin/document_distributions/destroy_all + # + # Destroys all document distributions provided in the file parameter. If successful, redirects + # with a success notice. Otherwise, redirects with an error notice. + def destroy_all + return if request.get? + + logger.debug("Destroy Distributions") + unless params.dig(:document_distribution, :distributions, :file) + raise ArgumentError, "File does not exist or is invalid." + end + + respond_to do |format| + if DocumentDistribution.destroy_all(params.dig(:document_distribution, :distributions, :file)) + format.html { redirect_to admin_document_distributions_path, notice: "Distributions were destroyed." } + else + format.html { redirect_to admin_document_distributions_path, notice: "Distributions could not be destroyed." } + end + rescue => e + format.html { redirect_to admin_document_distributions_path, notice: "Distributions could not be destroyed. #{e}" } + end + end + + # GET/POST /documents/1/distributions/import + # + # Imports document distributions from a file. If successful, redirects with a success notice. + # Otherwise, redirects with an error notice. + def import + return if request.get? + + logger.debug("Import Distributions") + + unless params.dig(:document_distribution, :distributions, :file) + raise ArgumentError, "File does not exist or is invalid." + end + + if DocumentDistribution.import(params.dig(:document_distribution, :distributions, :file)) + logger.debug("Distributions were created successfully.") + if params[:document_id] + redirect_to admin_document_document_distributions_path(@document), notice: "Distributions were created successfully." + else + redirect_to admin_document_document_distributions_path, notice: "Distributions were created successfully." + end + else + logger.debug("Distributions could not be created.") + if params[:document_id] + redirect_to admin_document_document_distributions_path(@document), warning: "Distributions could not be created." + else + redirect_to admin_document_document_distributions_path, warning: "Distributions could not be created." + end + end + rescue => e + logger.debug("Distributions could not be created. #{e}") + if params[:document_id] + redirect_to admin_document_document_distributions_path(@document), notice: "Distributions could not be created. #{e}" + else + redirect_to admin_document_document_distributions_path, notice: "Distributions could not be created. #{e}" + end + end + + private + + # Sets the document based on the document_id parameter. + # If not nested, it does nothing. + def set_document + return unless params[:document_id] # If not nested + + @document = Document.includes(:leaf_representative).find_by!(friendlier_id: params[:document_id]) + end + + # Sets the document distribution based on the id parameter. + def set_document_distribution + @document_distribution = DocumentDistribution.find(params[:id]) + end + + # Permits only the trusted parameters for document distributions. + def document_distribution_params + params.require(:document_distribution).permit(:friendlier_id, :reference_type_id, :url, :label, :position) + end + end +end diff --git a/app/controllers/admin/document_references_controller.rb b/app/controllers/admin/document_references_controller.rb deleted file mode 100644 index 4ef5b409..00000000 --- a/app/controllers/admin/document_references_controller.rb +++ /dev/null @@ -1,172 +0,0 @@ -# frozen_string_literal: true - -# Admin::DocumentReferencesController -# -# This controller manages the CRUD operations for Document References within the Admin namespace. -# It includes actions for listing, showing, creating, updating, and deleting document references. -# Additionally, it provides functionality for importing and destroying all references. -module Admin - class DocumentReferencesController < Admin::AdminController - before_action :set_document - before_action :set_document_reference, only: %i[show edit update destroy] - - # GET /admin/document_references or /admin/document_references.json - # - # Lists all document references. If a document_id is provided, it lists references - # associated with that document, ordered by position. Otherwise, it paginates all - # document references. - def index - @document_references = DocumentReference.all - if params[:document_id] - @document_references = DocumentReference.where(friendlier_id: @document.friendlier_id).order(position: :asc) - else - @pagy, @document_references = pagy(DocumentReference.all.order(friendlier_id: :asc, updated_at: :desc), items: 20) - end - end - - # GET /admin/document_references/1 or /admin/document_references/1.json - # - # Shows a specific document reference. - def show - end - - # GET /admin/document_references/new - # - # Initializes a new document reference. - def new - @document_reference = DocumentReference.new - end - - # GET /admin/document_references/1/edit - # - # Edits an existing document reference. - def edit - end - - # POST /admin/document_references or /admin/document_references.json - # - # Creates a new document reference. If successful, redirects to the document references - # list with a success notice. Otherwise, renders the new form with errors. - def create - @document_reference = DocumentReference.new(document_reference_params) - - respond_to do |format| - if @document_reference.save - format.html { redirect_to admin_document_document_references_path(@document), notice: "Document reference was successfully created." } - format.json { render :show, status: :created, location: @document_reference } - else - format.html { render :new, status: :unprocessable_entity } - format.json { render json: @document_reference.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /admin/document_references/1 or /admin/document_references/1.json - # - # Updates an existing document reference. If successful, redirects to the document reference - # with a success notice. Otherwise, renders the edit form with errors. - def update - respond_to do |format| - if @document_reference.update(document_reference_params) - format.html { redirect_to admin_document_document_reference_path(@document, @document_reference), notice: "Document reference was successfully updated." } - format.json { render :show, status: :ok, location: @document_reference } - else - format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @document_reference.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /admin/document_references/1 or /admin/document_references/1.json - # - # Deletes a document reference. Redirects to the document references list with a success notice. - def destroy - @document_reference.destroy! - - respond_to do |format| - format.html { redirect_to admin_document_document_references_path(@document), status: :see_other, notice: "Document reference was successfully destroyed." } - format.json { head :no_content } - end - end - - # DELETE /admin/document_references/destroy_all - # - # Destroys all document references provided in the file parameter. If successful, redirects - # with a success notice. Otherwise, redirects with an error notice. - def destroy_all - return if request.get? - - logger.debug("Destroy References") - unless params.dig(:document_reference, :references, :file) - raise ArgumentError, "File does not exist or is invalid." - end - - respond_to do |format| - if DocumentReference.destroy_all(params.dig(:document_reference, :references, :file)) - format.html { redirect_to admin_document_references_path, notice: "References were destroyed." } - else - format.html { redirect_to admin_document_references_path, notice: "References could not be destroyed." } - end - rescue => e - format.html { redirect_to admin_document_references_path, notice: "References could not be destroyed. #{e}" } - end - end - - # GET/POST /documents/1/references/import - # - # Imports document references from a file. If successful, redirects with a success notice. - # Otherwise, redirects with an error notice. - def import - return if request.get? - - logger.debug("Import References") - - unless params.dig(:document_reference, :references, :file) - raise ArgumentError, "File does not exist or is invalid." - end - - if DocumentReference.import(params.dig(:document_reference, :references, :file)) - logger.debug("References were created successfully.") - if params[:document_id] - redirect_to admin_document_document_references_path(@document), notice: "References were created successfully." - else - redirect_to admin_document_references_path, notice: "References were created successfully." - end - else - logger.debug("References could not be created.") - if params[:document_id] - redirect_to admin_document_document_references_path(@document), warning: "References could not be created." - else - redirect_to admin_document_references_path, warning: "References could not be created." - end - end - rescue => e - logger.debug("References could not be created. #{e}") - if params[:document_id] - redirect_to admin_document_document_references_path(@document), notice: "References could not be created. #{e}" - else - redirect_to admin_document_references_path, notice: "References could not be created. #{e}" - end - end - - private - - # Sets the document based on the document_id parameter. - # If not nested, it does nothing. - def set_document - return unless params[:document_id] # If not nested - - @document = Document.includes(:leaf_representative).find_by!(friendlier_id: params[:document_id]) - end - - # Sets the document reference based on the id parameter. - def set_document_reference - @document_reference = DocumentReference.find(params[:id]) - end - - # Permits only the trusted parameters for document references. - def document_reference_params - params.require(:document_reference).permit(:friendlier_id, :reference_type_id, :url, :label, :position) - end - end -end diff --git a/app/controllers/admin/documents_controller.rb b/app/controllers/admin/documents_controller.rb index 1910fab1..1fec0757 100644 --- a/app/controllers/admin/documents_controller.rb +++ b/app/controllers/admin/documents_controller.rb @@ -62,8 +62,8 @@ def index ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentAccessLinksService) head :no_content end - format.csv_document_references do - ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentReferencesService) + format.csv_document_distributions do + ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentDistributionsService) head :no_content end end @@ -102,8 +102,8 @@ def fetch ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_access_links"}, ExportCsvDocumentAccessLinksService) head :no_content end - format.csv_document_references do - ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_references"}, ExportCsvDocumentReferencesService) + format.csv_document_distributions do + ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_distributions"}, ExportCsvDocumentDistributionsService) head :no_content end end diff --git a/app/javascript/controllers/results_controller.js b/app/javascript/controllers/results_controller.js index 23edb635..03427234 100644 --- a/app/javascript/controllers/results_controller.js +++ b/app/javascript/controllers/results_controller.js @@ -250,14 +250,14 @@ export default class extends Controller { } } - exportCsvDocumentReferences() { - console.log('Export - CsvDocumentReferences') + exportCsvDocumentDistributions() { + console.log('Export - CsvDocumentDistributions') var scope = this.checkSelectionScope(); var el = document.querySelector('#result-selected-options'); if(scope === 'pageset') { - window.location = el.dataset.pageset + "&format=csv_document_references" + window.location = el.dataset.pageset + "&format=csv_document_distributions" } else { - window.location = el.dataset.resultset + "&format=csv_document_references" + window.location = el.dataset.resultset + "&format=csv_document_distributions" } } diff --git a/app/jobs/export_job.rb b/app/jobs/export_job.rb index c419e4f1..ff6b5a24 100644 --- a/app/jobs/export_job.rb +++ b/app/jobs/export_job.rb @@ -25,7 +25,7 @@ def perform(request, current_user, query_params, export_service) # Send progress file_content_documents = export_service.call(document_ids) - file_content_document_references = ExportCsvDocumentReferencesService.call(document_ids) + file_content_document_distributions = ExportCsvDocumentDistributionsService.call(document_ids) # Write Documents into tempfile @tempfile_documents = Tempfile.new(["documents-#{Time.zone.today}", ".csv"]).tap do |file| @@ -38,15 +38,15 @@ def perform(request, current_user, query_params, export_service) logger.debug("Tempfile Documents Size: #{File.size(file.path)} bytes") end - # Write DocumentReferences into tempfile - @tempfile_document_references = Tempfile.new(["document-references-#{Time.zone.today}", ".csv"]).tap do |file| + # Write DocumentDistributions into tempfile + @tempfile_document_distributions = Tempfile.new(["document-distributions-#{Time.zone.today}", ".csv"]).tap do |file| CSV.open(file, "wb") do |csv| - file_content_document_references.each do |row| + file_content_document_distributions.each do |row| csv << row end end - logger.debug("Tempfile Document References Path: #{file.path}") - logger.debug("Tempfile Document References Size: #{File.size(file.path)} bytes") + logger.debug("Tempfile Document Distributions Path: #{file.path}") + logger.debug("Tempfile Document Distributions Size: #{File.size(file.path)} bytes") end # Create a zip file containing both tempfiles @@ -56,7 +56,7 @@ def perform(request, current_user, query_params, export_service) Zip::File.open(@tempfile_zip.path, Zip::File::CREATE) do |zipfile| zipfile.add("documents.csv", @tempfile_documents.path) - zipfile.add("document-references.csv", @tempfile_document_references.path) + zipfile.add("document-distributions.csv", @tempfile_document_distributions.path) end logger.debug("Zipfile Path: #{@tempfile_zip.path}") logger.debug("Zipfile Size: #{File.size(@tempfile_zip.path)} bytes") diff --git a/app/models/document.rb b/app/models/document.rb index 71e76c41..2de00537 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -9,7 +9,7 @@ class Document < Kithe::Work delegate :viewer_endpoint, to: :item_viewer def item_viewer - GeoblacklightAdmin::ItemViewer.new(references) + GeoblacklightAdmin::ItemViewer.new(distributions) end attr_accessor :skip_callbacks @@ -34,8 +34,8 @@ def item_viewer has_many :document_downloads, primary_key: "friendlier_id", foreign_key: "friendlier_id", autosave: false, dependent: :destroy, inverse_of: :document - # - DocumentReferences - has_many :document_references, primary_key: "friendlier_id", foreign_key: "friendlier_id", autosave: false, dependent: :destroy, + # - DocumentDistributions + has_many :document_distributions, primary_key: "friendlier_id", foreign_key: "friendlier_id", autosave: false, dependent: :destroy, inverse_of: :document # DocumentAssets - Thumbnails, Attachments, etc @@ -89,7 +89,7 @@ def raw_solr_document # Downloadable Resouce def a_downloadable_resource? - references_json.include?("downloadUrl") + distributions_json.include?("downloadUrl") end validates_with Document::DateValidator @@ -113,70 +113,70 @@ def a_downloadable_resource? attr_json :dct_references_s, Document::Reference.to_type, array: true, default: -> { [] } # Index Transformations - *_json functions - def references - references = ActiveSupport::HashWithIndifferentAccess.new + def distributions + distributions = ActiveSupport::HashWithIndifferentAccess.new - # Add DocumentReferences to references + # Add DocumentDistributions to distributions if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "true" - references = document_references.to_aardvark_references + distributions = document_distributions.to_aardvark_distributions end # Prep value arrays send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref| if ref.category.present? - references[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] = [] + distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] = [] end end # Seed value arrays send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref| if ref.category.present? - references[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] << ref.value + distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] << ref.value end end - logger.debug("\n\nDocument#references > seeded: #{references}") + logger.debug("\n\nDocument#distributions > seeded: #{distributions}") # Apply Downloads - references = apply_downloads(references) + distributions = apply_downloads(distributions) - logger.debug("Document#references > downloads: #{references}\n\n") + logger.debug("Document#distributions > downloads: #{distributions}\n\n") # Need to flatten the arrays here to avoid the following potential error: # - ArgumentError: Please use symbols for polymorphic route arguments. # - Via: app/helpers/geoblacklight_helper.rb:224:in `render_references_url' - references.each do |key, value| + distributions.each do |key, value| next if key == "http://schema.org/downloadUrl" if value.is_a?(Array) && value.length == 1 - references[key] = value.first + distributions[key] = value.first end end - references + distributions end - # References JSON - # - Indexes to Solr as dct_references_s - def references_json + # Distributions JSON + # - Indexes to Solr as dct_distributions_s + def distributions_json if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "true" - logger.debug("Document#references_json > using document_references") - references = document_references.to_aardvark_references - references = apply_downloads(references) - references.to_json + logger.debug("Document#distributions_json > using document_distributions") + distributions = document_distributions.to_aardvark_distributions + distributions = apply_downloads(distributions) + distributions.to_json else - logger.debug("Document#references > #{references.inspect}") - logger.debug("Document#references_json > using references") + logger.debug("Document#distributions > #{distributions.inspect}") + logger.debug("Document#distributions_json > using distributions") logger.warn("Deprecation warning: AttrJSON-based dct_references_s will not be supported soon.") - self.references.to_json + distributions.to_json end end - def references_csv + def distributions_csv # Initialize CSV # - [document_id, category, value, label] csv = [] - references.each do |key, value| + distributions.each do |key, value| if key == "http://schema.org/downloadUrl" value.each do |download| csv << [friendlier_id, ReferenceType.find_by(reference_uri: key).name, download["url"], download["label"]] @@ -200,10 +200,10 @@ def asset_label(asset) # 1. Native Aardvark Downloads # 2. Multiple Document Download Links # 3. Downloadable Document Assets - def apply_downloads(references) + def apply_downloads(distributions) multiple_downloads = [] - dct_downloads = references["http://schema.org/downloadUrl"] + dct_downloads = distributions["http://schema.org/downloadUrl"] logger.debug("Document#dct_downloads > init: #{dct_downloads}\n\n") @@ -250,8 +250,8 @@ def apply_downloads(references) multiple_downloads = multiple_downloads.uniq { |d| [d[:label], d[:url]] } unless multiple_downloads.empty? - references[:"http://schema.org/downloadUrl"] = multiple_downloads.flatten unless multiple_downloads.empty? - references + distributions[:"http://schema.org/downloadUrl"] = multiple_downloads.flatten unless multiple_downloads.empty? + distributions end def multiple_downloads_array @@ -313,7 +313,7 @@ def downloadable? end def direct_download - references.download.to_hash if references.download.present? + distributions.download.to_hash if distributions.download.present? end def display_note @@ -321,11 +321,11 @@ def display_note end def hgl_download - references.hgl.to_hash if references.hgl.present? + distributions.hgl.to_hash if distributions.hgl.present? end def oembed - references.oembed.endpoint if references.oembed.present? + distributions.oembed.endpoint if distributions.oembed.present? end def same_institution? @@ -334,15 +334,15 @@ def same_institution? end def iiif_download - references.iiif.to_hash if references.iiif.present? + distributions.iiif.to_hash if distributions.iiif.present? end def data_dictionary_download - references.data_dictionary.to_hash if references.data_dictionary.present? + distributions.data_dictionary.to_hash if distributions.data_dictionary.present? end def external_url - references.url&.endpoint + distributions.url&.endpoint end def itemtype @@ -372,7 +372,7 @@ def file_format # :type => a string which if its a Geoblacklight::Constants::URI key # will return a coresponding Geoblacklight::Reference def checked_endpoint(type) - type = references.send(type) + type = distributions.send(type) type.endpoint if type.present? end diff --git a/app/models/document_reference.rb b/app/models/document_distribution.rb similarity index 68% rename from app/models/document_reference.rb rename to app/models/document_distribution.rb index 218a92ca..89a3651e 100644 --- a/app/models/document_reference.rb +++ b/app/models/document_distribution.rb @@ -2,9 +2,9 @@ require "csv" -# DocumentReference +# DocumentDistribution # -# This class represents a reference to a document, which includes a URL and a reference type. +# This class represents a distribution of a document, which includes a URL and a distribution type. # It belongs to a document and a reference type, and it supports CSV import and export. # # Associations: @@ -19,9 +19,9 @@ # - Validates uniqueness of :url scoped to :friendlier_id and :reference_type_id # # Scopes: -# - to_aardvark_references: Converts references to aardvark format -# - to_csv: Converts references to CSV format -class DocumentReference < ApplicationRecord +# - to_aardvark_distributions: Converts distributions to aardvark format +# - to_csv: Converts distributions to CSV format +class DocumentDistribution < ApplicationRecord belongs_to :document, foreign_key: :friendlier_id, primary_key: :friendlier_id belongs_to :reference_type after_save :reindex_document @@ -31,18 +31,18 @@ class DocumentReference < ApplicationRecord validates :url, uniqueness: {scope: [:friendlier_id, :reference_type_id]} # Scopes - scope :to_aardvark_references, -> { - references = where(friendlier_id: pluck(:friendlier_id)).map(&:to_aardvark_reference) + scope :to_aardvark_distributions, -> { + distributions = where(friendlier_id: pluck(:friendlier_id)).map(&:to_aardvark_distribution) merged = {} - references.each do |ref| - if ref.keys.first == "http://schema.org/downloadUrl" + distributions.each do |dist| + if dist.keys.first == "http://schema.org/downloadUrl" merged["http://schema.org/downloadUrl"] ||= [] merged["http://schema.org/downloadUrl"] << { - "url" => ref.values.first, - "label" => ref[:label] + "url" => dist.values.first, + "label" => dist[:label] } else - merged[ref.keys.first] = ref.values.first + merged[dist.keys.first] = dist.values.first end end merged @@ -55,12 +55,12 @@ class DocumentReference < ApplicationRecord # # @return [Array] the CSV column names def self.csv_column_names - ["friendlier_id", "reference_type", "reference_url", "label"] + ["friendlier_id", "reference_type", "distribution_url", "label"] end # Import # - # Imports document references from a CSV file. + # Imports document distributions from a CSV file. # # @param file [File] the CSV file to import # @return [Boolean] true if import is successful @@ -68,19 +68,19 @@ def self.import(file) logger.debug("CSV Import") ::CSV.foreach(file.path, headers: true) do |row| logger.debug("CSV Row: #{row.to_hash}") - document_reference = DocumentReference.find_or_initialize_by( + document_distribution = DocumentDistribution.find_or_initialize_by( friendlier_id: row.to_hash["friendlier_id"], reference_type_id: ReferenceType.find_by(name: row.to_hash["reference_type"]).id, - url: row.to_hash["reference_url"], + url: row.to_hash["distribution_url"], label: row.to_hash["label"] ) - logger.debug("Document Reference: #{document_reference.inspect}") + logger.debug("Document Distribution: #{document_distribution.inspect}") - document_reference.update!( + document_distribution.update!( friendlier_id: row.to_hash["friendlier_id"], reference_type_id: ReferenceType.find_by(name: row.to_hash["reference_type"]).id, - url: row.to_hash["reference_url"], + url: row.to_hash["distribution_url"], label: row.to_hash["label"] ) end @@ -89,7 +89,7 @@ def self.import(file) # Destroy All # - # Destroys document references based on a CSV file. + # Destroys document distributions based on a CSV file. # # @param file [File] the CSV file to process # @return [Boolean] true if destroy is successful @@ -97,10 +97,10 @@ def self.destroy_all(file) logger.debug("CSV Destroy") ::CSV.foreach(file.path, headers: true) do |row| logger.debug("CSV Row: #{row.to_hash}") - if DocumentReference.destroy_by( + if DocumentDistribution.destroy_by( friendlier_id: row.to_hash["friendlier_id"], reference_type_id: ReferenceType.find_by(name: row.to_hash["reference_type"]).id, - url: row.to_hash["reference_url"] + url: row.to_hash["distribution_url"] ) logger.debug("Destroyed: #{row.to_hash}") else @@ -112,7 +112,7 @@ def self.destroy_all(file) # To CSV # - # Converts the document reference to an array suitable for CSV export. + # Converts the document distribution to an array suitable for CSV export. # # @return [Array] the CSV row data def to_csv @@ -126,10 +126,10 @@ def to_csv # To Aardvark Reference # - # Converts the document reference to an aardvark reference format. + # Converts the document distribution to an aardvark distribution format. # # @return [Hash] the aardvark reference - def to_aardvark_reference + def to_aardvark_distribution hash = {} hash[reference_type.reference_uri.to_s] = url hash[:label] = label if reference_type.reference_uri.to_s == "http://schema.org/downloadUrl" diff --git a/app/models/reference_type.rb b/app/models/reference_type.rb index 90f8526b..4cb542c5 100644 --- a/app/models/reference_type.rb +++ b/app/models/reference_type.rb @@ -4,7 +4,7 @@ # It includes validations for presence and uniqueness of reference attributes, # and manages the position of references within the system. class ReferenceType < ApplicationRecord - has_many :document_references, dependent: :destroy + has_many :document_distributions, dependent: :destroy # Validations # Ensures that both reference_type and reference_uri are present and unique. diff --git a/app/services/export_csv_document_references_service.rb b/app/services/export_csv_document_distributions_service.rb similarity index 72% rename from app/services/export_csv_document_references_service.rb rename to app/services/export_csv_document_distributions_service.rb index 6fd5ba8a..9de70209 100644 --- a/app/services/export_csv_document_references_service.rb +++ b/app/services/export_csv_document_distributions_service.rb @@ -2,16 +2,16 @@ require "csv" -# ExportCsvDocumentReferencesService +# ExportCsvDocumentDistributionsService # -# This service is responsible for exporting document references to a CSV format. +# This service is responsible for exporting document distributions to a CSV format. # It broadcasts the progress of the export process via ActionCable. -class ExportCsvDocumentReferencesService +class ExportCsvDocumentDistributionsService # Returns a short name for the service. # # @return [String] the short name of the service. def self.short_name - "Document References" + "Document Distributions" end # Initiates the CSV export process for the given document IDs. @@ -31,10 +31,10 @@ def self.call(document_ids) slice_count = 100 csv_file = [] - Rails.logger.debug { "\n\nExportCsvDocumentReferencesService: #{document_ids.inspect}\n\n" } + Rails.logger.debug { "\n\nExportCsvDocumentDistributionsService: #{document_ids.inspect}\n\n" } CSV.generate(headers: true) do |_csv| - csv_file << DocumentReference.csv_column_names + csv_file << DocumentDistribution.csv_column_names document_ids.each_slice(slice_count) do |slice| # Broadcast progress percentage count += slice_count @@ -45,10 +45,10 @@ def self.call(document_ids) slice.each do |doc_id| doc = Document.find_by(friendlier_id: doc_id) - Rails.logger.debug { "\n\nDocReferences: #{doc.document_references.size}\n\n" } + Rails.logger.debug { "\n\nDocDistributions: #{doc.document_distributions.size}\n\n" } - doc.document_references.each do |reference| - csv_file << reference.to_csv + doc.document_distributions.each do |distribution| + csv_file << distribution.to_csv end rescue NoMethodError Rails.logger.debug { "\n\nExport Failed: #{doc_id.inspect}\n\n" } diff --git a/app/services/geoblacklight_admin/image_service.rb b/app/services/geoblacklight_admin/image_service.rb index 7279d980..8db2299b 100644 --- a/app/services/geoblacklight_admin/image_service.rb +++ b/app/services/geoblacklight_admin/image_service.rb @@ -191,7 +191,7 @@ def service_url # Retreives a url to a static thumbnail from the document's dct_references field, if it exists. def image_reference - @document.references["http://schema.org/thumbnailUrl"] + @document.distributions["http://schema.org/thumbnailUrl"] end # Default image size. diff --git a/app/services/geoblacklight_admin/item_viewer.rb b/app/services/geoblacklight_admin/item_viewer.rb index acc8431f..13d35de3 100644 --- a/app/services/geoblacklight_admin/item_viewer.rb +++ b/app/services/geoblacklight_admin/item_viewer.rb @@ -2,9 +2,9 @@ module GeoblacklightAdmin class ItemViewer - def initialize(references) - @references = references - @keys = references.keys.collect { |k| reference_uri_2_key(k) } + def initialize(distributions) + @distributions = distributions + @keys = distributions.keys.collect { |k| reference_uri_2_key(k) } end def viewer_protocol @@ -12,7 +12,7 @@ def viewer_protocol end def viewer_endpoint - @references[viewer_protocol_2_endpoint] + @distributions[viewer_protocol_2_endpoint] end def reference_uri_2_key(value) diff --git a/app/views/admin/document_distributions/_document_distribution.html.erb b/app/views/admin/document_distributions/_document_distribution.html.erb new file mode 100644 index 00000000..debef104 --- /dev/null +++ b/app/views/admin/document_distributions/_document_distribution.html.erb @@ -0,0 +1,39 @@ +<%- @page_title = "GBL♦Admin - Document - Distribution - #{document_distribution.url}" %> + +

Distribution

+ +
+
+

+ <%= document_distribution.url %> + + <%= link_to '~ Edit Distribution', edit_admin_document_document_distribution_path(@document, document_distribution), { class: 'btn btn-primary' } %> + <%= button_to "Destroy this distribution", admin_document_document_distribution_path(@document, document_distribution), method: :delete, class: "btn btn-danger" %> + +

+ + + + + + + + + + + + + + + + + + + + +
AttributeValue
Reference Type<%= document_distribution.reference_type.reference_type %>
Reference URL<%= document_distribution.url %>
Label<%= document_distribution.label %>
+
+
+ +<%= link_to 'Edit', edit_admin_document_document_distribution_path(@document, document_distribution) %> | +<%= link_to 'Back', admin_document_document_distributions_path(@document) %> diff --git a/app/views/admin/document_distributions/_document_distribution.json.jbuilder b/app/views/admin/document_distributions/_document_distribution.json.jbuilder new file mode 100644 index 00000000..2989ba23 --- /dev/null +++ b/app/views/admin/document_distributions/_document_distribution.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! document_distribution, :id, :created_at, :updated_at +json.url document_distribution_url(document_distribution, format: :json) diff --git a/app/views/admin/document_references/_form.html.erb b/app/views/admin/document_distributions/_form.html.erb similarity index 70% rename from app/views/admin/document_references/_form.html.erb rename to app/views/admin/document_distributions/_form.html.erb index f811536d..cdbadb4c 100644 --- a/app/views/admin/document_references/_form.html.erb +++ b/app/views/admin/document_distributions/_form.html.erb @@ -1,11 +1,11 @@ -<%= simple_form_for([:admin, @document, @document_reference]) do |f| %> +<%= simple_form_for([:admin, @document, @document_distribution]) do |f| %> <%= f.error_notification %> <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<%= f.input :friendlier_id, input_html: { value: @document.friendlier_id, readonly: true } %> <%= f.input :reference_type_id, as: :select, collection: ReferenceType.all.map { |r| [r.reference_type, r.id] }, label: 'Reference Type' %> - <%= f.input :url, label: 'Reference URL' %> + <%= f.input :url, label: 'Distribution URL' %> <%= f.input :label, autofocus: true, input_html: { disabled: true, id: 'label-input' } %>
@@ -17,18 +17,18 @@ \ No newline at end of file diff --git a/app/views/admin/document_references/destroy_all.html.erb b/app/views/admin/document_distributions/destroy_all.html.erb similarity index 70% rename from app/views/admin/document_references/destroy_all.html.erb rename to app/views/admin/document_distributions/destroy_all.html.erb index 8d8c8ac2..6bcb4356 100644 --- a/app/views/admin/document_references/destroy_all.html.erb +++ b/app/views/admin/document_distributions/destroy_all.html.erb @@ -1,9 +1,9 @@

<%= notice %>

- Document · Destroy References + Document · Destroy Distributions <% if params[:document_id] %> - <%= link_to '+ New Reference', new_document_document_reference_path(@document), { class: 'btn btn-primary float-right' } %> + <%= link_to '+ New Distribution', new_document_document_distribution_path(@document), { class: 'btn btn-primary float-right' } %> <% end %>

@@ -12,18 +12,18 @@ <% if params[:document_id] %>

<%= @document.title %>

<% else %> -

Destroy Multiple References

+

Destroy Multiple Distributions

<% end %>

Upload a CSV File

- <%= simple_form_for DocumentReference.new, url: destroy_all_admin_document_references_path, method: :post, multipart: true do |f| %> + <%= simple_form_for DocumentDistribution.new, url: destroy_all_admin_document_distributions_path, method: :post, multipart: true do |f| %>
- <%= f.simple_fields_for :references do |reference_fields| %> + <%= f.simple_fields_for :distributions do |distribution_fields| %> <%= reference_fields.input :file, as: :file, input_html: {} %> <%- end %>
@@ -41,7 +41,7 @@ friendlier_id reference_type - reference_url + distribution_url label @@ -73,10 +73,10 @@
The associated document's friendlier id
reference_type
The name of the reference type
-
reference_url
-
The URL for the reference
+
distribution_url
+
The URL for the distribution
label
-
The label for the reference, if the reference type is labeled
+
The label for the distribution, if the reference type is labeled
- + \ No newline at end of file diff --git a/app/views/admin/document_distributions/edit.html.erb b/app/views/admin/document_distributions/edit.html.erb new file mode 100644 index 00000000..2295de62 --- /dev/null +++ b/app/views/admin/document_distributions/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :title, "Editing document distribution" %> + +

Editing document distribution

+ +<%= render "form", document_distribution: @document_distribution %> + +
+ +
+ <%= link_to "Show this document distribution", admin_document_document_distribution_path(@document, @document_distribution) %> | + <%= link_to "Back to document distributions", admin_document_document_distributions_path(@document) %> +
diff --git a/app/views/admin/document_references/import.html.erb b/app/views/admin/document_distributions/import.html.erb similarity index 69% rename from app/views/admin/document_references/import.html.erb rename to app/views/admin/document_distributions/import.html.erb index 514cebd7..8055b6e5 100644 --- a/app/views/admin/document_references/import.html.erb +++ b/app/views/admin/document_distributions/import.html.erb @@ -1,9 +1,9 @@

<%= notice %>

- Document · References + Document · Distributions <% if params[:document_id] %> - <%= link_to '+ New Reference', new_admin_document_document_reference_path(@document), { class: 'btn btn-primary float-right' } %> + <%= link_to '+ New Distribution', new_admin_document_document_distribution_path(@document), { class: 'btn btn-primary float-right' } %> <% end %>

@@ -16,14 +16,14 @@ <% end %>

Upload a CSV File

- <%= simple_form_for DocumentReference.new, url: import_admin_document_references_path, method: :post, multipart: true do |f| %> + <%= simple_form_for DocumentDistribution.new, url: import_admin_document_distributions_path, method: :post, multipart: true do |f| %>
- <%= f.simple_fields_for :references do |reference_fields| %> - <%= reference_fields.input :file, as: :file, input_html: {} %> + <%= f.simple_fields_for :distributions do |distribution_fields| %> + <%= distribution_fields.input :file, as: :file, input_html: {} %> <%- end %>
@@ -39,7 +39,7 @@ friendlier_id reference_type - reference_url + distribution_url label @@ -71,10 +71,10 @@
The associated document's friendlier id
reference_type
The name of the reference type
-
reference_url
-
The URL for the reference
+
distribution_url
+
The URL for the distribution
label
-
The label for the reference, if the reference type is labeled
+
The label for the distribution, if the reference type is labeled
diff --git a/app/views/admin/document_references/index.html.erb b/app/views/admin/document_distributions/index.html.erb similarity index 69% rename from app/views/admin/document_references/index.html.erb rename to app/views/admin/document_distributions/index.html.erb index 96030738..675c854f 100644 --- a/app/views/admin/document_references/index.html.erb +++ b/app/views/admin/document_distributions/index.html.erb @@ -1,17 +1,17 @@ -<%- @page_title = "GBL♦Admin - Document - Download Links" %> +<%- @page_title = "GBL♦Admin - Document - Distributions" %>

- Document · References + Document · Distributions <% if params[:document_id] %> - <%= link_to '+ Import CSV', import_admin_document_document_references_path(@document), { class: 'btn btn-primary float-right' } %> + <%= link_to '+ Import CSV', import_admin_document_document_distributions_path(@document), { class: 'btn btn-primary float-right' } %> - <%= link_to '+ New Reference', new_admin_document_document_reference_path(@document), { class: 'btn btn-primary float-right mr-2' } %> + <%= link_to '+ New Distribution', new_admin_document_document_distribution_path(@document), { class: 'btn btn-primary float-right mr-2' } %> <% else %> - <%= link_to '- Delete CSV', destroy_all_admin_document_references_path, { class: 'btn btn-danger float-right' } %> - <%= link_to '+ Import CSV', import_admin_document_references_path, { class: 'btn btn-primary float-right mr-4' } %> + <%= link_to '- Delete CSV', destroy_all_admin_document_distributions_path, { class: 'btn btn-danger float-right' } %> + <%= link_to '+ Import CSV', import_admin_document_distributions_path, { class: 'btn btn-primary float-right mr-4' } %> <% end %>

@@ -19,10 +19,10 @@

<%= link_to(@document.title, admin_document_path(@document)) %> · - <%= @document_references.count %> references + <%= @document_distributions.count %> distributions

<% else %> -

References

+

Distributions

<% end %> @@ -58,7 +58,7 @@ <% end %> <% if @document %> -

External – Document References

+

External – Document Distributions

<% end %> @@ -74,15 +74,15 @@ - <% @document_references.each do |document_reference| %> + <% @document_distributions.each do |document_distribution| %> - - - - - - - + + + + + + + <% end %> @@ -108,9 +108,9 @@ <% if params[:document_id] %>

Ruby Hash

- <%= ap(@document.references).html_safe %> + <%= ap(@document.distributions).html_safe %>

JSON

- <%= ap(@document.references.to_json).html_safe %> + <%= ap(@document.distributions.to_json).html_safe %>
@@ -127,7 +127,7 @@
- <% @document.references_csv.each do |row| %> + <% @document.distributions_csv.each do |row| %> <% row.each do |value| %> diff --git a/app/views/admin/document_distributions/index.json.jbuilder b/app/views/admin/document_distributions/index.json.jbuilder new file mode 100644 index 00000000..58f5e140 --- /dev/null +++ b/app/views/admin/document_distributions/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @document_distributions, partial: "document_distributions/document_distribution", as: :document_distribution diff --git a/app/views/admin/document_distributions/new.html.erb b/app/views/admin/document_distributions/new.html.erb new file mode 100644 index 00000000..35eb1d70 --- /dev/null +++ b/app/views/admin/document_distributions/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "New document distribution" %> + +

New document distribution

+ +<%= render "form", document_distribution: @document_distribution %> + +
+ +
+ <%= link_to "Back to document distributions", admin_document_document_distributions_path(@document) %> +
diff --git a/app/views/admin/document_distributions/show.html.erb b/app/views/admin/document_distributions/show.html.erb new file mode 100644 index 00000000..62fa95d7 --- /dev/null +++ b/app/views/admin/document_distributions/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +<%= render @document_distribution %> + +
+ <%= link_to "Edit this document distribution", edit_admin_document_document_distribution_path(@document, @document_distribution) %> | + <%= link_to "Back to document distributions", admin_document_document_distributions_path(@document) %> + + <%= button_to "Destroy this document distribution", admin_document_document_distribution_path(@document, @document_distribution), method: :delete %> +
diff --git a/app/views/admin/document_distributions/show.json.jbuilder b/app/views/admin/document_distributions/show.json.jbuilder new file mode 100644 index 00000000..52d63fc8 --- /dev/null +++ b/app/views/admin/document_distributions/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "document_distributions/document_distribution", document_distribution: @document_distribution diff --git a/app/views/admin/document_references/_document_reference.html.erb b/app/views/admin/document_references/_document_reference.html.erb deleted file mode 100644 index df6395c1..00000000 --- a/app/views/admin/document_references/_document_reference.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -<%- @page_title = "GBL♦Admin - Document - Reference - #{document_reference.url}" %> - -

Reference

- -
-
-

- <%= document_reference.url %> - - <%= link_to '~ Edit Reference', edit_admin_document_document_reference_path(@document, document_reference), { class: 'btn btn-primary' } %> - <%= button_to "Destroy this reference", admin_document_document_reference_path(@document, document_reference), method: :delete, class: "btn btn-danger" %> - -

- -
<%= link_to document_reference.friendlier_id, admin_document_path(document_reference.document) %><%= document_reference.reference_type.reference_type %><%= document_reference.reference_type.reference_uri %><%= link_to document_reference.url, document_reference.url, target: '_blank' %><%= document_reference.label %><%= link_to 'Edit', edit_admin_document_document_reference_path(document_reference.document, document_reference) %><%= link_to 'Destroy', admin_document_document_reference_path(document_reference.document, document_reference), method: :delete, data: { confirm: 'Are you sure?' } %><%= link_to document_distribution.friendlier_id, admin_document_path(document_distribution.document) %><%= document_distribution.reference_type.reference_type %><%= document_distribution.reference_type.reference_uri %><%= link_to document_distribution.url, document_distribution.url, target: '_blank' %><%= document_distribution.label %><%= link_to 'Edit', edit_admin_document_document_distribution_path(document_distribution.document, document_distribution) %><%= link_to 'Destroy', admin_document_document_distribution_path(document_distribution.document, document_distribution), method: :delete, data: { confirm: 'Are you sure?' } %>
<%= value %>
- - - - - - - - - - - - - - - - - - -
AttributeValue
Reference Type<%= document_reference.reference_type.reference_type %>
Reference URL<%= document_reference.url %>
Label<%= document_reference.label %>
-
-
- -<%= link_to 'Edit', edit_admin_document_document_reference_path(@document, document_reference) %> | -<%= link_to 'Back', admin_document_document_references_path(@document) %> diff --git a/app/views/admin/document_references/_document_reference.json.jbuilder b/app/views/admin/document_references/_document_reference.json.jbuilder deleted file mode 100644 index c4a3bc05..00000000 --- a/app/views/admin/document_references/_document_reference.json.jbuilder +++ /dev/null @@ -1,2 +0,0 @@ -json.extract! document_reference, :id, :created_at, :updated_at -json.url document_reference_url(document_reference, format: :json) diff --git a/app/views/admin/document_references/edit.html.erb b/app/views/admin/document_references/edit.html.erb deleted file mode 100644 index 33973229..00000000 --- a/app/views/admin/document_references/edit.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -<% content_for :title, "Editing document reference" %> - -

Editing document reference

- -<%= render "form", document_reference: @document_reference %> - -
- -
- <%= link_to "Show this document reference", admin_document_document_reference_path(@document, @document_reference) %> | - <%= link_to "Back to document references", admin_document_document_references_path(@document) %> -
diff --git a/app/views/admin/document_references/index.json.jbuilder b/app/views/admin/document_references/index.json.jbuilder deleted file mode 100644 index 78a879fd..00000000 --- a/app/views/admin/document_references/index.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.array! @document_references, partial: "document_references/document_reference", as: :document_reference diff --git a/app/views/admin/document_references/new.html.erb b/app/views/admin/document_references/new.html.erb deleted file mode 100644 index 2741faa1..00000000 --- a/app/views/admin/document_references/new.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -<% content_for :title, "New document reference" %> - -

New document reference

- -<%= render "form", document_reference: @document_reference %> - -
- -
- <%= link_to "Back to document references", admin_document_document_references_path(@document) %> -
diff --git a/app/views/admin/document_references/show.html.erb b/app/views/admin/document_references/show.html.erb deleted file mode 100644 index 2bb86656..00000000 --- a/app/views/admin/document_references/show.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -

<%= notice %>

- -<%= render @document_reference %> - -
- <%= link_to "Edit this document reference", edit_admin_document_document_reference_path(@document, @document_reference) %> | - <%= link_to "Back to document references", admin_document_document_references_path(@document) %> - - <%= button_to "Destroy this document reference", admin_document_document_reference_path(@document, @document_reference), method: :delete %> -
diff --git a/app/views/admin/document_references/show.json.jbuilder b/app/views/admin/document_references/show.json.jbuilder deleted file mode 100644 index cfce5da6..00000000 --- a/app/views/admin/document_references/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.partial! "document_references/document_reference", document_reference: @document_reference diff --git a/app/views/admin/documents/_form_nav.html.erb b/app/views/admin/documents/_form_nav.html.erb index 645e806f..ea0922fc 100644 --- a/app/views/admin/documents/_form_nav.html.erb +++ b/app/views/admin/documents/_form_nav.html.erb @@ -32,9 +32,9 @@ Additional Assets <%= @document.document_assets.count %> <% end %> - <%= link_to admin_document_document_references_url(@document), class: "ml-2" do %> - References - <%= @document.document_references.size %> + <%= link_to admin_document_document_distributions_url(@document), class: "ml-2" do %> + Distributions + <%= @document.distributions.size %> <% end %> <% end %> diff --git a/app/views/admin/documents/_json_aardvark.jbuilder b/app/views/admin/documents/_json_aardvark.jbuilder index 6d4a1b25..d7e9b01e 100644 --- a/app/views/admin/documents/_json_aardvark.jbuilder +++ b/app/views/admin/documents/_json_aardvark.jbuilder @@ -38,7 +38,7 @@ json.dct_accessRights_s no_json_blanks document.send(GeoblacklightAdmin::Schema. json.dct_format_s no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:format]) json.gbl_fileSize_s no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:file_size]) json.gbl_wxsIdentifier_s no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:wxs_identifier]) -json.dct_references_s no_json_blanks document.references_json +json.dct_references_s no_json_blanks document.distributions_json json.id no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:id]) json.dct_identifier_sm no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:identifier]) json.gbl_mdModified_dt no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:updated_at]) diff --git a/app/views/admin/documents/_json_gbl_v1.jbuilder b/app/views/admin/documents/_json_gbl_v1.jbuilder index ee495882..58d42ceb 100644 --- a/app/views/admin/documents/_json_gbl_v1.jbuilder +++ b/app/views/admin/documents/_json_gbl_v1.jbuilder @@ -18,7 +18,7 @@ json.dc_creator_sm no_json_blanks document.send(GeoblacklightAdmin::Schema.insta json.dc_description_s no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:description]).join("|") json.dc_format_s no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:format]) json.dc_subject_sm no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:subject]) -json.dct_references_s no_json_blanks document.references_json +json.dct_references_s no_json_blanks document.distributions_json json.dct_spatial_sm no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:spatial_coverage]) json.layer_modified_dt no_json_blanks document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:updated_at]) diff --git a/app/views/admin/ids/fetch.json.jbuilder b/app/views/admin/ids/fetch.json.jbuilder index cf3427e0..a672db9e 100644 --- a/app/views/admin/ids/fetch.json.jbuilder +++ b/app/views/admin/ids/fetch.json.jbuilder @@ -1,5 +1,3 @@ -# frozen_string_literal: true - json.links do json.self url_for(search_state.to_h.merge(only_path: false)) json.prev url_for(search_state.to_h.merge(only_path: false, page: @response.prev_page.to_s)) if @response.prev_page diff --git a/app/views/admin/ids/index.json.jbuilder b/app/views/admin/ids/index.json.jbuilder index 0e156b9e..7acbc564 100644 --- a/app/views/admin/ids/index.json.jbuilder +++ b/app/views/admin/ids/index.json.jbuilder @@ -1,5 +1,3 @@ -# frozen_string_literal: true - json.links do json.self url_for(search_state.to_h.merge(only_path: false)) json.prev url_for(search_state.to_h.merge(only_path: false, page: @response.prev_page.to_s)) if @response.prev_page diff --git a/app/views/admin/shared/_navbar.html.erb b/app/views/admin/shared/_navbar.html.erb index c088401c..e6b7142e 100644 --- a/app/views/admin/shared/_navbar.html.erb +++ b/app/views/admin/shared/_navbar.html.erb @@ -53,7 +53,7 @@ <%= link_to "Assets", admin_assets_path, {class: 'dropdown-item'} %> <%= link_to "Access Links", admin_document_accesses_path, {class: 'dropdown-item'} %> <%= link_to "Download Links", admin_document_downloads_path, {class: 'dropdown-item'} %> - <%= link_to "References", admin_document_references_path, {class: 'dropdown-item'} %> + <%= link_to "References", admin_document_distributions_path, {class: 'dropdown-item'} %> <%= link_to "Blazer", '/admin/blazer', {class: 'dropdown-item', data: { turbolinks: false }} %> diff --git a/db/migrate/20241120238823_rename_references_to_distributions.rb b/db/migrate/20241120238823_rename_references_to_distributions.rb new file mode 100644 index 00000000..bc965417 --- /dev/null +++ b/db/migrate/20241120238823_rename_references_to_distributions.rb @@ -0,0 +1,5 @@ +class RenameReferencesToDistributions < ActiveRecord::Migration[7.2] + def change + rename_table :document_references, :document_distributions + end +end \ No newline at end of file diff --git a/db/seeds_elements.csv b/db/seeds_elements.csv index 10263865..0d78f387 100644 --- a/db/seeds_elements.csv +++ b/db/seeds_elements.csv @@ -37,7 +37,7 @@ License,dct_license_sm,https://opengeometadata.org/ogm-aardvark/#license,string, Access Rights,dct_accessRights_s,https://opengeometadata.org/ogm-aardvark/#access-rights,string,TRUE,FALSE,TRUE,,,access-rights1|access-rights2,access_rights,,,FALSE,TRUE,FALSE,,TRUE,,TRUE,,presence,36 Format,dct_format_s,https://opengeometadata.org/ogm-aardvark/#format,string,FALSE,FALSE,TRUE,,,format,formats,autocomplete,,FALSE,TRUE,FALSE,,TRUE,,TRUE,,,37 File Size,gbl_fileSize_s,https://opengeometadata.org/ogm-aardvark/#file-size,string,FALSE,FALSE,TRUE,,,60mb,,,,FALSE,TRUE,FALSE,,TRUE,,TRUE,,,38 -Reference,dct_references_s,https://opengeometadata.org/ogm-aardvark/#references,text,FALSE,TRUE,TRUE,,URIs and Values,,reference_values,,,FALSE,TRUE,FALSE,build_dct_references,TRUE,references_json,TRUE,references_json,,39 +Reference,dct_references_s,https://opengeometadata.org/ogm-aardvark/#references,text,FALSE,TRUE,TRUE,,URIs and Values,,reference_values,,,FALSE,TRUE,FALSE,build_dct_references,TRUE,distributions_json,TRUE,distributions_json,,39 WxS Identifier,gbl_wxsIdentifier_s,https://opengeometadata.org/ogm-aardvark/#wxs-identifier,string,FALSE,FALSE,TRUE,,,wxs-identifier,,,,FALSE,TRUE,FALSE,,TRUE,,TRUE,,,40 B1G Image URL,b1g_image_ss,https://geobtaa.github.io/metadata/b1g-custom-elements/#image,string,FALSE,FALSE,TRUE,,,image,,,,FALSE,TRUE,FALSE,,TRUE,,TRUE,,,41 ID,geomg_id_s,https://opengeometadata.org/ogm-aardvark/#id,string,TRUE,FALSE,TRUE,,,slug,,disable_if_persisted,,FALSE,TRUE,FALSE,,TRUE,,TRUE,,presence,42 diff --git a/db/seeds_elements.numbers b/db/seeds_elements.numbers index 22d4fccf6f9596c612256332fc9135e29c3ed89d..5812162450fcae21863e61259ed46f0361daac33 100755 GIT binary patch delta 7406 zcma($30M=?*7qb6oP=Z;0)Y?~f#QaO5Rd>yFd-;fs20Vd&sL+vN}r+y)Y{sD0xBp7 zj5^>#0>I*Xg$vC6A7SaP7%mi>k!NIy!#zw~xv%v~F+t)~ z3OqtAme|<|T}`_6%8ooLf$!3-XYScLB^Y;Y5_9LP*Ia~*Ap5XuQ=)ZCCdF&xb#8vX zK7J$QeY^LZi>_M5OGvygnA5pG_YX6B)weS^?F2BP#qQ+m&-wO`v=6}5>5X3bRQ zD|_|IM1yjkUkqox|WY2IX3VGToreFeumY{Rjc@J|n`pv3|&7r9rvMpj>TGrW%xK%oDpn@tXmz z=q=9#^~QNiisY2ZF@2 zdI>0zgVH(hdCxkuVjV)6yzfyKCddm<(UZ63`$xxP$(9Vm*;B;!_)iMxUk;%tv-rl-i{pLK-Y2}><_8(8W+XmCnEbtDu!}>BU z6rr!`r7Nu~FkJ`6He+&WRL5PaJ%Br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@ -1,13 +1,20 @@ # Upgrading -## 0.4.2 +## Steps for v0.5.0 +### Database Migrations * Copy migration for `reference_types` table * Copy migration for `documents_references` table +* Copy migration to rename `documents_references` to `document_distributions` * Seed the `reference_types` table + +### Application Changes * Mimetypes need to be updated in the application * New routes for reference types and documents references * Solr schema changes - new copyfield for database index auditing +* Set env var for `GBL_ADMIN_REFERENCES_MIGRATED` to `false` * Migrate existing `dct_reference_s` values to the new `document_reference` table * `rake geoblacklight_admin:references:migrate` * Audit the references migration + * `rake geoblacklight_admin:references:audit` +* Set env var for `GBL_ADMIN_REFERENCES_MIGRATED` to `true` diff --git a/lib/generators/geoblacklight_admin/config_generator.rb b/lib/generators/geoblacklight_admin/config_generator.rb index b372094b..84f1f683 100644 --- a/lib/generators/geoblacklight_admin/config_generator.rb +++ b/lib/generators/geoblacklight_admin/config_generator.rb @@ -213,7 +213,7 @@ def set_routes end # Document References - resources :document_references, path: "references" do + resources :document_distributions, path: "distributions" do collection do get "display_attach_form" post "attach_files" @@ -249,8 +249,8 @@ def set_routes end end - # Document References - resources :document_references, path: "references" do + # Document Distributions + resources :document_distributions, path: "distributions" do collection do get "import" post "import" diff --git a/lib/generators/geoblacklight_admin/templates/config/initializers/mime_types.rb b/lib/generators/geoblacklight_admin/templates/config/initializers/mime_types.rb index 6fabbade..3426ef92 100644 --- a/lib/generators/geoblacklight_admin/templates/config/initializers/mime_types.rb +++ b/lib/generators/geoblacklight_admin/templates/config/initializers/mime_types.rb @@ -13,4 +13,4 @@ Mime::Type.register "text/csv", :csv_document_downloads Mime::Type.register "text/csv", :csv_document_access_links -Mime::Type.register "text/csv", :csv_document_references +Mime::Type.register "text/csv", :csv_document_distributions diff --git a/lib/geoblacklight_admin/tasks/references.rake b/lib/geoblacklight_admin/tasks/distributions.rake similarity index 59% rename from lib/geoblacklight_admin/tasks/references.rake rename to lib/geoblacklight_admin/tasks/distributions.rake index 6bd3bf16..63a407b2 100644 --- a/lib/geoblacklight_admin/tasks/references.rake +++ b/lib/geoblacklight_admin/tasks/distributions.rake @@ -1,23 +1,23 @@ namespace :geoblacklight_admin do - namespace :references do - desc "Migrate references into DocumentReferences" + namespace :distributions do + desc "Migrate distributions into DocumentDistributions" task migrate: :environment do total_documents_processed = 0 puts "\n--- Migration Start ---" Document.find_in_batches(batch_size: 1000) do |documents| documents.each do |document| - # Moves AttrJson-based dct_references_s and Multiple Downloads into DocumentReferences + # Moves AttrJson-based dct_references_s and Multiple Downloads into DocumentDistributions - document.references_csv.each do |reference| - DocumentReference.find_or_create_by!( - friendlier_id: reference[0], - reference_type_id: ReferenceType.find_by(name: reference[1]).id, - url: reference[2], - label: reference[3] + document.distributions_csv.each do |distribution| + DocumentDistribution.find_or_create_by!( + friendlier_id: distribution[0], + reference_type_id: ReferenceType.find_by(name: distribution[1]).id, + url: distribution[2], + label: distribution[3] ) end rescue => e - puts "\nError processing references for document: #{document.friendlier_id} - #{e.inspect}\n" + puts "\nError processing distributions for document: #{document.friendlier_id} - #{e.inspect}\n" end total_documents_processed += documents.size puts "Processed #{documents.size} documents in this batch, total processed: #{total_documents_processed}" @@ -25,26 +25,26 @@ namespace :geoblacklight_admin do puts "--- Migration End ---\n" end - desc "Audit the references migration" + desc "Audit the distributions migration" task audit: :environment do total_documents_processed = 0 puts "\n--- Audit Start ---" Document.find_in_batches(batch_size: 1000) do |documents| documents.each do |document| - # Document > References as CSV + # Document > Distributions as CSV dr_csv = document.references_csv.sort - # document_references - doc_refs = document.document_references.collect { |dr| dr.to_csv }.sort + # document_distributions + doc_dists = document.document_distributions.collect { |dr| dr.to_csv }.sort - if dr_csv != doc_refs + if dr_csv != doc_dists puts "\nNO MATCH" puts "Document: #{document.friendlier_id}" - puts "CSV References Sorted: #{dr_csv.sort.inspect}" - puts "Document References Sorted: #{doc_refs.sort.inspect}\n" + puts "CSV Distributions Sorted: #{dr_csv.sort.inspect}" + puts "Document Distributions Sorted: #{doc_dists.sort.inspect}\n" end rescue => e - puts "\nError auditing references for document: #{document.friendlier_id} - #{e.inspect}\n" + puts "\nError auditing distributions for document: #{document.friendlier_id} - #{e.inspect}\n" end total_documents_processed += documents.size puts "Processed #{documents.size} documents in this batch, total processed: #{total_documents_processed}" @@ -57,7 +57,7 @@ namespace :geoblacklight_admin do # Done: Remove multiple download links from Documents # Done: Remove multiple download links from FormElements (it's a feature there) # Done: Remove multiple download links from FormNav (link) - # Done: Add DocumentReferences to the FormElements (as a feature - manual) + # Done: Add DocumentDistributions to the FormElements (as a feature - manual) # Step 2 - Finalize # Remove AttrJson dct_references_s values from Documents (data is redundant and/or incorrect) diff --git a/test/controllers/document_distributions_controller_test.rb b/test/controllers/document_distributions_controller_test.rb new file mode 100644 index 00000000..31cb2790 --- /dev/null +++ b/test/controllers/document_distributions_controller_test.rb @@ -0,0 +1,79 @@ +require "test_helper" + +class DocumentReferencesControllerTest < ActionDispatch::IntegrationTest + setup do + @document = documents(:ls) + @document_distribution = document_distributions(:one) + @file = fixture_file_upload("import_distributions.csv", "text/csv") + + get "/users/sign_in" + sign_in_as users(:user_001) + post user_session_url + + follow_redirect! + assert_response :success + end + + test "should get index" do + get admin_document_document_distributions_url(@document) + assert_response :success + end + + test "should get new" do + get new_admin_document_document_distribution_url(@document) + assert_response :success + end + + test "should create document_distribution" do + assert_difference("DocumentDistribution.count") do + post admin_document_document_distributions_url(@document), params: {document_distribution: { + friendlier_id: "35c8a641589c4e13b7aa11e37f3f00a1_0", + reference_type_id: ReferenceType.first.id, + url: "https://example.com" + }} + end + + assert_redirected_to admin_document_document_distributions_url(@document) + end + + test "should show document_distribution" do + get admin_document_document_distribution_url(@document, @document_distribution) + assert_response :success + end + + test "should get edit" do + get edit_admin_document_document_distribution_url(@document, @document_distribution) + assert_response :success + end + + test "should update document_distribution" do + patch admin_document_document_distribution_url(@document, @document_distribution), params: { + document_distribution: { + friendlier_id: "35c8a641589c4e13b7aa11e37f3f00a1_0", + reference_type_id: ReferenceType.first.id, + url: "https://example2.com" + } + } + assert_redirected_to admin_document_document_distributions_url(@document) + end + + test "should destroy document_distribution" do + assert_difference("DocumentDistribution.count", -1) do + delete admin_document_document_distribution_url(@document, @document_distribution) + end + + assert_redirected_to admin_document_document_distributions_url(@document) + end + + test "should import distributions successfully" do + post import_admin_document_distributions_url(@document), params: {document_id: @document.friendlier_id, document_distribution: {distributions: {file: @file}}} + assert_redirected_to admin_document_document_distributions_path(@document) + assert_equal "Distributions were created successfully.", flash[:notice] + end + + test "should not import distributions with invalid file" do + post import_admin_document_distributions_url(@document), params: {document_id: @document.friendlier_id, document_distribution: {distributions: {file: nil}}} + assert_redirected_to admin_document_document_distributions_path(@document) + assert_equal "Distributions could not be created. File does not exist or is invalid.", flash[:notice] + end +end diff --git a/test/controllers/document_references_controller_test.rb b/test/controllers/document_references_controller_test.rb deleted file mode 100644 index 1008b5ef..00000000 --- a/test/controllers/document_references_controller_test.rb +++ /dev/null @@ -1,79 +0,0 @@ -require "test_helper" - -class DocumentReferencesControllerTest < ActionDispatch::IntegrationTest - setup do - @document = documents(:ls) - @document_reference = document_references(:one) - @file = fixture_file_upload("import_references.csv", "text/csv") - - get "/users/sign_in" - sign_in_as users(:user_001) - post user_session_url - - follow_redirect! - assert_response :success - end - - test "should get index" do - get admin_document_document_references_url(@document) - assert_response :success - end - - test "should get new" do - get new_admin_document_document_reference_url(@document) - assert_response :success - end - - test "should create document_reference" do - assert_difference("DocumentReference.count") do - post admin_document_document_references_url(@document), params: {document_reference: { - friendlier_id: "35c8a641589c4e13b7aa11e37f3f00a1_0", - reference_type_id: ReferenceType.first.id, - url: "https://example.com" - }} - end - - assert_redirected_to admin_document_document_references_url(@document) - end - - test "should show document_reference" do - get admin_document_document_reference_url(@document, @document_reference) - assert_response :success - end - - test "should get edit" do - get edit_admin_document_document_reference_url(@document, @document_reference) - assert_response :success - end - - test "should update document_reference" do - patch admin_document_document_reference_url(@document, @document_reference), params: { - document_reference: { - friendlier_id: "35c8a641589c4e13b7aa11e37f3f00a1_0", - reference_type_id: ReferenceType.first.id, - url: "https://example2.com" - } - } - assert_redirected_to admin_document_document_reference_url(@document, @document_reference) - end - - test "should destroy document_reference" do - assert_difference("DocumentReference.count", -1) do - delete admin_document_document_reference_url(@document, @document_reference) - end - - assert_redirected_to admin_document_document_references_url(@document) - end - - test "should import references successfully" do - post import_admin_document_references_url(@document), params: {document_id: @document.friendlier_id, document_reference: {references: {file: @file}}} - assert_redirected_to admin_document_document_references_path(@document) - assert_equal "References were created successfully.", flash[:notice] - end - - test "should not import references with invalid file" do - post import_admin_document_references_url(@document), params: {document_id: @document.friendlier_id, document_reference: {references: {file: nil}}} - assert_redirected_to admin_document_document_references_path(@document) - assert_equal "References could not be created. File does not exist or is invalid.", flash[:notice] - end -end diff --git a/test/fixtures/document_references.yml b/test/fixtures/document_distributions.yml similarity index 100% rename from test/fixtures/document_references.yml rename to test/fixtures/document_distributions.yml diff --git a/test/fixtures/files/import_references.csv b/test/fixtures/files/import_distributions.csv similarity index 73% rename from test/fixtures/files/import_references.csv rename to test/fixtures/files/import_distributions.csv index fd6a5915..d45a1827 100644 --- a/test/fixtures/files/import_references.csv +++ b/test/fixtures/files/import_distributions.csv @@ -1,4 +1,4 @@ -friendlier_id,reference_type,reference_url,label +friendlier_id,reference_type,distribution_url,label p16022coll205:446,iiif_image,http://foo.com, p16022coll205:446,metadata_html,http://bar.com, p16022coll205:446,documentation_download,http://baz.com, \ No newline at end of file diff --git a/test/models/document_distribution_test.rb b/test/models/document_distribution_test.rb new file mode 100644 index 00000000..a2c78bf5 --- /dev/null +++ b/test/models/document_distribution_test.rb @@ -0,0 +1,81 @@ +require "test_helper" + +class DocumentDistributionTest < ActiveSupport::TestCase + def setup + @document_distribution = DocumentDistribution.new( + friendlier_id: documents(:ls).friendlier_id, + reference_type_id: ReferenceType.first.id, + url: "http://example.com", + label: "Example Label" + ) + end + + test "should be valid" do + assert @document_distribution.valid? + end + + test "friendlier_id should be present" do + @document_distribution.friendlier_id = nil + assert_not @document_distribution.valid? + end + + test "reference_type should be present" do + @document_distribution.reference_type = nil + assert_not @document_distribution.valid? + end + + test "url should be present" do + @document_distribution.url = nil + assert_not @document_distribution.valid? + end + + test "url should be unique scoped to friendlier_id and reference_type_id" do + duplicate_distribution = @document_distribution.dup + @document_distribution.save + assert_not duplicate_distribution.valid? + end + + test "should convert to CSV" do + expected_csv = [ + @document_distribution.friendlier_id, + @document_distribution.reference_type.name, + @document_distribution.url, + @document_distribution.label + ] + assert_equal expected_csv, @document_distribution.to_csv + end + + test "should convert to aardvark distribution" do + expected_aardvark = { + @document_distribution.reference_type.reference_uri.to_s => @document_distribution.url + } + expected_aardvark[:label] = @document_distribution.label if @document_distribution.reference_type.reference_uri.to_s == "http://schema.org/downloadUrl" + assert_equal expected_aardvark, @document_distribution.to_aardvark_distribution + end + + test "should import from CSV" do + file_path = File.expand_path("../../../test/fixtures/files/import_distributions.csv", __FILE__) + file = File.open(file_path) + assert_difference "DocumentDistribution.count", 3 do + DocumentDistribution.import(file) + end + end + + test "should destroy all from CSV" do + file_path = File.expand_path("../../../test/fixtures/files/import_distributions.csv", __FILE__) + file = File.open(file_path) + DocumentDistribution.import(file) + assert_difference "DocumentDistribution.count", -3 do + DocumentDistribution.destroy_all(file) + end + end + + test "should reindex document after save" do + document = documents(:ag) + @document_distribution.document = document + @document_distribution.save + assert document.saved_changes? + end + + # Add more tests for edge cases and other methods as needed +end diff --git a/test/models/document_reference_test.rb b/test/models/document_reference_test.rb deleted file mode 100644 index e75b372c..00000000 --- a/test/models/document_reference_test.rb +++ /dev/null @@ -1,81 +0,0 @@ -require "test_helper" - -class DocumentReferenceTest < ActiveSupport::TestCase - def setup - @document_reference = DocumentReference.new( - friendlier_id: documents(:ls).friendlier_id, - reference_type_id: ReferenceType.first.id, - url: "http://example.com", - label: "Example Label" - ) - end - - test "should be valid" do - assert @document_reference.valid? - end - - test "friendlier_id should be present" do - @document_reference.friendlier_id = nil - assert_not @document_reference.valid? - end - - test "reference_type should be present" do - @document_reference.reference_type = nil - assert_not @document_reference.valid? - end - - test "url should be present" do - @document_reference.url = nil - assert_not @document_reference.valid? - end - - test "url should be unique scoped to friendlier_id and reference_type_id" do - duplicate_reference = @document_reference.dup - @document_reference.save - assert_not duplicate_reference.valid? - end - - test "should convert to CSV" do - expected_csv = [ - @document_reference.friendlier_id, - @document_reference.reference_type.name, - @document_reference.url, - @document_reference.label - ] - assert_equal expected_csv, @document_reference.to_csv - end - - test "should convert to aardvark reference" do - expected_aardvark = { - @document_reference.reference_type.reference_uri.to_s => @document_reference.url - } - expected_aardvark[:label] = @document_reference.label if @document_reference.reference_type.reference_uri.to_s == "http://schema.org/downloadUrl" - assert_equal expected_aardvark, @document_reference.to_aardvark_reference - end - - test "should import from CSV" do - file_path = File.expand_path("../../../test/fixtures/files/import_references.csv", __FILE__) - file = File.open(file_path) - assert_difference "DocumentReference.count", 3 do - DocumentReference.import(file) - end - end - - test "should destroy all from CSV" do - file_path = File.expand_path("../../../test/fixtures/files/import_references.csv", __FILE__) - file = File.open(file_path) - DocumentReference.import(file) - assert_difference "DocumentReference.count", -3 do - DocumentReference.destroy_all(file) - end - end - - test "should reindex document after save" do - document = documents(:ag) - @document_reference.document = document - @document_reference.save - assert document.saved_changes? - end - - # Add more tests for edge cases and other methods as needed -end diff --git a/test/services/export_csv_document_distributions_service_test.rb b/test/services/export_csv_document_distributions_service_test.rb new file mode 100644 index 00000000..f59f3d5e --- /dev/null +++ b/test/services/export_csv_document_distributions_service_test.rb @@ -0,0 +1,40 @@ +require "test_helper" + +class ExportCsvDocumentDistributionsServiceTest < ActiveSupport::TestCase + def setup + @document1 = Document.create!(geomg_id_s: "doc1", friendlier_id: "doc1", title: "Document 1", gbl_resourceClass_sm: ["Map"], dct_accessRights_s: "Public") + @document2 = Document.create!(geomg_id_s: "doc2", friendlier_id: "doc2", title: "Document 2", gbl_resourceClass_sm: ["Map"], dct_accessRights_s: "Public") + @distribution1 = DocumentDistribution.create!(document: @document1, reference_type_id: 1, url: "http://b1g.com/") + @distribution2 = DocumentDistribution.create!(document: @document1, reference_type_id: 2, url: "https://btaa.org") + @distribution3 = DocumentDistribution.create!(document: @document2, reference_type_id: 3, url: "https://geo.btaa.org") + end + + test "short_name returns correct value" do + assert_equal "Document Distributions", ExportCsvDocumentDistributionsService.short_name + end + + test "call generates CSV with correct headers and data" do + document_ids = [@document1.friendlier_id, @document2.friendlier_id] + + csv_file = ExportCsvDocumentDistributionsService.call(document_ids) + + assert_includes csv_file, DocumentDistribution.csv_column_names + assert_includes csv_file, @distribution1.to_csv + assert_includes csv_file, @distribution2.to_csv + assert_includes csv_file, @distribution3.to_csv + end + + test "call handles non-existent documents" do + document_ids = [@document1.friendlier_id, "non_existent_id"] + result = ExportCsvDocumentDistributionsService.call(document_ids) + + csv_string = CSV.generate do |csv| + result.each do |row| + csv << row + end + end + + csv_rows = CSV.parse(csv_string) + assert_equal 3, csv_rows.size # Header + 2 document distributions for @document1 + end +end diff --git a/test/services/export_csv_document_references_service_test.rb b/test/services/export_csv_document_references_service_test.rb deleted file mode 100644 index 3e7e5165..00000000 --- a/test/services/export_csv_document_references_service_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require "test_helper" - -class ExportCsvDocumentReferencesServiceTest < ActiveSupport::TestCase - def setup - @document1 = Document.create!(geomg_id_s: "doc1", friendlier_id: "doc1", title: "Document 1", gbl_resourceClass_sm: ["Map"], dct_accessRights_s: "Public") - @document2 = Document.create!(geomg_id_s: "doc2", friendlier_id: "doc2", title: "Document 2", gbl_resourceClass_sm: ["Map"], dct_accessRights_s: "Public") - @reference1 = DocumentReference.create!(document: @document1, reference_type_id: 1, url: "http://b1g.com/") - @reference2 = DocumentReference.create!(document: @document1, reference_type_id: 2, url: "https://btaa.org") - @reference3 = DocumentReference.create!(document: @document2, reference_type_id: 3, url: "https://geo.btaa.org") - end - - test "short_name returns correct value" do - assert_equal "Document References", ExportCsvDocumentReferencesService.short_name - end - - test "call generates CSV with correct headers and data" do - document_ids = [@document1.friendlier_id, @document2.friendlier_id] - - csv_file = ExportCsvDocumentReferencesService.call(document_ids) - - assert_includes csv_file, DocumentReference.csv_column_names - assert_includes csv_file, @reference1.to_csv - assert_includes csv_file, @reference2.to_csv - assert_includes csv_file, @reference3.to_csv - end - - test "call handles non-existent documents" do - document_ids = [@document1.friendlier_id, "non_existent_id"] - result = ExportCsvDocumentReferencesService.call(document_ids) - - csv_string = CSV.generate do |csv| - result.each do |row| - csv << row - end - end - - csv_rows = CSV.parse(csv_string) - assert_equal 3, csv_rows.size # Header + 2 document references for @document1 - end -end diff --git a/test/services/geoblacklight_admin/image_service_test.rb b/test/services/geoblacklight_admin/image_service_test.rb index a15a009d..ec9f35a3 100644 --- a/test/services/geoblacklight_admin/image_service_test.rb +++ b/test/services/geoblacklight_admin/image_service_test.rb @@ -5,13 +5,13 @@ module GeoblacklightAdmin class ImageServiceTest < ActiveSupport::TestCase class MockDocument - attr_reader :id, :thumbnail_state_machine, :viewer_protocol, :references + attr_reader :id, :thumbnail_state_machine, :viewer_protocol, :distributions def initialize @id = "test_doc_id" @thumbnail_state_machine = MockStateMachine.new @viewer_protocol = "wms" - @references = {"http://schema.org/thumbnailUrl" => "http://example.com/reference_thumbnail.jpg"} + @distributions = {"http://schema.org/thumbnailUrl" => "http://example.com/distribution_thumbnail.jpg"} end def local_restricted? @@ -89,10 +89,10 @@ def transition_to!(state, metadata) end end - test "image_url falls back to image_reference when gblsi_thumbnail_uri and service_url are not present" do + test "image_url falls back to image_distribution when gblsi_thumbnail_uri and service_url are not present" do @image_service.stub :gblsi_thumbnail_uri, nil do @image_service.stub :service_url, nil do - assert_equal "http://example.com/reference_thumbnail.jpg", @image_service.send(:image_url) + assert_equal "http://example.com/distribution_thumbnail.jpg", @image_service.send(:image_url) end end end diff --git a/test/services/geoblacklight_admin/item_viewer_test.rb b/test/services/geoblacklight_admin/item_viewer_test.rb index 2c40d467..f8473dd5 100644 --- a/test/services/geoblacklight_admin/item_viewer_test.rb +++ b/test/services/geoblacklight_admin/item_viewer_test.rb @@ -6,12 +6,12 @@ module GeoblacklightAdmin class ItemViewerTest < ActiveSupport::TestCase setup do @document = documents(:ag) # Assuming you have a fixture or factory for documents - @item_viewer = GeoblacklightAdmin::ItemViewer.new(@document.references) - @references = {"http://schema.org/url" => "https://open-iowa.opendata.arcgis.com/datasets/35c8a641589c4e13b7aa11e37f3f00a1_0", "http://schema.org/downloadUrl" => [{"label" => "Original Shapefile", "url" => "https://open-iowa.opendata.arcgis.com/datasets/35c8a641589c4e13b7aa11e37f3f00a1_0.zip"}, {"label" => "Foo", "url" => "http://foo.com"}, {"label" => "Bar", "url" => "http://bar.com"}], "urn:x-esri:serviceType:ArcGIS#FeatureLayer" => "https://services2.arcgis.com/KhKjlwEBlPJd6v51/arcgis/rest/services/AgDistricts/FeatureServer/0"} + @item_viewer = GeoblacklightAdmin::ItemViewer.new(@document.distributions) + @distributions = {"http://schema.org/url"=>"https://open-iowa.opendata.arcgis.com/datasets/35c8a641589c4e13b7aa11e37f3f00a1_0", "http://schema.org/downloadUrl"=>[{"label"=>"Shapefile", "url"=>"https://open-iowa.opendata.arcgis.com/datasets/35c8a641589c4e13b7aa11e37f3f00a1_0.zip"}, {"label"=>"Foo", "url"=>"http://foo.com"}, {"label"=>"Bar", "url"=>"http://bar.com"}, {"label"=>"Asset Label", "url"=>"/uploads/asset/73245320-b305-405e-b4f2-ba3a2726cc23/fdafe052348f6599d47c54a26676bb86.png"}], "urn:x-esri:serviceType:ArcGIS#FeatureLayer"=>"https://services2.arcgis.com/KhKjlwEBlPJd6v51/arcgis/rest/services/AgDistricts/FeatureServer/0"} end - test "should initialize with references and keys" do - assert_equal @references, @item_viewer.instance_variable_get(:@references) + test "should initialize with distributions and keys" do + assert_equal @distributions, @item_viewer.instance_variable_get(:@distributions) assert_equal [:url, :download, :feature_layer], @item_viewer.instance_variable_get(:@keys) end From 2775b54fa7a5ed1976a25b81983589594c85aa02 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 20 Nov 2024 16:34:34 -0600 Subject: [PATCH 2/5] More ref2dist migration --- app/views/admin/documents/admin.html.erb | 10 +++++----- app/views/admin/shared/_navbar.html.erb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/admin/documents/admin.html.erb b/app/views/admin/documents/admin.html.erb index fffe78ea..5a76633b 100644 --- a/app/views/admin/documents/admin.html.erb +++ b/app/views/admin/documents/admin.html.erb @@ -132,12 +132,12 @@
-
-
-
+
@@ -147,7 +147,7 @@ - <% @document.references.each do |entry| %> + <% @document.distributions.each do |entry| %>
<%= entry[0] %> diff --git a/app/views/admin/shared/_navbar.html.erb b/app/views/admin/shared/_navbar.html.erb index e6b7142e..be2b3bda 100644 --- a/app/views/admin/shared/_navbar.html.erb +++ b/app/views/admin/shared/_navbar.html.erb @@ -50,10 +50,10 @@ <%= link_to "Bulk Actions", admin_bulk_actions_path, {class: 'dropdown-item'} %> - <%= link_to "Assets", admin_assets_path, {class: 'dropdown-item'} %> <%= link_to "Access Links", admin_document_accesses_path, {class: 'dropdown-item'} %> + <%= link_to "Assets", admin_assets_path, {class: 'dropdown-item'} %> + <%= link_to "Distributions", admin_document_distributions_path, {class: 'dropdown-item'} %> <%= link_to "Download Links", admin_document_downloads_path, {class: 'dropdown-item'} %> - <%= link_to "References", admin_document_distributions_path, {class: 'dropdown-item'} %> <%= link_to "Blazer", '/admin/blazer', {class: 'dropdown-item', data: { turbolinks: false }} %> From a221cbb04bd59058d560743b27eada1b3d4ca8b1 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 20 Nov 2024 16:34:41 -0600 Subject: [PATCH 3/5] StandardRB --- app/models/document.rb | 2 +- test/services/geoblacklight_admin/item_viewer_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/document.rb b/app/models/document.rb index 2de00537..3a208a9e 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -167,7 +167,7 @@ def distributions_json logger.debug("Document#distributions > #{distributions.inspect}") logger.debug("Document#distributions_json > using distributions") logger.warn("Deprecation warning: AttrJSON-based dct_references_s will not be supported soon.") - distributions.to_json + self.distributions.to_json end end diff --git a/test/services/geoblacklight_admin/item_viewer_test.rb b/test/services/geoblacklight_admin/item_viewer_test.rb index f8473dd5..57f7d38c 100644 --- a/test/services/geoblacklight_admin/item_viewer_test.rb +++ b/test/services/geoblacklight_admin/item_viewer_test.rb @@ -7,7 +7,7 @@ class ItemViewerTest < ActiveSupport::TestCase setup do @document = documents(:ag) # Assuming you have a fixture or factory for documents @item_viewer = GeoblacklightAdmin::ItemViewer.new(@document.distributions) - @distributions = {"http://schema.org/url"=>"https://open-iowa.opendata.arcgis.com/datasets/35c8a641589c4e13b7aa11e37f3f00a1_0", "http://schema.org/downloadUrl"=>[{"label"=>"Shapefile", "url"=>"https://open-iowa.opendata.arcgis.com/datasets/35c8a641589c4e13b7aa11e37f3f00a1_0.zip"}, {"label"=>"Foo", "url"=>"http://foo.com"}, {"label"=>"Bar", "url"=>"http://bar.com"}, {"label"=>"Asset Label", "url"=>"/uploads/asset/73245320-b305-405e-b4f2-ba3a2726cc23/fdafe052348f6599d47c54a26676bb86.png"}], "urn:x-esri:serviceType:ArcGIS#FeatureLayer"=>"https://services2.arcgis.com/KhKjlwEBlPJd6v51/arcgis/rest/services/AgDistricts/FeatureServer/0"} + @distributions = {"http://schema.org/url" => "https://open-iowa.opendata.arcgis.com/datasets/35c8a641589c4e13b7aa11e37f3f00a1_0", "http://schema.org/downloadUrl" => [{"label" => "Shapefile", "url" => "https://open-iowa.opendata.arcgis.com/datasets/35c8a641589c4e13b7aa11e37f3f00a1_0.zip"}, {"label" => "Foo", "url" => "http://foo.com"}, {"label" => "Bar", "url" => "http://bar.com"}, {"label" => "Asset Label", "url" => "/uploads/asset/73245320-b305-405e-b4f2-ba3a2726cc23/fdafe052348f6599d47c54a26676bb86.png"}], "urn:x-esri:serviceType:ArcGIS#FeatureLayer" => "https://services2.arcgis.com/KhKjlwEBlPJd6v51/arcgis/rest/services/AgDistricts/FeatureServer/0"} end test "should initialize with distributions and keys" do From da8da21f21d6b573d5c2de0e83c48ee2052c586b Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 20 Nov 2024 16:38:38 -0600 Subject: [PATCH 4/5] Update .standard.yml --- .standard.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.standard.yml b/.standard.yml index 58c75c81..3a9c4970 100644 --- a/.standard.yml +++ b/.standard.yml @@ -1,4 +1,5 @@ format: progress ignore: - 'db/seeds.rb' - - 'db/migrate/**' \ No newline at end of file + - 'db/migrate/**' + - 'app/models/document/bbox_validator.rb' \ No newline at end of file From b3808da5a769efddef7292f8c4372a05da2a843e Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 20 Nov 2024 16:47:44 -0600 Subject: [PATCH 5/5] Update distributions.rake --- lib/geoblacklight_admin/tasks/distributions.rake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/geoblacklight_admin/tasks/distributions.rake b/lib/geoblacklight_admin/tasks/distributions.rake index 63a407b2..60d85788 100644 --- a/lib/geoblacklight_admin/tasks/distributions.rake +++ b/lib/geoblacklight_admin/tasks/distributions.rake @@ -1,3 +1,6 @@ +require "rake" +require "csv" + namespace :geoblacklight_admin do namespace :distributions do desc "Migrate distributions into DocumentDistributions"