zizia 3.1.0.alpha.01 → 4.0.0.alpha.01

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -3
  3. data/lib/zizia/engine.rb +8 -0
  4. data/lib/zizia/{hyrax_basic_metadata_mapper.rb → hyrax/hyrax_basic_metadata_mapper.rb} +0 -0
  5. data/lib/zizia/hyrax/hyrax_default_updater.rb +11 -0
  6. data/lib/zizia/hyrax/hyrax_delete_files_updater.rb +16 -0
  7. data/lib/zizia/hyrax/hyrax_metadata_only_updater.rb +58 -0
  8. data/lib/zizia/{hyrax_record_importer.rb → hyrax/hyrax_record_importer.rb} +45 -56
  9. data/lib/zizia/{metadata_only_stack.rb → hyrax/metadata_only_stack.rb} +0 -0
  10. data/lib/zizia/version.rb +1 -1
  11. data/lib/zizia.rb +6 -3
  12. metadata +371 -213
  13. data/.circleci/config.yml +0 -44
  14. data/.gitignore +0 -16
  15. data/.rubocop.yml +0 -81
  16. data/.rubocop_todo.yml +0 -21
  17. data/.solr_wrapper +0 -8
  18. data/.travis.yml +0 -12
  19. data/Gemfile +0 -14
  20. data/Rakefile +0 -38
  21. data/app/assets/config/zizia_manifest.js +0 -2
  22. data/app/assets/images/zizia/.keep +0 -0
  23. data/app/assets/javascripts/zizia/DisplayUploadedFile.es6 +0 -43
  24. data/app/assets/javascripts/zizia/application.js +0 -13
  25. data/app/assets/javascripts/zizia/zizia.js +0 -6
  26. data/app/assets/stylesheets/zizia/_file_upload.scss +0 -17
  27. data/app/assets/stylesheets/zizia/application.css +0 -15
  28. data/app/assets/stylesheets/zizia/zizia.scss +0 -1
  29. data/app/controllers/zizia/application_controller.rb +0 -6
  30. data/app/controllers/zizia/csv_imports_controller.rb +0 -53
  31. data/app/controllers/zizia/importer_documentation_controller.rb +0 -11
  32. data/app/helpers/importer_documentation_helper.rb +0 -13
  33. data/app/helpers/zizia/application_helper.rb +0 -14
  34. data/app/importers/modular_importer.rb +0 -31
  35. data/app/jobs/zizia/application_job.rb +0 -5
  36. data/app/jobs/zizia/start_csv_import_job.rb +0 -14
  37. data/app/models/zizia/application_record.rb +0 -6
  38. data/app/models/zizia/csv_import.rb +0 -21
  39. data/app/models/zizia/csv_import_detail.rb +0 -13
  40. data/app/models/zizia/pre_ingest_file.rb +0 -6
  41. data/app/models/zizia/pre_ingest_work.rb +0 -6
  42. data/app/uploaders/zizia/csv_manifest_uploader.rb +0 -62
  43. data/app/uploaders/zizia/csv_manifest_validator.rb +0 -163
  44. data/app/views/layouts/zizia/application.html.erb +0 -14
  45. data/app/views/zizia/csv_imports/_actions.html.erb +0 -3
  46. data/app/views/zizia/csv_imports/_collection_selection.html.erb +0 -3
  47. data/app/views/zizia/csv_imports/_error.html.erb +0 -10
  48. data/app/views/zizia/csv_imports/_file_upload.html.erb +0 -3
  49. data/app/views/zizia/csv_imports/_form.html.erb +0 -75
  50. data/app/views/zizia/csv_imports/_no_collection.html.erb +0 -7
  51. data/app/views/zizia/csv_imports/_record_count.html.erb +0 -7
  52. data/app/views/zizia/csv_imports/_start_import_form.html.erb +0 -9
  53. data/app/views/zizia/csv_imports/index.html.erb +0 -21
  54. data/app/views/zizia/csv_imports/new.html.erb +0 -2
  55. data/app/views/zizia/csv_imports/preview.html.erb +0 -76
  56. data/app/views/zizia/csv_imports/show.html.erb +0 -31
  57. data/app/views/zizia/importer_documentation/guide.html.erb +0 -1
  58. data/bin/rails +0 -15
  59. data/config/routes.rb +0 -9
  60. data/db/migrate/201901162141281_create_zizia_csv_imports.rb +0 -10
  61. data/db/migrate/201901162203121_add_manifest_to_zizia_csv_imports.rb +0 -6
  62. data/db/migrate/201901241536541_add_fedora_collection_id_to_zizia_csv_imports.rb +0 -5
  63. data/db/migrate/20190911133657_create_zizia_pre_ingest_files.rb +0 -12
  64. data/db/migrate/20190911134002_create_zizia_pre_ingest_works.rb +0 -9
  65. data/db/migrate/20190911142616_create_zizia_csv_import_details.rb +0 -8
  66. data/docs/_config.yml +0 -1
  67. data/docs/customizing_metadata.md +0 -41
  68. data/docs/index.md +0 -113
  69. data/log/.keep +0 -0
  70. data/solr/config/_rest_managed.json +0 -3
  71. data/solr/config/admin-extra.html +0 -31
  72. data/solr/config/elevate.xml +0 -36
  73. data/solr/config/mapping-ISOLatin1Accent.txt +0 -246
  74. data/solr/config/protwords.txt +0 -21
  75. data/solr/config/routes.rb +0 -9
  76. data/solr/config/schema.xml +0 -366
  77. data/solr/config/scripts.conf +0 -24
  78. data/solr/config/solrconfig.xml +0 -322
  79. data/solr/config/spellings.txt +0 -2
  80. data/solr/config/stopwords.txt +0 -58
  81. data/solr/config/stopwords_en.txt +0 -58
  82. data/solr/config/synonyms.txt +0 -31
  83. data/solr/config/xslt/example.xsl +0 -132
  84. data/solr/config/xslt/example_atom.xsl +0 -67
  85. data/solr/config/xslt/example_rss.xsl +0 -66
  86. data/solr/config/xslt/luke.xsl +0 -337
  87. data/spec/controllers/importer_documentation_controller_spec.rb +0 -14
  88. data/spec/dummy/.gitignore +0 -23
  89. data/spec/dummy/Gemfile +0 -57
  90. data/spec/dummy/README.md +0 -24
  91. data/spec/dummy/Rakefile +0 -6
  92. data/spec/dummy/app/assets/config/manifest.js +0 -3
  93. data/spec/dummy/app/assets/csv/import_manifest.csv +0 -1
  94. data/spec/dummy/app/assets/images/.keep +0 -0
  95. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  96. data/spec/dummy/app/assets/javascripts/cable.js +0 -13
  97. data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
  98. data/spec/dummy/app/assets/markdown/importer_guide.md +0 -256
  99. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  100. data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
  101. data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
  102. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  103. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  104. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  105. data/spec/dummy/app/jobs/application_job.rb +0 -2
  106. data/spec/dummy/app/mailers/application_mailer.rb +0 -4
  107. data/spec/dummy/app/models/application_record.rb +0 -3
  108. data/spec/dummy/app/models/concerns/.keep +0 -0
  109. data/spec/dummy/app/models/user.rb +0 -2
  110. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  111. data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
  112. data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
  113. data/spec/dummy/bin/bundle +0 -3
  114. data/spec/dummy/bin/rails +0 -9
  115. data/spec/dummy/bin/rake +0 -9
  116. data/spec/dummy/bin/setup +0 -38
  117. data/spec/dummy/bin/spring +0 -17
  118. data/spec/dummy/bin/update +0 -29
  119. data/spec/dummy/bin/yarn +0 -11
  120. data/spec/dummy/config/application.rb +0 -18
  121. data/spec/dummy/config/boot.rb +0 -3
  122. data/spec/dummy/config/cable.yml +0 -10
  123. data/spec/dummy/config/database.yml +0 -25
  124. data/spec/dummy/config/environment.rb +0 -5
  125. data/spec/dummy/config/environments/development.rb +0 -54
  126. data/spec/dummy/config/environments/production.rb +0 -91
  127. data/spec/dummy/config/environments/test.rb +0 -42
  128. data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
  129. data/spec/dummy/config/initializers/assets.rb +0 -14
  130. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  131. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
  132. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  133. data/spec/dummy/config/initializers/inflections.rb +0 -16
  134. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  135. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  136. data/spec/dummy/config/locales/en.yml +0 -33
  137. data/spec/dummy/config/puma.rb +0 -56
  138. data/spec/dummy/config/routes.rb +0 -4
  139. data/spec/dummy/config/secrets.yml +0 -32
  140. data/spec/dummy/config/spring.rb +0 -6
  141. data/spec/dummy/config.ru +0 -5
  142. data/spec/dummy/db/migrate/20190911165049_create_users.rb +0 -8
  143. data/spec/dummy/db/schema.rb +0 -55
  144. data/spec/dummy/db/seeds.rb +0 -7
  145. data/spec/dummy/lib/assets/.keep +0 -0
  146. data/spec/dummy/lib/tasks/.keep +0 -0
  147. data/spec/dummy/log/.keep +0 -0
  148. data/spec/dummy/package.json +0 -5
  149. data/spec/dummy/public/404.html +0 -67
  150. data/spec/dummy/public/422.html +0 -67
  151. data/spec/dummy/public/500.html +0 -66
  152. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  153. data/spec/dummy/public/apple-touch-icon.png +0 -0
  154. data/spec/dummy/public/favicon.ico +0 -0
  155. data/spec/dummy/public/robots.txt +0 -1
  156. data/spec/dummy/test/application_system_test_case.rb +0 -5
  157. data/spec/dummy/test/controllers/.keep +0 -0
  158. data/spec/dummy/test/fixtures/.keep +0 -0
  159. data/spec/dummy/test/fixtures/files/.keep +0 -0
  160. data/spec/dummy/test/fixtures/users.yml +0 -11
  161. data/spec/dummy/test/helpers/.keep +0 -0
  162. data/spec/dummy/test/integration/.keep +0 -0
  163. data/spec/dummy/test/mailers/.keep +0 -0
  164. data/spec/dummy/test/models/.keep +0 -0
  165. data/spec/dummy/test/models/user_test.rb +0 -7
  166. data/spec/dummy/test/system/.keep +0 -0
  167. data/spec/dummy/test/test_helper.rb +0 -10
  168. data/spec/dummy/vendor/.keep +0 -0
  169. data/spec/fixtures/bad_example.csv +0 -2
  170. data/spec/fixtures/dog.jpg +0 -0
  171. data/spec/fixtures/example.csv +0 -4
  172. data/spec/fixtures/hyrax/example.csv +0 -3
  173. data/spec/fixtures/images/animals/cat.png +0 -0
  174. data/spec/fixtures/images/zizia.png +0 -0
  175. data/spec/fixtures/zizia.png +0 -0
  176. data/spec/integration/csv_import_detail_spec.rb +0 -48
  177. data/spec/integration/import_csv_spec.rb +0 -27
  178. data/spec/integration/import_hyrax_csv.rb +0 -71
  179. data/spec/models/csv_import_spec.rb +0 -18
  180. data/spec/spec_helper.rb +0 -31
  181. data/spec/support/hyrax/basic_metadata.rb +0 -30
  182. data/spec/support/hyrax/core_metadata.rb +0 -15
  183. data/spec/support/shared_contexts/with_work_type.rb +0 -101
  184. data/spec/uploaders/csv_manifest_uploader_spec.rb +0 -30
  185. data/spec/views/zizia/importer_documentation/guide.html.erb_spec.rb +0 -13
  186. data/spec/zizia/csv_format_validator_spec.rb +0 -38
  187. data/spec/zizia/csv_parser_spec.rb +0 -73
  188. data/spec/zizia/csv_template_spec.rb +0 -15
  189. data/spec/zizia/hash_mapper_spec.rb +0 -8
  190. data/spec/zizia/hyrax_basic_metadata_mapper_spec.rb +0 -190
  191. data/spec/zizia/hyrax_record_importer_spec.rb +0 -176
  192. data/spec/zizia/importer_spec.rb +0 -46
  193. data/spec/zizia/input_record_spec.rb +0 -71
  194. data/spec/zizia/record_importer_spec.rb +0 -53
  195. data/spec/zizia/title_validator_spec.rb +0 -23
  196. data/spec/zizia/validator_spec.rb +0 -9
  197. data/spec/zizia/version_spec.rb +0 -7
  198. data/spec/zizia_spec.rb +0 -20
  199. data/zizia.gemspec +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a24728641684b8789177ad48a5a3053089f58b10258dc17d2ff580d09da8ca3a
4
- data.tar.gz: 0eda7cd8f1446c5565bb4720ac8d633babc30653ef242fdf61e65fae1dd924ee
3
+ metadata.gz: 654b0dc7674b00f784802b512f8307f9ca68f86fdf53853ede30e2bdb643a67f
4
+ data.tar.gz: c132c6399545bd7b89b47d895cb397f1ccdcda5d85c34ef9864de2d8c64ce42f
5
5
  SHA512:
6
- metadata.gz: 2aa309d328946d8bf4bcaeeb46a0445388941105107ff5b9d079bd15138b8ad3785bc210a1b11f7ea24c52a7ba5817becf41b0897640e32ee95ddb8be4e69b31
7
- data.tar.gz: 2166ccfb776ea3ffd52a63fca25e5066ea3d867698f29bf02be4a51f33b7f4c360acb2da9d9e1588e3774b35e3d30d900d2584a82ef0065b65718c194c6308d3
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
  [![Gem Version](https://badge.fury.io/rb/zizia.svg)](https://badge.fury.io/rb/zizia)
14
14
  [![CircleCI](https://circleci.com/gh/curationexperts/zizia.svg?style=svg)](https://circleci.com/gh/curationexperts/zizia)
15
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/zizia) [![Coverage Status](https://coveralls.io/repos/github/curationexperts/zizia/badge.svg?branch=coveralls)](https://coveralls.io/github/curationexperts/zizia?branch=coveralls)
15
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/zizia) [![Coverage Status](https://coveralls.io/repos/github/curationexperts/zizia/badge.svg?branch=master)](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. Add documentation and sample csv files to your project at
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
- 4. Add links to `/csv_imports/new` and `/importer_documentation/csv` in the Hyrax dashboard
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
@@ -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
- self.collection_id = attributes[:collection_id]
49
- self.batch_id = attributes[:batch_id]
50
- self.deduplication_field = attributes[:deduplication_field]
51
- set_depositor(attributes[:depositor_id])
52
- @success_count = 0
53
- @failure_count = 0
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 set_depositor(user_key)
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: @depositor, file: file)
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
- Rails.logger.info "[zizia] event: record_update_started, batch_id: #{batch_id}, collection_id: #{collection_id}, #{deduplication_field}: #{update_record.respond_to?(deduplication_field) ? update_record.send(deduplication_field) : update_record}"
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
- depositor: @depositor.user_key
210
+ uploaded_files: create_upload_files(record),
211
+ depositor: depositor.user_key
196
212
  }
197
- attrs = update_record.attributes.merge(additional_attrs)
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 = attrs.merge(based_near_attributes: based_near_attributes(based_near)) unless based_near.nil? || based_near.empty?
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(@depositor),
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
- @success_count += 1
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
- @failure_count += 1
242
+ csv_import_detail.failure_count += 1
255
243
  end
244
+ csv_import_detail.save
256
245
  end
257
246
  end
258
247
  end
data/lib/zizia/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zizia
4
- VERSION = '3.1.0.alpha.01'
4
+ VERSION = '4.0.0.alpha.01'
5
5
  end
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