sdr-client 0.36.0 → 0.37.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sdr_client/deposit.rb +3 -1
- data/lib/sdr_client/deposit/{upload_resource.rb → create_resource.rb} +7 -13
- data/lib/sdr_client/deposit/model_process.rb +2 -2
- data/lib/sdr_client/deposit/process.rb +2 -2
- data/lib/sdr_client/deposit/unexpected_response.rb +16 -0
- data/lib/sdr_client/deposit/update_resource.rb +48 -0
- data/lib/sdr_client/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0317804f79b720e64c6f6625b248c33ce62c90b41f7100b80f5a692f2686ff01'
|
4
|
+
data.tar.gz: 80cfbe267682f2b272a45ae380bb1db9749fd626f4b40279f4ce7bae76a2ed9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 113498f64f0e405daa754b8e20ce126e8ed2c1ef2ce2c0cbe0c4cfb1a8343dd261529ec146228b560d7dc13af22a1837cf3b7377c1c62e8da17fbc9b0c493d63
|
7
|
+
data.tar.gz: d2fe355591c76be1c2242d6420eb08742bddee7c784b38419b6d99f1293e82024a17a2c66d0530a92a740805b3121a45dc76a6ca29524b807b76a6054f047d51
|
data/lib/sdr_client/deposit.rb
CHANGED
@@ -68,6 +68,7 @@ module SdrClient
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
require 'json'
|
71
|
+
require 'sdr_client/deposit/create_resource'
|
71
72
|
require 'sdr_client/deposit/single_file_grouping_strategy'
|
72
73
|
require 'sdr_client/deposit/matching_file_grouping_strategy'
|
73
74
|
require 'sdr_client/deposit/files/direct_upload_request'
|
@@ -79,7 +80,8 @@ require 'sdr_client/deposit/request'
|
|
79
80
|
require 'sdr_client/deposit/metadata_builder'
|
80
81
|
require 'sdr_client/deposit/model_process'
|
81
82
|
require 'sdr_client/deposit/process'
|
83
|
+
require 'sdr_client/deposit/unexpected_response'
|
84
|
+
require 'sdr_client/deposit/update_resource'
|
82
85
|
require 'sdr_client/deposit/update_dro_with_file_identifiers'
|
83
86
|
require 'sdr_client/deposit/upload_files'
|
84
87
|
require 'sdr_client/deposit/upload_files_metadata_builder'
|
85
|
-
require 'sdr_client/deposit/upload_resource'
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module SdrClient
|
4
4
|
module Deposit
|
5
|
-
#
|
6
|
-
class
|
5
|
+
# Creates a resource (metadata) in SDR
|
6
|
+
class CreateResource
|
7
7
|
DRO_PATH = '/v1/resources'
|
8
8
|
|
9
9
|
def self.run(accession:, metadata:, logger:, connection:)
|
@@ -11,7 +11,7 @@ module SdrClient
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# @param [Boolean] accession should the accessionWF be started
|
14
|
-
# @param [
|
14
|
+
# @param [Cocina::Models::RequestDRO, Cocina::Models::RequestCollection] metadata
|
15
15
|
# @param [Hash<Symbol,String>] the result of the metadata call
|
16
16
|
def initialize(accession:, metadata:, logger:, connection:)
|
17
17
|
@accession = accession
|
@@ -24,7 +24,7 @@ module SdrClient
|
|
24
24
|
# @return [String] job id for the background job result
|
25
25
|
def run
|
26
26
|
response = metadata_request
|
27
|
-
|
27
|
+
UnexpectedResponse.call(response) unless response.status == 201
|
28
28
|
|
29
29
|
logger.info("Response from server: #{response.body}")
|
30
30
|
|
@@ -36,16 +36,10 @@ module SdrClient
|
|
36
36
|
attr_reader :metadata, :logger, :connection
|
37
37
|
|
38
38
|
def metadata_request
|
39
|
-
|
39
|
+
json = metadata.to_json
|
40
|
+
logger.debug("Starting upload metadata: #{json}")
|
40
41
|
|
41
|
-
connection.post(path,
|
42
|
-
end
|
43
|
-
|
44
|
-
def unexpected_response(response)
|
45
|
-
raise "There was an error with your request: #{response.body}" if response.status == 400
|
46
|
-
raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
|
47
|
-
|
48
|
-
raise "unexpected response: #{response.status} #{response.body}"
|
42
|
+
connection.post(path, json, 'Content-Type' => 'application/json')
|
49
43
|
end
|
50
44
|
|
51
45
|
def accession?
|
@@ -29,8 +29,8 @@ module SdrClient
|
|
29
29
|
logger: logger,
|
30
30
|
connection: connection)
|
31
31
|
new_request_dro = UpdateDroWithFileIdentifiers.update(request_dro: request_dro, upload_responses: upload_responses)
|
32
|
-
|
33
|
-
metadata: new_request_dro
|
32
|
+
CreateResource.run(accession: @accession,
|
33
|
+
metadata: new_request_dro,
|
34
34
|
logger: logger,
|
35
35
|
connection: connection)
|
36
36
|
end
|
@@ -39,8 +39,8 @@ module SdrClient
|
|
39
39
|
logger: logger)
|
40
40
|
request = metadata_builder.with_uploads(upload_responses)
|
41
41
|
model = Cocina::Models.build_request(request.as_json.with_indifferent_access)
|
42
|
-
|
43
|
-
metadata:
|
42
|
+
CreateResource.run(accession: @accession,
|
43
|
+
metadata: model,
|
44
44
|
logger: logger,
|
45
45
|
connection: connection)
|
46
46
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SdrClient
|
4
|
+
module Deposit
|
5
|
+
# Handles unexpected responses when manipulating resources
|
6
|
+
class UnexpectedResponse
|
7
|
+
# @param [Faraday::Response] response
|
8
|
+
def self.call(response)
|
9
|
+
raise "There was an error with your request: #{response.body}" if response.status == 400
|
10
|
+
raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
|
11
|
+
|
12
|
+
raise "unexpected response: #{response.status} #{response.body}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SdrClient
|
4
|
+
module Deposit
|
5
|
+
# Updates a resource (metadata) in SDR
|
6
|
+
class UpdateResource
|
7
|
+
DRO_PATH = '/v1/resources/%<id>s'
|
8
|
+
|
9
|
+
def self.run(metadata:, logger:, connection:)
|
10
|
+
new(metadata: metadata, logger: logger, connection: connection).run
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [Cocina::Models::DRO] metadata
|
14
|
+
# @param [Hash<Symbol,String>] the result of the metadata call
|
15
|
+
def initialize(metadata:, logger:, connection:)
|
16
|
+
@metadata = metadata
|
17
|
+
@logger = logger
|
18
|
+
@connection = connection
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param [Hash<Symbol,String>] the result of the metadata call
|
22
|
+
# @return [String] job id for the background job result
|
23
|
+
def run
|
24
|
+
response = metadata_request
|
25
|
+
UnexpectedResponse.call(response) unless response.status == 202
|
26
|
+
|
27
|
+
logger.info("Response from server: #{response.body}")
|
28
|
+
|
29
|
+
JSON.parse(response.body)['jobId']
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :metadata, :logger, :connection
|
35
|
+
|
36
|
+
def metadata_request
|
37
|
+
json = metadata.to_json
|
38
|
+
logger.debug("Starting upload metadata: #{json}")
|
39
|
+
|
40
|
+
connection.put(path(metadata), json, 'Content-Type' => 'application/json')
|
41
|
+
end
|
42
|
+
|
43
|
+
def path(metadata)
|
44
|
+
format(DRO_PATH, id: metadata.externalIdentifier)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/sdr_client/version.rb
CHANGED
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.
|
4
|
+
version: 0.37.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: 2020-11-
|
11
|
+
date: 2020-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- lib/sdr_client/connection.rb
|
194
194
|
- lib/sdr_client/credentials.rb
|
195
195
|
- lib/sdr_client/deposit.rb
|
196
|
+
- lib/sdr_client/deposit/create_resource.rb
|
196
197
|
- lib/sdr_client/deposit/file.rb
|
197
198
|
- lib/sdr_client/deposit/file_metadata_builder.rb
|
198
199
|
- lib/sdr_client/deposit/file_metadata_builder_operations/md5.rb
|
@@ -207,10 +208,11 @@ files:
|
|
207
208
|
- lib/sdr_client/deposit/process.rb
|
208
209
|
- lib/sdr_client/deposit/request.rb
|
209
210
|
- lib/sdr_client/deposit/single_file_grouping_strategy.rb
|
211
|
+
- lib/sdr_client/deposit/unexpected_response.rb
|
210
212
|
- lib/sdr_client/deposit/update_dro_with_file_identifiers.rb
|
213
|
+
- lib/sdr_client/deposit/update_resource.rb
|
211
214
|
- lib/sdr_client/deposit/upload_files.rb
|
212
215
|
- lib/sdr_client/deposit/upload_files_metadata_builder.rb
|
213
|
-
- lib/sdr_client/deposit/upload_resource.rb
|
214
216
|
- lib/sdr_client/login.rb
|
215
217
|
- lib/sdr_client/login_prompt.rb
|
216
218
|
- lib/sdr_client/version.rb
|