sdr-client 0.97.0 → 1.0.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 +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +20 -23
- data/lib/sdr_client/cli.rb +3 -0
- data/lib/sdr_client/deposit/file_metadata_builder.rb +15 -10
- data/lib/sdr_client/deposit/file_metadata_builder_operations/md5.rb +2 -2
- data/lib/sdr_client/deposit/file_metadata_builder_operations/mime_type.rb +2 -2
- data/lib/sdr_client/deposit/file_metadata_builder_operations/sha1.rb +2 -2
- data/lib/sdr_client/deposit/model_process.rb +24 -7
- data/lib/sdr_client/deposit/process.rb +19 -5
- data/lib/sdr_client/deposit/upload_files.rb +15 -12
- data/lib/sdr_client/deposit/upload_files_metadata_builder.rb +15 -18
- data/lib/sdr_client/deposit.rb +29 -18
- data/lib/sdr_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a66643c6ea7e08e14f529c7e5396a5037ab39cae895fa65bb7ddf7a6d98ca93c
|
|
4
|
+
data.tar.gz: 7a7986eb90c7de9eb1f4b0335e4bae0981fe2679ac2317de2f66daaee92f141f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8fc2bb28ace65e03d8cf5336b080924a7ed6d2899cf5d2d54459b38b3d2849738cdaf9bee4fb8021a5b174f3062410748e20345cba9e10e42690995d4e0cd9f9
|
|
7
|
+
data.tar.gz: 4a3dcc3903a17266469c3ad2ca18c2d3fbb7ff57b1711b5753993a5202361d7cb9b526fbef9806a31daabcebc307cae4ba052b5f185bd6a34bfb75e694fbfd11
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
sdr-client (0.
|
|
4
|
+
sdr-client (1.0.0)
|
|
5
5
|
activesupport
|
|
6
6
|
cocina-models (~> 0.86.0)
|
|
7
7
|
dry-monads
|
|
@@ -18,7 +18,7 @@ GEM
|
|
|
18
18
|
addressable (2.8.1)
|
|
19
19
|
public_suffix (>= 2.0.2, < 6.0)
|
|
20
20
|
ast (2.4.2)
|
|
21
|
-
attr_extras (
|
|
21
|
+
attr_extras (7.0.0)
|
|
22
22
|
byebug (11.1.3)
|
|
23
23
|
cocina-models (0.86.0)
|
|
24
24
|
activesupport
|
|
@@ -43,40 +43,37 @@ GEM
|
|
|
43
43
|
activesupport
|
|
44
44
|
diff-lcs (1.5.0)
|
|
45
45
|
docile (1.4.0)
|
|
46
|
-
dry-
|
|
47
|
-
concurrent-ruby (~> 1.0)
|
|
48
|
-
dry-core (0.9.1)
|
|
46
|
+
dry-core (1.0.0)
|
|
49
47
|
concurrent-ruby (~> 1.0)
|
|
50
48
|
zeitwerk (~> 2.6)
|
|
51
|
-
dry-inflector (0.
|
|
52
|
-
dry-logic (1.
|
|
49
|
+
dry-inflector (1.0.0)
|
|
50
|
+
dry-logic (1.4.0)
|
|
53
51
|
concurrent-ruby (~> 1.0)
|
|
54
|
-
dry-core (~> 0
|
|
52
|
+
dry-core (~> 1.0, < 2)
|
|
55
53
|
zeitwerk (~> 2.6)
|
|
56
|
-
dry-monads (1.
|
|
54
|
+
dry-monads (1.6.0)
|
|
57
55
|
concurrent-ruby (~> 1.0)
|
|
58
|
-
dry-core (~> 0
|
|
56
|
+
dry-core (~> 1.0, < 2)
|
|
59
57
|
zeitwerk (~> 2.6)
|
|
60
|
-
dry-struct (1.
|
|
61
|
-
dry-core (~> 0
|
|
62
|
-
dry-types (
|
|
58
|
+
dry-struct (1.6.0)
|
|
59
|
+
dry-core (~> 1.0, < 2)
|
|
60
|
+
dry-types (>= 1.7, < 2)
|
|
63
61
|
ice_nine (~> 0.11)
|
|
64
62
|
zeitwerk (~> 2.6)
|
|
65
|
-
dry-types (1.
|
|
63
|
+
dry-types (1.7.0)
|
|
66
64
|
concurrent-ruby (~> 1.0)
|
|
67
|
-
dry-
|
|
68
|
-
dry-
|
|
69
|
-
dry-
|
|
70
|
-
dry-logic (~> 1.3, >= 1.3)
|
|
65
|
+
dry-core (~> 1.0, < 2)
|
|
66
|
+
dry-inflector (~> 1.0, < 2)
|
|
67
|
+
dry-logic (>= 1.4, < 2)
|
|
71
68
|
zeitwerk (~> 2.6)
|
|
72
69
|
edtf (3.1.0)
|
|
73
70
|
activesupport (>= 3.0, < 8.0)
|
|
74
71
|
equivalent-xml (0.6.0)
|
|
75
72
|
nokogiri (>= 1.4.3)
|
|
76
|
-
faraday (2.
|
|
73
|
+
faraday (2.7.0)
|
|
77
74
|
faraday-net_http (>= 2.0, < 3.1)
|
|
78
75
|
ruby2_keywords (>= 0.0.4)
|
|
79
|
-
faraday-net_http (3.0.
|
|
76
|
+
faraday-net_http (3.0.2)
|
|
80
77
|
hashdiff (1.0.1)
|
|
81
78
|
i18n (1.12.0)
|
|
82
79
|
concurrent-ruby (~> 1.0)
|
|
@@ -122,7 +119,7 @@ GEM
|
|
|
122
119
|
rspec-core (>= 2, < 4, != 2.12.0)
|
|
123
120
|
rss (0.2.9)
|
|
124
121
|
rexml
|
|
125
|
-
rubocop (1.
|
|
122
|
+
rubocop (1.39.0)
|
|
126
123
|
json (~> 2.3)
|
|
127
124
|
parallel (~> 1.10)
|
|
128
125
|
parser (>= 3.1.2.1)
|
|
@@ -136,7 +133,7 @@ GEM
|
|
|
136
133
|
parser (>= 3.1.1.0)
|
|
137
134
|
rubocop-rake (0.6.0)
|
|
138
135
|
rubocop (~> 1.0)
|
|
139
|
-
rubocop-rspec (2.
|
|
136
|
+
rubocop-rspec (2.15.0)
|
|
140
137
|
rubocop (~> 1.33)
|
|
141
138
|
ruby-progressbar (1.11.0)
|
|
142
139
|
ruby2_keywords (0.0.5)
|
|
@@ -158,7 +155,7 @@ GEM
|
|
|
158
155
|
addressable (>= 2.8.0)
|
|
159
156
|
crack (>= 0.3.2)
|
|
160
157
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
161
|
-
zeitwerk (2.6.
|
|
158
|
+
zeitwerk (2.6.6)
|
|
162
159
|
|
|
163
160
|
PLATFORMS
|
|
164
161
|
x86_64-darwin-19
|
data/lib/sdr_client/cli.rb
CHANGED
|
@@ -72,6 +72,7 @@ module SdrClient
|
|
|
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
74
|
option :cocina_pipe, type: :boolean, default: false, desc: 'Indicate Cocina JSON is being piped in'
|
|
75
|
+
option :basepath, default: Dir.getwd, desc: 'Base path for the files'
|
|
75
76
|
def update(druid)
|
|
76
77
|
validate_druid!(druid)
|
|
77
78
|
job_id = SdrClient::Update.run(druid, **options)
|
|
@@ -95,6 +96,7 @@ module SdrClient
|
|
|
95
96
|
option :view, enum: %w[world stanford location-based citation-only dark], desc: 'Access view level for the object'
|
|
96
97
|
option :files_metadata, desc: 'JSON string representing per-file metadata'
|
|
97
98
|
option :grouping_strategy, enum: %w[default filename], desc: 'Strategy for grouping files into filesets'
|
|
99
|
+
option :basepath, default: Dir.getwd, desc: 'Base path for the files'
|
|
98
100
|
def deposit(*files)
|
|
99
101
|
register_or_deposit(files: files, accession: true)
|
|
100
102
|
end
|
|
@@ -113,6 +115,7 @@ module SdrClient
|
|
|
113
115
|
option :view, enum: %w[world stanford location-based citation-only dark], desc: 'Access view level for the object'
|
|
114
116
|
option :files_metadata, desc: 'JSON string representing per-file metadata'
|
|
115
117
|
option :grouping_strategy, enum: %w[default filename], desc: 'Strategy for grouping files into filesets'
|
|
118
|
+
option :basepath, default: Dir.getwd, desc: 'Base path for the files'
|
|
116
119
|
def register(*files)
|
|
117
120
|
register_or_deposit(files: files, accession: false)
|
|
118
121
|
end
|
|
@@ -18,25 +18,26 @@ module SdrClient
|
|
|
18
18
|
|
|
19
19
|
# @param (see #initialize)
|
|
20
20
|
# @return (see #build)
|
|
21
|
-
def self.build(files:, files_metadata:)
|
|
22
|
-
new(files: files, files_metadata: files_metadata.dup).build
|
|
21
|
+
def self.build(files:, files_metadata:, basepath:)
|
|
22
|
+
new(files: files, files_metadata: files_metadata.dup, basepath: basepath).build
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
# @param [Array<String>] files the list of
|
|
26
|
-
def initialize(files:, files_metadata:)
|
|
25
|
+
# @param [Array<String>] files the list of relative filepaths for which to generate metadata
|
|
26
|
+
def initialize(files:, files_metadata:, basepath:)
|
|
27
27
|
@files = files
|
|
28
28
|
@files_metadata = files_metadata
|
|
29
|
+
@basepath = basepath
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
# @return [Hash<String, Hash<String, String>>]
|
|
32
|
+
# @return [Hash<String, Hash<String, String>>] a map of relative filepaths to a map of metadata
|
|
32
33
|
def build
|
|
33
|
-
files.each do |
|
|
34
|
+
files.each do |filepath|
|
|
34
35
|
OPERATIONS.each do |operation|
|
|
35
|
-
result = operation.for(
|
|
36
|
+
result = operation.for(filepath: absolute_filepath_for(filepath))
|
|
36
37
|
next if result.nil?
|
|
37
38
|
|
|
38
|
-
files_metadata[
|
|
39
|
-
files_metadata[
|
|
39
|
+
files_metadata[filepath] ||= {}
|
|
40
|
+
files_metadata[filepath][operation::NAME] = result
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
43
|
files_metadata
|
|
@@ -44,7 +45,11 @@ module SdrClient
|
|
|
44
45
|
|
|
45
46
|
private
|
|
46
47
|
|
|
47
|
-
attr_reader :files, :files_metadata
|
|
48
|
+
attr_reader :files, :files_metadata, :basepath
|
|
49
|
+
|
|
50
|
+
def absolute_filepath_for(filepath)
|
|
51
|
+
::File.join(basepath, filepath)
|
|
52
|
+
end
|
|
48
53
|
end
|
|
49
54
|
end
|
|
50
55
|
end
|
|
@@ -8,8 +8,8 @@ module SdrClient
|
|
|
8
8
|
# Mime-type for this file.
|
|
9
9
|
class MimeType
|
|
10
10
|
NAME = 'mime_type'
|
|
11
|
-
def self.for(
|
|
12
|
-
argv = Shellwords.escape(
|
|
11
|
+
def self.for(filepath:, **)
|
|
12
|
+
argv = Shellwords.escape(filepath)
|
|
13
13
|
`file --mime-type -b #{argv}`.chomp
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -11,17 +11,20 @@ module SdrClient
|
|
|
11
11
|
# @param [Boolean] accession should the accessionWF be started
|
|
12
12
|
# @param [String] priority (nil) what processing priority should be used
|
|
13
13
|
# either 'low' or 'default'
|
|
14
|
-
# @param [Array<String>] files a list of
|
|
14
|
+
# @param [Array<String>] files a list of relative filepaths to upload
|
|
15
|
+
# @param [String] basepath filepath to which filepaths are relative
|
|
15
16
|
# @param [Boolean] assign_doi should a DOI be assigned to this item
|
|
16
17
|
# @param [Logger] logger the logger to use
|
|
17
18
|
def initialize(request_dro:, # rubocop:disable Metrics/ParameterLists
|
|
18
19
|
connection:,
|
|
19
20
|
accession:,
|
|
21
|
+
basepath:,
|
|
20
22
|
priority: nil,
|
|
21
23
|
files: [],
|
|
22
24
|
assign_doi: false,
|
|
23
25
|
logger: Logger.new($stdout))
|
|
24
26
|
@files = files
|
|
27
|
+
@basepath = basepath
|
|
25
28
|
@connection = connection
|
|
26
29
|
@request_dro = request_dro
|
|
27
30
|
@logger = logger
|
|
@@ -34,10 +37,14 @@ module SdrClient
|
|
|
34
37
|
check_files_exist
|
|
35
38
|
child_files_match
|
|
36
39
|
|
|
37
|
-
file_metadata
|
|
40
|
+
# file_metadata is a map of relative filepaths to Files::DirectUploadRequests
|
|
41
|
+
file_metadata = UploadFilesMetadataBuilder.build(files: files, mime_types: mime_types, basepath: basepath)
|
|
42
|
+
# upload_response is an array of Files::DirectUploadResponse
|
|
38
43
|
upload_responses = UploadFiles.upload(file_metadata: file_metadata,
|
|
44
|
+
filepath_map: filepath_map,
|
|
39
45
|
logger: logger,
|
|
40
46
|
connection: connection)
|
|
47
|
+
|
|
41
48
|
new_request_dro = UpdateDroWithFileIdentifiers.update(request_dro: request_dro, upload_responses: upload_responses)
|
|
42
49
|
CreateResource.run(accession: @accession,
|
|
43
50
|
priority: @priority,
|
|
@@ -49,12 +56,12 @@ module SdrClient
|
|
|
49
56
|
|
|
50
57
|
private
|
|
51
58
|
|
|
52
|
-
attr_reader :request_dro, :files, :logger, :connection
|
|
59
|
+
attr_reader :request_dro, :files, :logger, :connection, :basepath
|
|
53
60
|
|
|
54
61
|
def check_files_exist
|
|
55
62
|
logger.info('checking to see if files exist')
|
|
56
|
-
files.each do |
|
|
57
|
-
raise Errno::ENOENT,
|
|
63
|
+
files.each do |filepath|
|
|
64
|
+
raise Errno::ENOENT, filepath unless ::File.exist?(absolute_filepath_for(filepath))
|
|
58
65
|
end
|
|
59
66
|
end
|
|
60
67
|
|
|
@@ -70,7 +77,7 @@ module SdrClient
|
|
|
70
77
|
end
|
|
71
78
|
end
|
|
72
79
|
|
|
73
|
-
# Map of
|
|
80
|
+
# Map of relative filepaths to mimetypes
|
|
74
81
|
def mime_types
|
|
75
82
|
@mime_types ||=
|
|
76
83
|
request_files.transform_values do |file|
|
|
@@ -78,7 +85,7 @@ module SdrClient
|
|
|
78
85
|
end
|
|
79
86
|
end
|
|
80
87
|
|
|
81
|
-
# Map of
|
|
88
|
+
# Map of absolute filepaths to Cocina::Models::RequestFiles
|
|
82
89
|
def request_files
|
|
83
90
|
@request_files ||= begin
|
|
84
91
|
return {} unless request_dro.structural
|
|
@@ -90,6 +97,16 @@ module SdrClient
|
|
|
90
97
|
end.flatten(1).to_h
|
|
91
98
|
end
|
|
92
99
|
end
|
|
100
|
+
|
|
101
|
+
def absolute_filepath_for(filename)
|
|
102
|
+
::File.join(basepath, filename)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def filepath_map
|
|
106
|
+
@filepath_map ||= files.each_with_object({}) do |filepath, obj|
|
|
107
|
+
obj[filepath] = absolute_filepath_for(filepath)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
93
110
|
end
|
|
94
111
|
end
|
|
95
112
|
end
|
|
@@ -13,7 +13,8 @@ module SdrClient
|
|
|
13
13
|
# either 'low' or 'default'
|
|
14
14
|
# @param [Class] grouping_strategy class whose run method groups an array of uploads
|
|
15
15
|
# @param [Class] file_set_type_strategy class whose run method determines file_set type
|
|
16
|
-
# @param [Array<String>] files a list of
|
|
16
|
+
# @param [Array<String>] files a list of relative filepaths to upload
|
|
17
|
+
# @param [String] basepath filepath to which filepaths are relative
|
|
17
18
|
# @param [Boolean] assign_doi should a DOI be assigned to this item
|
|
18
19
|
# @param [Logger] logger the logger to use
|
|
19
20
|
#
|
|
@@ -21,6 +22,7 @@ module SdrClient
|
|
|
21
22
|
def initialize(metadata:,
|
|
22
23
|
connection:,
|
|
23
24
|
accession:,
|
|
25
|
+
basepath:,
|
|
24
26
|
priority: nil,
|
|
25
27
|
grouping_strategy: SingleFileGroupingStrategy,
|
|
26
28
|
file_set_type_strategy: FileTypeFileSetStrategy,
|
|
@@ -36,6 +38,7 @@ module SdrClient
|
|
|
36
38
|
@accession = accession
|
|
37
39
|
@priority = priority
|
|
38
40
|
@assign_doi = assign_doi
|
|
41
|
+
@basepath = basepath
|
|
39
42
|
end
|
|
40
43
|
# rubocop:enable Metrics/ParameterLists
|
|
41
44
|
|
|
@@ -44,8 +47,9 @@ module SdrClient
|
|
|
44
47
|
def run
|
|
45
48
|
check_files_exist
|
|
46
49
|
|
|
47
|
-
file_metadata = UploadFilesMetadataBuilder.build(files: files, mime_types: mime_types)
|
|
50
|
+
file_metadata = UploadFilesMetadataBuilder.build(files: files, mime_types: mime_types, basepath: basepath)
|
|
48
51
|
upload_responses = UploadFiles.upload(file_metadata: file_metadata,
|
|
52
|
+
filepath_map: filepath_map,
|
|
49
53
|
logger: logger,
|
|
50
54
|
connection: connection)
|
|
51
55
|
metadata_builder = MetadataBuilder.new(metadata: metadata,
|
|
@@ -65,12 +69,12 @@ module SdrClient
|
|
|
65
69
|
|
|
66
70
|
private
|
|
67
71
|
|
|
68
|
-
attr_reader :metadata, :files, :connection, :logger, :grouping_strategy, :file_set_type_strategy
|
|
72
|
+
attr_reader :metadata, :files, :connection, :logger, :grouping_strategy, :file_set_type_strategy, :basepath
|
|
69
73
|
|
|
70
74
|
def check_files_exist
|
|
71
75
|
logger.info('checking to see if files exist')
|
|
72
|
-
files.each do |
|
|
73
|
-
raise Errno::ENOENT,
|
|
76
|
+
files.each do |filepath|
|
|
77
|
+
raise Errno::ENOENT, filepath unless ::File.exist?(absolute_filepath_for(filepath))
|
|
74
78
|
end
|
|
75
79
|
end
|
|
76
80
|
|
|
@@ -80,6 +84,16 @@ module SdrClient
|
|
|
80
84
|
[filepath, metadata.for(filepath)['mime_type']]
|
|
81
85
|
end
|
|
82
86
|
end
|
|
87
|
+
|
|
88
|
+
def filepath_map
|
|
89
|
+
@filepath_map ||= files.each_with_object({}) do |filepath, obj|
|
|
90
|
+
obj[filepath] = absolute_filepath_for(filepath)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def absolute_filepath_for(filepath)
|
|
95
|
+
::File.join(basepath, filepath)
|
|
96
|
+
end
|
|
83
97
|
end
|
|
84
98
|
end
|
|
85
99
|
end
|
|
@@ -8,40 +8,43 @@ module SdrClient
|
|
|
8
8
|
class UploadFiles
|
|
9
9
|
BLOB_PATH = '/v1/direct_uploads'
|
|
10
10
|
|
|
11
|
-
# @param [Hash<String,Files::DirectUploadRequest>]
|
|
11
|
+
# @param [Hash<String,Files::DirectUploadRequest>] file_metadata map of relative filepaths to file metadata
|
|
12
|
+
# @param [Hash<String,String>] filepath_map map of relative filepaths to absolute filepaths
|
|
12
13
|
# @param [Logger] logger the logger to use
|
|
13
14
|
# @param [Connection] connection
|
|
14
|
-
def self.upload(file_metadata:, logger:, connection:)
|
|
15
|
-
new(file_metadata: file_metadata, logger: logger, connection: connection).run
|
|
15
|
+
def self.upload(file_metadata:, filepath_map:, logger:, connection:)
|
|
16
|
+
new(file_metadata: file_metadata, filepath_map: filepath_map, logger: logger, connection: connection).run
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
# @param [Hash<String,Files::DirectUploadRequest>]
|
|
19
|
+
# @param [Hash<String,Files::DirectUploadRequest>] file_metadata map of relative filepaths to file metadata
|
|
20
|
+
# @param [Hash<String,String>] filepath_map map of relative filepaths to absolute filepaths
|
|
19
21
|
# @param [Logger] logger the logger to use
|
|
20
22
|
# @param [Connection] connection
|
|
21
|
-
def initialize(file_metadata:, logger:, connection:)
|
|
23
|
+
def initialize(file_metadata:, filepath_map:, logger:, connection:)
|
|
22
24
|
@file_metadata = file_metadata
|
|
25
|
+
@filepath_map = filepath_map
|
|
23
26
|
@logger = logger
|
|
24
27
|
@connection = connection
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
# @return [Array<Files::DirectUploadResponse>] the responses from the server for the uploads
|
|
28
31
|
def run
|
|
29
|
-
file_metadata.map do |
|
|
32
|
+
file_metadata.map do |filepath, metadata|
|
|
30
33
|
direct_upload(metadata.to_json).tap do |response|
|
|
31
|
-
# ActiveStorage modifies the filename provided in response, so setting here
|
|
32
|
-
response.filename =
|
|
33
|
-
upload_file(filename:
|
|
34
|
+
# ActiveStorage modifies the filename provided in response, so setting here with the relative filename
|
|
35
|
+
response.filename = filepath
|
|
36
|
+
upload_file(filename: filepath,
|
|
34
37
|
url: response.direct_upload.fetch('url'),
|
|
35
38
|
content_type: response.content_type,
|
|
36
39
|
content_length: response.byte_size)
|
|
37
|
-
logger.info("Upload of #{
|
|
40
|
+
logger.info("Upload of #{filepath} complete")
|
|
38
41
|
end
|
|
39
42
|
end
|
|
40
43
|
end
|
|
41
44
|
|
|
42
45
|
private
|
|
43
46
|
|
|
44
|
-
attr_reader :logger, :connection, :file_metadata
|
|
47
|
+
attr_reader :logger, :connection, :file_metadata, :filepath_map
|
|
45
48
|
|
|
46
49
|
def direct_upload(metadata_json)
|
|
47
50
|
logger.info("Starting an upload request: #{metadata_json}")
|
|
@@ -63,7 +66,7 @@ module SdrClient
|
|
|
63
66
|
logger.info("Uploading `#{filename}' to #{url}")
|
|
64
67
|
|
|
65
68
|
upload_response = connection.put(url) do |req|
|
|
66
|
-
req.body = ::File.open(filename)
|
|
69
|
+
req.body = ::File.open(filepath_map[filename])
|
|
67
70
|
req.headers['Content-Type'] = content_type
|
|
68
71
|
req.headers['Content-Length'] = content_length.to_s
|
|
69
72
|
end
|
|
@@ -6,39 +6,36 @@ module SdrClient
|
|
|
6
6
|
module Deposit
|
|
7
7
|
# Collecting all the metadata about the files for a deposit
|
|
8
8
|
class UploadFilesMetadataBuilder
|
|
9
|
-
# @param [Array<String>] files a list of filepaths to upload
|
|
9
|
+
# @param [Array<String>] files a list of relative filepaths to upload
|
|
10
10
|
# @param [Hash<String,String>] mime_types a map of filenames to mime types
|
|
11
|
+
# @param [String] basepath path to which files are relative
|
|
11
12
|
# @return [Hash<String, Files::DirectUploadRequest>] the metadata for uploading the files
|
|
12
|
-
def self.build(files:, mime_types:)
|
|
13
|
-
new(files: files, mime_types: mime_types).build
|
|
13
|
+
def self.build(files:, mime_types:, basepath:)
|
|
14
|
+
new(files: files, mime_types: mime_types, basepath: basepath).build
|
|
14
15
|
end
|
|
15
16
|
|
|
16
|
-
# @param [Array<String>] files a list of filepaths to upload
|
|
17
|
+
# @param [Array<String>] files a list of absolute filepaths to upload
|
|
17
18
|
# @param [Hash<String,String>] mime_types a map of filenames to mime types
|
|
18
|
-
|
|
19
|
+
# @param [String] basepath path to which files are relative
|
|
20
|
+
def initialize(files:, mime_types:, basepath:)
|
|
19
21
|
@files = files
|
|
20
22
|
@mime_types = mime_types
|
|
23
|
+
@basepath = basepath
|
|
21
24
|
end
|
|
22
25
|
|
|
23
|
-
attr_reader :files, :mime_types
|
|
26
|
+
attr_reader :files, :mime_types, :basepath
|
|
24
27
|
|
|
25
28
|
# @return [Hash<String, Files::DirectUploadRequest>] the metadata for uploading the files
|
|
26
29
|
def build
|
|
27
|
-
files.each_with_object({}) do |
|
|
28
|
-
obj[
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
files.each_with_object({}) do |filepath, obj|
|
|
31
|
+
obj[filepath] = Files::DirectUploadRequest.from_file(absolute_filepath_for(filepath),
|
|
32
|
+
file_name: filepath,
|
|
33
|
+
content_type: mime_types[filepath])
|
|
31
34
|
end
|
|
32
35
|
end
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def filename_for(file_path)
|
|
37
|
-
file_path
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def mime_type_for(file_path)
|
|
41
|
-
mime_types[filename_for(file_path)]
|
|
37
|
+
def absolute_filepath_for(filepath)
|
|
38
|
+
::File.join(basepath, filepath)
|
|
42
39
|
end
|
|
43
40
|
end
|
|
44
41
|
end
|
data/lib/sdr_client/deposit.rb
CHANGED
|
@@ -8,6 +8,9 @@ module SdrClient
|
|
|
8
8
|
BOOK_TYPE = Cocina::Models::ObjectType.book
|
|
9
9
|
# rubocop:disable Metrics/ParameterLists
|
|
10
10
|
# rubocop:disable Metrics/MethodLength
|
|
11
|
+
# params [Array<String>] files a list of relative filepaths to upload
|
|
12
|
+
# params [String] basepath filepath to which filepaths are relative, defaults to current directory
|
|
13
|
+
# params [Hash<String,Hash>] file_metadata relative filepath, hash of metadata per-file metadata
|
|
11
14
|
# @return [String] job id for the background job result
|
|
12
15
|
def self.run(label: nil,
|
|
13
16
|
type: BOOK_TYPE,
|
|
@@ -26,29 +29,34 @@ module SdrClient
|
|
|
26
29
|
url:,
|
|
27
30
|
files: [],
|
|
28
31
|
files_metadata: {},
|
|
32
|
+
basepath: Dir.getwd,
|
|
29
33
|
accession: false,
|
|
30
34
|
priority: nil,
|
|
31
35
|
grouping_strategy: SingleFileGroupingStrategy,
|
|
32
36
|
file_set_type_strategy: FileTypeFileSetStrategy,
|
|
33
37
|
logger: Logger.new($stdout))
|
|
34
|
-
augmented_metadata
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
# augmented_metadata is a map of relative filepaths to file metadata
|
|
39
|
+
augmented_metadata = FileMetadataBuilder.build(files: files, files_metadata: files_metadata, basepath: basepath)
|
|
40
|
+
request = Request.new(label: label,
|
|
41
|
+
type: type,
|
|
42
|
+
view: view,
|
|
43
|
+
download: download,
|
|
44
|
+
apo: apo,
|
|
45
|
+
use_and_reproduction: use_and_reproduction,
|
|
46
|
+
copyright: copyright,
|
|
47
|
+
collection: collection,
|
|
48
|
+
source_id: source_id,
|
|
49
|
+
catkey: catkey,
|
|
50
|
+
embargo_release_date: embargo_release_date,
|
|
51
|
+
embargo_access: embargo_access,
|
|
52
|
+
embargo_download: embargo_download,
|
|
53
|
+
viewing_direction: viewing_direction,
|
|
54
|
+
files_metadata: augmented_metadata)
|
|
50
55
|
connection = Connection.new(url: url)
|
|
51
|
-
Process.new(metadata:
|
|
56
|
+
Process.new(metadata: request,
|
|
57
|
+
connection: connection,
|
|
58
|
+
files: files,
|
|
59
|
+
basepath: basepath,
|
|
52
60
|
grouping_strategy: grouping_strategy,
|
|
53
61
|
file_set_type_strategy: file_set_type_strategy,
|
|
54
62
|
accession: accession,
|
|
@@ -57,9 +65,11 @@ module SdrClient
|
|
|
57
65
|
end
|
|
58
66
|
# rubocop:enable Metrics/MethodLength
|
|
59
67
|
|
|
60
|
-
# @param [Array<String>] files
|
|
68
|
+
# @param [Array<String>] files relative paths to files
|
|
69
|
+
# @params [String] basepath path to which files are relative
|
|
61
70
|
def self.model_run(request_dro:,
|
|
62
71
|
files: [],
|
|
72
|
+
basepath: Dir.getwd,
|
|
63
73
|
url:,
|
|
64
74
|
accession:,
|
|
65
75
|
priority: nil,
|
|
@@ -68,6 +78,7 @@ module SdrClient
|
|
|
68
78
|
ModelProcess.new(request_dro: request_dro,
|
|
69
79
|
connection: connection,
|
|
70
80
|
files: files,
|
|
81
|
+
basepath: basepath,
|
|
71
82
|
logger: logger,
|
|
72
83
|
accession: accession,
|
|
73
84
|
priority: priority).run
|
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: 1.0.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-11-
|
|
11
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|