zizia 3.1.0.alpha.01 → 4.0.0.alpha.01
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/README.md +14 -3
- data/lib/zizia/engine.rb +8 -0
- data/lib/zizia/{hyrax_basic_metadata_mapper.rb → hyrax/hyrax_basic_metadata_mapper.rb} +0 -0
- data/lib/zizia/hyrax/hyrax_default_updater.rb +11 -0
- data/lib/zizia/hyrax/hyrax_delete_files_updater.rb +16 -0
- data/lib/zizia/hyrax/hyrax_metadata_only_updater.rb +58 -0
- data/lib/zizia/{hyrax_record_importer.rb → hyrax/hyrax_record_importer.rb} +45 -56
- data/lib/zizia/{metadata_only_stack.rb → hyrax/metadata_only_stack.rb} +0 -0
- data/lib/zizia/version.rb +1 -1
- data/lib/zizia.rb +6 -3
- metadata +371 -213
- data/.circleci/config.yml +0 -44
- data/.gitignore +0 -16
- data/.rubocop.yml +0 -81
- data/.rubocop_todo.yml +0 -21
- data/.solr_wrapper +0 -8
- data/.travis.yml +0 -12
- data/Gemfile +0 -14
- data/Rakefile +0 -38
- data/app/assets/config/zizia_manifest.js +0 -2
- data/app/assets/images/zizia/.keep +0 -0
- data/app/assets/javascripts/zizia/DisplayUploadedFile.es6 +0 -43
- data/app/assets/javascripts/zizia/application.js +0 -13
- data/app/assets/javascripts/zizia/zizia.js +0 -6
- data/app/assets/stylesheets/zizia/_file_upload.scss +0 -17
- data/app/assets/stylesheets/zizia/application.css +0 -15
- data/app/assets/stylesheets/zizia/zizia.scss +0 -1
- data/app/controllers/zizia/application_controller.rb +0 -6
- data/app/controllers/zizia/csv_imports_controller.rb +0 -53
- data/app/controllers/zizia/importer_documentation_controller.rb +0 -11
- data/app/helpers/importer_documentation_helper.rb +0 -13
- data/app/helpers/zizia/application_helper.rb +0 -14
- data/app/importers/modular_importer.rb +0 -31
- data/app/jobs/zizia/application_job.rb +0 -5
- data/app/jobs/zizia/start_csv_import_job.rb +0 -14
- data/app/models/zizia/application_record.rb +0 -6
- data/app/models/zizia/csv_import.rb +0 -21
- data/app/models/zizia/csv_import_detail.rb +0 -13
- data/app/models/zizia/pre_ingest_file.rb +0 -6
- data/app/models/zizia/pre_ingest_work.rb +0 -6
- data/app/uploaders/zizia/csv_manifest_uploader.rb +0 -62
- data/app/uploaders/zizia/csv_manifest_validator.rb +0 -163
- data/app/views/layouts/zizia/application.html.erb +0 -14
- data/app/views/zizia/csv_imports/_actions.html.erb +0 -3
- data/app/views/zizia/csv_imports/_collection_selection.html.erb +0 -3
- data/app/views/zizia/csv_imports/_error.html.erb +0 -10
- data/app/views/zizia/csv_imports/_file_upload.html.erb +0 -3
- data/app/views/zizia/csv_imports/_form.html.erb +0 -75
- data/app/views/zizia/csv_imports/_no_collection.html.erb +0 -7
- data/app/views/zizia/csv_imports/_record_count.html.erb +0 -7
- data/app/views/zizia/csv_imports/_start_import_form.html.erb +0 -9
- data/app/views/zizia/csv_imports/index.html.erb +0 -21
- data/app/views/zizia/csv_imports/new.html.erb +0 -2
- data/app/views/zizia/csv_imports/preview.html.erb +0 -76
- data/app/views/zizia/csv_imports/show.html.erb +0 -31
- data/app/views/zizia/importer_documentation/guide.html.erb +0 -1
- data/bin/rails +0 -15
- data/config/routes.rb +0 -9
- data/db/migrate/201901162141281_create_zizia_csv_imports.rb +0 -10
- data/db/migrate/201901162203121_add_manifest_to_zizia_csv_imports.rb +0 -6
- data/db/migrate/201901241536541_add_fedora_collection_id_to_zizia_csv_imports.rb +0 -5
- data/db/migrate/20190911133657_create_zizia_pre_ingest_files.rb +0 -12
- data/db/migrate/20190911134002_create_zizia_pre_ingest_works.rb +0 -9
- data/db/migrate/20190911142616_create_zizia_csv_import_details.rb +0 -8
- data/docs/_config.yml +0 -1
- data/docs/customizing_metadata.md +0 -41
- data/docs/index.md +0 -113
- data/log/.keep +0 -0
- data/solr/config/_rest_managed.json +0 -3
- data/solr/config/admin-extra.html +0 -31
- data/solr/config/elevate.xml +0 -36
- data/solr/config/mapping-ISOLatin1Accent.txt +0 -246
- data/solr/config/protwords.txt +0 -21
- data/solr/config/routes.rb +0 -9
- data/solr/config/schema.xml +0 -366
- data/solr/config/scripts.conf +0 -24
- data/solr/config/solrconfig.xml +0 -322
- data/solr/config/spellings.txt +0 -2
- data/solr/config/stopwords.txt +0 -58
- data/solr/config/stopwords_en.txt +0 -58
- data/solr/config/synonyms.txt +0 -31
- data/solr/config/xslt/example.xsl +0 -132
- data/solr/config/xslt/example_atom.xsl +0 -67
- data/solr/config/xslt/example_rss.xsl +0 -66
- data/solr/config/xslt/luke.xsl +0 -337
- data/spec/controllers/importer_documentation_controller_spec.rb +0 -14
- data/spec/dummy/.gitignore +0 -23
- data/spec/dummy/Gemfile +0 -57
- data/spec/dummy/README.md +0 -24
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/config/manifest.js +0 -3
- data/spec/dummy/app/assets/csv/import_manifest.csv +0 -1
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/javascripts/cable.js +0 -13
- data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
- data/spec/dummy/app/assets/markdown/importer_guide.md +0 -256
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
- data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/jobs/application_job.rb +0 -2
- data/spec/dummy/app/mailers/application_mailer.rb +0 -4
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/user.rb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -9
- data/spec/dummy/bin/rake +0 -9
- data/spec/dummy/bin/setup +0 -38
- data/spec/dummy/bin/spring +0 -17
- data/spec/dummy/bin/update +0 -29
- data/spec/dummy/bin/yarn +0 -11
- data/spec/dummy/config/application.rb +0 -18
- data/spec/dummy/config/boot.rb +0 -3
- data/spec/dummy/config/cable.yml +0 -10
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -54
- data/spec/dummy/config/environments/production.rb +0 -91
- data/spec/dummy/config/environments/test.rb +0 -42
- data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
- data/spec/dummy/config/initializers/assets.rb +0 -14
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -33
- data/spec/dummy/config/puma.rb +0 -56
- data/spec/dummy/config/routes.rb +0 -4
- data/spec/dummy/config/secrets.yml +0 -32
- data/spec/dummy/config/spring.rb +0 -6
- data/spec/dummy/config.ru +0 -5
- data/spec/dummy/db/migrate/20190911165049_create_users.rb +0 -8
- data/spec/dummy/db/schema.rb +0 -55
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/package.json +0 -5
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +0 -1
- data/spec/dummy/test/application_system_test_case.rb +0 -5
- data/spec/dummy/test/controllers/.keep +0 -0
- data/spec/dummy/test/fixtures/.keep +0 -0
- data/spec/dummy/test/fixtures/files/.keep +0 -0
- data/spec/dummy/test/fixtures/users.yml +0 -11
- data/spec/dummy/test/helpers/.keep +0 -0
- data/spec/dummy/test/integration/.keep +0 -0
- data/spec/dummy/test/mailers/.keep +0 -0
- data/spec/dummy/test/models/.keep +0 -0
- data/spec/dummy/test/models/user_test.rb +0 -7
- data/spec/dummy/test/system/.keep +0 -0
- data/spec/dummy/test/test_helper.rb +0 -10
- data/spec/dummy/vendor/.keep +0 -0
- data/spec/fixtures/bad_example.csv +0 -2
- data/spec/fixtures/dog.jpg +0 -0
- data/spec/fixtures/example.csv +0 -4
- data/spec/fixtures/hyrax/example.csv +0 -3
- data/spec/fixtures/images/animals/cat.png +0 -0
- data/spec/fixtures/images/zizia.png +0 -0
- data/spec/fixtures/zizia.png +0 -0
- data/spec/integration/csv_import_detail_spec.rb +0 -48
- data/spec/integration/import_csv_spec.rb +0 -27
- data/spec/integration/import_hyrax_csv.rb +0 -71
- data/spec/models/csv_import_spec.rb +0 -18
- data/spec/spec_helper.rb +0 -31
- data/spec/support/hyrax/basic_metadata.rb +0 -30
- data/spec/support/hyrax/core_metadata.rb +0 -15
- data/spec/support/shared_contexts/with_work_type.rb +0 -101
- data/spec/uploaders/csv_manifest_uploader_spec.rb +0 -30
- data/spec/views/zizia/importer_documentation/guide.html.erb_spec.rb +0 -13
- data/spec/zizia/csv_format_validator_spec.rb +0 -38
- data/spec/zizia/csv_parser_spec.rb +0 -73
- data/spec/zizia/csv_template_spec.rb +0 -15
- data/spec/zizia/hash_mapper_spec.rb +0 -8
- data/spec/zizia/hyrax_basic_metadata_mapper_spec.rb +0 -190
- data/spec/zizia/hyrax_record_importer_spec.rb +0 -176
- data/spec/zizia/importer_spec.rb +0 -46
- data/spec/zizia/input_record_spec.rb +0 -71
- data/spec/zizia/record_importer_spec.rb +0 -53
- data/spec/zizia/title_validator_spec.rb +0 -23
- data/spec/zizia/validator_spec.rb +0 -9
- data/spec/zizia/version_spec.rb +0 -7
- data/spec/zizia_spec.rb +0 -20
- data/zizia.gemspec +0 -42
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 654b0dc7674b00f784802b512f8307f9ca68f86fdf53853ede30e2bdb643a67f
|
|
4
|
+
data.tar.gz: c132c6399545bd7b89b47d895cb397f1ccdcda5d85c34ef9864de2d8c64ce42f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 04ea361c7696ca069519523668caf8adc9bac1ed3e3a89ef17a14de2f19807ff9c8006cd9ca3bcd2a46fdcfc1dd1c88cc90ea5c4aa2f312de72015d97606c201
|
|
7
|
+
data.tar.gz: fd69e42c506a87a830b051334cee9b5df6162dffdae2a449859d24045782be505039899e08a307c31774bca097cedf1e55268e3ff72a26e2b120859920929220
|
data/README.md
CHANGED
|
@@ -12,7 +12,7 @@ information. See the <a href="https://curationexperts.github.io/zizia/">Getting
|
|
|
12
12
|
|
|
13
13
|
[](https://badge.fury.io/rb/zizia)
|
|
14
14
|
[](https://circleci.com/gh/curationexperts/zizia)
|
|
15
|
-
[](http://www.rubydoc.info/gems/zizia) [](http://www.rubydoc.info/gems/zizia) [](https://coveralls.io/github/curationexperts/zizia?branch=master)
|
|
16
16
|
|
|
17
17
|
</td></tr>
|
|
18
18
|
</table>
|
|
@@ -72,7 +72,13 @@ Zizia can be installed as a Rails Engine in a Hyrax application. To use the Zizi
|
|
|
72
72
|
helper Zizia::Engine.helpers
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
3.
|
|
75
|
+
3. Give admin users permission to import in your `Ability.custom_permissions`:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
can :manage, Zizia::CsvImport if current_user.admin?
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
4. Add documentation and sample csv files to your project at
|
|
76
82
|
|
|
77
83
|
`app/assets/csv/import_manifest.csv`
|
|
78
84
|
|
|
@@ -80,7 +86,12 @@ and
|
|
|
80
86
|
|
|
81
87
|
`app/assets/markdown/importer_guide.md`
|
|
82
88
|
|
|
83
|
-
|
|
89
|
+
5. Add links to `/csv_imports/new` and `/importer_documentation/csv` in the Hyrax dashboard
|
|
90
|
+
|
|
91
|
+
The `spec/dummy` folder in this application is a complete Hyrax application with Zizia installed.
|
|
92
|
+
You can use that as an example for adding this to your current Hyrax application or copy that
|
|
93
|
+
to create a new application with Zizia installed.
|
|
94
|
+
|
|
84
95
|
|
|
85
96
|
## Development
|
|
86
97
|
|
data/lib/zizia/engine.rb
CHANGED
|
@@ -4,11 +4,19 @@ require 'rails/all'
|
|
|
4
4
|
require 'carrierwave'
|
|
5
5
|
require 'carrierwave/orm/activerecord'
|
|
6
6
|
require 'redcarpet'
|
|
7
|
+
require 'devise'
|
|
8
|
+
require 'hyrax'
|
|
9
|
+
require 'riiif'
|
|
10
|
+
require 'hydra-role-management'
|
|
7
11
|
|
|
8
12
|
module Zizia
|
|
9
13
|
class Engine < ::Rails::Engine
|
|
10
14
|
isolate_namespace Zizia
|
|
11
15
|
|
|
16
|
+
config.generators do |g|
|
|
17
|
+
g.test_framework :rspec
|
|
18
|
+
end
|
|
19
|
+
|
|
12
20
|
initializer :zizia_assets_precompile do |app|
|
|
13
21
|
app.config.assets.precompile << %w[zizia/application.js zizia/application.css]
|
|
14
22
|
end
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Zizia
|
|
3
|
+
class HyraxDefaultUpdater < HyraxMetadataOnlyUpdater
|
|
4
|
+
attr_reader :attrs
|
|
5
|
+
|
|
6
|
+
def actor_stack
|
|
7
|
+
terminator = Hyrax::Actors::Terminator.new
|
|
8
|
+
Hyrax::DefaultMiddlewareStack.build_stack.build(terminator)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Zizia
|
|
3
|
+
class HyraxDeleteFilesUpdater < HyraxMetadataOnlyUpdater
|
|
4
|
+
attr_reader :attrs
|
|
5
|
+
|
|
6
|
+
def actor_stack
|
|
7
|
+
terminator = Hyrax::Actors::Terminator.new
|
|
8
|
+
Hyrax::DefaultMiddlewareStack.build_stack.build(terminator)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def update
|
|
12
|
+
existing_record.file_sets.map(&:destroy)
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Zizia
|
|
3
|
+
class HyraxMetadataOnlyUpdater
|
|
4
|
+
attr_accessor :depositor,
|
|
5
|
+
:existing_record,
|
|
6
|
+
:update_record,
|
|
7
|
+
:based_near_attributes,
|
|
8
|
+
:csv_import_detail
|
|
9
|
+
|
|
10
|
+
def initialize(csv_import_detail:,
|
|
11
|
+
existing_record:,
|
|
12
|
+
update_record:,
|
|
13
|
+
attrs:)
|
|
14
|
+
@csv_import_detail = csv_import_detail
|
|
15
|
+
@depositor = ::User.find(csv_import_detail.depositor_id)
|
|
16
|
+
@update_record = update_record
|
|
17
|
+
@existing_record = existing_record
|
|
18
|
+
@attrs = attrs
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def attrs
|
|
22
|
+
@attrs.reject { |k, _v| k == :uploaded_files }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def actor_stack
|
|
26
|
+
terminator = Hyrax::Actors::Terminator.new
|
|
27
|
+
Zizia::MetadataOnlyStack.build_stack.build(terminator)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def started
|
|
31
|
+
Rails.logger.info "[zizia] event: record_update_started, batch_id: #{csv_import_detail.batch_id}, collection_id: #{csv_import_detail.collection_id}, #{csv_import_detail.deduplication_field}: #{update_record.respond_to?(csv_import_detail.deduplication_field) ? update_record.send(csv_import_detail.deduplication_field.deduplication_field) : update_record}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def succeeded
|
|
35
|
+
Rails.logger.info "[zizia] event: record_updated, batch_id: #{csv_import_detail.batch_id}, record_id: #{csv_import_detail.existing_record.id}, collection_id: #{csv_import_detail.collection_id}, #{csv_import_detail.deduplication_field}: #{existing_record.respond_to?(csv_import_detail.deduplication_field) ? existing_record.send(csv_import_detail.deduplication_field) : existing_record}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def failed(attr)
|
|
39
|
+
Rails.logger.error "[zizia] event: validation_failed, batch_id: #{csv_import_detail.batch_id}, collection_id: #{csv_import_detail.collection_id}, attribute: #{attr.capitalize}, message: #{msg}, record_title: record_title: #{attrs[:title] ? attrs[:title] : attrs}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def create_actor_env
|
|
43
|
+
Hyrax::Actors::Environment.new(existing_record, ::Ability.new(depositor), attrs)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def update
|
|
47
|
+
if actor_stack.update(create_actor_env)
|
|
48
|
+
csv_import_detail.success_count += 1
|
|
49
|
+
else
|
|
50
|
+
existing_record.errors.each_key do |attr, _msg|
|
|
51
|
+
failed(attr)
|
|
52
|
+
end
|
|
53
|
+
csv_import_detail.failure_count += 1
|
|
54
|
+
end
|
|
55
|
+
csv_import_detail.save
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
2
|
module Zizia
|
|
4
3
|
class HyraxRecordImporter < RecordImporter
|
|
5
4
|
# TODO: Get this from Hyrax config
|
|
6
5
|
DEFAULT_CREATOR_KEY = 'batchuser@example.com'
|
|
7
6
|
|
|
7
|
+
attr_accessor :csv_import_detail
|
|
8
|
+
|
|
8
9
|
# @!attribute [rw] depositor
|
|
9
10
|
# @return [User]
|
|
10
11
|
attr_accessor :depositor
|
|
@@ -45,18 +46,20 @@ module Zizia
|
|
|
45
46
|
# deduplication_field: 'legacy_id'
|
|
46
47
|
# }
|
|
47
48
|
def initialize(attributes: {})
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
@
|
|
53
|
-
@
|
|
49
|
+
# These attributes are persisted in the CsvImportDetail model
|
|
50
|
+
@csv_import_detail = attributes[:csv_import_detail]
|
|
51
|
+
@deduplication_field = csv_import_detail.deduplication_field
|
|
52
|
+
@collection_id = csv_import_detail.collection_id
|
|
53
|
+
@batch_id = csv_import_detail.batch_id
|
|
54
|
+
@success_count = csv_import_detail.success_count
|
|
55
|
+
@failure_count = csv_import_detail.failure_count
|
|
56
|
+
find_depositor(csv_import_detail.depositor_id)
|
|
54
57
|
end
|
|
55
58
|
|
|
56
59
|
# "depositor" is a required field for Hyrax. If
|
|
57
60
|
# it hasn't been set, set it to the Hyrax default
|
|
58
61
|
# batch user.
|
|
59
|
-
def
|
|
62
|
+
def find_depositor(user_key)
|
|
60
63
|
user = ::User.find_by_user_key(user_key) if user_key
|
|
61
64
|
user ||= ::User.find(user_key) if user_key
|
|
62
65
|
user ||= ::User.find_or_create_system_user(DEFAULT_CREATOR_KEY)
|
|
@@ -118,7 +121,7 @@ module Zizia
|
|
|
118
121
|
uploaded_file_ids = []
|
|
119
122
|
files_to_attach.each do |filename|
|
|
120
123
|
file = File.open(find_file_path(filename))
|
|
121
|
-
uploaded_file = Hyrax::UploadedFile.create(user:
|
|
124
|
+
uploaded_file = Hyrax::UploadedFile.create(user: depositor, file: file)
|
|
122
125
|
uploaded_file_ids << uploaded_file.id
|
|
123
126
|
file.close
|
|
124
127
|
end
|
|
@@ -177,45 +180,45 @@ module Zizia
|
|
|
177
180
|
|
|
178
181
|
private
|
|
179
182
|
|
|
180
|
-
# Build a pared down actor stack that will not re-attach files,
|
|
181
|
-
# or set workflow, or do anything except update metadata.
|
|
182
|
-
# TODO: We should be able to set an environment variable that would allow updates to go through the regular
|
|
183
|
-
# actor stack instead of the stripped down one, in case we want to re-import files.
|
|
184
|
-
def metadata_only_middleware
|
|
185
|
-
terminator = Hyrax::Actors::Terminator.new
|
|
186
|
-
Zizia::MetadataOnlyStack.build_stack.build(terminator)
|
|
187
|
-
end
|
|
188
|
-
|
|
189
183
|
# Update an existing object using the Hyrax actor stack
|
|
190
184
|
# We assume the object was created as expected if the actor stack returns true.
|
|
191
185
|
# Note that for now the update stack will only update metadata and update collection membership, it will not re-import files.
|
|
192
186
|
def update_for(existing_record:, update_record:)
|
|
193
|
-
|
|
187
|
+
updater = case csv_import_detail.update_actor_stack
|
|
188
|
+
when 'HyraxMetadataOnly'
|
|
189
|
+
Zizia::HyraxMetadataOnlyUpdater.new(csv_import_detail: csv_import_detail,
|
|
190
|
+
existing_record: existing_record,
|
|
191
|
+
update_record: update_record,
|
|
192
|
+
attrs: process_attrs(record: update_record))
|
|
193
|
+
when 'HyraxDelete'
|
|
194
|
+
Zizia::HyraxDeleteFilesUpdater.new(csv_import_detail: csv_import_detail,
|
|
195
|
+
existing_record: existing_record,
|
|
196
|
+
update_record: update_record,
|
|
197
|
+
attrs: process_attrs(record: update_record))
|
|
198
|
+
when 'HyraxOnlyNew'
|
|
199
|
+
return unless existing_record[deduplication_field] != update_record.try(deduplication_field)
|
|
200
|
+
Zizia::HyraxDefaultUpdater.new(csv_import_detail: csv_import_detail,
|
|
201
|
+
existing_record: existing_record,
|
|
202
|
+
update_record: update_record,
|
|
203
|
+
attrs: process_attrs(record: update_record))
|
|
204
|
+
end
|
|
205
|
+
updater.update
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def process_attrs(record:)
|
|
194
209
|
additional_attrs = {
|
|
195
|
-
|
|
210
|
+
uploaded_files: create_upload_files(record),
|
|
211
|
+
depositor: depositor.user_key
|
|
196
212
|
}
|
|
197
|
-
|
|
213
|
+
|
|
214
|
+
attrs = record.attributes.merge(additional_attrs)
|
|
198
215
|
attrs = attrs.merge(member_of_collections_attributes: { '0' => { id: collection_id } }) if collection_id
|
|
216
|
+
|
|
199
217
|
# Ensure nothing is passed in the files field,
|
|
200
218
|
# since this is reserved for Hyrax and is where uploaded_files will be attached
|
|
201
219
|
attrs.delete(:files)
|
|
202
|
-
|
|
203
|
-
# We aren't using the attach remote files actor, so make sure any remote files are removed from the params before we try to save the object.
|
|
204
|
-
attrs.delete(:remote_files)
|
|
205
|
-
|
|
206
220
|
based_near = attrs.delete(:based_near)
|
|
207
|
-
attrs
|
|
208
|
-
|
|
209
|
-
actor_env = Hyrax::Actors::Environment.new(existing_record, ::Ability.new(@depositor), attrs)
|
|
210
|
-
if metadata_only_middleware.update(actor_env)
|
|
211
|
-
Rails.logger.info "[zizia] event: record_updated, batch_id: #{batch_id}, record_id: #{existing_record.id}, collection_id: #{collection_id}, #{deduplication_field}: #{existing_record.respond_to?(deduplication_field) ? existing_record.send(deduplication_field) : existing_record}"
|
|
212
|
-
@success_count += 1
|
|
213
|
-
else
|
|
214
|
-
existing_record.errors.each do |attr, msg|
|
|
215
|
-
Rails.logger.error "[zizia] event: validation_failed, batch_id: #{batch_id}, collection_id: #{collection_id}, attribute: #{attr.capitalize}, message: #{msg}, record_title: record_title: #{attrs[:title] ? attrs[:title] : attrs}"
|
|
216
|
-
end
|
|
217
|
-
@failure_count += 1
|
|
218
|
-
end
|
|
221
|
+
attrs.merge(based_near_attributes: based_near_attributes(based_near)) unless based_near.nil? || based_near.empty?
|
|
219
222
|
end
|
|
220
223
|
|
|
221
224
|
# Create an object using the Hyrax actor stack
|
|
@@ -223,36 +226,22 @@ module Zizia
|
|
|
223
226
|
def create_for(record:)
|
|
224
227
|
Rails.logger.info "[zizia] event: record_import_started, batch_id: #{batch_id}, collection_id: #{collection_id}, record_title: #{record.respond_to?(:title) ? record.title : record}"
|
|
225
228
|
|
|
226
|
-
additional_attrs = {
|
|
227
|
-
uploaded_files: create_upload_files(record),
|
|
228
|
-
depositor: @depositor.user_key
|
|
229
|
-
}
|
|
230
|
-
|
|
231
229
|
created = import_type.new
|
|
232
|
-
|
|
233
|
-
attrs = record.attributes.merge(additional_attrs)
|
|
234
|
-
attrs = attrs.merge(member_of_collections_attributes: { '0' => { id: collection_id } }) if collection_id
|
|
235
|
-
|
|
236
|
-
# Ensure nothing is passed in the files field,
|
|
237
|
-
# since this is reserved for Hyrax and is where uploaded_files will be attached
|
|
238
|
-
attrs.delete(:files)
|
|
239
|
-
|
|
240
|
-
based_near = attrs.delete(:based_near)
|
|
241
|
-
attrs = attrs.merge(based_near_attributes: based_near_attributes(based_near)) unless based_near.nil? || based_near.empty?
|
|
242
|
-
|
|
230
|
+
attrs = process_attrs(record: record)
|
|
243
231
|
actor_env = Hyrax::Actors::Environment.new(created,
|
|
244
|
-
::Ability.new(
|
|
232
|
+
::Ability.new(depositor),
|
|
245
233
|
attrs)
|
|
246
234
|
|
|
247
235
|
if Hyrax::CurationConcern.actor.create(actor_env)
|
|
248
236
|
Rails.logger.info "[zizia] event: record_created, batch_id: #{batch_id}, record_id: #{created.id}, collection_id: #{collection_id}, record_title: #{attrs[:title]&.first}"
|
|
249
|
-
|
|
237
|
+
csv_import_detail.success_count += 1
|
|
250
238
|
else
|
|
251
239
|
created.errors.each do |attr, msg|
|
|
252
240
|
Rails.logger.error "[zizia] event: validation_failed, batch_id: #{batch_id}, collection_id: #{collection_id}, attribute: #{attr.capitalize}, message: #{msg}, record_title: record_title: #{attrs[:title] ? attrs[:title] : attrs}"
|
|
253
241
|
end
|
|
254
|
-
|
|
242
|
+
csv_import_detail.failure_count += 1
|
|
255
243
|
end
|
|
244
|
+
csv_import_detail.save
|
|
256
245
|
end
|
|
257
246
|
end
|
|
258
247
|
end
|
|
File without changes
|
data/lib/zizia/version.rb
CHANGED
data/lib/zizia.rb
CHANGED
|
@@ -35,10 +35,10 @@ module Zizia
|
|
|
35
35
|
require 'zizia/version'
|
|
36
36
|
require 'zizia/metadata_mapper'
|
|
37
37
|
require 'zizia/hash_mapper'
|
|
38
|
-
require 'zizia/hyrax_basic_metadata_mapper'
|
|
38
|
+
require 'zizia/hyrax/hyrax_basic_metadata_mapper'
|
|
39
39
|
require 'zizia/importer'
|
|
40
40
|
require 'zizia/record_importer'
|
|
41
|
-
require 'zizia/hyrax_record_importer'
|
|
41
|
+
require 'zizia/hyrax/hyrax_record_importer'
|
|
42
42
|
require 'zizia/input_record'
|
|
43
43
|
require 'zizia/validator'
|
|
44
44
|
require 'zizia/validators/csv_format_validator'
|
|
@@ -59,5 +59,8 @@ module Zizia
|
|
|
59
59
|
@configuration = Configuration.new
|
|
60
60
|
|
|
61
61
|
require 'zizia/parsers/csv_parser'
|
|
62
|
-
require 'zizia/metadata_only_stack'
|
|
62
|
+
require 'zizia/hyrax/metadata_only_stack'
|
|
63
|
+
require 'zizia/hyrax/hyrax_metadata_only_updater'
|
|
64
|
+
require 'zizia/hyrax/hyrax_default_updater'
|
|
65
|
+
require 'zizia/hyrax/hyrax_delete_files_updater'
|
|
63
66
|
end
|