bulkrax 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +205 -0
- data/README.md +202 -0
- data/Rakefile +42 -0
- data/app/assets/config/bulkrax_manifest.js +2 -0
- data/app/assets/javascripts/bulkrax/application.js +14 -0
- data/app/assets/javascripts/bulkrax/bulkrax.js +11 -0
- data/app/assets/javascripts/bulkrax/entries.js +15 -0
- data/app/assets/javascripts/bulkrax/exporters.js +60 -0
- data/app/assets/javascripts/bulkrax/importers.js.erb +166 -0
- data/app/assets/stylesheets/bulkrax/accordion.scss +40 -0
- data/app/assets/stylesheets/bulkrax/application.css +15 -0
- data/app/assets/stylesheets/bulkrax/coderay.scss +264 -0
- data/app/assets/stylesheets/bulkrax/import_export.scss +37 -0
- data/app/controllers/bulkrax/application_controller.rb +8 -0
- data/app/controllers/bulkrax/entries_controller.rb +44 -0
- data/app/controllers/bulkrax/exporters_controller.rb +125 -0
- data/app/controllers/bulkrax/importers_controller.rb +315 -0
- data/app/controllers/concerns/bulkrax/api.rb +29 -0
- data/app/factories/bulkrax/object_factory.rb +230 -0
- data/app/helpers/bulkrax/application_helper.rb +15 -0
- data/app/helpers/bulkrax/exporters_helper.rb +6 -0
- data/app/helpers/bulkrax/importers_helper.rb +13 -0
- data/app/helpers/bulkrax/validation_helper.rb +153 -0
- data/app/jobs/bulkrax/application_job.rb +6 -0
- data/app/jobs/bulkrax/child_relationships_job.rb +128 -0
- data/app/jobs/bulkrax/delete_work_job.rb +16 -0
- data/app/jobs/bulkrax/download_cloud_file_job.rb +18 -0
- data/app/jobs/bulkrax/export_work_job.rb +37 -0
- data/app/jobs/bulkrax/exporter_job.rb +14 -0
- data/app/jobs/bulkrax/import_work_collection_job.rb +41 -0
- data/app/jobs/bulkrax/import_work_job.rb +32 -0
- data/app/jobs/bulkrax/importer_job.rb +26 -0
- data/app/mailers/bulkrax/application_mailer.rb +8 -0
- data/app/matchers/bulkrax/application_matcher.rb +113 -0
- data/app/matchers/bulkrax/bagit_matcher.rb +6 -0
- data/app/matchers/bulkrax/csv_matcher.rb +6 -0
- data/app/matchers/bulkrax/oai_matcher.rb +6 -0
- data/app/models/bulkrax/application_record.rb +7 -0
- data/app/models/bulkrax/csv_collection_entry.rb +19 -0
- data/app/models/bulkrax/csv_entry.rb +163 -0
- data/app/models/bulkrax/entry.rb +104 -0
- data/app/models/bulkrax/exporter.rb +122 -0
- data/app/models/bulkrax/exporter_run.rb +7 -0
- data/app/models/bulkrax/import_failed.rb +13 -0
- data/app/models/bulkrax/importer.rb +155 -0
- data/app/models/bulkrax/importer_run.rb +8 -0
- data/app/models/bulkrax/oai_dc_entry.rb +6 -0
- data/app/models/bulkrax/oai_entry.rb +74 -0
- data/app/models/bulkrax/oai_qualified_dc_entry.rb +6 -0
- data/app/models/bulkrax/oai_set_entry.rb +19 -0
- data/app/models/bulkrax/rdf_collection_entry.rb +19 -0
- data/app/models/bulkrax/rdf_entry.rb +90 -0
- data/app/models/bulkrax/status.rb +25 -0
- data/app/models/bulkrax/xml_entry.rb +73 -0
- data/app/models/concerns/bulkrax/download_behavior.rb +61 -0
- data/app/models/concerns/bulkrax/errored_entries.rb +45 -0
- data/app/models/concerns/bulkrax/export_behavior.rb +58 -0
- data/app/models/concerns/bulkrax/file_factory.rb +140 -0
- data/app/models/concerns/bulkrax/has_local_processing.rb +7 -0
- data/app/models/concerns/bulkrax/has_matchers.rb +155 -0
- data/app/models/concerns/bulkrax/import_behavior.rb +90 -0
- data/app/models/concerns/bulkrax/importer_exporter_behavior.rb +34 -0
- data/app/models/concerns/bulkrax/status_info.rb +56 -0
- data/app/parsers/bulkrax/application_parser.rb +299 -0
- data/app/parsers/bulkrax/bagit_parser.rb +157 -0
- data/app/parsers/bulkrax/csv_parser.rb +266 -0
- data/app/parsers/bulkrax/oai_dc_parser.rb +130 -0
- data/app/parsers/bulkrax/oai_qualified_dc_parser.rb +9 -0
- data/app/parsers/bulkrax/xml_parser.rb +103 -0
- data/app/views/bulkrax/entries/_parsed_metadata.html.erb +19 -0
- data/app/views/bulkrax/entries/_raw_metadata.html.erb +19 -0
- data/app/views/bulkrax/entries/show.html.erb +63 -0
- data/app/views/bulkrax/exporters/_form.html.erb +120 -0
- data/app/views/bulkrax/exporters/edit.html.erb +23 -0
- data/app/views/bulkrax/exporters/index.html.erb +67 -0
- data/app/views/bulkrax/exporters/new.html.erb +23 -0
- data/app/views/bulkrax/exporters/show.html.erb +124 -0
- data/app/views/bulkrax/importers/_bagit_fields.html.erb +54 -0
- data/app/views/bulkrax/importers/_browse_everything.html.erb +12 -0
- data/app/views/bulkrax/importers/_csv_fields.html.erb +39 -0
- data/app/views/bulkrax/importers/_edit_form_buttons.html.erb +16 -0
- data/app/views/bulkrax/importers/_form.html.erb +35 -0
- data/app/views/bulkrax/importers/_oai_fields.html.erb +42 -0
- data/app/views/bulkrax/importers/_xml_fields.html.erb +60 -0
- data/app/views/bulkrax/importers/edit.html.erb +20 -0
- data/app/views/bulkrax/importers/index.html.erb +77 -0
- data/app/views/bulkrax/importers/new.html.erb +25 -0
- data/app/views/bulkrax/importers/show.html.erb +175 -0
- data/app/views/bulkrax/importers/upload_corrected_entries.html.erb +37 -0
- data/app/views/bulkrax/shared/_bulkrax_errors.html.erb +52 -0
- data/app/views/bulkrax/shared/_bulkrax_field_mapping.html.erb +39 -0
- data/app/views/hyrax/dashboard/sidebar/_bulkrax_sidebar_additions.html.erb +6 -0
- data/app/views/hyrax/dashboard/sidebar/_repository_content.html.erb +19 -0
- data/app/views/layouts/bulkrax/application.html.erb +14 -0
- data/config/locales/bulkrax.en.yml +36 -0
- data/config/routes.rb +18 -0
- data/db/migrate/20181011230201_create_bulkrax_importers.rb +18 -0
- data/db/migrate/20181011230228_create_bulkrax_importer_runs.rb +16 -0
- data/db/migrate/20190325183136_create_bulkrax_entries.rb +16 -0
- data/db/migrate/20190601221109_add_status_to_entry.rb +9 -0
- data/db/migrate/20190715161939_add_collections_to_importer_runs.rb +6 -0
- data/db/migrate/20190715162044_change_collection_ids_on_entries.rb +5 -0
- data/db/migrate/20190729124607_create_bulkrax_exporters.rb +19 -0
- data/db/migrate/20190729134158_create_bulkrax_exporter_runs.rb +14 -0
- data/db/migrate/20190731114016_change_importer_and_exporter_to_polymorphic.rb +12 -0
- data/db/migrate/20191203225129_add_total_collection_records_to_importer_runs.rb +5 -0
- data/db/migrate/20191204191623_add_children_to_importer_runs.rb +6 -0
- data/db/migrate/20191204223857_change_total_records_to_total_work_entries.rb +6 -0
- data/db/migrate/20191212155530_change_entry_last_error.rb +19 -0
- data/db/migrate/20200108194557_add_validate_only_to_bulkrax_importers.rb +5 -0
- data/db/migrate/20200301232856_add_status_to_importers.rb +9 -0
- data/db/migrate/20200312190638_remove_foreign_key_from_bulkrax_entries.rb +5 -0
- data/db/migrate/20200326235838_add_status_to_exporters.rb +7 -0
- data/db/migrate/20200601204556_add_invalid_record_to_importer_run.rb +5 -0
- data/db/migrate/20200818055819_create_bulkrax_statuses.rb +18 -0
- data/db/migrate/20200819054016_move_to_statuses.rb +30 -0
- data/db/migrate/20201106014204_add_date_filter_and_status_to_bulkrax_exporters.rb +7 -0
- data/db/migrate/20201117220007_add_workflow_status_to_bulkrax_exporter.rb +5 -0
- data/db/migrate/20210806044408_remove_unused_last_error.rb +7 -0
- data/db/migrate/20210806065737_increase_text_sizes.rb +12 -0
- data/lib/bulkrax.rb +161 -0
- data/lib/bulkrax/engine.rb +37 -0
- data/lib/bulkrax/version.rb +5 -0
- data/lib/generators/bulkrax/install_generator.rb +80 -0
- data/lib/generators/bulkrax/templates/README +3 -0
- data/lib/generators/bulkrax/templates/app/assets/images/bulkrax/removed.png +0 -0
- data/lib/generators/bulkrax/templates/app/models/concerns/bulkrax/has_local_processing.rb +8 -0
- data/lib/generators/bulkrax/templates/bin/importer +140 -0
- data/lib/generators/bulkrax/templates/config/bulkrax_api.yml +84 -0
- data/lib/generators/bulkrax/templates/config/initializers/bulkrax.rb +72 -0
- data/lib/tasks/bulkrax_tasks.rake +6 -0
- metadata +388 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bulkrax
|
4
|
+
module API
|
5
|
+
private
|
6
|
+
|
7
|
+
def api_request?
|
8
|
+
true if request.headers['Content-Type'] == 'application/json'
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_authenticate!
|
12
|
+
return true if request.headers['Authorization'] == "Token: #{ENV['BULKRAX_API_TOKEN']}"
|
13
|
+
return json_response('invalid', :unauthorized, "Please supply the authorization token")
|
14
|
+
end
|
15
|
+
|
16
|
+
def json_response(method, status = :ok, message = nil)
|
17
|
+
case method
|
18
|
+
when 'index'
|
19
|
+
render json: @importers, status: status
|
20
|
+
when 'new', 'edit'
|
21
|
+
render json: message, status: :method_not_allowed
|
22
|
+
when 'destroy', 'invalid'
|
23
|
+
render json: message, status: status
|
24
|
+
else
|
25
|
+
render json: message || @importer, status: status
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bulkrax
|
4
|
+
class ObjectFactory
|
5
|
+
extend ActiveModel::Callbacks
|
6
|
+
include Bulkrax::FileFactory
|
7
|
+
define_model_callbacks :save, :create
|
8
|
+
attr_reader :attributes, :object, :source_identifier_value, :klass, :replace_files, :update_files, :work_identifier
|
9
|
+
|
10
|
+
# rubocop:disable Metrics/ParameterLists
|
11
|
+
def initialize(attributes:, source_identifier_value:, work_identifier:, replace_files: false, user: nil, klass: nil, update_files: false)
|
12
|
+
@attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes)
|
13
|
+
@replace_files = replace_files
|
14
|
+
@update_files = update_files
|
15
|
+
@user = user || User.batch_user
|
16
|
+
@work_identifier = work_identifier
|
17
|
+
@source_identifier_value = source_identifier_value
|
18
|
+
@klass = klass || Bulkrax.default_work_type.constantize
|
19
|
+
end
|
20
|
+
# rubocop:enable Metrics/ParameterLists
|
21
|
+
|
22
|
+
def run
|
23
|
+
arg_hash = { id: attributes[:id], name: 'UPDATE', klass: klass }
|
24
|
+
@object = find
|
25
|
+
if object
|
26
|
+
object.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
|
27
|
+
ActiveSupport::Notifications.instrument('import.importer', arg_hash) { update }
|
28
|
+
else
|
29
|
+
ActiveSupport::Notifications.instrument('import.importer', arg_hash.merge(name: 'CREATE')) { create }
|
30
|
+
end
|
31
|
+
yield(object) if block_given?
|
32
|
+
object
|
33
|
+
end
|
34
|
+
|
35
|
+
def run!
|
36
|
+
self.run
|
37
|
+
# Create the error exception if the object is not validly saved for some reason
|
38
|
+
raise ActiveFedora::RecordInvalid, object if !object.persisted? || object.changed?
|
39
|
+
end
|
40
|
+
|
41
|
+
def update
|
42
|
+
raise "Object doesn't exist" unless object
|
43
|
+
destroy_existing_files if @replace_files && klass != Collection
|
44
|
+
attrs = attribute_update
|
45
|
+
run_callbacks :save do
|
46
|
+
klass == Collection ? update_collection(attrs) : work_actor.update(environment(attrs))
|
47
|
+
end
|
48
|
+
log_updated(object)
|
49
|
+
end
|
50
|
+
|
51
|
+
def find
|
52
|
+
return find_by_id if attributes[:id]
|
53
|
+
return search_by_identifier if attributes[work_identifier].present?
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_by_id
|
57
|
+
klass.find(attributes[:id]) if klass.exists?(attributes[:id])
|
58
|
+
end
|
59
|
+
|
60
|
+
def find_or_create
|
61
|
+
o = find
|
62
|
+
return o if o
|
63
|
+
run(&:save!)
|
64
|
+
end
|
65
|
+
|
66
|
+
def search_by_identifier
|
67
|
+
query = { work_identifier =>
|
68
|
+
source_identifier_value }
|
69
|
+
# Query can return partial matches (something6 matches both something6 and something68)
|
70
|
+
# so we need to weed out any that are not the correct full match. But other items might be
|
71
|
+
# in the multivalued field, so we have to go through them one at a time.
|
72
|
+
match = klass.where(query).detect { |m| m.send(work_identifier).include?(source_identifier_value) }
|
73
|
+
return match if match
|
74
|
+
end
|
75
|
+
|
76
|
+
# An ActiveFedora bug when there are many habtm <-> has_many associations means they won't all get saved.
|
77
|
+
# https://github.com/projecthydra/active_fedora/issues/874
|
78
|
+
# 2+ years later, still open!
|
79
|
+
def create
|
80
|
+
attrs = create_attributes
|
81
|
+
@object = klass.new
|
82
|
+
object.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
|
83
|
+
run_callbacks :save do
|
84
|
+
run_callbacks :create do
|
85
|
+
klass == Collection ? create_collection(attrs) : work_actor.create(environment(attrs))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
log_created(object)
|
89
|
+
end
|
90
|
+
|
91
|
+
def log_created(obj)
|
92
|
+
msg = "Created #{klass.model_name.human} #{obj.id}"
|
93
|
+
Rails.logger.info("#{msg} (#{Array(attributes[work_identifier]).first})")
|
94
|
+
end
|
95
|
+
|
96
|
+
def log_updated(obj)
|
97
|
+
msg = "Updated #{klass.model_name.human} #{obj.id}"
|
98
|
+
Rails.logger.info("#{msg} (#{Array(attributes[work_identifier]).first})")
|
99
|
+
end
|
100
|
+
|
101
|
+
def log_deleted_fs(obj)
|
102
|
+
msg = "Deleted All Files from #{obj.id}"
|
103
|
+
Rails.logger.info("#{msg} (#{Array(attributes[work_identifier]).first})")
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
# @param [Hash] attrs the attributes to put in the environment
|
109
|
+
# @return [Hyrax::Actors::Environment]
|
110
|
+
def environment(attrs)
|
111
|
+
Hyrax::Actors::Environment.new(object, Ability.new(@user), attrs)
|
112
|
+
end
|
113
|
+
|
114
|
+
def work_actor
|
115
|
+
Hyrax::CurationConcern.actor
|
116
|
+
end
|
117
|
+
|
118
|
+
def create_collection(attrs)
|
119
|
+
attrs = collection_type(attrs)
|
120
|
+
object.members = members
|
121
|
+
object.member_of_collections = member_of_collections
|
122
|
+
object.attributes = attrs
|
123
|
+
object.apply_depositor_metadata(@user)
|
124
|
+
object.save!
|
125
|
+
end
|
126
|
+
|
127
|
+
def update_collection(attrs)
|
128
|
+
object.members = members
|
129
|
+
object.member_of_collections = member_of_collections
|
130
|
+
object.attributes = attrs
|
131
|
+
object.save!
|
132
|
+
end
|
133
|
+
|
134
|
+
# Collections don't respond to member_of_collections_attributes or member_of_collection_ids=
|
135
|
+
# or member_ids=
|
136
|
+
# Add them directly with members / member_of_collections
|
137
|
+
# collection should be in the form { id: collection_id }
|
138
|
+
# and collections [{ id: collection_id }]
|
139
|
+
# member_ids comes from
|
140
|
+
# @todo - consider performance implications although we wouldn't expect a Collection to be a member of many Collections
|
141
|
+
def members
|
142
|
+
ms = object.members.to_a
|
143
|
+
[:children].each do |atat|
|
144
|
+
next if attributes[atat].blank?
|
145
|
+
ms.concat(
|
146
|
+
Array.wrap(
|
147
|
+
find_collection(attributes[atat])
|
148
|
+
)
|
149
|
+
)
|
150
|
+
end
|
151
|
+
ms.flatten.compact.uniq
|
152
|
+
end
|
153
|
+
|
154
|
+
def member_of_collections
|
155
|
+
ms = object.member_of_collection_ids.to_a.map { |id| find_collection(id) }
|
156
|
+
[:collection, :collections].each do |atat|
|
157
|
+
next if attributes[atat].blank?
|
158
|
+
ms.concat(
|
159
|
+
Array.wrap(
|
160
|
+
find_collection(attributes[atat])
|
161
|
+
)
|
162
|
+
)
|
163
|
+
end
|
164
|
+
ms.flatten.compact.uniq
|
165
|
+
end
|
166
|
+
|
167
|
+
def find_collection(id)
|
168
|
+
case id
|
169
|
+
when Hash
|
170
|
+
Collection.find(id[:id])
|
171
|
+
when String
|
172
|
+
Collection.find(id)
|
173
|
+
when Array
|
174
|
+
id.map { |i| find_collection(i) }
|
175
|
+
else
|
176
|
+
[]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def collection_type(attrs)
|
181
|
+
return attrs if attrs['collection_type_gid'].present?
|
182
|
+
attrs['collection_type_gid'] = Hyrax::CollectionType.find_or_create_default_collection_type.gid
|
183
|
+
attrs
|
184
|
+
end
|
185
|
+
|
186
|
+
# Strip out the :collection key, and add the member_of_collection_ids,
|
187
|
+
# which is used by Hyrax::Actors::AddAsMemberOfCollectionsActor
|
188
|
+
def create_attributes
|
189
|
+
return transform_attributes if klass == Collection
|
190
|
+
if attributes[:collection].present?
|
191
|
+
transform_attributes.except(:collection).merge(member_of_collections_attributes: { 0 => { id: collection.id } })
|
192
|
+
elsif attributes[:collections].present?
|
193
|
+
collection_ids = attributes[:collections].each.with_index.each_with_object({}) do |(element, index), ids|
|
194
|
+
ids[index] = { id: element }
|
195
|
+
end
|
196
|
+
transform_attributes.except(:collections).merge(member_of_collections_attributes: collection_ids)
|
197
|
+
else
|
198
|
+
transform_attributes
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
# Strip out the :collection key, and add the member_of_collection_ids,
|
203
|
+
# which is used by Hyrax::Actors::AddAsMemberOfCollectionsActor
|
204
|
+
def attribute_update
|
205
|
+
return transform_attributes.except(:id) if klass == Collection
|
206
|
+
if attributes[:collection].present?
|
207
|
+
transform_attributes.except(:id).except(:collection).merge(member_of_collections_attributes: { 0 => { id: collection.id } })
|
208
|
+
elsif attributes[:collections].present?
|
209
|
+
collection_ids = attributes[:collections].each.with_index.each_with_object({}) do |(element, index), ids|
|
210
|
+
ids[index] = element
|
211
|
+
end
|
212
|
+
transform_attributes.except(:id).except(:collections).merge(member_of_collections_attributes: collection_ids)
|
213
|
+
else
|
214
|
+
transform_attributes.except(:id)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# Override if we need to map the attributes from the parser in
|
219
|
+
# a way that is compatible with how the factory needs them.
|
220
|
+
def transform_attributes
|
221
|
+
attributes.slice(*permitted_attributes)
|
222
|
+
.merge(file_attributes(update_files))
|
223
|
+
end
|
224
|
+
|
225
|
+
# Regardless of what the Parser gives us, these are the properties we are prepared to accept.
|
226
|
+
def permitted_attributes
|
227
|
+
klass.properties.keys.map(&:to_sym) + %i[id edit_users edit_groups read_groups visibility work_members_attributes admin_set_id]
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'coderay'
|
3
|
+
|
4
|
+
module Bulkrax
|
5
|
+
module ApplicationHelper
|
6
|
+
include ::Hyrax::HyraxHelperBehavior
|
7
|
+
|
8
|
+
def coderay(value, opts)
|
9
|
+
CodeRay
|
10
|
+
.scan(value, :ruby)
|
11
|
+
.html(opts)
|
12
|
+
.html_safe # rubocop:disable Rails/OutputSafety
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bulkrax
|
4
|
+
module ImportersHelper
|
5
|
+
# borrowd from batch-importer https://github.com/samvera-labs/hyrax-batch_ingest/blob/main/app/controllers/hyrax/batch_ingest/batches_controller.rb
|
6
|
+
def available_admin_sets
|
7
|
+
# Restrict available_admin_sets to only those current user can desposit to.
|
8
|
+
@available_admin_sets ||= Hyrax::Collections::PermissionsService.source_ids_for_deposit(ability: current_ability, source_type: 'admin_set').map do |admin_set_id|
|
9
|
+
[AdminSet.find(admin_set_id).title.first, admin_set_id]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bulkrax
|
4
|
+
module ValidationHelper
|
5
|
+
def valid_create_params?
|
6
|
+
check_admin_set
|
7
|
+
check_user
|
8
|
+
return true if valid_importer? &&
|
9
|
+
valid_commit? &&
|
10
|
+
valid_name? &&
|
11
|
+
valid_parser_klass? &&
|
12
|
+
valid_parser_fields?
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid_update_params?
|
16
|
+
check_admin_set
|
17
|
+
check_user
|
18
|
+
return valid_commit?
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_admin_set
|
22
|
+
if params[:importer][:admin_set_id].blank?
|
23
|
+
params[:importer][:admin_set_id] = AdminSet::DEFAULT_ID
|
24
|
+
else
|
25
|
+
AdminSet.find(params[:importer][:admin_set_id])
|
26
|
+
end
|
27
|
+
return true
|
28
|
+
rescue ActiveFedora::ObjectNotFoundError
|
29
|
+
logger.warn("AdminSet #{params[:importer][:admin_set_id]} not found. Using default admin set.")
|
30
|
+
params[:importer][:admin_set_id] = AdminSet::DEFAULT_ID
|
31
|
+
return true
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_user
|
35
|
+
if params[:importer][:user_id].blank?
|
36
|
+
params[:importer][:user_id] = User.batch_user.id
|
37
|
+
else
|
38
|
+
User.find(params[:importer][:user_id])
|
39
|
+
end
|
40
|
+
return true
|
41
|
+
rescue ActiveRecord::RecordNotFound
|
42
|
+
logger.warn("User #{params[:importer][:user_id]} not found. Using default batch_user.")
|
43
|
+
params[:importer][:user_id] = User.batch_user.id
|
44
|
+
return true
|
45
|
+
end
|
46
|
+
|
47
|
+
def return_value(method, status, message)
|
48
|
+
@return_value ||= [method, status, message]
|
49
|
+
end
|
50
|
+
|
51
|
+
def return_json_response
|
52
|
+
json_response(@return_value[0], @return_value[1], @return_value[2])
|
53
|
+
end
|
54
|
+
|
55
|
+
def valid_importer?
|
56
|
+
return true if params[:importer].present?
|
57
|
+
return_value('invalid',
|
58
|
+
:unprocessable_entity,
|
59
|
+
"Missing required parameters")
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
|
63
|
+
def valid_commit?
|
64
|
+
return true if params[:commit].present? && valid_commit_message?(params[:commit])
|
65
|
+
return_value('invalid',
|
66
|
+
:unprocessable_entity,
|
67
|
+
"[:commit] is required")
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
|
71
|
+
def valid_name?
|
72
|
+
return true if params[:importer][:name].present?
|
73
|
+
return_value('invalid',
|
74
|
+
:unprocessable_entity,
|
75
|
+
"[:importer][:name] is required")
|
76
|
+
return false
|
77
|
+
end
|
78
|
+
|
79
|
+
def valid_parser_klass?
|
80
|
+
return true if params[:importer][:parser_klass].present?
|
81
|
+
return_value('invalid',
|
82
|
+
:unprocessable_entity,
|
83
|
+
"[:importer][:parser_klass] is required")
|
84
|
+
return false
|
85
|
+
end
|
86
|
+
|
87
|
+
def valid_parser_fields?
|
88
|
+
if params[:importer][:parser_fields].present?
|
89
|
+
case params[:importer][:parser_klass]
|
90
|
+
when 'Bulkrax::OaiParser'
|
91
|
+
return valid_oai?
|
92
|
+
when 'Bulkrax::CsvParser'
|
93
|
+
return valid_csv?
|
94
|
+
when 'Bulkrax::BagitParser'
|
95
|
+
return valid_bagit?
|
96
|
+
else
|
97
|
+
return_value('invalid',
|
98
|
+
:unprocessable_entity,
|
99
|
+
"#{params[:importer][:parser_klass]} not recognised")
|
100
|
+
return false
|
101
|
+
end
|
102
|
+
else
|
103
|
+
return_value('invalid',
|
104
|
+
:unprocessable_entity,
|
105
|
+
"params[:importer][:parser_fields] is required")
|
106
|
+
return false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def valid_bagit?
|
111
|
+
return true if params[:importer][:parser_fields][:metadata_format].present? &&
|
112
|
+
params[:importer][:parser_fields][:metadata_file_name].present? &&
|
113
|
+
params[:importer][:parser_fields][:import_file_path].present?
|
114
|
+
return_value('invalid',
|
115
|
+
:unprocessable_entity,
|
116
|
+
"[:importer][:parser_fields] [:metadata_format], [:metadata_file_name] and [:import_file_path] are required")
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
|
120
|
+
def valid_csv?
|
121
|
+
return true if params[:importer][:parser_fields][:import_file_path].present?
|
122
|
+
return_value('invalid',
|
123
|
+
:unprocessable_entity,
|
124
|
+
"[:importer][:parser_fields] [:import_file_path] is required")
|
125
|
+
return false
|
126
|
+
end
|
127
|
+
|
128
|
+
def valid_oai?
|
129
|
+
return true if params[:base_url].present? &&
|
130
|
+
params[:importer][:parser_fields][:set].present? &&
|
131
|
+
params[:importer][:parser_fields][:collection_name].present?
|
132
|
+
return_value('invalid',
|
133
|
+
:unprocessable_entity,
|
134
|
+
"[:base_url], [:importer][:parser_fields][:set] and [:importer][:parser_fields][:collection_name] are required")
|
135
|
+
return false
|
136
|
+
end
|
137
|
+
|
138
|
+
def valid_commit_message?(commit)
|
139
|
+
# @todo - manual list because this line causes the importer script to fail - why?
|
140
|
+
# Bulkrax.api_definition['bulkrax']['importer']['commit']['valid_values'].include?(commit)
|
141
|
+
[
|
142
|
+
"Create",
|
143
|
+
"Create and Import",
|
144
|
+
"Update Importer",
|
145
|
+
"Update and Re-Import (update metadata and replace files)",
|
146
|
+
"Update and Harvest Updated Items",
|
147
|
+
"Update and Re-Harvest All Items",
|
148
|
+
"Update and Re-Import (update metadata only)",
|
149
|
+
"Update and Import (importer has not yet been run)"
|
150
|
+
].include?(commit)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|