geoblacklight_admin 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/admin/document_distributions_controller.rb +7 -6
- data/app/models/document.rb +18 -8
- data/app/models/document_distribution.rb +12 -4
- 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 +2 -2
- 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: dc6016dba641608f129d84c4c8706fcf2494ddf18b028228799643e0e8b4ef3b
|
4
|
+
data.tar.gz: f58448208f48871f44c09588cb0c55d7c8beac7906b608052478aee2eaa587a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c956657c0b5f55f5e9b18eb5712ce35c185bddc498dcd950bcb4a52108ed0961690bbcc4753f6cbbe8cf5702315df4c4bf82dc33154e97a2dd852d367d871f81
|
7
|
+
data.tar.gz: 89981e31e878f519ad6cecb42df557cfb7031dcce7b11209c9451355c8e310cfb86957aa16c71dfa46f4686d14fbc9aab0e4868e6059c5722083e6ce9a3ca9fa
|
@@ -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
@@ -147,10 +147,8 @@ class Document < Kithe::Work
|
|
147
147
|
|
148
148
|
# BEFORE - Apply Multiple Downloads
|
149
149
|
# @TODO: Remove this once we've migrated to DocumentDistributions
|
150
|
-
|
151
|
-
|
152
|
-
logger.debug("Document#distributions > downloads: #{distributions}")
|
153
|
-
end
|
150
|
+
distributions = apply_downloads(distributions)
|
151
|
+
logger.debug("Document#distributions > downloads: #{distributions}")
|
154
152
|
end
|
155
153
|
|
156
154
|
# BEFORE & AFTER - Apply Distributable Assets
|
@@ -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
|
-
|
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 << [
|
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[
|
277
|
+
distributions["http://schema.org/downloadUrl"] = multiple_downloads.flatten unless multiple_downloads.empty?
|
268
278
|
distributions
|
269
279
|
end
|
270
280
|
|
@@ -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
|
|
@@ -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"><%= @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
|
|
@@ -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.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-12-
|
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
|