sdr-client 0.21.0 → 0.22.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/README.md +8 -1
- data/exe/sdr +65 -59
- data/lib/sdr_client/cli.rb +3 -1
- data/lib/sdr_client/deposit.rb +4 -1
- data/lib/sdr_client/deposit/process.rb +25 -4
- data/lib/sdr_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52457756d6413fcbb3d78c6778e705dd000f73d4bfd9be51b4455c91f861f2cf
|
4
|
+
data.tar.gz: 2e3fbb925f332ddbf6f70a011f708ed659bb768bf3cea618e3b40cea70b7e1a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdaa5ce7b1c83361d33911f02191d4a34c97c24113ffc01e4594a2300b966ef7b0ff399ea56ee033650be0eb808dd3a363dbf04357c2e124ebfe378d78a69459
|
7
|
+
data.tar.gz: 238c7ff0047034134d1a3c4421bed157e09b97692ec6d57226edfc2e4e5ef0a7be3a88a39b9c10f816ae6e53dc7f44d10dea7d38a1f7424bb9a6a5c9b3ea7fd2
|
data/README.md
CHANGED
@@ -21,8 +21,15 @@ Log in:
|
|
21
21
|
sdr --service-url http://sdr-api-server:3000 login
|
22
22
|
```
|
23
23
|
|
24
|
+
Register a new object:
|
25
|
+
```
|
26
|
+
sdr --service-url https://sdr-api-server:3000 register --label 'hey there' \
|
27
|
+
--admin-policy 'druid:bk123gh4567' \
|
28
|
+
--collection 'druid:gh456kw9876' \
|
29
|
+
--source-id 'googlebooks:stanford_12345' file1.png file2.png
|
30
|
+
```
|
24
31
|
|
25
|
-
Deposit a new object:
|
32
|
+
Deposit (register + accession) a new object:
|
26
33
|
```
|
27
34
|
sdr --service-url https://sdr-api-server:3000 deposit --label 'hey there' \
|
28
35
|
--admin-policy 'druid:bk123gh4567' \
|
data/exe/sdr
CHANGED
@@ -27,7 +27,10 @@ global = OptionParser.new do |opts|
|
|
27
27
|
|
28
28
|
COMMANDS
|
29
29
|
deposit
|
30
|
-
|
30
|
+
accession object into the SDR
|
31
|
+
|
32
|
+
register
|
33
|
+
create a draft object in SDR
|
31
34
|
|
32
35
|
login
|
33
36
|
Will prompt for email & password and exchange it for an login token, which it saves in ~/.sdr/token
|
@@ -40,77 +43,80 @@ end
|
|
40
43
|
global.order!
|
41
44
|
command = ARGV.shift
|
42
45
|
|
43
|
-
|
44
|
-
'
|
45
|
-
|
46
|
-
|
47
|
-
end
|
46
|
+
deposit_options = OptionParser.new do |opts|
|
47
|
+
opts.on('--label LABEL', 'The object label') do |label|
|
48
|
+
options[:label] = label
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
opts.on('--admin-policy ADMIN_POLICY', 'The druid identifier of the admin policy object') do |apo|
|
52
|
+
options[:apo] = apo
|
53
|
+
end
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
55
|
+
opts.on('--type TYPE', 'The object type to create. ' \
|
56
|
+
'One of: "image", "book", "document", "map", "manuscript", "media", ' \
|
57
|
+
'"three_dimensional", "collection", or "admin_policy"') do |type|
|
58
|
+
if %w[image book document map manuscript media three_dimensional collection admin_policy].include?(type)
|
59
|
+
options[:type] = "http://cocina.sul.stanford.edu/models/#{type}.jsonld"
|
59
60
|
end
|
61
|
+
end
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
opts.on('--collection COLLECTION', 'The druid identifier of the collection object') do |collection|
|
64
|
+
options[:collection] = collection
|
65
|
+
end
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
opts.on('--catkey CATKEY', 'The catkey for this item') do |catkey|
|
68
|
+
options[:catkey] = catkey
|
69
|
+
end
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
71
|
+
opts.on('--source-id SOURCE_ID', 'The source id for this object') do |source_id|
|
72
|
+
options[:source_id] = source_id
|
73
|
+
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
opts.on('--copyright COPYRIGHT', 'The copyright statement') do |copyright|
|
76
|
+
options[:copyright] = copyright
|
77
|
+
end
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
-
|
79
|
+
opts.on('--use-statement STATEMENT', 'The use and reproduction statement') do |use_statement|
|
80
|
+
options[:use_statement] = use_statement
|
81
|
+
end
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
opts.on('--viewing-direction DIRECTION', 'The viewing direction (if a book). ' \
|
84
|
+
'Either "left-to-right" or "right-to-left"') do |viewing_direction|
|
85
|
+
options[:viewing_direction] = viewing_direction if %w[left-to-right right-to-left].include?(viewing_direction)
|
86
|
+
end
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
opts.on('--access LEVEL', 'The access level for this object. ' \
|
89
|
+
'Either "world", "stanford", "location-based", "citation-only" or "dark"') do |level|
|
90
|
+
options[:access] = level if %w[world stanford location-based citation-only dark].include?(level)
|
91
|
+
end
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
|
93
|
+
opts.on('--files-metadata FILES_METADATA', 'A JSON object representing per-file metadata') do |files_metadata|
|
94
|
+
options[:files_metadata] = JSON.parse(files_metadata)
|
95
|
+
end
|
94
96
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
97
|
+
opts.on('--strategy STRATEGY',
|
98
|
+
'The strategy to use for distributing files into filesets. Either "default" or "filename"') do |strategy|
|
99
|
+
strategy_class = case strategy
|
100
|
+
when 'filename'
|
101
|
+
SdrClient::Deposit::MatchingFileGroupingStrategy
|
102
|
+
when 'default'
|
103
|
+
SdrClient::Deposit::SingleFileGroupingStrategy
|
104
|
+
else
|
105
|
+
warn "Unknown strategy #{strategy}"
|
106
|
+
exit(1)
|
107
|
+
end
|
108
|
+
options[:grouping_strategy] = strategy_class
|
109
|
+
end
|
108
110
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
opts.on('-h', '--help', 'Display this screen') do
|
112
|
+
puts opts
|
113
|
+
exit
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
subcommands = {
|
118
|
+
'deposit' => deposit_options,
|
119
|
+
'register' => deposit_options,
|
114
120
|
'login' => OptionParser.new
|
115
121
|
}
|
116
122
|
|
data/lib/sdr_client/cli.rb
CHANGED
@@ -6,7 +6,9 @@ module SdrClient
|
|
6
6
|
def self.start(command, options)
|
7
7
|
case command
|
8
8
|
when 'deposit'
|
9
|
-
SdrClient::Deposit.run(options)
|
9
|
+
SdrClient::Deposit.run(accession: true, **options)
|
10
|
+
when 'register'
|
11
|
+
SdrClient::Deposit.run(accession: false, **options)
|
10
12
|
when 'login'
|
11
13
|
status = SdrClient::Login.run(options)
|
12
14
|
puts status.value if status.failure?
|
data/lib/sdr_client/deposit.rb
CHANGED
@@ -23,6 +23,7 @@ module SdrClient
|
|
23
23
|
url:,
|
24
24
|
files: [],
|
25
25
|
files_metadata: {},
|
26
|
+
accession: false,
|
26
27
|
grouping_strategy: SingleFileGroupingStrategy,
|
27
28
|
logger: Logger.new(STDOUT))
|
28
29
|
augmented_metadata = FileMetadataBuilder.build(files: files, files_metadata: files_metadata)
|
@@ -41,7 +42,9 @@ module SdrClient
|
|
41
42
|
files_metadata: augmented_metadata)
|
42
43
|
connection = Connection.new(url: url)
|
43
44
|
Process.new(metadata: metadata, connection: connection, files: files,
|
44
|
-
grouping_strategy: grouping_strategy,
|
45
|
+
grouping_strategy: grouping_strategy,
|
46
|
+
accession: accession,
|
47
|
+
logger: logger).run
|
45
48
|
end
|
46
49
|
# rubocop:enable Metrics/MethodLength
|
47
50
|
# rubocop:enable Metrics/ParameterLists
|
@@ -11,15 +11,20 @@ module SdrClient
|
|
11
11
|
# @param [Class] grouping_strategy class whose run method groups an array of uploads
|
12
12
|
# @param [String] connection the server connection to use
|
13
13
|
# @param [Array<String>] files a list of file names to upload
|
14
|
+
# @param [Boolean] accession should the accessionWF be started
|
14
15
|
# @param [Logger] logger the logger to use
|
16
|
+
#
|
17
|
+
# rubocop:disable Metrics/ParameterLists
|
15
18
|
def initialize(metadata:, grouping_strategy: SingleFileGroupingStrategy,
|
16
|
-
connection:, files: [], logger: Logger.new(STDOUT))
|
19
|
+
connection:, files: [], accession:, logger: Logger.new(STDOUT))
|
17
20
|
@files = files
|
18
21
|
@connection = connection
|
19
22
|
@metadata = metadata
|
20
23
|
@logger = logger
|
21
24
|
@grouping_strategy = grouping_strategy
|
25
|
+
@accession = accession
|
22
26
|
end
|
27
|
+
# rubocop:enable Metrics/ParameterLists
|
23
28
|
|
24
29
|
# rubocop:disable Metrics/AbcSize
|
25
30
|
def run
|
@@ -48,11 +53,15 @@ module SdrClient
|
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
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
|
51
62
|
# @return [Hash<Symbol,String>] the result of the metadata call
|
52
63
|
def upload_metadata(metadata)
|
53
|
-
|
54
|
-
request_json = JSON.generate(metadata)
|
55
|
-
response = connection.post(DRO_PATH, request_json, 'Content-Type' => 'application/json')
|
64
|
+
response = metadata_request(metadata)
|
56
65
|
unexpected_response(response) unless response.status == 201
|
57
66
|
|
58
67
|
logger.info("Response from server: #{response.body}")
|
@@ -60,6 +69,18 @@ module SdrClient
|
|
60
69
|
{ druid: JSON.parse(response.body)['druid'], background_job: response.headers['Location'] }
|
61
70
|
end
|
62
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
|
+
|
63
84
|
def unexpected_response(response)
|
64
85
|
raise "There was an error with your request: #{response.body}" if response.status == 400
|
65
86
|
raise 'There was an error with your credentials. Perhaps they have expired?' if response.status == 401
|
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.22.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
|
+
date: 2020-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -233,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
233
|
- !ruby/object:Gem::Version
|
234
234
|
version: '0'
|
235
235
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
236
|
+
rubygems_version: 3.1.2
|
237
237
|
signing_key:
|
238
238
|
specification_version: 4
|
239
239
|
summary: The CLI for https://github.com/sul-dlss/sdr-api
|