sdr-client 0.22.0 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26eecb6134b706eb60ac7623c53576d6ae93f18d7bb9399b8e18c07f04e6da99
|
4
|
+
data.tar.gz: 9c2a3d384225a21571ef5618e0bf1606599a44f429a0c81735c8c7f0f04172a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adadb90117ec098b281ff87b03796fd20fed3772fd03e3aa165f8c97b8c05a5510ed7980d9321effa15757cd505bbae8ba30bbdb3dd2c57257b24ce7bf40aa0e
|
7
|
+
data.tar.gz: 06ee1f2f6b22e364cfe1fe32059619b527026e7f9dd2dd2e05a6e30865c07946d8e9d1c8b98d1fbb91b68f7867400534a9eb83c3406942e54438947c2eed1ed3
|
data/lib/sdr_client/deposit.rb
CHANGED
@@ -59,6 +59,7 @@ require 'sdr_client/deposit/file'
|
|
59
59
|
require 'sdr_client/deposit/file_metadata_builder'
|
60
60
|
require 'sdr_client/deposit/file_set'
|
61
61
|
require 'sdr_client/deposit/request'
|
62
|
-
require 'sdr_client/deposit/upload_files'
|
63
62
|
require 'sdr_client/deposit/metadata_builder'
|
64
63
|
require 'sdr_client/deposit/process'
|
64
|
+
require 'sdr_client/deposit/upload_files'
|
65
|
+
require 'sdr_client/deposit/upload_resource'
|
@@ -6,16 +6,18 @@ module SdrClient
|
|
6
6
|
module Deposit
|
7
7
|
# The process for doing a deposit from a Cocina Model
|
8
8
|
class ModelProcess
|
9
|
-
DRO_PATH = '/v1/resources'
|
10
9
|
# @param [Cocina::Model::RequestDRO] request_dro for depositing
|
11
10
|
# @param [Connection] connection the connection to use
|
12
11
|
# @param [Array<String>] files a list of file names to upload
|
12
|
+
# @param [Boolean] accession should the accessionWF be started
|
13
13
|
# @param [Logger] logger the logger to use
|
14
|
-
def initialize(request_dro:, connection:,
|
14
|
+
def initialize(request_dro:, connection:,
|
15
|
+
files: [], accession:, logger: Logger.new(STDOUT))
|
15
16
|
@files = files
|
16
17
|
@connection = connection
|
17
18
|
@request_dro = request_dro
|
18
19
|
@logger = logger
|
20
|
+
@accession = accession
|
19
21
|
end
|
20
22
|
|
21
23
|
def run
|
@@ -27,7 +29,10 @@ module SdrClient
|
|
27
29
|
connection: connection,
|
28
30
|
mime_types: mime_types).run
|
29
31
|
new_request_dro = with_external_identifiers(upload_responses)
|
30
|
-
|
32
|
+
UploadResource.run(accession: @accession,
|
33
|
+
metadata: new_request_dro.to_json,
|
34
|
+
logger: logger,
|
35
|
+
connection: connection)
|
31
36
|
end
|
32
37
|
|
33
38
|
private
|
@@ -56,24 +61,6 @@ module SdrClient
|
|
56
61
|
end
|
57
62
|
end
|
58
63
|
|
59
|
-
# @return [Hash<Symbol,String>] the result of the metadata call
|
60
|
-
def upload_request_dro(request_json)
|
61
|
-
logger.info("Starting upload metadata: #{request_json}")
|
62
|
-
response = connection.post(DRO_PATH, request_json, 'Content-Type' => 'application/json')
|
63
|
-
unexpected_response(response) unless response.status == 201
|
64
|
-
|
65
|
-
logger.info("Response from server: #{response.body}")
|
66
|
-
|
67
|
-
{ druid: JSON.parse(response.body)['druid'], background_job: response.headers['Location'] }
|
68
|
-
end
|
69
|
-
|
70
|
-
def unexpected_response(response)
|
71
|
-
raise "There was an error with your request: #{response.body}" if response.status == 400
|
72
|
-
raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
|
73
|
-
|
74
|
-
raise "unexpected response: #{response.status} #{response.body}"
|
75
|
-
end
|
76
|
-
|
77
64
|
# Map of filenames to mimetypes
|
78
65
|
def mime_types
|
79
66
|
@mime_types ||=
|
@@ -6,7 +6,6 @@ module SdrClient
|
|
6
6
|
module Deposit
|
7
7
|
# The process for doing a deposit
|
8
8
|
class Process
|
9
|
-
DRO_PATH = '/v1/resources'
|
10
9
|
# @param [Request] metadata information about the object
|
11
10
|
# @param [Class] grouping_strategy class whose run method groups an array of uploads
|
12
11
|
# @param [String] connection the server connection to use
|
@@ -38,7 +37,10 @@ module SdrClient
|
|
38
37
|
logger: logger)
|
39
38
|
request = metadata_builder.with_uploads(upload_responses)
|
40
39
|
model = Cocina::Models.build_request(request.as_json.with_indifferent_access)
|
41
|
-
|
40
|
+
UploadResource.run(accession: @accession,
|
41
|
+
metadata: JSON.generate(model.to_h),
|
42
|
+
logger: logger,
|
43
|
+
connection: connection)
|
42
44
|
end
|
43
45
|
# rubocop:enable Metrics/AbcSize
|
44
46
|
|
@@ -53,41 +55,6 @@ module SdrClient
|
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
def accession?
|
57
|
-
@accession
|
58
|
-
end
|
59
|
-
|
60
|
-
# @param [Hash<Symbol,String>] the result of the metadata call
|
61
|
-
# @param [Boolean] accession should the accessionWF be started
|
62
|
-
# @return [Hash<Symbol,String>] the result of the metadata call
|
63
|
-
def upload_metadata(metadata)
|
64
|
-
response = metadata_request(metadata)
|
65
|
-
unexpected_response(response) unless response.status == 201
|
66
|
-
|
67
|
-
logger.info("Response from server: #{response.body}")
|
68
|
-
|
69
|
-
{ druid: JSON.parse(response.body)['druid'], background_job: response.headers['Location'] }
|
70
|
-
end
|
71
|
-
|
72
|
-
def metadata_request(metadata)
|
73
|
-
logger.debug("Starting upload metadata: #{metadata}")
|
74
|
-
|
75
|
-
connection.post(path, JSON.generate(metadata), 'Content-Type' => 'application/json')
|
76
|
-
end
|
77
|
-
|
78
|
-
def path
|
79
|
-
path = DRO_PATH
|
80
|
-
path += '?accession=true' if accession?
|
81
|
-
path
|
82
|
-
end
|
83
|
-
|
84
|
-
def unexpected_response(response)
|
85
|
-
raise "There was an error with your request: #{response.body}" if response.status == 400
|
86
|
-
raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
|
87
|
-
|
88
|
-
raise "unexpected response: #{response.status} #{response.body}"
|
89
|
-
end
|
90
|
-
|
91
58
|
def mime_types
|
92
59
|
@mime_types ||=
|
93
60
|
Hash[
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SdrClient
|
4
|
+
module Deposit
|
5
|
+
# Uploads a resource (metadata) to the server
|
6
|
+
class UploadResource
|
7
|
+
DRO_PATH = '/v1/resources'
|
8
|
+
|
9
|
+
def self.run(accession:, metadata:, logger:, connection:)
|
10
|
+
new(accession: accession, metadata: metadata, logger: logger, connection: connection).run
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [Boolean] accession should the accessionWF be started
|
14
|
+
# @param [String] metadata
|
15
|
+
# @param [Hash<Symbol,String>] the result of the metadata call
|
16
|
+
def initialize(accession:, metadata:, logger:, connection:)
|
17
|
+
@accession = accession
|
18
|
+
@metadata = metadata
|
19
|
+
@logger = logger
|
20
|
+
@connection = connection
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param [Hash<Symbol,String>] the result of the metadata call
|
24
|
+
# @return [Hash<Symbol,String>] the result of the metadata call
|
25
|
+
def run
|
26
|
+
response = metadata_request
|
27
|
+
unexpected_response(response) unless response.status == 201
|
28
|
+
|
29
|
+
logger.info("Response from server: #{response.body}")
|
30
|
+
|
31
|
+
{ druid: JSON.parse(response.body)['druid'], background_job: response.headers['Location'] }
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_reader :metadata, :logger, :connection
|
37
|
+
|
38
|
+
def metadata_request
|
39
|
+
logger.debug("Starting upload metadata: #{metadata}")
|
40
|
+
|
41
|
+
connection.post(path, metadata, 'Content-Type' => 'application/json')
|
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}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def accession?
|
52
|
+
@accession
|
53
|
+
end
|
54
|
+
|
55
|
+
def path
|
56
|
+
path = DRO_PATH
|
57
|
+
path += '?accession=true' if accession?
|
58
|
+
path
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
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.23.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-04-
|
11
|
+
date: 2020-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -207,6 +207,7 @@ files:
|
|
207
207
|
- lib/sdr_client/deposit/request.rb
|
208
208
|
- lib/sdr_client/deposit/single_file_grouping_strategy.rb
|
209
209
|
- lib/sdr_client/deposit/upload_files.rb
|
210
|
+
- lib/sdr_client/deposit/upload_resource.rb
|
210
211
|
- lib/sdr_client/login.rb
|
211
212
|
- lib/sdr_client/login_prompt.rb
|
212
213
|
- lib/sdr_client/model_deposit.rb
|