datacite 0.8.4 → 0.8.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b403085232bd106bb3b6be7fec2d5c536b83c91f38ab87def4df2e36f2a9f6f
4
- data.tar.gz: 25367ebe7804eaefd8da17e5cdc96fedea5f6a77a890e47775c77661d66b207f
3
+ metadata.gz: 4673dab2c36b209696de4969fd06ef8ca6a85d6e0d14dc8b2455b85dd3ee83bb
4
+ data.tar.gz: 93f119fb2ca080a2fe664574310342ed4859bd82944eabff1932137acab66189
5
5
  SHA512:
6
- metadata.gz: aeace413f533ea1aff7d2632285ea203c955b767683b784a24f57d9d306616255b3e6bfea2f5ea275460a49521c4e92ee35da140ea5e0ab63b7225e2d92286bf
7
- data.tar.gz: 10d254d5705859bdabcc54c253b17f825ed88b2b819066778f06c0682a386c7ec56e9694595d29b685363884480cc8d00b98bfddae77f6641a0e26463378205e
6
+ metadata.gz: 4a68baebbf3e4685a920c84d77846a20565b318be6e3fe528d11d4471eea02fa82e6dfd141c41aa4e78f546b4137034086d6e8061a7384a4d7898da6516b00a9
7
+ data.tar.gz: 53d018337e391ceeb366b0260fda2777595b1c618d8bbde7a43619d1338cc777c2d62a8e623c979bc20732c89bff8830c0ec8f81d5b10bfc88dabb7534ba4120
data/.rubocop.yml CHANGED
@@ -357,3 +357,48 @@ Style/RedundantArrayFlatten: # new in 1.76
357
357
  Enabled: true
358
358
  RSpec/IncludeExamples: # new in 3.6
359
359
  Enabled: true
360
+
361
+ Lint/DataDefineOverride: # new in 1.85
362
+ Enabled: true
363
+ Lint/DeprecatedReference: # new in 1.89
364
+ Enabled: true
365
+ Lint/NameTypo: # new in 1.89
366
+ Enabled: true
367
+ Lint/UnreachablePatternBranch: # new in 1.85
368
+ Enabled: true
369
+ Style/EmptyClassDefinition: # new in 1.84
370
+ Enabled: true
371
+ Style/FileOpen: # new in 1.85
372
+ Enabled: true
373
+ Style/MapJoin: # new in 1.85
374
+ Enabled: true
375
+ Style/ModuleMemberExistenceCheck: # new in 1.82
376
+ Enabled: true
377
+ Style/NegativeArrayIndex: # new in 1.84
378
+ Enabled: true
379
+ Style/OneClassPerFile: # new in 1.85
380
+ Enabled: true
381
+ Style/PartitionInsteadOfDoubleSelect: # new in 1.85
382
+ Enabled: true
383
+ Style/PredicateWithKind: # new in 1.85
384
+ Enabled: true
385
+ Style/ReduceToHash: # new in 1.85
386
+ Enabled: true
387
+ Style/RedundantMinMaxBy: # new in 1.85
388
+ Enabled: true
389
+ Style/ReverseFind: # new in 1.84
390
+ Enabled: true
391
+ Style/SelectByKind: # new in 1.85
392
+ Enabled: true
393
+ Style/SelectByRange: # new in 1.85
394
+ Enabled: true
395
+ Style/TallyMethod: # new in 1.85
396
+ Enabled: true
397
+ RSpec/DiscardedMatcher: # new in 3.10
398
+ Enabled: true
399
+ RSpec/LeakyLocalVariable: # new in 3.8
400
+ Enabled: true
401
+ RSpec/MatchWithSimpleRegex: # new in 3.10
402
+ Enabled: true
403
+ RSpec/Output: # new in 3.9
404
+ Enabled: true
data/Gemfile CHANGED
@@ -7,8 +7,8 @@ gemspec
7
7
 
8
8
  # Specify development dependencies here
9
9
  gem 'base64'
10
- gem 'byebug'
11
10
  gem 'cocina-models' # only used in tests
11
+ gem 'debug'
12
12
  gem 'rake', '~> 13.0'
13
13
  gem 'rspec', '~> 3.0'
14
14
  gem 'rubocop', '~> 1.7'
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datacite (0.8.4)
4
+ datacite (0.8.6)
5
5
  activesupport
6
+ cocina_display
6
7
  dry-monads (~> 1.3)
7
8
  faraday (~> 2.0)
8
9
  json_schemer
@@ -11,7 +12,7 @@ PATH
11
12
  GEM
12
13
  remote: https://rubygems.org/
13
14
  specs:
14
- activesupport (8.1.3)
15
+ activesupport (8.1.3.1)
15
16
  base64
16
17
  bigdecimal
17
18
  concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -30,9 +31,7 @@ GEM
30
31
  attr_extras (7.1.0)
31
32
  base64 (0.3.0)
32
33
  bigdecimal (4.1.2)
33
- byebug (13.0.0)
34
- reline (>= 0.6.0)
35
- cocina-models (0.132.0)
34
+ cocina-models (0.133.0)
36
35
  activesupport
37
36
  cocina_display
38
37
  deprecation
@@ -46,7 +45,7 @@ GEM
46
45
  super_diff
47
46
  thor
48
47
  zeitwerk (~> 2.1)
49
- cocina_display (2.9.0)
48
+ cocina_display (2.12.0)
50
49
  activesupport (>= 7)
51
50
  edtf (~> 3.2)
52
51
  geo_coord (~> 0.2)
@@ -59,6 +58,9 @@ GEM
59
58
  crack (1.0.1)
60
59
  bigdecimal
61
60
  rexml
61
+ debug (1.11.1)
62
+ irb (~> 1.10)
63
+ reline (>= 0.3.8)
62
64
  deprecation (1.1.0)
63
65
  activesupport
64
66
  diff-lcs (1.6.2)
@@ -93,6 +95,7 @@ GEM
93
95
  activesupport (>= 3.0, < 9.0)
94
96
  equivalent-xml (0.6.0)
95
97
  nokogiri (>= 1.4.3)
98
+ erb (6.0.7)
96
99
  faraday (2.14.3)
97
100
  faraday-net_http (>= 2.0, < 3.5)
98
101
  json
@@ -105,29 +108,34 @@ GEM
105
108
  i18n (1.15.2)
106
109
  concurrent-ruby (~> 1.0)
107
110
  ice_nine (0.11.2)
108
- io-console (0.8.2)
111
+ io-console (0.9.2)
112
+ irb (1.18.0)
113
+ pp (>= 0.6.0)
114
+ prism (>= 1.3.0)
115
+ rdoc (>= 4.0.0)
116
+ reline (>= 0.4.2)
109
117
  iso8601 (0.13.0)
110
- janeway-jsonpath (1.0.0)
111
- json (2.21.1)
118
+ janeway-jsonpath (1.1.0)
119
+ json (2.21.2)
112
120
  json_schemer (2.5.0)
113
121
  bigdecimal
114
122
  hana (~> 1.3)
115
123
  regexp_parser (~> 2.0)
116
124
  simpleidn (~> 0.2)
117
- jsonschema_rs (0.49.1)
125
+ jsonschema_rs (0.50.0)
118
126
  bigdecimal (>= 3.1, < 5)
119
127
  rb_sys (~> 0.9.124)
120
- jsonschema_rs (0.49.1-aarch64-linux)
128
+ jsonschema_rs (0.50.0-aarch64-linux)
121
129
  bigdecimal (>= 3.1, < 5)
122
- jsonschema_rs (0.49.1-aarch64-linux-musl)
130
+ jsonschema_rs (0.50.0-aarch64-linux-musl)
123
131
  bigdecimal (>= 3.1, < 5)
124
- jsonschema_rs (0.49.1-arm64-darwin)
132
+ jsonschema_rs (0.50.0-arm64-darwin)
125
133
  bigdecimal (>= 3.1, < 5)
126
- jsonschema_rs (0.49.1-x86_64-darwin)
134
+ jsonschema_rs (0.50.0-x86_64-darwin)
127
135
  bigdecimal (>= 3.1, < 5)
128
- jsonschema_rs (0.49.1-x86_64-linux)
136
+ jsonschema_rs (0.50.0-x86_64-linux)
129
137
  bigdecimal (>= 3.1, < 5)
130
- jsonschema_rs (0.49.1-x86_64-linux-musl)
138
+ jsonschema_rs (0.50.0-x86_64-linux-musl)
131
139
  bigdecimal (>= 3.1, < 5)
132
140
  language_server-protocol (3.17.0.6)
133
141
  lint_roller (1.1.0)
@@ -160,6 +168,9 @@ GEM
160
168
  racc
161
169
  patience_diff (1.2.0)
162
170
  optimist (~> 3.0)
171
+ pp (0.6.4)
172
+ prettyprint
173
+ prettyprint (0.2.0)
163
174
  prism (1.9.0)
164
175
  public_suffix (7.0.5)
165
176
  racc (1.8.1)
@@ -168,8 +179,17 @@ GEM
168
179
  rake-compiler-dock (1.12.0)
169
180
  rb_sys (0.9.128)
170
181
  rake-compiler-dock (= 1.12.0)
182
+ rbs (4.1.3)
183
+ logger
184
+ prism (>= 1.6.0)
185
+ tsort
186
+ rdoc (8.0.0)
187
+ erb
188
+ prism (>= 1.6.0)
189
+ rbs (>= 4.0.0)
190
+ tsort
171
191
  regexp_parser (2.12.0)
172
- reline (0.6.3)
192
+ reline (0.7.0)
173
193
  io-console (~> 0.5)
174
194
  rexml (3.4.4)
175
195
  rspec (3.13.2)
@@ -185,7 +205,7 @@ GEM
185
205
  diff-lcs (>= 1.2.0, < 2.0)
186
206
  rspec-support (~> 3.13.0)
187
207
  rspec-support (3.13.7)
188
- rubocop (1.88.2)
208
+ rubocop (1.89.0)
189
209
  json (~> 2.3)
190
210
  language_server-protocol (~> 3.17.0.2)
191
211
  lint_roller (~> 1.1.0)
@@ -208,13 +228,14 @@ GEM
208
228
  rubocop (~> 1.86, >= 1.86.2)
209
229
  ruby-progressbar (1.13.0)
210
230
  securerandom (0.4.1)
211
- simplecov (1.0.3)
231
+ simplecov (1.1.1)
212
232
  simpleidn (0.2.3)
213
233
  super_diff (0.19.0)
214
234
  attr_extras (>= 6.2.4, < 8)
215
235
  diff-lcs (~> 1.5)
216
236
  patience_diff (~> 1.2)
217
237
  thor (1.5.0)
238
+ tsort (0.2.0)
218
239
  tzinfo (2.0.6)
219
240
  concurrent-ruby (~> 1.0)
220
241
  unicode-display_width (3.2.0)
@@ -225,7 +246,7 @@ GEM
225
246
  addressable (>= 2.8.0)
226
247
  crack (>= 0.3.2)
227
248
  hashdiff (>= 0.4.0, < 2.0.0)
228
- zeitwerk (2.8.2)
249
+ zeitwerk (2.8.3)
229
250
 
230
251
  PLATFORMS
231
252
  aarch64-linux-gnu
@@ -239,9 +260,9 @@ PLATFORMS
239
260
 
240
261
  DEPENDENCIES
241
262
  base64
242
- byebug
243
263
  cocina-models
244
264
  datacite!
265
+ debug
245
266
  rake (~> 13.0)
246
267
  rspec (~> 3.0)
247
268
  rubocop (~> 1.7)
@@ -251,4 +272,4 @@ DEPENDENCIES
251
272
  webmock (~> 3.13)
252
273
 
253
274
  BUNDLED WITH
254
- 4.0.17
275
+ 4.0.18
data/README.md CHANGED
@@ -117,6 +117,26 @@ validator = Datacite::Validators::AttributesValidator.new(attributes: datacite_a
117
117
  puts validator.errors.join(', ') unless validator.valid?
118
118
  ```
119
119
 
120
+ ## Validating cocina locally
121
+
122
+ With cocina json saved from arge (append `.json` to an argo view URL and save the content locally) then run:
123
+
124
+ ```
125
+ bin/validate-cocina path/to/file.json
126
+ ```
127
+
128
+ This will result in either a `Valid!` message or an `Invalid!` message with a list of validation errors.
129
+
130
+ ## Transforming cocina locally
131
+
132
+ With cocina json saved from Argo (append `.json` to an Argo view URL and save the content locally) then run:
133
+
134
+ ```
135
+ bin/transform path/to/file.json
136
+ ```
137
+
138
+ This will output the formatted json content that would be sent to DataCite.
139
+
120
140
  ## Development
121
141
 
122
142
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/bin/transform ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This is used to review the transformation of a cocina object
5
+ # to a datacite payload
6
+ # usage: bin/transform tmp/druid.json
7
+
8
+ require 'bundler/setup'
9
+ require 'datacite'
10
+ require 'cocina/models'
11
+ require 'json'
12
+
13
+ if ARGV.empty?
14
+ warn "Usage: #{$PROGRAM_NAME} <path-to-cocina-json>"
15
+ exit 1
16
+ end
17
+
18
+ json_path = ARGV[0]
19
+
20
+ unless File.exist?(json_path)
21
+ warn "File not found: #{json_path}"
22
+ exit 1
23
+ end
24
+
25
+ json = JSON.parse(File.read(json_path))
26
+ cocina_object = Cocina::Models::DROWithMetadata.new(json)
27
+ attributes = Datacite::Mapping::FromCocina::Attributes.build(cocina_object:)
28
+
29
+ puts JSON.pretty_generate(attributes)
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This is used to validate if a cocina object will produce
5
+ # a valid datacite payload
6
+ # usage: bin/validate-cocina tmp/druid.json
7
+
8
+ require 'bundler/setup'
9
+ require 'datacite'
10
+ require 'cocina/models'
11
+ require 'json'
12
+
13
+ if ARGV.empty?
14
+ warn "Usage: #{$PROGRAM_NAME} <path-to-cocina-json>"
15
+ exit 1
16
+ end
17
+
18
+ json_path = ARGV[0]
19
+
20
+ unless File.exist?(json_path)
21
+ warn "File not found: #{json_path}"
22
+ exit 1
23
+ end
24
+
25
+ json = JSON.parse(File.read(json_path))
26
+ cocina_object = Cocina::Models::DROWithMetadata.new(json)
27
+ validator = Datacite::Validators::CocinaValidator.new(cocina_object: cocina_object)
28
+
29
+ if validator.valid?
30
+ puts 'Valid!'
31
+ else
32
+ puts 'Invalid:'
33
+ validator.errors.each { |error| puts " - #{error}" }
34
+ exit 1
35
+ end
data/datacite.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ['lib']
30
30
 
31
31
  spec.add_dependency 'activesupport'
32
+ spec.add_dependency 'cocina_display'
32
33
  spec.add_dependency 'dry-monads', '~> 1.3'
33
34
  spec.add_dependency 'faraday', '~> 2.0'
34
35
  spec.add_dependency 'json_schemer'
@@ -30,7 +30,7 @@ module Datacite
30
30
  event: 'publish',
31
31
  url: description.purl,
32
32
  identifiers: Identifiers.build(identification:),
33
- titles: Titles.build(description:),
33
+ titles: Titles.build(title: cocina_display.full_title),
34
34
  publisher: { name: 'Stanford Digital Repository' }, # per DataCite schema
35
35
  publicationYear: publication_year,
36
36
  subjects: Subject.build(description:),
@@ -46,6 +46,10 @@ module Datacite
46
46
  }.merge(ContributorAttributes.build(description:)).compact
47
47
  end
48
48
 
49
+ def cocina_display
50
+ @cocina_display ||= CocinaDisplay::CocinaRecord.from_json(cocina_object.to_json)
51
+ end
52
+
49
53
  private
50
54
 
51
55
  def publication_year
@@ -13,19 +13,19 @@ module Datacite
13
13
  new(...).call
14
14
  end
15
15
 
16
- def initialize(description:)
17
- @description = description
16
+ def initialize(title:)
17
+ @title = title
18
18
  end
19
19
 
20
20
  # @return [Array<Hash>] list of titles for DataCite, conforming to the expectations of HTTP PUT request
21
21
  # to DataCite
22
22
  def call
23
- [{ title: description.title.first.value }]
23
+ [{ title: }]
24
24
  end
25
25
 
26
26
  private
27
27
 
28
- attr_reader :description
28
+ attr_reader :title
29
29
  end
30
30
  end
31
31
  end
@@ -39,26 +39,33 @@ module Datacite
39
39
  end&.value
40
40
  end
41
41
 
42
- # @return [String] DataCite resourceType value
42
+ # @return [String, nil] DataCite resourceType value
43
43
  def resource_type
44
- @resource_type ||= begin
45
- self_deposit_form = Array(description.form).find { |cocina_form| self_deposit_form?(cocina_form) }
46
-
47
- subtypes = self_deposit_subtypes(self_deposit_form)
48
- if subtypes.blank?
49
- self_deposit_type(self_deposit_form)
50
- else
51
- subtypes.select { |subtype| subtype if subtype != resource_type_general }.join('; ')
52
- end
53
- end
44
+ @resource_type ||= resource_type_from_subtypes || resource_type_from_type
45
+ end
46
+
47
+ def resource_type_from_subtypes
48
+ subtypes = self_deposit_subtypes(self_deposit_form)
49
+ return if subtypes.blank?
50
+
51
+ subtypes.reject { |subtype| subtype == resource_type_general }.join('; ')
52
+ end
53
+
54
+ def resource_type_from_type
55
+ self_deposit_type(self_deposit_form) || self_deposit_form&.value
56
+ end
57
+
58
+ def self_deposit_form
59
+ @self_deposit_form ||= Array(description.form).find { |cocina_form| self_deposit_form?(cocina_form) }
54
60
  end
55
61
 
56
- # call with cocina form element for Stanford self deposit resource types
57
- # @return String the value from the structuredValue when the type is 'type' for the cocina form element
62
+ # @param cocina_self_deposit_form [Cocina::Models::DescriptiveValue, nil] cocina form element for
63
+ # Stanford self deposit resource types
64
+ # @return [String, nil] the value from the structuredValue when the type is 'type'
58
65
  def self_deposit_type(cocina_self_deposit_form)
59
- cocina_self_deposit_form&.structuredValue&.each do |struct_val|
60
- return struct_val.value if struct_val.type == 'type'
61
- end
66
+ cocina_self_deposit_form&.structuredValue&.find do |struct_val|
67
+ struct_val.type == 'type'
68
+ end&.value
62
69
  end
63
70
 
64
71
  def self_deposit_subtypes(cocina_self_deposit_form)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Datacite
4
- VERSION = '0.8.4'
4
+ VERSION = '0.8.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datacite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: cocina_display
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: dry-monads
28
42
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +112,8 @@ files:
98
112
  - Rakefile
99
113
  - bin/console
100
114
  - bin/setup
115
+ - bin/transform
116
+ - bin/validate-cocina
101
117
  - datacite.gemspec
102
118
  - lib/datacite.rb
103
119
  - lib/datacite/autogenerate_doi_request_body.rb