bulkrax 8.2.4 → 8.3.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/assets/javascripts/bulkrax/bulkrax.js +9 -7
- data/app/assets/javascripts/bulkrax/importers.js.erb +134 -99
- data/app/controllers/bulkrax/importers_controller.rb +28 -112
- data/app/controllers/concerns/bulkrax/datatables_behavior.rb +1 -1
- data/app/factories/bulkrax/object_factory.rb +1 -4
- data/app/jobs/bulkrax/download_cloud_file_job.rb +21 -156
- data/app/jobs/bulkrax/export_work_job.rb +1 -1
- data/app/models/bulkrax/status.rb +1 -1
- data/app/models/concerns/bulkrax/export_behavior.rb +4 -8
- data/app/parsers/bulkrax/application_parser.rb +2 -25
- data/app/parsers/bulkrax/bagit_parser.rb +3 -10
- data/app/parsers/bulkrax/csv_parser.rb +17 -51
- data/app/parsers/bulkrax/parser_export_record_set.rb +1 -1
- data/app/views/bulkrax/importers/_bagit_fields.html.erb +10 -3
- data/app/views/bulkrax/importers/_csv_fields.html.erb +13 -9
- data/app/views/bulkrax/importers/_file_uploader.html.erb +37 -0
- data/app/views/bulkrax/importers/_xml_fields.html.erb +10 -4
- data/config/locales/bulkrax.en.yml +0 -3
- data/lib/bulkrax/version.rb +1 -1
- data/lib/bulkrax.rb +0 -1
- data/lib/tasks/bulkrax_tasks.rake +1 -1
- metadata +9 -32
- data/app/errors/bulkrax/unsafe_cloud_source_error.rb +0 -11
- data/app/errors/bulkrax/unsafe_path_error.rb +0 -8
- data/app/parsers/bulkrax/application_parser.rb.orig +0 -545
- data/app/services/bulkrax/cloud_source_validator.rb +0 -123
- data/app/services/bulkrax/safe_path.rb +0 -142
- data/db/migrate/20241203010707_entry_error_denormalization.rb +0 -7
- data/db/migrate/20241205212513_faster_first_entry.rb +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a409c17f35bc09ef0a8c63d06a064d01fbff68a0e4c0b91c9bfaed45d6e8169
|
|
4
|
+
data.tar.gz: 7fad94124795ff133b83d05030c550f2a52f808ac017fdd3a436c17ce039cd01
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 65280762e81baa620e73d965d5e7c58ec4ccb40d303c00cf634e7f9b3b3850e541cc9964900ce7b9aec9f6be1a7fe81dd9781db5b74209a9f8661f5f8a96f595
|
|
7
|
+
data.tar.gz: e91e65f6de8edc1640dd9b6e75c246fff4fd0812a3f87f6b4600dd9c95afc095be6076c9a80c5bca50ccc73c3831fc0a30c1160b46f18c483a6d68277bf762a8
|
|
@@ -5,18 +5,20 @@ $(document).on('turbolinks:load ready', function() {
|
|
|
5
5
|
$('button#err_toggle').click(function() {
|
|
6
6
|
$('#error_trace').toggle();
|
|
7
7
|
});
|
|
8
|
+
|
|
8
9
|
$('button#fm_toggle').click(function() {
|
|
9
10
|
$('#field_mapping').toggle();
|
|
10
11
|
});
|
|
12
|
+
|
|
11
13
|
$('#bulkraxItemModal').on('show.bs.modal', function (event) {
|
|
12
|
-
var button = $(event.relatedTarget) // Button that triggered the modal
|
|
13
|
-
var recipient = button.data('entry-id') // Extract info from data-* attributes
|
|
14
|
+
var button = $(event.relatedTarget); // Button that triggered the modal
|
|
15
|
+
var recipient = button.data('entry-id'); // Extract info from data-* attributes
|
|
14
16
|
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
|
|
15
17
|
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
|
|
16
|
-
var modal = $(this)
|
|
18
|
+
var modal = $(this);
|
|
17
19
|
modal.find('a').each(function() {
|
|
18
|
-
this.href = this.href.replace(/\d+\?/, recipient + '?')
|
|
19
|
-
})
|
|
20
|
-
return true
|
|
21
|
-
})
|
|
20
|
+
this.href = this.href.replace(/\d+\?/, recipient + '?');
|
|
21
|
+
});
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
22
24
|
});
|
|
@@ -2,205 +2,240 @@
|
|
|
2
2
|
// All this logic will automatically be available in application.js.
|
|
3
3
|
|
|
4
4
|
function prepBulkrax(event) {
|
|
5
|
-
var refresh_button = $('.refresh-set-source')
|
|
6
|
-
var base_url = $('#importer_parser_fields_base_url')
|
|
7
|
-
var initial_base_url = base_url.val()
|
|
8
|
-
var file_path_value = $('#importer_parser_fields_import_file_path').val()
|
|
9
|
-
handleFileToggle(file_path_value)
|
|
5
|
+
var refresh_button = $('.refresh-set-source');
|
|
6
|
+
var base_url = $('#importer_parser_fields_base_url');
|
|
7
|
+
var initial_base_url = base_url.val();
|
|
8
|
+
var file_path_value = $('#importer_parser_fields_import_file_path').val();
|
|
9
|
+
handleFileToggle(file_path_value);
|
|
10
|
+
|
|
11
|
+
// Initialize the uploader only if hyraxUploader is defined
|
|
12
|
+
if (typeof $.fn.hyraxUploader === 'function') {
|
|
13
|
+
// Initialize the uploader
|
|
14
|
+
$('.fileupload-bulkrax').hyraxUploader({ maxNumberOfFiles: 1 });
|
|
15
|
+
|
|
16
|
+
// Function to toggle 'required' attribute based on uploaded files
|
|
17
|
+
function toggleRequiredAttribute() {
|
|
18
|
+
const fileInput = $('#addfiles');
|
|
19
|
+
const uploadedFilesTable = $('.fileupload-bulkrax tbody.files');
|
|
20
|
+
|
|
21
|
+
if (uploadedFilesTable.find('tr.template-download').length > 0) {
|
|
22
|
+
// Remove 'required' if there are uploaded files
|
|
23
|
+
fileInput.removeAttr('required');
|
|
24
|
+
} else {
|
|
25
|
+
// Add 'required' if no uploaded files
|
|
26
|
+
fileInput.attr('required', 'required');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Check the required attribute when a file is added or removed
|
|
31
|
+
$('#addfiles').on('change', function() {
|
|
32
|
+
toggleRequiredAttribute();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Also check when an upload completes or is canceled
|
|
36
|
+
$('.fileupload-bulkrax').on('fileuploadcompleted fileuploaddestroyed', function() {
|
|
37
|
+
toggleRequiredAttribute();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Ensure 'required' is only added if there are no files on form reset
|
|
41
|
+
$('#file-upload-cancel-btn').on('click', function() {
|
|
42
|
+
$('#addfiles').attr('required', 'required');
|
|
43
|
+
$('#addfiles').val(''); // Clear file input to ensure 'required' behavior resets
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Initial check in case files are already uploaded
|
|
47
|
+
toggleRequiredAttribute();
|
|
48
|
+
}
|
|
10
49
|
|
|
11
50
|
// handle refreshing/loading of external sets via button click
|
|
12
51
|
$('body').on('click', '.refresh-set-source', function(e) {
|
|
13
|
-
e.preventDefault()
|
|
52
|
+
e.preventDefault();
|
|
14
53
|
|
|
15
|
-
external_set_select = $("#importer_parser_fields_set")
|
|
16
|
-
handleSourceLoad(refresh_button, base_url, external_set_select)
|
|
17
|
-
})
|
|
54
|
+
external_set_select = $("#importer_parser_fields_set");
|
|
55
|
+
handleSourceLoad(refresh_button, base_url, external_set_select);
|
|
56
|
+
});
|
|
18
57
|
|
|
19
58
|
// handle refreshing/loading of external sets via blur event for the base_url field
|
|
20
59
|
$('body').on('blur', '#importer_parser_fields_base_url', function(e) {
|
|
21
|
-
e.preventDefault()
|
|
60
|
+
e.preventDefault();
|
|
22
61
|
|
|
23
62
|
// retrieve the latest base_url
|
|
24
|
-
base_url = $('#importer_parser_fields_base_url')
|
|
63
|
+
base_url = $('#importer_parser_fields_base_url');
|
|
25
64
|
|
|
26
65
|
// ensure we don't make another query if the value is the same -- this can be forced by clicking the refresh button
|
|
27
66
|
if (initial_base_url != base_url.val()) {
|
|
28
|
-
external_set_select = $("#importer_parser_fields_set")
|
|
29
|
-
handleSourceLoad(refresh_button, base_url, external_set_select)
|
|
30
|
-
initial_base_url = base_url.val()
|
|
67
|
+
external_set_select = $("#importer_parser_fields_set");
|
|
68
|
+
handleSourceLoad(refresh_button, base_url, external_set_select);
|
|
69
|
+
initial_base_url = base_url.val();
|
|
31
70
|
}
|
|
32
|
-
})
|
|
71
|
+
});
|
|
33
72
|
|
|
34
73
|
// hide and show correct parser fields depending on klass setting
|
|
35
74
|
$('body').on('change', '#importer_parser_klass', function(e) {
|
|
36
|
-
handleParserKlass()
|
|
37
|
-
})
|
|
38
|
-
handleParserKlass()
|
|
75
|
+
handleParserKlass();
|
|
76
|
+
});
|
|
77
|
+
handleParserKlass();
|
|
39
78
|
|
|
40
79
|
// observer for cloud files being added
|
|
41
80
|
var form = document.getElementById('new_importer');
|
|
42
81
|
if (form == null) {
|
|
43
|
-
|
|
82
|
+
form = document.getElementsByClassName('edit_importer')[0];
|
|
44
83
|
}
|
|
84
|
+
|
|
45
85
|
// only setup the observer on the new and edit importer pages
|
|
46
86
|
if (form != null) {
|
|
47
87
|
var config = { childList: true, attributes: true };
|
|
48
88
|
var callback = function(mutationsList) {
|
|
49
89
|
for(var mutation of mutationsList) {
|
|
50
|
-
|
|
51
90
|
if (mutation.type == 'childList') {
|
|
52
91
|
browseButton = document.getElementById('browse');
|
|
53
|
-
var exp = /selected_files\[[0-9]*\]\[url\]
|
|
92
|
+
var exp = /selected_files\[[0-9]*\]\[url\]/;
|
|
54
93
|
for (var node of mutation.addedNodes) {
|
|
55
94
|
if (node.attributes != undefined) {
|
|
56
|
-
var name = node.attributes.name.value
|
|
95
|
+
var name = node.attributes.name.value;
|
|
57
96
|
if (exp.test(name)) {
|
|
58
97
|
browseButton.innerHTML = 'Cloud Files Added';
|
|
59
98
|
browseButton.style.backgroundColor = 'green';
|
|
60
|
-
browseButton.after(document.createElement("br"), node.value.toString())
|
|
99
|
+
browseButton.after(document.createElement("br"), node.value.toString());
|
|
61
100
|
}
|
|
62
101
|
}
|
|
63
102
|
}
|
|
64
103
|
}
|
|
65
104
|
}
|
|
66
105
|
};
|
|
67
|
-
var observer = new MutationObserver
|
|
68
|
-
observer.observe
|
|
106
|
+
var observer = new MutationObserver(callback);
|
|
107
|
+
observer.observe(form, config);
|
|
69
108
|
}
|
|
70
109
|
}
|
|
71
110
|
|
|
72
111
|
function handleFileToggle(file_path) {
|
|
73
112
|
if (file_path === undefined || file_path.length === 0) {
|
|
74
|
-
$('#file_path').hide()
|
|
75
|
-
$('#file_upload').hide()
|
|
76
|
-
$('#cloud').hide()
|
|
77
|
-
$('#existing_options').hide()
|
|
78
|
-
$('#file_path input').attr('required', null)
|
|
79
|
-
$('#file_upload input').attr('required', null)
|
|
113
|
+
$('#file_path').hide();
|
|
114
|
+
$('#file_upload').hide();
|
|
115
|
+
$('#cloud').hide();
|
|
116
|
+
$('#existing_options').hide();
|
|
117
|
+
$('#file_path input').attr('required', null);
|
|
118
|
+
$('#file_upload input').attr('required', null);
|
|
80
119
|
} else {
|
|
81
|
-
$('#file_path').show()
|
|
82
|
-
$('#file_upload').hide()
|
|
83
|
-
$('#cloud').hide()
|
|
84
|
-
$('#existing_options').hide()
|
|
85
|
-
$('#file_path input').attr('required', 'required')
|
|
86
|
-
$('#file_upload input').attr('required', null)
|
|
87
|
-
$('#importer_parser_fields_file_style_specify_a_path_on_the_server').attr('checked', true)
|
|
120
|
+
$('#file_path').show();
|
|
121
|
+
$('#file_upload').hide();
|
|
122
|
+
$('#cloud').hide();
|
|
123
|
+
$('#existing_options').hide();
|
|
124
|
+
$('#file_path input').attr('required', 'required');
|
|
125
|
+
$('#file_upload input').attr('required', null);
|
|
126
|
+
$('#importer_parser_fields_file_style_specify_a_path_on_the_server').attr('checked', true);
|
|
88
127
|
}
|
|
89
128
|
|
|
90
129
|
$('#importer_parser_fields_file_style_upload_a_file').click(function(e){
|
|
91
|
-
$('#file_path').hide()
|
|
92
|
-
$('#file_upload').show()
|
|
93
|
-
$('#cloud').hide()
|
|
94
|
-
$('#existing_options').hide()
|
|
95
|
-
$('#file_path input').attr('required', null)
|
|
96
|
-
$('#file_upload input').attr('required', 'required')
|
|
97
|
-
})
|
|
130
|
+
$('#file_path').hide();
|
|
131
|
+
$('#file_upload').show();
|
|
132
|
+
$('#cloud').hide();
|
|
133
|
+
$('#existing_options').hide();
|
|
134
|
+
$('#file_path input').attr('required', null);
|
|
135
|
+
$('#file_upload input').attr('required', 'required');
|
|
136
|
+
});
|
|
98
137
|
$('#importer_parser_fields_file_style_specify_a_path_on_the_server').click(function(e){
|
|
99
|
-
$('#file_path').show()
|
|
100
|
-
$('#file_upload').hide()
|
|
101
|
-
$('#cloud').hide()
|
|
102
|
-
$('#existing_options').hide()
|
|
103
|
-
$('#file_path input').attr('required', 'required')
|
|
104
|
-
$('#file_upload input').attr('required', null)
|
|
105
|
-
})
|
|
138
|
+
$('#file_path').show();
|
|
139
|
+
$('#file_upload').hide();
|
|
140
|
+
$('#cloud').hide();
|
|
141
|
+
$('#existing_options').hide();
|
|
142
|
+
$('#file_path input').attr('required', 'required');
|
|
143
|
+
$('#file_upload input').attr('required', null);
|
|
144
|
+
});
|
|
106
145
|
$('#importer_parser_fields_file_style_add_cloud_file').click(function(e){
|
|
107
|
-
$('#file_path').hide()
|
|
108
|
-
$('#file_upload').hide()
|
|
109
|
-
$('#cloud').show()
|
|
110
|
-
$('#existing_options').hide()
|
|
111
|
-
$('#file_path input').attr('required', null)
|
|
112
|
-
$('#file_upload input').attr('required', null)
|
|
113
|
-
})
|
|
146
|
+
$('#file_path').hide();
|
|
147
|
+
$('#file_upload').hide();
|
|
148
|
+
$('#cloud').show();
|
|
149
|
+
$('#existing_options').hide();
|
|
150
|
+
$('#file_path input').attr('required', null);
|
|
151
|
+
$('#file_upload input').attr('required', null);
|
|
152
|
+
});
|
|
114
153
|
$('#importer_parser_fields_file_style_existing_entries').click(function(e){
|
|
115
|
-
$('#file_path').hide()
|
|
116
|
-
$('#file_upload').hide()
|
|
117
|
-
$('#cloud').hide()
|
|
118
|
-
$('#existing_options').show()
|
|
119
|
-
$('#file_path input').attr('required', null)
|
|
120
|
-
$('#file_upload input').attr('required', null)
|
|
121
|
-
})
|
|
122
|
-
|
|
154
|
+
$('#file_path').hide();
|
|
155
|
+
$('#file_upload').hide();
|
|
156
|
+
$('#cloud').hide();
|
|
157
|
+
$('#existing_options').show();
|
|
158
|
+
$('#file_path input').attr('required', null);
|
|
159
|
+
$('#file_upload input').attr('required', null);
|
|
160
|
+
});
|
|
123
161
|
}
|
|
124
162
|
|
|
125
163
|
function handleParserKlass() {
|
|
126
164
|
<% Bulkrax.parsers.map{ |p| p[:partial]}.uniq.each do |partial| %>
|
|
127
165
|
if($('.<%= partial %>').length > 0) {
|
|
128
|
-
window.<%= partial %> = $('.<%= partial %>').detach()
|
|
166
|
+
window.<%= partial %> = $('.<%= partial %>').detach();
|
|
129
167
|
}
|
|
130
168
|
<% end %>
|
|
131
169
|
|
|
132
|
-
var parser_klass = $("#importer_parser_klass option:selected")
|
|
170
|
+
var parser_klass = $("#importer_parser_klass option:selected");
|
|
133
171
|
if(parser_klass.length > 0 && parser_klass.data('partial') && parser_klass.data('partial').length > 0) {
|
|
134
|
-
$('.parser_fields').append(window[parser_klass.data('partial')])
|
|
172
|
+
$('.parser_fields').append(window[parser_klass.data('partial')]);
|
|
135
173
|
}
|
|
136
174
|
|
|
137
|
-
handleBrowseEverything()
|
|
138
|
-
var file_path_value = $('#importer_parser_fields_import_file_path').val()
|
|
139
|
-
handleFileToggle(file_path_value)
|
|
175
|
+
handleBrowseEverything();
|
|
176
|
+
var file_path_value = $('#importer_parser_fields_import_file_path').val();
|
|
177
|
+
handleFileToggle(file_path_value);
|
|
140
178
|
}
|
|
141
179
|
|
|
142
180
|
function handleBrowseEverything(){
|
|
143
|
-
var button = $("button[data-toggle='browse-everything']")
|
|
181
|
+
var button = $("button[data-toggle='browse-everything']");
|
|
144
182
|
if(button.length == 0) { return; }
|
|
145
183
|
button.browseEverything({
|
|
146
184
|
route: button.data('route'),
|
|
147
185
|
target: button.data('target')
|
|
148
186
|
}).done(function(data) {
|
|
149
187
|
var evt = { isDefaultPrevented: function() { return false; } };
|
|
150
|
-
$('.ev-browser.show').removeClass('show')
|
|
188
|
+
$('.ev-browser.show').removeClass('show');
|
|
151
189
|
if($('#fileupload').length > 0) {
|
|
152
|
-
var files = $.map(data, function(d) { return { name: d.file_name, size: d.file_size, id: d.url } });
|
|
190
|
+
var files = $.map(data, function(d) { return { name: d.file_name, size: d.file_size, id: d.url }; });
|
|
153
191
|
$.blueimp.fileupload.prototype.options.done.call($('#fileupload').fileupload(), evt, { result: { files: files }});
|
|
154
192
|
}
|
|
155
|
-
return true
|
|
156
|
-
// User has submitted files; data contains an array of URLs and their options
|
|
193
|
+
return true;
|
|
157
194
|
}).cancel(function() {
|
|
158
|
-
$('.ev-browser.show').removeClass('show')
|
|
159
|
-
// User cancelled the browse operation
|
|
195
|
+
$('.ev-browser.show').removeClass('show');
|
|
160
196
|
}).fail(function(status, error, text) {
|
|
161
|
-
$('.ev-browser.show').removeClass('show')
|
|
162
|
-
// URL retrieval experienced a technical failure
|
|
197
|
+
$('.ev-browser.show').removeClass('show');
|
|
163
198
|
});
|
|
164
199
|
}
|
|
165
200
|
|
|
166
201
|
function handleSourceLoad(refresh_button, base_url, external_set_select) {
|
|
167
202
|
if (base_url.val() == "") { // ignore empty base_url value
|
|
168
|
-
return
|
|
203
|
+
return;
|
|
169
204
|
}
|
|
170
205
|
|
|
171
|
-
var initial_button_text = refresh_button.html()
|
|
206
|
+
var initial_button_text = refresh_button.html();
|
|
172
207
|
|
|
173
|
-
refresh_button.html('Refreshing...')
|
|
174
|
-
refresh_button.attr('disabled', true)
|
|
208
|
+
refresh_button.html('Refreshing...');
|
|
209
|
+
refresh_button.attr('disabled', true);
|
|
175
210
|
|
|
176
211
|
$.post('/importers/external_sets', {
|
|
177
212
|
base_url: base_url.val(),
|
|
178
213
|
}, function(res) {
|
|
179
214
|
if (!res.error) {
|
|
180
|
-
genExternalSetOptions(external_set_select, res.sets)
|
|
215
|
+
genExternalSetOptions(external_set_select, res.sets);
|
|
181
216
|
} else {
|
|
182
|
-
setError(external_set_select, res.error)
|
|
217
|
+
setError(external_set_select, res.error);
|
|
183
218
|
}
|
|
184
219
|
|
|
185
|
-
refresh_button.html(initial_button_text)
|
|
186
|
-
refresh_button.attr('disabled', false)
|
|
187
|
-
})
|
|
220
|
+
refresh_button.html(initial_button_text);
|
|
221
|
+
refresh_button.attr('disabled', false);
|
|
222
|
+
});
|
|
188
223
|
}
|
|
189
224
|
|
|
190
225
|
function genExternalSetOptions(selector, sets) {
|
|
191
|
-
out = '<option value="">- Select One -</option>'
|
|
226
|
+
out = '<option value="">- Select One -</option>';
|
|
192
227
|
|
|
193
228
|
out += sets.map(function(set) {
|
|
194
|
-
return '<option value="'+set[1]+'">'+set[0]+'</option>'
|
|
195
|
-
})
|
|
229
|
+
return '<option value="'+set[1]+'">'+set[0]+'</option>';
|
|
230
|
+
});
|
|
196
231
|
|
|
197
|
-
selector.html(out)
|
|
198
|
-
selector.attr('disabled', false)
|
|
232
|
+
selector.html(out);
|
|
233
|
+
selector.attr('disabled', false);
|
|
199
234
|
}
|
|
200
235
|
|
|
201
236
|
function setError(selector, error) {
|
|
202
|
-
selector.html('<option value="none">Error - Please enter Base URL and try again</option>')
|
|
203
|
-
selector.attr('disabled', true)
|
|
237
|
+
selector.html('<option value="none">Error - Please enter Base URL and try again</option>');
|
|
238
|
+
selector.attr('disabled', true);
|
|
204
239
|
}
|
|
205
240
|
|
|
206
|
-
$(document).on({'ready': prepBulkrax, 'turbolinks:load': prepBulkrax})
|
|
241
|
+
$(document).on({'ready': prepBulkrax, 'turbolinks:load': prepBulkrax});
|
|
@@ -84,6 +84,7 @@ module Bulkrax
|
|
|
84
84
|
if api_request?
|
|
85
85
|
return return_json_response unless valid_create_params?
|
|
86
86
|
end
|
|
87
|
+
uploads = Hyrax::UploadedFile.find(params[:uploaded_files]) if params[:uploaded_files].present?
|
|
87
88
|
file = file_param
|
|
88
89
|
cloud_files = cloud_params
|
|
89
90
|
|
|
@@ -93,15 +94,8 @@ module Bulkrax
|
|
|
93
94
|
# the following line is needed to handle updating remote files of a FileSet
|
|
94
95
|
# on a new import otherwise it only gets updated during the update path
|
|
95
96
|
@importer.parser_fields['update_files'] = true if params[:commit] == 'Create and Import'
|
|
96
|
-
|
|
97
|
-
# Reject an unsafe cloud selection before the importer is ever
|
|
98
|
-
# persisted, rather than after save when a row would already exist.
|
|
99
|
-
preflight_cloud_files!(cloud_files)
|
|
100
|
-
|
|
101
97
|
if @importer.save
|
|
102
|
-
|
|
103
|
-
dispatch_cloud_downloads!
|
|
104
|
-
|
|
98
|
+
files_for_import(file, cloud_files, uploads)
|
|
105
99
|
if params[:commit] == 'Create and Import'
|
|
106
100
|
Bulkrax::ImporterJob.send(@importer.parser.perform_method, @importer.id)
|
|
107
101
|
render_request('Importer was successfully created and import has been queued.')
|
|
@@ -112,11 +106,13 @@ module Bulkrax
|
|
|
112
106
|
render_request('Importer was successfully created.')
|
|
113
107
|
end
|
|
114
108
|
else
|
|
115
|
-
|
|
109
|
+
if api_request?
|
|
110
|
+
json_response('create', :unprocessable_entity)
|
|
111
|
+
else
|
|
112
|
+
render :new
|
|
113
|
+
end
|
|
116
114
|
end
|
|
117
115
|
# rubocop:enable Style/IfInsideElse
|
|
118
|
-
rescue Bulkrax::UnsafeCloudSourceError, Bulkrax::UnsafePathError => e
|
|
119
|
-
reject_unsafe_cloud_files(e)
|
|
120
116
|
end
|
|
121
117
|
# rubocop:enable Metrics/AbcSize
|
|
122
118
|
|
|
@@ -127,26 +123,18 @@ module Bulkrax
|
|
|
127
123
|
if api_request?
|
|
128
124
|
return return_json_response unless valid_update_params?
|
|
129
125
|
end
|
|
130
|
-
|
|
126
|
+
uploads = Hyrax::UploadedFile.find(params[:uploaded_files]) if params[:uploaded_files].present?
|
|
131
127
|
file = file_param
|
|
132
128
|
cloud_files = cloud_params
|
|
133
129
|
|
|
134
130
|
# Skipped during a continue
|
|
135
131
|
field_mapping_params if params[:importer][:parser_fields].present?
|
|
136
132
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
# below then leaves the importer's persisted attributes untouched.
|
|
140
|
-
@importer.assign_attributes(importer_params)
|
|
141
|
-
preflight_cloud_files!(cloud_files)
|
|
142
|
-
|
|
143
|
-
if @importer.save
|
|
144
|
-
return render_update_failure if files_for_import(file, cloud_files) && !@importer.save
|
|
145
|
-
return render_update_failure if params[:commit] != 'Update Importer' && !set_files_parser_fields
|
|
146
|
-
dispatch_cloud_downloads!
|
|
147
|
-
|
|
133
|
+
if @importer.update(importer_params)
|
|
134
|
+
files_for_import(file, cloud_files, uploads)
|
|
148
135
|
# do not perform the import
|
|
149
136
|
unless params[:commit] == 'Update Importer'
|
|
137
|
+
set_files_parser_fields
|
|
150
138
|
Bulkrax::ImporterJob.send(@importer.parser.perform_method, @importer.id, update_harvest)
|
|
151
139
|
end
|
|
152
140
|
if api_request?
|
|
@@ -155,10 +143,12 @@ module Bulkrax
|
|
|
155
143
|
redirect_to importers_path, notice: 'Importer was successfully updated.'
|
|
156
144
|
end
|
|
157
145
|
else
|
|
158
|
-
|
|
146
|
+
if api_request?
|
|
147
|
+
json_response('update', :unprocessable_entity, 'Something went wrong.')
|
|
148
|
+
else
|
|
149
|
+
render :edit
|
|
150
|
+
end
|
|
159
151
|
end
|
|
160
|
-
rescue Bulkrax::UnsafeCloudSourceError, Bulkrax::UnsafePathError => e
|
|
161
|
-
reject_unsafe_cloud_files(e)
|
|
162
152
|
end
|
|
163
153
|
# rubocop:enable all
|
|
164
154
|
# rubocop:enable Metrics/MethodLength
|
|
@@ -231,68 +221,26 @@ module Bulkrax
|
|
|
231
221
|
|
|
232
222
|
private
|
|
233
223
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
# touch the importer's workspace (no path_for_import, no directory
|
|
237
|
-
# creation, no download): for #create that workspace doesn't exist
|
|
238
|
-
# yet, and for #update it must not be assumed safe to touch before the
|
|
239
|
-
# proposed attributes are known to be acceptable.
|
|
240
|
-
#
|
|
241
|
-
# @param cloud_files [Hash, nil] cloud file specs from browse-everything
|
|
242
|
-
# @raise [Bulkrax::UnsafePathError, Bulkrax::UnsafeCloudSourceError] on the first unsafe entry
|
|
243
|
-
def preflight_cloud_files!(cloud_files)
|
|
244
|
-
return if cloud_files.blank?
|
|
245
|
-
|
|
246
|
-
cloud_files.values.each { |file| Bulkrax::CloudSourceValidator.preflight!(file) }
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
# Assigns files/cloud selections onto the importer record's in-memory
|
|
250
|
-
# parser fields, but does not save: the caller owns the second save,
|
|
251
|
-
# so it can check its result and avoid rendering success or enqueueing
|
|
252
|
-
# an import on failure.
|
|
253
|
-
#
|
|
254
|
-
# @return [Boolean] true if any parser field was touched and a second save is needed
|
|
255
|
-
def files_for_import(file, cloud_files)
|
|
256
|
-
@cloud_download_plan = nil
|
|
257
|
-
return false if file.blank? && cloud_files.blank?
|
|
224
|
+
def files_for_import(file, cloud_files, uploads)
|
|
225
|
+
return if file.blank? && cloud_files.blank? && uploads.blank?
|
|
258
226
|
|
|
259
227
|
@importer[:parser_fields]['import_file_path'] = @importer.parser.write_import_file(file) if file.present?
|
|
260
228
|
if cloud_files.present?
|
|
261
229
|
@importer[:parser_fields]['cloud_file_paths'] = cloud_files
|
|
262
|
-
assign_cloud_file_paths(cloud_files)
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
true
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
# For a parser that separates planning from dispatch (currently only
|
|
269
|
-
# CsvParser), resolves and validates the whole batch and records the
|
|
270
|
-
# target paths, deferring enqueue until {#dispatch_cloud_downloads!} is
|
|
271
|
-
# called after the controller persists those paths. Other parsers
|
|
272
|
-
# (e.g. BagitParser) already complete cloud retrieval synchronously
|
|
273
|
-
# and return the resolved path directly, so there's nothing left to
|
|
274
|
-
# dispatch.
|
|
275
|
-
def assign_cloud_file_paths(cloud_files)
|
|
276
|
-
parser = @importer.parser
|
|
277
|
-
if parser.respond_to?(:plan_cloud_files)
|
|
278
|
-
@cloud_download_plan = parser.plan_cloud_files(cloud_files)
|
|
279
|
-
@importer[:parser_fields]['original_file_paths'] =
|
|
280
|
-
@cloud_download_plan.map { |_file, _relative_filename, target_file| target_file }
|
|
281
|
-
else
|
|
282
230
|
# For BagIt, there will only be one bag, so we get the file_path back and set import_file_path
|
|
283
|
-
|
|
231
|
+
# For CSV, we expect only file uploads, so we won't get the file_path back
|
|
232
|
+
# and we expect the import_file_path to be set already
|
|
233
|
+
target = @importer.parser.retrieve_cloud_files(cloud_files, @importer)
|
|
284
234
|
@importer[:parser_fields]['import_file_path'] = target if target.present?
|
|
285
235
|
end
|
|
286
|
-
end
|
|
287
236
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return if @cloud_download_plan.blank?
|
|
237
|
+
if uploads.present?
|
|
238
|
+
uploads.each do |upload|
|
|
239
|
+
@importer[:parser_fields]['import_file_path'] = @importer.parser.write_import_file(upload.file.file)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
294
242
|
|
|
295
|
-
@importer.
|
|
243
|
+
@importer.save
|
|
296
244
|
end
|
|
297
245
|
|
|
298
246
|
# Use callbacks to share common setup or constraints between actions.
|
|
@@ -378,36 +326,6 @@ module Bulkrax
|
|
|
378
326
|
'text/csv'
|
|
379
327
|
end
|
|
380
328
|
|
|
381
|
-
# Reports an unsafe cloud-file batch without leaking the error's class
|
|
382
|
-
# or backtrace (which could include a provider auth header) to the
|
|
383
|
-
# response; `e.message` is always one of our own static, credential-free
|
|
384
|
-
# strings (see Bulkrax::CloudSourceValidator / Bulkrax::SafePath).
|
|
385
|
-
def reject_unsafe_cloud_files(e)
|
|
386
|
-
Rails.logger.error("Bulkrax: rejected unsafe cloud file batch for importer #{@importer&.id}: #{e.class}: #{e.message}")
|
|
387
|
-
if api_request?
|
|
388
|
-
json_response('create', :unprocessable_entity, e.message)
|
|
389
|
-
else
|
|
390
|
-
flash[:error] = e.message
|
|
391
|
-
redirect_back fallback_location: importers_path
|
|
392
|
-
end
|
|
393
|
-
end
|
|
394
|
-
|
|
395
|
-
def render_create_failure
|
|
396
|
-
if api_request?
|
|
397
|
-
json_response('create', :unprocessable_entity)
|
|
398
|
-
else
|
|
399
|
-
render :new
|
|
400
|
-
end
|
|
401
|
-
end
|
|
402
|
-
|
|
403
|
-
def render_update_failure
|
|
404
|
-
if api_request?
|
|
405
|
-
json_response('update', :unprocessable_entity, 'Something went wrong.')
|
|
406
|
-
else
|
|
407
|
-
render :edit
|
|
408
|
-
end
|
|
409
|
-
end
|
|
410
|
-
|
|
411
329
|
def render_request(message, validate_only = false)
|
|
412
330
|
if api_request?
|
|
413
331
|
json_response('create', :created, message)
|
|
@@ -423,8 +341,6 @@ module Bulkrax
|
|
|
423
341
|
params[:commit] == 'Update and Harvest Updated Items'
|
|
424
342
|
end
|
|
425
343
|
|
|
426
|
-
# @return [Boolean] the result of the save, so the caller can treat a
|
|
427
|
-
# failure here like an ordinary validation failure
|
|
428
344
|
def set_files_parser_fields
|
|
429
345
|
@importer.parser_fields['update_files'] =
|
|
430
346
|
@importer.parser_fields['replace_files'] =
|
|
@@ -437,7 +353,7 @@ module Bulkrax
|
|
|
437
353
|
elsif params[:commit] == 'Remove and Rerun'
|
|
438
354
|
@importer.parser_fields['remove_and_rerun'] = true
|
|
439
355
|
elsif params[:commit] == 'Update and Harvest Updated Items'
|
|
440
|
-
return
|
|
356
|
+
return
|
|
441
357
|
else
|
|
442
358
|
@importer.parser_fields['metadata_only'] = true
|
|
443
359
|
end
|
|
@@ -132,7 +132,7 @@ module Bulkrax
|
|
|
132
132
|
status_message: status_message_for(e),
|
|
133
133
|
type: e.type,
|
|
134
134
|
updated_at: e.updated_at,
|
|
135
|
-
errors: e.
|
|
135
|
+
errors: e.latest_status&.error_class&.present? ? view_context.link_to(e.latest_status.error_class, view_context.item_entry_path(item, e), title: e.latest_status.error_message) : "",
|
|
136
136
|
actions: entry_util_links(e, item)
|
|
137
137
|
}
|
|
138
138
|
end
|