sdr-client 0.88.0 → 0.89.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 306e1af071e673f1d0c15b8158d49e25b83266ffa46282034774a07a54a7ff1e
4
- data.tar.gz: 98bc8d20f6a46e3f89e7f8250c56962944ae74fc19b028a8d7df06323d3d5e48
3
+ metadata.gz: 0e749426dd330fcaf3d0988f32707bde37010f2f305c6cdc383992c73f16ff3e
4
+ data.tar.gz: 1526a4e18c42b5e1ce30ae4283173112cedbe83b24bdb78b928c2e84b5471b1a
5
5
  SHA512:
6
- metadata.gz: 57312c7aa2947b0233f080030de611344dd6d3fffbca9af480c14eeb93b53f70f0dcce20a31721e1a92ca7f22efa87595bbbdff917b8e21bc8f6ee7142af32cb
7
- data.tar.gz: 7ab17c0b16f0c44a35c7cfa1418363fa108c2061b3d78b209c8bcb314761bcbaf83a4541151adb5d92a86af2c6c70285f384a94c0d111a2b163af730c8cc6e9e
6
+ metadata.gz: bc684b73cf7e8d9cbc2d4f0da3c02c1cc0db8277941c8a7888273ed5ed1c98e1eb83d979ec419342d182604dbcbb8231d6a3547e9a5905a88f1db6b53dcdea94
7
+ data.tar.gz: 7acff379f70c228a728bfeb7a31119adde73f60703e350a0d413524194578e31c19ee02a4137232ae215b66a96953812294190103aa5de48ca85b26be4f6b6d9
data/.circleci/config.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  version: 2.1
2
2
  orbs:
3
- ruby-rails: sul-dlss/ruby-rails@2.0.0
3
+ ruby-rails: sul-dlss/ruby-rails@3.1.2
4
4
  workflows:
5
5
  build:
6
6
  jobs:
data/.rubocop.yml CHANGED
@@ -157,3 +157,21 @@ RSpec/BeNil: # new in 2.9.0
157
157
  Enabled: true
158
158
  RSpec/VerifiedDoubleReference: # new in 2.10.0
159
159
  Enabled: true
160
+ Layout/LineContinuationLeadingSpace: # new in 1.31
161
+ Enabled: true
162
+ Layout/LineContinuationSpacing: # new in 1.31
163
+ Enabled: true
164
+ Lint/ConstantOverwrittenInRescue: # new in 1.31
165
+ Enabled: true
166
+ Lint/NonAtomicFileOperation: # new in 1.31
167
+ Enabled: true
168
+ Style/EnvHome: # new in 1.29
169
+ Enabled: true
170
+ Style/MapCompactWithConditionalBlock: # new in 1.30
171
+ Enabled: true
172
+ RSpec/ChangeByZero: # new in 2.11.0
173
+ Enabled: true
174
+ RSpec/Capybara/SpecificMatcher: # new in 2.12
175
+ Enabled: true
176
+ RSpec/Rails/HaveHttpStatus: # new in 2.12
177
+ Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sdr-client (0.88.0)
4
+ sdr-client (0.89.0)
5
5
  activesupport
6
6
  cocina-models (~> 0.83.0)
7
7
  dry-monads
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (7.0.3)
13
+ activesupport (7.0.3.1)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 1.6, < 2)
16
16
  minitest (>= 5.1)
@@ -43,15 +43,11 @@ GEM
43
43
  activesupport
44
44
  diff-lcs (1.5.0)
45
45
  docile (1.4.0)
46
- dry-configurable (0.15.0)
46
+ dry-container (0.10.0)
47
47
  concurrent-ruby (~> 1.0)
48
- dry-core (~> 0.6)
49
- dry-container (0.9.0)
50
- concurrent-ruby (~> 1.0)
51
- dry-configurable (~> 0.13, >= 0.13.0)
52
48
  dry-core (0.7.1)
53
49
  concurrent-ruby (~> 1.0)
54
- dry-inflector (0.2.1)
50
+ dry-inflector (0.3.0)
55
51
  dry-logic (1.2.0)
56
52
  concurrent-ruby (~> 1.0)
57
53
  dry-core (~> 0.5, >= 0.5)
@@ -68,7 +64,7 @@ GEM
68
64
  dry-core (~> 0.5, >= 0.5)
69
65
  dry-inflector (~> 0.1, >= 0.1.2)
70
66
  dry-logic (~> 1.0, >= 1.0.2)
71
- edtf (3.0.8)
67
+ edtf (3.1.0)
72
68
  activesupport (>= 3.0, < 8.0)
73
69
  equivalent-xml (0.6.0)
74
70
  nokogiri (>= 1.4.3)
@@ -77,14 +73,18 @@ GEM
77
73
  ruby2_keywords (>= 0.0.4)
78
74
  faraday-net_http (2.0.3)
79
75
  hashdiff (1.0.1)
80
- i18n (1.10.0)
76
+ i18n (1.11.0)
81
77
  concurrent-ruby (~> 1.0)
82
78
  ice_nine (0.11.2)
83
79
  json (2.6.2)
84
80
  jsonpath (1.1.2)
85
81
  multi_json
82
+ mini_portile2 (2.8.0)
86
83
  minitest (5.16.2)
87
84
  multi_json (1.15.0)
85
+ nokogiri (1.13.6)
86
+ mini_portile2 (~> 2.8.0)
87
+ racc (~> 1.4)
88
88
  nokogiri (1.13.6-x86_64-darwin)
89
89
  racc (~> 1.4)
90
90
  openapi3_parser (0.9.2)
@@ -119,7 +119,7 @@ GEM
119
119
  rspec-core (>= 2, < 4, != 2.12.0)
120
120
  rss (0.2.9)
121
121
  rexml
122
- rubocop (1.31.1)
122
+ rubocop (1.31.2)
123
123
  json (~> 2.3)
124
124
  parallel (~> 1.10)
125
125
  parser (>= 3.1.0.0)
@@ -129,7 +129,7 @@ GEM
129
129
  rubocop-ast (>= 1.18.0, < 2.0)
130
130
  ruby-progressbar (~> 1.7)
131
131
  unicode-display_width (>= 1.4.0, < 3.0)
132
- rubocop-ast (1.18.0)
132
+ rubocop-ast (1.19.1)
133
133
  parser (>= 3.1.1.0)
134
134
  rubocop-rake (0.6.0)
135
135
  rubocop (~> 1.0)
@@ -159,6 +159,7 @@ GEM
159
159
 
160
160
  PLATFORMS
161
161
  x86_64-darwin-21
162
+ x86_64-linux
162
163
 
163
164
  DEPENDENCIES
164
165
  bundler (~> 2.0)
data/README.md CHANGED
@@ -95,9 +95,12 @@ sdr update druid:bb408qn5061 --url https://sdr-api-server:3000 --license "https:
95
95
  # Change access controls
96
96
  sdr update druid:bb408qn5061 --url https://sdr-api-server:3000 --view "location-based" --download "none" --location "music" --cdl false
97
97
 
98
- # Change Cocina wholesale from a file (note that you can use this flag with the
99
- # others above, and the flags above will replace what's supplied in the cocina file)
98
+ # Change Cocina wholesale, either:
99
+ # 1. From a file
100
100
  sdr update druid:bb408qn5061 --url https://sdr-api-server:3000 --cocina-file bb408qn5061.json
101
+ # 2. Piped in on the command-line
102
+ sdr get druid:b408qn5061 --url https://sdr-api-server:3000 | exe/remove_w3cdtf_encoding_from_event_dates | sdr update druid:bb408qn5061 --url https://sdr-api-server:3000 --cocina-pipe
103
+ # Note that you can use either of these flags with the others above, and the flags above will replace what's supplied in the cocina file or pipe
101
104
  ```
102
105
 
103
106
  ## Testing
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift 'lib'
5
+
6
+ require 'sdr_client'
7
+
8
+ output = JSON.parse($stdin.read).tap do |hash|
9
+ hash.dig('description', 'event').each do |event|
10
+ event['date'].each do |event_date|
11
+ event_date.delete('encoding') if event_date.dig('encoding', 'code') == 'w3cdtf'
12
+ end
13
+ end
14
+ end.to_json
15
+
16
+ puts output
@@ -31,7 +31,7 @@ module SdrClient
31
31
 
32
32
  desc 'get DRUID', 'Retrieve an object from the SDR'
33
33
  def get(druid)
34
- say SdrClient::Find.run(druid, url: options[:url])
34
+ say SdrClient::Find.run(druid, url: options[:url], logger: Logger.new($stderr))
35
35
  rescue SdrClient::Credentials::NoCredentialsError
36
36
  say_error 'Log in first'
37
37
  exit(1)
@@ -71,10 +71,11 @@ module SdrClient
71
71
  option :location, enum: %w[spec music ars art hoover m&m], desc: 'Access location for the object'
72
72
  option :cdl, type: :boolean, default: false, desc: 'Controlled digital lending'
73
73
  option :cocina_file, desc: 'Path to a file containing Cocina JSON'
74
+ option :cocina_pipe, type: :boolean, default: false, desc: 'Indicate Cocina JSON is being piped in'
74
75
  def update(druid)
75
76
  validate_druid!(druid)
76
77
  job_id = SdrClient::Update.run(druid, **options)
77
- poll_for_job_complete(job_id: job_id, url: options[:url]) # TODO: add an option that skips this
78
+ poll_for_job_complete(job_id: job_id, url: options[:url])
78
79
  rescue SdrClient::Credentials::NoCredentialsError
79
80
  say_error 'Log in first'
80
81
  exit(1)
@@ -156,7 +157,7 @@ module SdrClient
156
157
  # the extra args to `say` prevent appending a newline
157
158
  say('SDR is processing your request.', nil, false)
158
159
  result = nil
159
- (1).upto(60) do
160
+ 1.upto(60) do
160
161
  result = SdrClient::BackgroundJobResults.show(url: url, job_id: job_id)
161
162
  break unless %w[pending processing].include?(result['status'])
162
163
 
@@ -8,7 +8,7 @@ module SdrClient
8
8
  # @param [String] a json string that contains a field 'token'
9
9
  def self.write(body)
10
10
  json = JSON.parse(body)
11
- Dir.mkdir(credentials_path, 0o700) unless Dir.exist?(credentials_path)
11
+ FileUtils.mkdir_p(credentials_path, mode: 0o700)
12
12
  File.atomic_write(credentials_file) do |file|
13
13
  file.write(json.fetch('token'))
14
14
  end
@@ -5,9 +5,10 @@ module SdrClient
5
5
  # Creates a resource (metadata) in SDR
6
6
  class CreateResource
7
7
  DRO_PATH = '/v1/resources'
8
-
9
- def self.run(accession:, metadata:, logger:, connection:, assign_doi: false)
8
+ # rubocop:disable Metrics/ParameterLists
9
+ def self.run(accession:, metadata:, logger:, connection:, assign_doi: false, priority: nil)
10
10
  new(accession: accession,
11
+ priority: priority,
11
12
  assign_doi: assign_doi,
12
13
  metadata: metadata,
13
14
  logger: logger,
@@ -18,13 +19,17 @@ module SdrClient
18
19
  # @param [Boolean] assign_doi should a DOI be assigned to this item
19
20
  # @param [Cocina::Models::RequestDRO, Cocina::Models::RequestCollection] metadata
20
21
  # @param [Hash<Symbol,String>] the result of the metadata call
21
- def initialize(accession:, assign_doi:, metadata:, logger:, connection:)
22
+ # @param [String] priority what processing priority should be used
23
+ # either 'low' or 'default'
24
+ def initialize(accession:, assign_doi:, metadata:, logger:, connection:, priority: nil)
22
25
  @accession = accession
26
+ @priority = priority
23
27
  @assign_doi = assign_doi
24
28
  @metadata = metadata
25
29
  @logger = logger
26
30
  @connection = connection
27
31
  end
32
+ # rubocop:enable Metrics/ParameterLists
28
33
 
29
34
  # @param [Hash<Symbol,String>] the result of the metadata call
30
35
  # @return [String] job id for the background job result
@@ -39,7 +44,7 @@ module SdrClient
39
44
 
40
45
  private
41
46
 
42
- attr_reader :metadata, :logger, :connection
47
+ attr_reader :metadata, :logger, :connection, :priority
43
48
 
44
49
  def metadata_request
45
50
  json = metadata.to_json
@@ -60,6 +65,7 @@ module SdrClient
60
65
 
61
66
  def path
62
67
  params = { accession: accession? }
68
+ params[:priority] = priority if priority
63
69
  params[:assign_doi] = true if assign_doi? # false is default
64
70
  DRO_PATH + '?' + params.map { |k, v| "#{k}=#{v}" }.join('&')
65
71
  end
@@ -9,6 +9,8 @@ module SdrClient
9
9
  # @param [Request] metadata information about the object
10
10
  # @param [String] connection the server connection to use
11
11
  # @param [Boolean] accession should the accessionWF be started
12
+ # @param [String] priority (nil) what processing priority should be used
13
+ # either 'low' or 'default'
12
14
  # @param [Class] grouping_strategy class whose run method groups an array of uploads
13
15
  # @param [Class] file_set_type_strategy class whose run method determines file_set type
14
16
  # @param [Array<String>] files a list of file names to upload
@@ -19,6 +21,7 @@ module SdrClient
19
21
  def initialize(metadata:,
20
22
  connection:,
21
23
  accession:,
24
+ priority: nil,
22
25
  grouping_strategy: SingleFileGroupingStrategy,
23
26
  file_set_type_strategy: FileTypeFileSetStrategy,
24
27
  files: [],
@@ -31,6 +34,7 @@ module SdrClient
31
34
  @grouping_strategy = grouping_strategy
32
35
  @file_set_type_strategy = file_set_type_strategy
33
36
  @accession = accession
37
+ @priority = priority
34
38
  @assign_doi = assign_doi
35
39
  end
36
40
  # rubocop:enable Metrics/ParameterLists
@@ -51,6 +55,7 @@ module SdrClient
51
55
  request = metadata_builder.with_uploads(upload_responses)
52
56
  model = Cocina::Models.build_request(request.as_json.with_indifferent_access)
53
57
  CreateResource.run(accession: @accession,
58
+ priority: @priority,
54
59
  assign_doi: @assign_doi,
55
60
  metadata: model,
56
61
  logger: logger,
@@ -27,6 +27,7 @@ module SdrClient
27
27
  files: [],
28
28
  files_metadata: {},
29
29
  accession: false,
30
+ priority: nil,
30
31
  grouping_strategy: SingleFileGroupingStrategy,
31
32
  file_set_type_strategy: FileTypeFileSetStrategy,
32
33
  logger: Logger.new($stdout))
@@ -51,6 +52,7 @@ module SdrClient
51
52
  grouping_strategy: grouping_strategy,
52
53
  file_set_type_strategy: file_set_type_strategy,
53
54
  accession: accession,
55
+ priority: priority,
54
56
  logger: logger).run
55
57
  end
56
58
  # rubocop:enable Metrics/MethodLength
@@ -50,10 +50,22 @@ module SdrClient
50
50
  @cocina_hash_from_file ||= JSON.parse(File.read(options[:cocina_file]), symbolize_names: true)
51
51
  end
52
52
 
53
+ def cocina_hash_from_pipe
54
+ @cocina_hash_from_pipe ||= JSON.parse($stdin.read, symbolize_names: true)
55
+ end
56
+
53
57
  # Update the Cocina in full
54
58
  def update_cocina(cocina_object)
55
- return cocina_object unless options[:cocina_file]
59
+ if options[:cocina_file]
60
+ update_cocina_from_file(cocina_object)
61
+ elsif options[:cocina_pipe]
62
+ update_cocina_from_pipe(cocina_object)
63
+ else
64
+ cocina_object
65
+ end
66
+ end
56
67
 
68
+ def update_cocina_from_file(cocina_object)
57
69
  if !File.file?(options[:cocina_file]) || !File.readable?(options[:cocina_file])
58
70
  raise "File not found: #{options[:cocina_file]}"
59
71
  end
@@ -66,6 +78,17 @@ module SdrClient
66
78
  cocina_object.new(cocina_hash_from_file)
67
79
  end
68
80
 
81
+ def update_cocina_from_pipe(cocina_object)
82
+ raise 'No pipe provided' unless $stdin.stat.pipe?
83
+
84
+ # NOTE: We may want to add more checks later. For now, make sure the identifiers match.
85
+ if cocina_object.externalIdentifier != cocina_hash_from_pipe[:externalIdentifier]
86
+ raise "Cocina piped in has a different external identifier than #{cocina_object.externalIdentifier}: #{cocina_hash_from_pipe[:externalIdentifier]}"
87
+ end
88
+
89
+ cocina_object.new(cocina_hash_from_pipe)
90
+ end
91
+
69
92
  # Update the APO of a Cocina item if the options specify a new one, else return the original
70
93
  def update_apo(cocina_object)
71
94
  return cocina_object unless options[:apo]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.88.0'
4
+ VERSION = '0.89.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdr-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.88.0
4
+ version: 0.89.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-05 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -197,6 +197,7 @@ description: This provides a way to deposit repository objects into the Stanford
197
197
  email:
198
198
  - jcoyne@justincoyne.com
199
199
  executables:
200
+ - remove_w3cdtf_encoding_from_event_dates
200
201
  - sdr
201
202
  extensions: []
202
203
  extra_rdoc_files: []
@@ -214,6 +215,7 @@ files:
214
215
  - Rakefile
215
216
  - bin/console
216
217
  - bin/setup
218
+ - exe/remove_w3cdtf_encoding_from_event_dates
217
219
  - exe/sdr
218
220
  - lib/sdr-client.rb
219
221
  - lib/sdr_client.rb