geoblacklight_admin 0.8.0 → 0.9.0
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_licensed_accesses_controller.rb +169 -0
- data/app/controllers/admin/documents_controller.rb +12 -12
- data/app/controllers/admin/elements_controller.rb +1 -1
- data/app/controllers/admin/import_distributions_controller.rb +2 -1
- data/app/controllers/admin/imports_controller.rb +2 -1
- data/app/indexers/document_indexer.rb +2 -2
- data/app/javascript/controllers/results_controller.js +5 -15
- data/app/jobs/bulk_action_run_document_job.rb +12 -2
- data/app/jobs/export_job.rb +40 -30
- data/app/jobs/export_json_bulk_job.rb +1 -1
- data/app/jobs/export_json_job.rb +1 -1
- data/app/jobs/import_document_job.rb +12 -1
- data/app/jobs/import_run_job.rb +5 -0
- data/app/models/asset.rb +13 -3
- data/app/models/document/controlled_lists.rb +3 -2
- data/app/models/document/date_validator.rb +14 -12
- data/app/models/document.rb +21 -107
- data/app/models/{document_access.rb → document_licensed_access.rb} +8 -6
- data/app/models/geoblacklight_admin/schema.rb +0 -10
- data/app/models/import_document.rb +5 -0
- data/app/services/export_csv_document_distributions_service.rb +8 -4
- data/app/services/export_csv_document_licensed_access_links_service.rb +27 -0
- data/app/services/export_csv_service.rb +5 -1
- data/app/views/admin/document_assets/_assets_table.html.erb +4 -0
- data/app/views/admin/document_assets/index.html.erb +3 -1
- data/app/views/admin/document_distributions/destroy_all.html.erb +1 -1
- data/app/views/admin/document_distributions/index.html.erb +5 -7
- data/app/views/admin/document_licensed_accesses/_document_licensed_access.json.jbuilder +4 -0
- data/app/views/admin/{document_accesses → document_licensed_accesses}/_form.html.erb +4 -5
- data/app/views/admin/{document_accesses → document_licensed_accesses}/destroy_all.html.erb +7 -7
- data/app/views/admin/document_licensed_accesses/edit.html.erb +5 -0
- data/app/views/admin/{document_accesses → document_licensed_accesses}/import.html.erb +12 -9
- data/app/views/admin/document_licensed_accesses/index.html.erb +78 -0
- data/app/views/admin/document_licensed_accesses/index.json.jbuilder +3 -0
- data/app/views/admin/document_licensed_accesses/new.html.erb +8 -0
- data/app/views/admin/documents/_form_control.html.erb +0 -10
- data/app/views/admin/documents/_form_nav.html.erb +3 -12
- data/app/views/admin/documents/_form_nav_kithe.html.erb +0 -4
- data/app/views/admin/documents/_result_selected_options.html.erb +14 -18
- data/app/views/admin/documents/features/_document_references.html.erb +18 -20
- data/app/views/admin/documents/features/_licensed_access.html.erb +3 -0
- data/app/views/admin/elements/index.html.erb +0 -18
- data/app/views/admin/import_distributions/_form.html.erb +1 -1
- data/app/views/admin/import_distributions/_show_queued_tab.html.erb +36 -0
- data/app/views/admin/import_distributions/index.html.erb +3 -3
- data/app/views/admin/import_distributions/new.html.erb +3 -1
- data/app/views/admin/import_distributions/show.html.erb +5 -0
- data/app/views/admin/imports/_form.html.erb +1 -1
- data/app/views/admin/imports/_show_queued_tab.html.erb +31 -0
- data/app/views/admin/imports/index.html.erb +3 -3
- data/app/views/admin/imports/new.html.erb +3 -1
- data/app/views/admin/imports/show.html.erb +6 -0
- data/app/views/admin/notifications/_notification.html.haml +0 -1
- data/app/views/admin/notifications/index.html.erb +2 -2
- data/app/views/admin/notifications/update.js.erb +1 -1
- data/app/views/admin/shared/_navbar.html.erb +9 -8
- data/config/routes.rb +2 -25
- data/db/migrate/20240321000000_rename_document_accesses_to_document_licensed_accesses.rb +5 -0
- data/db/seeds_form_elements.csv +1 -2
- data/db/seeds_form_elements.numbers +0 -0
- data/lib/generators/geoblacklight_admin/config_generator.rb +4 -26
- data/lib/generators/geoblacklight_admin/templates/config/initializers/mime_types.rb +1 -1
- data/lib/geoblacklight_admin/version.rb +1 -1
- metadata +17 -30
- data/app/controllers/admin/document_accesses_controller.rb +0 -169
- data/app/controllers/admin/document_downloads_controller.rb +0 -129
- data/app/models/document_download.rb +0 -39
- data/app/services/export_csv_document_access_links_service.rb +0 -47
- data/app/services/export_csv_document_downloads_service.rb +0 -47
- data/app/views/admin/document_accesses/_document_access.json.jbuilder +0 -4
- data/app/views/admin/document_accesses/edit.html.erb +0 -5
- data/app/views/admin/document_accesses/index.html.erb +0 -78
- data/app/views/admin/document_accesses/index.json.jbuilder +0 -3
- data/app/views/admin/document_accesses/new.html.erb +0 -6
- data/app/views/admin/document_accesses/show.html.erb +0 -19
- data/app/views/admin/document_accesses/show.json.jbuilder +0 -3
- data/app/views/admin/document_downloads/_document_download.json.jbuilder +0 -4
- data/app/views/admin/document_downloads/_form.html.erb +0 -15
- data/app/views/admin/document_downloads/destroy_all.html.erb +0 -70
- data/app/views/admin/document_downloads/edit.html.erb +0 -5
- data/app/views/admin/document_downloads/import.html.erb +0 -74
- data/app/views/admin/document_downloads/index.html.erb +0 -72
- data/app/views/admin/document_downloads/index.json.jbuilder +0 -3
- data/app/views/admin/document_downloads/new.html.erb +0 -5
- data/app/views/admin/document_downloads/show.html.erb +0 -24
- data/app/views/admin/document_downloads/show.json.jbuilder +0 -3
- data/app/views/admin/documents/features/_institutional_access_links.html.erb +0 -3
- data/app/views/admin/documents/features/_multiple_download_links.html.erb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d79715a53de267b1c6610d96834bafc9564fa1f1ffd1cc42040ede65c3b3e831
|
4
|
+
data.tar.gz: 8ffad49338a30230adc65578911502f2d349474b6c1b6e51fb3f41bf7743cf1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 314eb14972a616c59c5c229defdec096ba5c4300520898f636f23f783c62251aec5dd48dea1d0db519a9a442258c11e83b6159422d1e7457ba234a38c9a10189
|
7
|
+
data.tar.gz: 1f6cd97abecdf5d29e39a7e7088c4db076ceb08e48b49cb0a7fbe0aa0e4a1e4cd37a8a4b42a793f579ca93821ce36da089c48fc923dedbfb2f8dd017ba9d1c3e
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Admin::DocumentLicensedAccessesController
|
4
|
+
#
|
5
|
+
# This controller manages the CRUD operations for DocumentAccess objects
|
6
|
+
# within the admin namespace. It provides actions to list, show, create,
|
7
|
+
# update, and destroy document access records. It also includes custom
|
8
|
+
# actions for importing and destroying all document access links.
|
9
|
+
#
|
10
|
+
# Actions:
|
11
|
+
# - index: Lists all document accesses, optionally filtered by document_id.
|
12
|
+
# - show: Displays a specific document access.
|
13
|
+
# - new: Renders a form for creating a new document access.
|
14
|
+
# - edit: Renders a form for editing an existing document access.
|
15
|
+
# - create: Creates a new document access.
|
16
|
+
# - update: Updates an existing document access.
|
17
|
+
# - destroy: Deletes a specific document access.
|
18
|
+
# - destroy_all: Deletes all document access links provided in the params.
|
19
|
+
# - import: Imports document licensed access links from a file provided in the params.
|
20
|
+
#
|
21
|
+
# Before Actions:
|
22
|
+
# - set_document: Sets the @document instance variable if document_id is present.
|
23
|
+
# - set_document_licensed_access: Sets the @document_licensed_access instance variable for specific actions.
|
24
|
+
#
|
25
|
+
# Private Methods:
|
26
|
+
# - set_document: Finds and sets the document based on the document_id parameter.
|
27
|
+
# - set_document_licensed_access: Finds and sets the document licensed access based on the id parameter.
|
28
|
+
# - document_licensed_access_params: Permits only trusted parameters for document licensed access.
|
29
|
+
module Admin
|
30
|
+
class DocumentLicensedAccessesController < Admin::AdminController
|
31
|
+
before_action :set_document
|
32
|
+
before_action :set_document_licensed_access, only: %i[show edit update destroy]
|
33
|
+
|
34
|
+
# GET /documents/#id/licensed_access
|
35
|
+
# GET /documents/#id/licensed_access.json
|
36
|
+
# Lists all document licensed accesses, optionally filtered by document_id.
|
37
|
+
def index
|
38
|
+
if params[:document_id]
|
39
|
+
@document_licensed_accesses = DocumentLicensedAccess.where(friendlier_id: @document.friendlier_id).order(institution_code: :asc)
|
40
|
+
else
|
41
|
+
@pagy, @document_licensed_accesses = pagy(DocumentLicensedAccess.all.order(friendlier_id: :asc, updated_at: :desc), items: 20)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# GET /document_licensed_accesses/1
|
46
|
+
# GET /document_licensed_accesses/1.json
|
47
|
+
# Displays a specific document licensed access.
|
48
|
+
def show
|
49
|
+
end
|
50
|
+
|
51
|
+
# GET /document_licensed_accesses/new
|
52
|
+
# Renders a form for creating a new document licensed access.
|
53
|
+
def new
|
54
|
+
@document_licensed_access = DocumentLicensedAccess.new
|
55
|
+
end
|
56
|
+
|
57
|
+
# GET /document_licensed_accesses/1/edit
|
58
|
+
# Renders a form for editing an existing document licensed access.
|
59
|
+
def edit
|
60
|
+
end
|
61
|
+
|
62
|
+
# POST /document_licensed_accesses
|
63
|
+
# POST /document_licensed_accesses.json
|
64
|
+
# Creates a new document licensed access.
|
65
|
+
def create
|
66
|
+
@document_licensed_access = DocumentLicensedAccess.new(document_licensed_access_params)
|
67
|
+
logger.debug("DA Params: #{DocumentLicensedAccess.new(document_licensed_access_params).inspect}")
|
68
|
+
logger.debug("Document LICENSED ACCESS: #{@document_licensed_access.inspect}")
|
69
|
+
|
70
|
+
respond_to do |format|
|
71
|
+
if @document_licensed_access.save
|
72
|
+
format.html do
|
73
|
+
redirect_to admin_document_document_licensed_accesses_path(@document), notice: "Document licensed access was successfully created."
|
74
|
+
end
|
75
|
+
format.json { render :show, status: :created, location: @document_licensed_access }
|
76
|
+
else
|
77
|
+
format.html { render :new }
|
78
|
+
format.json { render json: @document_licensed_access.errors, status: :unprocessable_entity }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# PATCH/PUT /document_licensed_accesses/1
|
84
|
+
# PATCH/PUT /document_licensed_accesses/1.json
|
85
|
+
# Updates an existing document licensed access.
|
86
|
+
def update
|
87
|
+
respond_to do |format|
|
88
|
+
if @document_licensed_access.update(document_licensed_access_params)
|
89
|
+
format.html do
|
90
|
+
redirect_to admin_document_document_licensed_accesses_path(@document), notice: "Document licensed access was successfully updated."
|
91
|
+
end
|
92
|
+
format.json { render :show, status: :ok, location: @document_licensed_access }
|
93
|
+
else
|
94
|
+
format.html { render :edit }
|
95
|
+
format.json { render json: @document_licensed_access.errors, status: :unprocessable_entity }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# DELETE /document_licensed_accesses/1
|
101
|
+
# DELETE /document_licensed_accesses/1.json
|
102
|
+
# Deletes a specific document licensed access.
|
103
|
+
def destroy
|
104
|
+
@document_licensed_access.destroy
|
105
|
+
respond_to do |format|
|
106
|
+
format.html do
|
107
|
+
redirect_to admin_document_document_licensed_accesses_path(@document), notice: "Document licensed access was successfully destroyed."
|
108
|
+
end
|
109
|
+
format.json { head :no_content }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# DELETE /document_licensed_accesses/destroy_all
|
114
|
+
# Deletes all document licensed access links provided in the params.
|
115
|
+
def destroy_all
|
116
|
+
logger.debug("Destroy Access Links")
|
117
|
+
return unless params.dig(:document_licensed_access, :assets, :file)
|
118
|
+
|
119
|
+
respond_to do |format|
|
120
|
+
if DocumentLicensedAccess.destroy_all(params.dig(:document_licensed_access, :assets, :file))
|
121
|
+
format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document Licensed Access Links were created destroyed." }
|
122
|
+
else
|
123
|
+
format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document Licensed Access Links could not be destroyed." }
|
124
|
+
end
|
125
|
+
rescue => e
|
126
|
+
format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document Licensed Access Links could not be destroyed. #{e}" }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# GET /documents/#id/licensed_access/import
|
131
|
+
# POST /documents/#id/licensed_access/import
|
132
|
+
# Imports document licensed access links from a file provided in the params.
|
133
|
+
def import
|
134
|
+
logger.debug("Import Action")
|
135
|
+
return unless params.dig(:document_licensed_access, :assets, :file)
|
136
|
+
|
137
|
+
respond_to do |format|
|
138
|
+
if DocumentLicensedAccess.import(params.dig(:document_licensed_access, :assets, :file))
|
139
|
+
format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document licensed access links were created successfully." }
|
140
|
+
else
|
141
|
+
format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document licensed access links could not be created." }
|
142
|
+
end
|
143
|
+
rescue => e
|
144
|
+
format.html { redirect_to admin_document_licensed_accesses_path, notice: "Document licensed access links could not be created. #{e}" }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
# Use callbacks to share common setup or constraints between actions.
|
151
|
+
# Finds and sets the document based on the document_id parameter.
|
152
|
+
def set_document
|
153
|
+
return unless params[:document_id] # If not nested
|
154
|
+
|
155
|
+
@document = Document.includes(:leaf_representative).find_by!(friendlier_id: params[:document_id])
|
156
|
+
end
|
157
|
+
|
158
|
+
# Finds and sets the document licensed access based on the id parameter.
|
159
|
+
def set_document_licensed_access
|
160
|
+
@document_licensed_access = DocumentLicensedAccess.find(params[:id])
|
161
|
+
end
|
162
|
+
|
163
|
+
# Only allow a list of trusted parameters through.
|
164
|
+
# Permits only trusted parameters for document licensed access.
|
165
|
+
def document_licensed_access_params
|
166
|
+
params.require(:document_licensed_access).permit(:friendlier_id, :institution_code, :access_url)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -54,12 +54,8 @@ module Admin
|
|
54
54
|
ExportJob.perform_later(@request, current_user, query_params, ExportCsvService)
|
55
55
|
head :no_content
|
56
56
|
end
|
57
|
-
format.
|
58
|
-
ExportJob.perform_later(@request, current_user, query_params,
|
59
|
-
head :no_content
|
60
|
-
end
|
61
|
-
format.csv_document_access_links do
|
62
|
-
ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentAccessLinksService)
|
57
|
+
format.csv_document_licensed_access_links do
|
58
|
+
ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentLicensedAccessLinksService)
|
63
59
|
head :no_content
|
64
60
|
end
|
65
61
|
format.csv_document_distributions do
|
@@ -94,12 +90,8 @@ module Admin
|
|
94
90
|
ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv"}, ExportCsvService)
|
95
91
|
head :no_content
|
96
92
|
end
|
97
|
-
format.
|
98
|
-
ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "
|
99
|
-
head :no_content
|
100
|
-
end
|
101
|
-
format.csv_document_access_links do
|
102
|
-
ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_access_links"}, ExportCsvDocumentAccessLinksService)
|
93
|
+
format.csv_document_licensed_access_links do
|
94
|
+
ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_licensed_access_links"}, ExportCsvDocumentLicensedAccessLinksService)
|
103
95
|
head :no_content
|
104
96
|
end
|
105
97
|
format.csv_document_distributions do
|
@@ -189,6 +181,14 @@ module Admin
|
|
189
181
|
end
|
190
182
|
end
|
191
183
|
|
184
|
+
def export
|
185
|
+
case params[:format]
|
186
|
+
when "csv_document_licensed_access_links"
|
187
|
+
ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentLicensedAccessLinksService)
|
188
|
+
redirect_to admin_documents_path, notice: "Export job started. You will receive a notification when it is complete."
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
192
|
private
|
193
193
|
|
194
194
|
# Use callbacks to share common setup or constraints between actions.
|
@@ -12,7 +12,7 @@ module Admin
|
|
12
12
|
# Lists all elements, ordered by position in ascending order.
|
13
13
|
# Uses pagination to limit the number of elements displayed per page.
|
14
14
|
def index
|
15
|
-
@
|
15
|
+
@elements = Element.all.order(position: :asc)
|
16
16
|
end
|
17
17
|
|
18
18
|
# GET /elements/1 or /elements/1.json
|
@@ -37,8 +37,9 @@ module Admin
|
|
37
37
|
# GET /import_distributions/1.json
|
38
38
|
# Displays a specific import distribution and its associated documents, with pagination for success and failed states.
|
39
39
|
def show
|
40
|
-
@pagy_failed, @import_failed_distributions = pagy(@import_distribution.import_document_distributions.not_in_state(:success), items: 50, page_param: :failed_page)
|
41
40
|
@pagy_success, @import_success_distributions = pagy(@import_distribution.import_document_distributions.in_state(:success), items: 50, page_param: :success_page)
|
41
|
+
@pagy_queued, @import_queued_distributions = pagy(@import_distribution.import_document_distributions.in_state(:queued), items: 50, page_param: :queued_page)
|
42
|
+
@pagy_failed, @import_failed_distributions = pagy(@import_distribution.import_document_distributions.in_state(:failed), items: 50, page_param: :failed_page)
|
42
43
|
end
|
43
44
|
|
44
45
|
# GET /import_distributions/new
|
@@ -37,8 +37,9 @@ module Admin
|
|
37
37
|
# GET /imports/1.json
|
38
38
|
# Displays a specific import and its associated documents, with pagination for success and failed states.
|
39
39
|
def show
|
40
|
-
@pagy_failed, @import_failed_documents = pagy(@import.import_documents.not_in_state(:success), items: 50, page_param: :failed_page)
|
41
40
|
@pagy_success, @import_success_documents = pagy(@import.import_documents.in_state(:success), items: 50, page_param: :success_page)
|
41
|
+
@pagy_queued, @import_queued_documents = pagy(@import.import_documents.in_state(:queued), items: 50, page_param: :queued_page)
|
42
|
+
@pagy_failed, @import_failed_documents = pagy(@import.import_documents.in_state(:failed), items: 50, page_param: :failed_page)
|
42
43
|
end
|
43
44
|
|
44
45
|
# GET /imports/new
|
@@ -41,11 +41,11 @@ class DocumentIndexer < Kithe::Indexer
|
|
41
41
|
# May want to switch to or add a 'date published' instead, right
|
42
42
|
# now we only have date added to DB, which is what we had in sufia.
|
43
43
|
to_field "date_created_dtsi" do |rec, _acc|
|
44
|
-
rec
|
44
|
+
rec&.created_at&.utc&.iso8601
|
45
45
|
end
|
46
46
|
|
47
47
|
to_field "date_modified_dtsi" do |rec, _acc|
|
48
|
-
rec
|
48
|
+
rec&.updated_at&.utc&.iso8601
|
49
49
|
end
|
50
50
|
|
51
51
|
# - GBL ADMIN
|
@@ -103,6 +103,7 @@ export default class extends Controller {
|
|
103
103
|
this.setResultSelectionVisibility('hide');
|
104
104
|
this.setResultActionsVisibility('hide')
|
105
105
|
this.removeResultSet();
|
106
|
+
this.setPagesetURL();
|
106
107
|
|
107
108
|
// Set selection scope
|
108
109
|
var el = document.querySelector('div#result-selection-options');
|
@@ -228,25 +229,14 @@ export default class extends Controller {
|
|
228
229
|
}
|
229
230
|
}
|
230
231
|
|
231
|
-
|
232
|
-
console.log('Export -
|
233
|
-
var scope = this.checkSelectionScope();
|
234
|
-
var el = document.querySelector('#result-selected-options');
|
235
|
-
if(scope === 'pageset') {
|
236
|
-
window.location = el.dataset.pageset + "&format=csv_document_downloads"
|
237
|
-
} else {
|
238
|
-
window.location = el.dataset.resultset + "&format=csv_document_downloads"
|
239
|
-
}
|
240
|
-
}
|
241
|
-
|
242
|
-
exportCsvDocumentAccessLinks() {
|
243
|
-
console.log('Export - CsvDocumentAccessLinks')
|
232
|
+
exportCsvDocumentLicensedAccessLinks() {
|
233
|
+
console.log('Export - CsvDocumentLicensedAccessLinks')
|
244
234
|
var scope = this.checkSelectionScope();
|
245
235
|
var el = document.querySelector('#result-selected-options');
|
246
236
|
if(scope === 'pageset') {
|
247
|
-
window.location = el.dataset.pageset + "&format=
|
237
|
+
window.location = el.dataset.pageset + "&format=csv_document_licensed_access_links"
|
248
238
|
} else {
|
249
|
-
window.location = el.dataset.resultset + "&format=
|
239
|
+
window.location = el.dataset.resultset + "&format=csv_document_licensed_access_links"
|
250
240
|
}
|
251
241
|
}
|
252
242
|
|
@@ -23,9 +23,19 @@ class BulkActionRunDocumentJob < ApplicationJob
|
|
23
23
|
def update_publication_status(doc, field_value)
|
24
24
|
document = Document.find_by!(friendlier_id: doc.friendlier_id)
|
25
25
|
|
26
|
-
|
26
|
+
# Map field value to publication state
|
27
|
+
pub_state = case field_value
|
28
|
+
when "publish"
|
29
|
+
"published"
|
30
|
+
when "unpublish"
|
31
|
+
"unpublished"
|
32
|
+
when "set as draft"
|
33
|
+
"draft"
|
34
|
+
end
|
35
|
+
|
36
|
+
logger.debug("Update PubStatus - #{document.friendlier_id} - #{pub_state} - #{field_value}")
|
27
37
|
|
28
|
-
document.update!(publication_state:
|
38
|
+
document.update!(publication_state: pub_state)
|
29
39
|
end
|
30
40
|
|
31
41
|
def update_delete(doc, field_value)
|
data/app/jobs/export_job.rb
CHANGED
@@ -27,8 +27,14 @@ class ExportJob < ApplicationJob
|
|
27
27
|
file_content_documents = export_service.call(document_ids)
|
28
28
|
file_content_document_distributions = ExportCsvDocumentDistributionsService.call(document_ids)
|
29
29
|
|
30
|
+
# Filename
|
31
|
+
filename = export_service.short_name.parameterize(separator: "_")
|
32
|
+
|
33
|
+
# Include Distributions?
|
34
|
+
include_distributions = export_service&.include_distributions? || false
|
35
|
+
|
30
36
|
# Write Documents into tempfile
|
31
|
-
@tempfile_documents = Tempfile.new(["
|
37
|
+
@tempfile_documents = Tempfile.new(["#{filename}-#{Time.zone.now.strftime("%Y-%m-%d-%H%M%S")}", ".csv"]).tap do |file|
|
32
38
|
CSV.open(file, "wb") do |csv|
|
33
39
|
file_content_documents.each do |row|
|
34
40
|
csv << row
|
@@ -38,39 +44,43 @@ class ExportJob < ApplicationJob
|
|
38
44
|
logger.debug("Tempfile Documents Size: #{File.size(file.path)} bytes")
|
39
45
|
end
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
if include_distributions
|
48
|
+
# Write DocumentDistributions into tempfile
|
49
|
+
@tempfile_document_distributions = Tempfile.new(["distributions-#{Time.zone.now.strftime("%Y-%m-%d-%H%M%S")}", ".csv"]).tap do |file|
|
50
|
+
CSV.open(file, "wb") do |csv|
|
51
|
+
file_content_document_distributions.each do |row|
|
52
|
+
csv << row
|
53
|
+
end
|
46
54
|
end
|
55
|
+
logger.debug("Tempfile Document Distributions Path: #{file.path}")
|
56
|
+
logger.debug("Tempfile Document Distributions Size: #{File.size(file.path)} bytes")
|
47
57
|
end
|
48
|
-
logger.debug("Tempfile Document Distributions Path: #{file.path}")
|
49
|
-
logger.debug("Tempfile Document Distributions Size: #{File.size(file.path)} bytes")
|
50
|
-
end
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
59
|
+
# Create a zip file containing both tempfiles
|
60
|
+
zipfile_name = "export-#{filename}-#{Time.zone.now.strftime("%Y-%m-%d-%H%M%S")}.zip"
|
61
|
+
tmp_dir = Rails.root.join("tmp")
|
62
|
+
@tempfile_zip = Tempfile.new([zipfile_name, ".zip"], tmp_dir)
|
56
63
|
|
57
|
-
|
58
|
-
|
59
|
-
|
64
|
+
Zip::File.open(@tempfile_zip.path, Zip::File::CREATE) do |zipfile|
|
65
|
+
zipfile.add("#{filename}.csv", @tempfile_documents.path)
|
66
|
+
zipfile.add("distributions.csv", @tempfile_document_distributions.path)
|
67
|
+
end
|
68
|
+
logger.debug("Zipfile Path: #{@tempfile_zip.path}")
|
69
|
+
logger.debug("Zipfile Size: #{File.size(@tempfile_zip.path)} bytes")
|
70
|
+
|
71
|
+
# Create notification
|
72
|
+
notification = ExportNotification.with(message: "#{export_service.short_name}|#{ActionController::Base.helpers.number_with_delimiter(file_content_documents.size - 1)} rows|ZIP")
|
73
|
+
notification.deliver(current_user)
|
74
|
+
notification.record.file.attach(io: File.open(@tempfile_zip), filename: zipfile_name,
|
75
|
+
content_type: "application/zip")
|
76
|
+
else
|
77
|
+
# Only primary CSV, attach directly
|
78
|
+
csvfile_name = "#{filename}-#{Time.zone.now.strftime("%Y-%m-%d-%H%M%S")}.csv"
|
79
|
+
notification = ExportNotification.with(message: "#{export_service.short_name}|#{ActionController::Base.helpers.number_with_delimiter(file_content_documents.size - 1)} rows|CSV")
|
80
|
+
notification.deliver(current_user)
|
81
|
+
notification.record.file.attach(io: File.open(@tempfile_documents), filename: csvfile_name,
|
82
|
+
content_type: "text/csv")
|
60
83
|
end
|
61
|
-
logger.debug("Zipfile Path: #{@tempfile_zip.path}")
|
62
|
-
logger.debug("Zipfile Size: #{File.size(@tempfile_zip.path)} bytes")
|
63
|
-
|
64
|
-
# Create notification
|
65
|
-
# Message: "Download Type|Row Count|Button Label"
|
66
|
-
notification = ExportNotification.with(message: "ZIP (#{export_service.short_name})|#{ActionController::Base.helpers.number_with_delimiter(file_content_documents.size - 1)} rows|ZIP")
|
67
|
-
|
68
|
-
# Deliver notification
|
69
|
-
notification.deliver(current_user)
|
70
|
-
|
71
|
-
# Attach ZIP file (can only attach after persisted)
|
72
|
-
notification.record.file.attach(io: File.open(@tempfile_zip), filename: zipfile_name,
|
73
|
-
content_type: "application/zip")
|
74
84
|
|
75
85
|
# Update UI
|
76
86
|
ActionCable.server.broadcast("export_channel", {
|
@@ -97,6 +107,6 @@ class ExportJob < ApplicationJob
|
|
97
107
|
doc_ids)
|
98
108
|
end
|
99
109
|
|
100
|
-
doc_ids
|
110
|
+
doc_ids.flatten
|
101
111
|
end
|
102
112
|
end
|
data/app/jobs/export_json_job.rb
CHANGED
@@ -10,7 +10,18 @@ class ImportDocumentJob < ApplicationJob
|
|
10
10
|
# Set the geom
|
11
11
|
document.set_geometry
|
12
12
|
|
13
|
-
|
13
|
+
# Update document with import data
|
14
|
+
document_data = import_document.to_hash
|
15
|
+
publication_state = document_data[:json_attributes]["b1g_publication_state_s"]
|
16
|
+
document_data[:json_attributes].delete("b1g_publication_state_s")
|
17
|
+
document_data.delete(:publication_state)
|
18
|
+
|
19
|
+
if document.update(document_data)
|
20
|
+
# Handle state transition separately
|
21
|
+
if publication_state.present?
|
22
|
+
document.publication_state = publication_state
|
23
|
+
document.save
|
24
|
+
end
|
14
25
|
import_document.state_machine.transition_to!(:success)
|
15
26
|
else
|
16
27
|
import_document.state_machine.transition_to!(:failed, "Failed - #{document.errors.inspect}")
|
data/app/jobs/import_run_job.rb
CHANGED
@@ -12,6 +12,11 @@ class ImportRunJob < ApplicationJob
|
|
12
12
|
|
13
13
|
converted_data = import.convert_data(extract_hash)
|
14
14
|
|
15
|
+
# Set default publication state if not present
|
16
|
+
unless converted_data["b1g_publication_state_s"].present?
|
17
|
+
converted_data["b1g_publication_state_s"] = "draft"
|
18
|
+
end
|
19
|
+
|
15
20
|
kithe_document = {
|
16
21
|
title: converted_data[GeoblacklightAdmin::Schema.instance.solr_fields[:title]],
|
17
22
|
json_attributes: converted_data,
|
data/app/models/asset.rb
CHANGED
@@ -43,11 +43,21 @@ class Asset < Kithe::Asset
|
|
43
43
|
GeoblacklightAdmin::RemoveParentDctReferencesUriJob.perform_later(self) if parent_id.present?
|
44
44
|
end
|
45
45
|
|
46
|
-
# After
|
47
|
-
|
46
|
+
# After Commit Callbacks
|
47
|
+
after_commit :reindex_parent
|
48
48
|
|
49
49
|
def reindex_parent
|
50
|
-
|
50
|
+
# Set the "file size" on the parent document
|
51
|
+
file_size = 0
|
52
|
+
if parent.present? && !parent.destroyed?
|
53
|
+
unless thumbnail?
|
54
|
+
parent.document_assets.each do |document_asset|
|
55
|
+
file_size += document_asset.file_data["metadata"]["size"]
|
56
|
+
end
|
57
|
+
parent.gbl_fileSize_s = ApplicationController.helpers.number_to_human_size(file_size)
|
58
|
+
parent.save(validate: false)
|
59
|
+
end
|
60
|
+
end
|
51
61
|
end
|
52
62
|
|
53
63
|
def to_aardvark_reference
|
@@ -12,19 +12,21 @@ class Document
|
|
12
12
|
# Assume true
|
13
13
|
valid_date = true
|
14
14
|
|
15
|
-
|
15
|
+
# Cache date elements to avoid repeated queries
|
16
|
+
@date_elements ||= Element.where(field_type: "date").to_a
|
16
17
|
|
17
18
|
# Sane date values?
|
18
|
-
date_elements.each do |element|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
@date_elements.each do |element|
|
20
|
+
value = record.send(element.solr_field)
|
21
|
+
next if value.nil?
|
22
|
+
|
23
|
+
Rails.logger.debug("Date Validator")
|
24
|
+
Rails.logger.debug("Dates: #{value.inspect}")
|
25
|
+
|
26
|
+
Array(value).each do |date|
|
27
|
+
Rails.logger.debug("\nDate: #{date}")
|
28
|
+
valid_date = proper_date(record, element, date, valid_date)
|
29
|
+
break if !valid_date
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -36,7 +38,7 @@ class Document
|
|
36
38
|
valid_date = true
|
37
39
|
elsif date.class != Date
|
38
40
|
valid_date = false
|
39
|
-
record.errors.add(
|
41
|
+
record.errors.add(element.solr_field, "Bad date field type.")
|
40
42
|
end
|
41
43
|
|
42
44
|
Rails.logger.debug("#{date} - #{valid_date}")
|