geoblacklight_admin 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/admin/document_distributions_controller.rb +7 -6
- data/app/models/document.rb +22 -8
- data/app/models/document_distribution.rb +13 -5
- data/app/views/admin/document_distributions/destroy_all.html.erb +1 -1
- data/app/views/admin/document_distributions/import.html.erb +4 -1
- data/app/views/admin/document_distributions/index.html.erb +26 -24
- data/app/views/admin/documents/_result_selected_options.html.erb +2 -2
- data/app/views/admin/imports/show.html.erb +3 -3
- data/lib/generators/geoblacklight_admin/config_generator.rb +1 -1
- data/lib/geoblacklight_admin/tasks/distributions.rake +39 -2
- data/lib/geoblacklight_admin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faa51021e7c742dbc13abb29e2114de5f917716955034cff20b433d6a3c275de
|
4
|
+
data.tar.gz: 71050ece81fb99a0377793467e09e4bb0d67fc892b6f49296a1c278ab4a00460
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fef4d2444d40f92f7731471f3647959b440e0a1ff9d74f5fb4973bff02701b626a6b0d83c7175e8bc0a0bb9bc7519edb3ef3f660d1584b0e4bbc22cb9f4df30
|
7
|
+
data.tar.gz: 3cc6ed9f3b4f25c67b30ba05a601a05022baab8ace7081d609db514f175746d43a5e91225c2889d8963eb74fbf96cca96f4cd112fae5066d65b455eb6cf3d72e
|
@@ -125,19 +125,20 @@ module Admin
|
|
125
125
|
raise ArgumentError, "File does not exist or is invalid."
|
126
126
|
end
|
127
127
|
|
128
|
-
|
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
|
134
|
+
redirect_to admin_document_distributions_path, notice: "Distributions were created successfully."
|
134
135
|
end
|
135
136
|
else
|
136
|
-
logger.debug("
|
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),
|
139
|
+
redirect_to admin_document_document_distributions_path(@document), notice: "Some distributions could not be created. #{errors.join(", ")}"
|
139
140
|
else
|
140
|
-
redirect_to
|
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
|
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/document.rb
CHANGED
@@ -124,9 +124,13 @@ class Document < Kithe::Work
|
|
124
124
|
def distributions
|
125
125
|
distributions = {}
|
126
126
|
|
127
|
+
logger.debug("Document#distributions > ENV['GBL_ADMIN_REFERENCES_MIGRATED']: #{ENV["GBL_ADMIN_REFERENCES_MIGRATED"]}")
|
128
|
+
|
127
129
|
# AFTER - Add DocumentDistributions to distributions
|
128
130
|
if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "true"
|
129
131
|
distributions = document_distributions.to_aardvark_distributions
|
132
|
+
|
133
|
+
logger.debug("Document#distributions > document_distributions: #{distributions}")
|
130
134
|
else
|
131
135
|
# BEFORE - Prep value arrays
|
132
136
|
# @TODO: Remove this once we've migrated to DocumentDistributions
|
@@ -147,10 +151,8 @@ class Document < Kithe::Work
|
|
147
151
|
|
148
152
|
# BEFORE - Apply Multiple Downloads
|
149
153
|
# @TODO: Remove this once we've migrated to DocumentDistributions
|
150
|
-
|
151
|
-
|
152
|
-
logger.debug("Document#distributions > downloads: #{distributions}")
|
153
|
-
end
|
154
|
+
distributions = apply_downloads(distributions)
|
155
|
+
logger.debug("Document#distributions > downloads: #{distributions}")
|
154
156
|
end
|
155
157
|
|
156
158
|
# BEFORE & AFTER - Apply Distributable Assets
|
@@ -192,12 +194,24 @@ class Document < Kithe::Work
|
|
192
194
|
csv = []
|
193
195
|
|
194
196
|
distributions.each do |key, value|
|
195
|
-
if key == "http://schema.org/downloadUrl"
|
197
|
+
if key == "http://schema.org/downloadUrl" || key == :"http://schema.org/downloadUrl"
|
196
198
|
value.each do |download|
|
197
|
-
|
199
|
+
logger.debug("Document#distributions_csv > download: #{download.inspect}")
|
200
|
+
|
201
|
+
csv << [
|
202
|
+
friendlier_id,
|
203
|
+
ReferenceType.find_by(reference_uri: key).name,
|
204
|
+
download["url"],
|
205
|
+
download["label"]
|
206
|
+
]
|
198
207
|
end
|
199
208
|
else
|
200
|
-
csv << [
|
209
|
+
csv << [
|
210
|
+
friendlier_id,
|
211
|
+
ReferenceType.find_by(reference_uri: key)&.name,
|
212
|
+
value,
|
213
|
+
nil
|
214
|
+
]
|
201
215
|
end
|
202
216
|
end
|
203
217
|
csv
|
@@ -264,7 +278,7 @@ class Document < Kithe::Work
|
|
264
278
|
|
265
279
|
multiple_downloads = multiple_downloads.uniq { |d| [d[:label], d[:url]] } unless multiple_downloads.empty?
|
266
280
|
|
267
|
-
distributions[
|
281
|
+
distributions["http://schema.org/downloadUrl"] = multiple_downloads.flatten unless multiple_downloads.empty?
|
268
282
|
distributions
|
269
283
|
end
|
270
284
|
|
@@ -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[
|
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
|
-
|
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[
|
143
|
+
hash["label"] = label if reference_type.reference_uri.to_s == "http://schema.org/downloadUrl"
|
136
144
|
hash
|
137
145
|
end
|
138
146
|
|
@@ -24,7 +24,7 @@
|
|
24
24
|
<div class="form-group">
|
25
25
|
<div class="form-inputs">
|
26
26
|
<%= f.simple_fields_for :distributions do |distribution_fields| %>
|
27
|
-
<%=
|
27
|
+
<%= distribution_fields.input :file, as: :file, input_html: {} %>
|
28
28
|
<%- end %>
|
29
29
|
</div>
|
30
30
|
|
@@ -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,
|
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: {} %>
|
@@ -59,32 +59,34 @@
|
|
59
59
|
<h3>External – Document Distributions</h3>
|
60
60
|
<% end %>
|
61
61
|
|
62
|
-
<
|
63
|
-
<
|
64
|
-
<
|
65
|
-
<th class="header">Layer Slug</th>
|
66
|
-
<th class="header">Type</th>
|
67
|
-
<th class="header">URI</th>
|
68
|
-
<th class="header">Value</th>
|
69
|
-
<th class="header">Label</th>
|
70
|
-
<th class="header" colspan="2">Actions</th>
|
71
|
-
</tr>
|
72
|
-
</thead>
|
73
|
-
|
74
|
-
<tbody>
|
75
|
-
<% @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">
|
76
65
|
<tr>
|
77
|
-
<
|
78
|
-
<
|
79
|
-
<
|
80
|
-
<
|
81
|
-
<
|
82
|
-
<
|
83
|
-
<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>
|
84
72
|
</tr>
|
85
|
-
|
86
|
-
|
87
|
-
|
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>
|
88
90
|
|
89
91
|
<% if @pagy %>
|
90
92
|
<h6>
|
@@ -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#
|
32
|
-
CSV - Document
|
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>
|
@@ -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
|
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"><%= @pagy_success.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"><%= @pagy_failed.count %></span> </a>
|
136
136
|
</div>
|
137
137
|
</nav>
|
138
138
|
|
@@ -146,4 +146,4 @@
|
|
146
146
|
</div>
|
147
147
|
</div>
|
148
148
|
</div>
|
149
|
-
</div>
|
149
|
+
</div>
|
@@ -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}"
|
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.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Larson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_storage_validations
|