geoblacklight_admin 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -2
  3. data/app/controllers/admin/document_distributions_controller.rb +7 -6
  4. data/app/models/asset.rb +2 -0
  5. data/app/models/document.rb +33 -23
  6. data/app/models/document_distribution.rb +13 -5
  7. data/app/models/geoblacklight_admin.rb +0 -1
  8. data/app/views/admin/advanced_search/facets.json.jbuilder +0 -2
  9. data/app/views/admin/advanced_search/index.json.jbuilder +0 -2
  10. data/app/views/admin/api/_field.json.jbuilder +0 -2
  11. data/app/views/admin/api/fetch.json.jbuilder +0 -2
  12. data/app/views/admin/api/index.json.jbuilder +0 -2
  13. data/app/views/admin/document_distributions/_form.html.erb +1 -1
  14. data/app/views/admin/document_distributions/import.html.erb +4 -1
  15. data/app/views/admin/document_distributions/index.html.erb +26 -26
  16. data/app/views/admin/documents/_form_nav.html.erb +0 -1
  17. data/app/views/admin/documents/_json_aardvark.jbuilder +0 -2
  18. data/app/views/admin/documents/_json_btaa_aardvark.jbuilder +0 -2
  19. data/app/views/admin/documents/_json_file.jbuilder +0 -2
  20. data/app/views/admin/documents/_json_gbl_v1.jbuilder +0 -2
  21. data/app/views/admin/documents/_result_selected_options.html.erb +2 -2
  22. data/app/views/admin/documents/fetch.json_aardvark.jbuilder +0 -2
  23. data/app/views/admin/documents/fetch.json_btaa_aardvark.jbuilder +0 -2
  24. data/app/views/admin/documents/fetch.json_file.jbuilder +0 -2
  25. data/app/views/admin/documents/fetch.json_gbl_v1.jbuilder +0 -2
  26. data/app/views/admin/documents/index.json_aardvark.jbuilder +0 -2
  27. data/app/views/admin/documents/index.json_btaa_aardvark.jbuilder +0 -2
  28. data/app/views/admin/documents/index.json_file.jbuilder +0 -2
  29. data/app/views/admin/documents/index.json_gbl_v1.jbuilder +0 -2
  30. data/app/views/admin/documents/show.json_aardvark.jbuilder +0 -2
  31. data/app/views/admin/documents/show.json_btaa_aardvark.jbuilder +0 -2
  32. data/app/views/admin/documents/show.json_gbl_v1.jbuilder +0 -2
  33. data/app/views/admin/imports/show.html.erb +2 -2
  34. data/lib/generators/geoblacklight_admin/config_generator.rb +1 -1
  35. data/lib/geoblacklight_admin/tasks/distributions.rake +39 -2
  36. data/lib/geoblacklight_admin/version.rb +1 -1
  37. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb7dfdea7cb8626ae4e65999624310642a89c81cea03a8d0e58a5649c080091b
4
- data.tar.gz: e08e45d57f47e372d574e7cce41e1babd93697741a1261a22dcf816e07a0b74b
3
+ metadata.gz: dc6016dba641608f129d84c4c8706fcf2494ddf18b028228799643e0e8b4ef3b
4
+ data.tar.gz: f58448208f48871f44c09588cb0c55d7c8beac7906b608052478aee2eaa587a5
5
5
  SHA512:
6
- metadata.gz: b7e2504e7f0fb46e55e0ba3359577a4d6e90842afa5c6be608e79a52d2b278ec39fe24812b68d8ca6d950ff2ef7842905550bb2a1354ba012f82f8b6349da154
7
- data.tar.gz: d913fe08b848b6b9a2f2cd730570cecbb1f0e98157540b967306fc903ee7433bdae04a422b7d0b06c20678103bd30440bfaa939b04369c9b9f100bdd55611a65
6
+ metadata.gz: c956657c0b5f55f5e9b18eb5712ce35c185bddc498dcd950bcb4a52108ed0961690bbcc4753f6cbbe8cf5702315df4c4bf82dc33154e97a2dd852d367d871f81
7
+ data.tar.gz: 89981e31e878f519ad6cecb42df557cfb7031dcce7b11209c9451355c8e310cfb86957aa16c71dfa46f4686d14fbc9aab0e4868e6059c5722083e6ce9a3ca9fa
data/README.md CHANGED
@@ -69,8 +69,11 @@ The gem is available as open source under the terms of the [Apache 2.0 License](
69
69
  * ~~Debug Rails 7.2 support (remove devise_invitable, see [#915](https://github.com/scambra/devise_invitable/issues/915))~~
70
70
  * ~~Separate dct_references_s support into a separate model~~
71
71
  * ~~Import/Export dct_references_s outside of the main document model~~
72
- * Migrate our GBL API controllers to just RSolr-based models
73
- * DRY up Gem dependencies and Engine routing
72
+ * Data Dictionary: Add support for `document_data_dictionary`
74
73
  * Gazetteer: Add GeoNames support
75
74
  * Gazetteer: Add Who's On First support
75
+ * Gazetteer: Add Ollama support
76
+ * Gazetteer: Add BTAA spatial file support
77
+ * Migrate our GBL API controllers to just RSolr-based models
78
+ * DRY up Gem dependencies and Engine routing
76
79
  * Remove any remaining GEOMG references
@@ -125,19 +125,20 @@ module Admin
125
125
  raise ArgumentError, "File does not exist or is invalid."
126
126
  end
127
127
 
128
- if DocumentDistribution.import(params.dig(:document_distribution, :distributions, :file))
128
+ success, errors = DocumentDistribution.import(params.dig(:document_distribution, :distributions, :file))
129
+ if success == true
129
130
  logger.debug("Distributions were created successfully.")
130
131
  if params[:document_id]
131
132
  redirect_to admin_document_document_distributions_path(@document), notice: "Distributions were created successfully."
132
133
  else
133
- redirect_to admin_document_document_distributions_path, notice: "Distributions were created successfully."
134
+ redirect_to admin_document_distributions_path, notice: "Distributions were created successfully."
134
135
  end
135
136
  else
136
- logger.debug("Distributions could not be created.")
137
+ logger.debug("Some distributions could not be created. #{errors.join(", ")}")
137
138
  if params[:document_id]
138
- redirect_to admin_document_document_distributions_path(@document), warning: "Distributions could not be created."
139
+ redirect_to admin_document_document_distributions_path(@document), notice: "Some distributions could not be created. #{errors.join(", ")}"
139
140
  else
140
- redirect_to admin_document_document_distributions_path, warning: "Distributions could not be created."
141
+ redirect_to admin_document_distributions_path, notice: "Some distributions could not be created. #{errors.join(", ")}"
141
142
  end
142
143
  end
143
144
  rescue => e
@@ -145,7 +146,7 @@ module Admin
145
146
  if params[:document_id]
146
147
  redirect_to admin_document_document_distributions_path(@document), notice: "Distributions could not be created. #{e}"
147
148
  else
148
- redirect_to admin_document_document_distributions_path, notice: "Distributions could not be created. #{e}"
149
+ redirect_to admin_document_distributions_path, notice: "Distributions could not be created. #{e}"
149
150
  end
150
151
  end
151
152
 
data/app/models/asset.rb CHANGED
@@ -55,6 +55,8 @@ class Asset < Kithe::Asset
55
55
  if dct_references_uri_key.present?
56
56
  reference_type = ReferenceType.find_by_name(dct_references_uri_key)
57
57
  hash[reference_type.reference_uri.to_s] = if reference_type.reference_uri.to_s == "http://schema.org/downloadUrl"
58
+ logger.debug("Asset#to_aardvark_reference > downloadUrl: #{full_file_url} > #{label.present? ? label : file.metadata["filename"]}")
59
+
58
60
  {
59
61
  "url" => full_file_url,
60
62
  "label" => label.present? ? label : file.metadata["filename"]
@@ -122,33 +122,31 @@ class Document < Kithe::Work
122
122
  # - Use distributable assets
123
123
  # @TODO: Remove BEFORE path once we've migrated to DocumentDistributions
124
124
  def distributions
125
- distributions = ActiveSupport::HashWithIndifferentAccess.new
125
+ distributions = {}
126
126
 
127
127
  # AFTER - Add DocumentDistributions to distributions
128
128
  if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "true"
129
129
  distributions = document_distributions.to_aardvark_distributions
130
- end
131
-
132
- # BEFORE - Prep value arrays
133
- # @TODO: Remove this once we've migrated to DocumentDistributions
134
- send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref|
135
- if ref.category.present?
136
- distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] = []
130
+ else
131
+ # BEFORE - Prep value arrays
132
+ # @TODO: Remove this once we've migrated to DocumentDistributions
133
+ send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref|
134
+ if ref.category.present?
135
+ distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] = []
136
+ end
137
137
  end
138
- end
139
138
 
140
- # BEFORE - Seed value arrays
141
- # @TODO: Remove this once we've migrated to DocumentDistributions
142
- send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref|
143
- if ref.category.present?
144
- distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] << ref.value
139
+ # BEFORE - Seed value arrays
140
+ # @TODO: Remove this once we've migrated to DocumentDistributions
141
+ send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref|
142
+ if ref.category.present?
143
+ distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] << ref.value
144
+ end
145
145
  end
146
- end
147
- logger.debug("\n\nDocument#distributions > seeded: #{distributions}")
146
+ logger.debug("\n\nDocument#distributions > seeded: #{distributions}")
148
147
 
149
- # BEFORE - Apply Multiple Downloads
150
- # @TODO: Remove this once we've migrated to DocumentDistributions
151
- if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "false"
148
+ # BEFORE - Apply Multiple Downloads
149
+ # @TODO: Remove this once we've migrated to DocumentDistributions
152
150
  distributions = apply_downloads(distributions)
153
151
  logger.debug("Document#distributions > downloads: #{distributions}")
154
152
  end
@@ -192,12 +190,24 @@ class Document < Kithe::Work
192
190
  csv = []
193
191
 
194
192
  distributions.each do |key, value|
195
- if key == "http://schema.org/downloadUrl"
193
+ if key == "http://schema.org/downloadUrl" || key == :"http://schema.org/downloadUrl"
196
194
  value.each do |download|
197
- csv << [friendlier_id, ReferenceType.find_by(reference_uri: key).name, download["url"], download["label"]]
195
+ logger.debug("Document#distributions_csv > download: #{download.inspect}")
196
+
197
+ csv << [
198
+ friendlier_id,
199
+ ReferenceType.find_by(reference_uri: key).name,
200
+ download["url"],
201
+ download["label"]
202
+ ]
198
203
  end
199
204
  else
200
- csv << [friendlier_id, ReferenceType.find_by(reference_uri: key)&.name, value, nil]
205
+ csv << [
206
+ friendlier_id,
207
+ ReferenceType.find_by(reference_uri: key)&.name,
208
+ value,
209
+ nil
210
+ ]
201
211
  end
202
212
  end
203
213
  csv
@@ -264,7 +274,7 @@ class Document < Kithe::Work
264
274
 
265
275
  multiple_downloads = multiple_downloads.uniq { |d| [d[:label], d[:url]] } unless multiple_downloads.empty?
266
276
 
267
- distributions[:"http://schema.org/downloadUrl"] = multiple_downloads.flatten unless multiple_downloads.empty?
277
+ distributions["http://schema.org/downloadUrl"] = multiple_downloads.flatten unless multiple_downloads.empty?
268
278
  distributions
269
279
  end
270
280
 
@@ -39,7 +39,7 @@ class DocumentDistribution < ApplicationRecord
39
39
  merged["http://schema.org/downloadUrl"] ||= []
40
40
  merged["http://schema.org/downloadUrl"] << {
41
41
  "url" => dist.values.first,
42
- "label" => dist[:label]
42
+ "label" => dist[:label].present? ? dist[:label] : dist.values.first
43
43
  }
44
44
  else
45
45
  merged[dist.keys.first] = dist.values.first
@@ -65,14 +65,22 @@ class DocumentDistribution < ApplicationRecord
65
65
  # @param file [File] the CSV file to import
66
66
  # @return [Boolean] true if import is successful
67
67
  def self.import(file)
68
+ @errors = []
69
+
68
70
  logger.debug("CSV Import")
69
71
  ::CSV.foreach(file.path, headers: true) do |row|
70
72
  logger.debug("CSV Row: #{row.to_hash}")
73
+
74
+ unless Document.exists?(friendlier_id: row.to_hash["friendlier_id"])
75
+ logger.debug("Document not found: #{row.to_hash["friendlier_id"]}")
76
+ @errors << "Document not found: #{row.to_hash["friendlier_id"]}"
77
+ next
78
+ end
79
+
71
80
  document_distribution = DocumentDistribution.find_or_initialize_by(
72
81
  friendlier_id: row.to_hash["friendlier_id"],
73
82
  reference_type_id: ReferenceType.find_by(name: row.to_hash["reference_type"]).id,
74
- url: row.to_hash["distribution_url"],
75
- label: row.to_hash["label"]
83
+ url: row.to_hash["distribution_url"]
76
84
  )
77
85
 
78
86
  logger.debug("Document Distribution: #{document_distribution.inspect}")
@@ -84,7 +92,7 @@ class DocumentDistribution < ApplicationRecord
84
92
  label: row.to_hash["label"]
85
93
  )
86
94
  end
87
- true
95
+ [@errors.empty?, @errors]
88
96
  end
89
97
 
90
98
  # Destroy All
@@ -132,7 +140,7 @@ class DocumentDistribution < ApplicationRecord
132
140
  def to_aardvark_distribution
133
141
  hash = {}
134
142
  hash[reference_type.reference_uri.to_s] = url
135
- hash[:label] = label if reference_type.reference_uri.to_s == "http://schema.org/downloadUrl"
143
+ hash["label"] = label if reference_type.reference_uri.to_s == "http://schema.org/downloadUrl"
136
144
  hash
137
145
  end
138
146
 
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GeoblacklightAdmin
4
- include GeoblacklightAdmin::IsoLanguageCodes
5
4
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.data do
4
2
  json.array! @presenter.documents do |document|
5
3
  document_url = polymorphic_url(url_for_document(document))
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.links do
4
2
  json.self url_for(search_state.to_h.merge(only_path: false))
5
3
  json.prev url_for(search_state.to_h.merge(only_path: false, page: @response.prev_page.to_s)) if @response.prev_page
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.set!(field_name) do
4
2
  json.id "#{document_url}##{field_name}"
5
3
  json.type "document_value"
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.links do
4
2
  json.self url_for(search_state.to_h.merge(only_path: false))
5
3
  json.prev url_for(search_state.to_h.merge(only_path: false, page: @response.prev_page.to_s)) if @response.prev_page
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.links do
4
2
  json.self url_for(search_state.to_h.merge(only_path: false))
5
3
  json.prev url_for(search_state.to_h.merge(only_path: false, page: @response.prev_page.to_s)) if @response.prev_page
@@ -21,7 +21,7 @@ document.addEventListener('DOMContentLoaded', function() {
21
21
  const labelInput = document.getElementById('label-input');
22
22
 
23
23
  function toggleLabelInput() {
24
- if (distributionSelect.options[distributionSelect.selectedIndex].text === 'Download file') {
24
+ if (distributionSelect.options[distributionSelect.selectedIndex].text === 'Download') {
25
25
  labelInput.disabled = false;
26
26
  } else {
27
27
  labelInput.disabled = true;
@@ -20,7 +20,10 @@
20
20
  </p>
21
21
 
22
22
  <h3 class="h4">Upload a CSV File</h3>
23
- <%= simple_form_for DocumentDistribution.new, url: import_admin_document_distributions_path, method: :post, multipart: true do |f| %>
23
+ <%= simple_form_for DocumentDistribution.new,
24
+ url: @document || params[:document_id] ? import_admin_document_document_distributions_path(@document) : import_admin_document_distributions_path,
25
+ method: :post,
26
+ multipart: true do |f| %>
24
27
  <div class="form-inputs">
25
28
  <%= f.simple_fields_for :distributions do |distribution_fields| %>
26
29
  <%= distribution_fields.input :file, as: :file, input_html: {} %>
@@ -18,8 +18,6 @@
18
18
  <% if params[:document_id] %>
19
19
  <h2 class='h3'>
20
20
  <%= link_to(@document.title, admin_document_path(@document)) %>
21
- &middot;
22
- <%= @document_distributions.count %> distributions
23
21
  </h2>
24
22
  <% else %>
25
23
  <h2 class='h3'>Distributions</h2>
@@ -61,32 +59,34 @@
61
59
  <h3>External – Document Distributions</h3>
62
60
  <% end %>
63
61
 
64
- <table class="table table-striped table-bordered sortable">
65
- <thead class="thead-dark">
66
- <tr>
67
- <th class="header">Layer Slug</th>
68
- <th class="header">Type</th>
69
- <th class="header">URI</th>
70
- <th class="header">Value</th>
71
- <th class="header">Label</th>
72
- <th class="header" colspan="2">Actions</th>
73
- </tr>
74
- </thead>
75
-
76
- <tbody>
77
- <% @document_distributions.each do |document_distribution| %>
62
+ <div class="table-responsive">
63
+ <table class="table table-striped table-bordered sortable">
64
+ <thead class="thead-dark">
78
65
  <tr>
79
- <td><%= link_to document_distribution.friendlier_id, admin_document_path(document_distribution.document) %></td>
80
- <td><%= document_distribution.reference_type.reference_type %></td>
81
- <td><%= document_distribution.reference_type.reference_uri %></td>
82
- <td><%= link_to document_distribution.url, document_distribution.url, target: '_blank' %></td>
83
- <td><%= document_distribution.label %></td>
84
- <td><%= link_to 'Edit', edit_admin_document_document_distribution_path(document_distribution.document, document_distribution) %></td>
85
- <td><%= link_to 'Destroy', admin_document_document_distribution_path(document_distribution.document, document_distribution), method: :delete, data: { confirm: 'Are you sure?' } %></td>
66
+ <th class="header">Layer Slug</th>
67
+ <th class="header">Type</th>
68
+ <th class="header">URI</th>
69
+ <th class="header">Value</th>
70
+ <th class="header">Label</th>
71
+ <th class="header" colspan="2">Actions</th>
86
72
  </tr>
87
- <% end %>
88
- </tbody>
89
- </table>
73
+ </thead>
74
+
75
+ <tbody>
76
+ <% @document_distributions.each do |document_distribution| %>
77
+ <tr>
78
+ <td><%= link_to document_distribution.friendlier_id, admin_document_path(document_distribution.document) %></td>
79
+ <td><%= document_distribution.reference_type.reference_type %></td>
80
+ <td><%= document_distribution.reference_type.reference_uri %></td>
81
+ <td><%= link_to document_distribution.url, document_distribution.url, target: '_blank' %></td>
82
+ <td><%= document_distribution.label %></td>
83
+ <td><%= link_to 'Edit', edit_admin_document_document_distribution_path(document_distribution.document, document_distribution) %></td>
84
+ <td><%= link_to 'Destroy', admin_document_document_distribution_path(document_distribution.document, document_distribution), method: :delete, data: { confirm: 'Are you sure?' } %></td>
85
+ </tr>
86
+ <% end %>
87
+ </tbody>
88
+ </table>
89
+ </div>
90
90
 
91
91
  <% if @pagy %>
92
92
  <h6>
@@ -34,7 +34,6 @@
34
34
  <% end %>
35
35
  <%= link_to admin_document_document_distributions_url(@document), class: "ml-2" do %>
36
36
  Distributions
37
- <span class="badge badge-light"><%= @document.distributions.size %></span>
38
37
  <% end %>
39
38
  <% end %>
40
39
  </nav>
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # See GBL Aardvark Schema
4
2
  # https://docs.google.com/spreadsheets/d/1QQjUzRe8YdPGKK4h0GYoNPTow2zZ1f0KFA0zzZyHAsk/edit?ts=602d52f2#gid=252925024
5
3
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # Required
4
2
  json.set! :gbl_mdVersion_s, "BTAA Aardvark"
5
3
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # Required
4
2
  json.set! :gbl_mdVersion_s, "BTAA Aardvark"
5
3
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # See OpenGeoMetadata Legacy Versions
4
2
  # https://opengeometadata.org/docs/gbl-1.0
5
3
 
@@ -28,8 +28,8 @@
28
28
  <a class="dropdown-item" data-action="click->results#exportCsvDocumentDownloads" href="javascript:void(0);">
29
29
  CSV - Document Downloads
30
30
  </a>
31
- <a class="dropdown-item" data-action="click->results#exportCsvDocumentReferences" href="javascript:void(0);">
32
- CSV - Document References
31
+ <a class="dropdown-item" data-action="click->results#exportCsvDocumentDistributions" href="javascript:void(0);">
32
+ CSV - Document Distributions
33
33
  </a>
34
34
  </div>
35
35
  </span>
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.ignore_nil!
4
2
 
5
3
  json.array! @documents.map do |document|
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.ignore_nil!
4
2
 
5
3
  json.array! @documents.map do |document|
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.ignore_nil!
4
2
 
5
3
  json.array! @documents.map do |document|
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.ignore_nil!
4
2
 
5
3
  json.array! @documents.map do |document|
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.ignore_nil!
4
2
 
5
3
  json.array! @documents.load_all.map do |document|
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.ignore_nil!
4
2
 
5
3
  json.array! @documents.load_all.map do |document|
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.ignore_nil!
4
2
 
5
3
  json.array! @documents.load_all.map do |document|
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.ignore_nil!
4
2
 
5
3
  json.array! @documents.load_all.map do |document|
@@ -1,3 +1 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.partial! "json_aardvark", document: @document
@@ -1,3 +1 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.partial! "json_btaa_aardvark", document: @document
@@ -1,3 +1 @@
1
- # frozen_string_literal: true
2
-
3
1
  json.partial! "json_gbl_v1", document: @document
@@ -131,8 +131,8 @@
131
131
 
132
132
  <nav>
133
133
  <div class="nav nav-tabs" id="import-state-tabs" role="tablist">
134
- <a class="nav-item nav-link active" id="import-success-tab" data-toggle="tab" href="#import-state-success" role="tab" aria-controls="import-state-success" aria-selected="true">Success</a>
135
- <a class="nav-item nav-link" id="import-failed-tab" data-toggle="tab" href="#import-state-failed" role="tab" aria-controls="import-state-failed" aria-selected="false">Failed</a>
134
+ <a class="nav-item nav-link active" id="import-success-tab" data-toggle="tab" href="#import-state-success" role="tab" aria-controls="import-state-success" aria-selected="true">Success <span class="badge badge-success"><%= @import_success_documents.count %></span></a>
135
+ <a class="nav-item nav-link" id="import-failed-tab" data-toggle="tab" href="#import-state-failed" role="tab" aria-controls="import-state-failed" aria-selected="false">Failed <span class="badge badge-danger"><%= @import_failed_documents.count %></span> </a>
136
136
  </div>
137
137
  </nav>
138
138
 
@@ -216,7 +216,7 @@ module GeoblacklightAdmin
216
216
  end
217
217
  end
218
218
 
219
- # Document References
219
+ # Document Distributions
220
220
  resources :document_distributions, path: "distributions" do
221
221
  collection do
222
222
  get "display_attach_form"
@@ -18,9 +18,46 @@ namespace :geoblacklight_admin do
18
18
  url: distribution[2],
19
19
  label: distribution[3]
20
20
  )
21
+ rescue ActiveRecord::RecordInvalid => e
22
+ if !distribution[2].nil? && distribution[2].is_a?(Hash)
23
+ puts "Distribution rescued and skipped: #{distribution.inspect}"
24
+ else
25
+ puts "RecordInvalid processing distribution: #{distribution[0]} - #{e.inspect}"
26
+ end
27
+ rescue TypeError => e
28
+ puts "TypeError processing distribution: #{distribution[0]} - #{e.inspect}"
29
+ puts "Distribution: #{distribution.inspect}"
30
+
31
+ # Fix for #<TypeError: can't cast Hash>
32
+ # These are download links that are not already in an array
33
+ # ex. "{\"http://schema.org/url\":\"https://datacore.iu.edu/concern/data_sets/hx11xf65s\",\"http://schema.org/downloadUrl\":{\"label\":\"PDF\",\"url\":\"https://datacore.iu.edu/downloads/ms35t9074\"}}"
34
+ if !distribution[2].nil? && distribution[2].is_a?(Hash)
35
+ DocumentDistribution.find_or_create_by!(
36
+ friendlier_id: distribution[0],
37
+ reference_type_id: ReferenceType.find_by(name: distribution[1]).id,
38
+ url: distribution[2][:url],
39
+ label: distribution[2][:label]
40
+ )
41
+ puts "Distribution rescued and migrated: #{distribution.inspect}"
42
+ elsif distribution[2].nil? && distribution[2].is_a?(Array)
43
+ distribution[2].each do |download|
44
+ if download.is_a?(Hash) && download[:url].present? && download[:label].present?
45
+ DocumentDistribution.find_or_create_by!(
46
+ friendlier_id: distribution[0],
47
+ reference_type_id: ReferenceType.find_by(name: distribution[1]).id,
48
+ url: download[:url],
49
+ label: download[:label]
50
+ )
51
+ end
52
+ end
53
+ puts "Distribution array rescued and migrated: #{distribution.inspect}"
54
+ else
55
+ puts "Distribution not migrated: #{distribution.inspect}"
56
+ end
57
+ rescue => e
58
+ puts "Error processing distribution: #{distribution[0]} - #{e.inspect}"
59
+ puts "Distribution: #{distribution.inspect}"
21
60
  end
22
- rescue => e
23
- puts "\nError processing distributions for document: #{document.friendlier_id} - #{e.inspect}\n"
24
61
  end
25
62
  total_documents_processed += documents.size
26
63
  puts "Processed #{documents.size} documents in this batch, total processed: #{total_documents_processed}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GeoblacklightAdmin
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoblacklight_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Larson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-22 00:00:00.000000000 Z
11
+ date: 2024-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_storage_validations