sdr-client 0.8.1 → 0.9.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: 4e8f69b9d4d664873ab3b08a6bc148fdf79e899f225ae31e745601f71fb7a183
4
- data.tar.gz: 673b32c6e7358680608d583eae9ca57aafa464d8ce968b920f0b3b2adb36eac0
3
+ metadata.gz: '0578c4fbb93d5b8118a9d55f9751f1b50b633d15405411a31b8a4376b3d2f297'
4
+ data.tar.gz: 0bc45cbbe780f1e386685bca4cd500ca8ed8b227ddd0377c290c36b918a5dd96
5
5
  SHA512:
6
- metadata.gz: ce3d3f552e3e70d1e078f1f21f684635719f8437252673c5eb100f69bcf86a8db2c36596eb0770415e77f46c95f3b48c544b5fe409c604875b45284cbda69480
7
- data.tar.gz: fa511f36501e0ec134aa383615d3cc21a3d5d2b3944eae18add53feb8fa9049c49e83f2da58bfc2053b0f8149eac48ba8442172740a6b2adc250cdbca3cd390e
6
+ metadata.gz: 8cc065044b53e035c4eb73901ab635684c8b956ec280713ad50293e410a6525c5d15d274acaf7cf266f3a7f31a77309c85a9067449f03885ca1abde0b0e4d53a
7
+ data.tar.gz: 7a03cfd0cbf6a48e2fea9c71fb587c74e58b624a6ce1a299c55534c7fce9043d0a4dd0c4682f914ad54b4074bf4fda4ee95e3c70ac3d17d77d0b0a6c9a786bf0
data/README.md CHANGED
@@ -27,3 +27,12 @@ sdr --service-url https://sdr-api-server:3000 deposit --label 'hey there' \
27
27
  --collection 'druid:gh456kw9876' \
28
28
  --source-id 'googlebooks:stanford_12345' file1.png file2.png
29
29
  ```
30
+
31
+ Deposit a new object, providing metadata for files:
32
+ ```
33
+ sdr --service-url https://sdr-api-server:3000 deposit --label 'hey there' \
34
+ --files-metadata '{"image42.jp2":{"mime_type":"image/jp2"},"ocr.html":{"use":"transcription"}}'
35
+ --admin-policy 'druid:bk123gh4567' \
36
+ --collection 'druid:gh456kw9876' \
37
+ --source-id 'googlebooks:stanford_12345' image42.jp2 ocr.html
38
+ ```
data/exe/sdr CHANGED
@@ -49,6 +49,7 @@ subcommands = {
49
49
  opts.on('--admin-policy ADMIN_POLICY', 'The druid identifier of the admin policy object') do |apo|
50
50
  options[:apo] = apo
51
51
  end
52
+
52
53
  opts.on('--collection COLLECTION', 'The druid identifier of the collection object') do |collection|
53
54
  options[:collection] = collection
54
55
  end
@@ -61,6 +62,10 @@ subcommands = {
61
62
  options[:source_id] = source_id
62
63
  end
63
64
 
65
+ opts.on('--files-metadata FILES_METADATA', 'A JSON object representing per-file metadata') do |files_metadata|
66
+ options[:files_metadata] = JSON.parse(files_metadata)
67
+ end
68
+
64
69
  opts.on('--strategy STRATEGY',
65
70
  'The strategy to use for distributing files into filesets. Either "default" or "filename"') do |strategy|
66
71
  strategy_class = case strategy
@@ -24,9 +24,10 @@ module SdrClient
24
24
  apo: apo,
25
25
  collection: collection,
26
26
  source_id: source_id,
27
- catkey: catkey)
27
+ catkey: catkey,
28
+ files_metadata: files_metadata)
28
29
  Process.new(metadata: metadata, url: url, token: token, files: files,
29
- files_metadata: files_metadata, grouping_strategy: grouping_strategy, logger: logger).run
30
+ grouping_strategy: grouping_strategy, logger: logger).run
30
31
  end
31
32
  # rubocop:enable Metrics/ParameterLists
32
33
  end
@@ -7,7 +7,7 @@ module SdrClient
7
7
  # rubocop:disable Metrics/ParameterLists
8
8
  def initialize(external_identifier:, label:, filename:,
9
9
  access: 'dark', preserve: false, shelve: false,
10
- mime_type: nil, md5: nil, sha1: nil)
10
+ mime_type: nil, md5: nil, sha1: nil, use: nil)
11
11
  @external_identifier = external_identifier
12
12
  @label = label
13
13
  @filename = filename
@@ -17,6 +17,7 @@ module SdrClient
17
17
  @mime_type = mime_type
18
18
  @md5 = md5
19
19
  @sha1 = sha1
20
+ @use = use
20
21
  end
21
22
  # rubocop:enable Metrics/ParameterLists
22
23
 
@@ -37,6 +38,7 @@ module SdrClient
37
38
  }.tap do |json|
38
39
  json['hasMessageDigests'] = message_digests unless message_digests.empty?
39
40
  json['hasMimeType'] = @mime_type if @mime_type
41
+ json['use'] = @use if @use
40
42
  end
41
43
  end
42
44
  # rubocop:enable Metrics/MethodLength
@@ -4,6 +4,10 @@ module SdrClient
4
4
  module Deposit
5
5
  # This represents the FileSet metadata that we send to the server for doing a deposit
6
6
  class FileSet
7
+ # @param [Array] uploads
8
+ # @param [Hash<String,Hash<String,String>>] the file level metadata
9
+ # @param [Array] files
10
+ # @param [String] label
7
11
  def initialize(uploads: [], uploads_metadata: {}, files: [], label:)
8
12
  @label = label
9
13
  @files = if !uploads.empty?
@@ -29,6 +33,8 @@ module SdrClient
29
33
 
30
34
  attr_reader :files, :label
31
35
 
36
+ # This creates the metadata for each file and symbolizes the keys
37
+ # @return [Hash<Symbol,String>]
32
38
  def file_args(upload, upload_metadata)
33
39
  args = {
34
40
  external_identifier: upload.signed_id,
@@ -8,14 +8,12 @@ module SdrClient
8
8
  class MetadataBuilder
9
9
  # @param [Request] metadata information about the object
10
10
  # @param [Class] grouping_strategy class whose run method groups an array of uploads
11
- # @param [Hash<String, Hash<String, String>>] files_metadata file name, hash of additional file metadata
12
11
  # Additional metadata includes access, preserve, shelve, md5, sha1
13
12
  # @param [Logger] logger the logger to use
14
- def initialize(metadata:, grouping_strategy:, files_metadata:, logger:)
13
+ def initialize(metadata:, grouping_strategy:, logger:)
15
14
  @metadata = metadata
16
15
  @logger = logger
17
16
  @grouping_strategy = grouping_strategy
18
- @files_metadata = files_metadata
19
17
  end
20
18
 
21
19
  def with_uploads(upload_responses)
@@ -25,7 +23,7 @@ module SdrClient
25
23
 
26
24
  private
27
25
 
28
- attr_reader :metadata, :files, :logger, :grouping_strategy, :files_metadata
26
+ attr_reader :metadata, :files, :logger, :grouping_strategy
29
27
 
30
28
  # @param [Array<SdrClient::Deposit::Files::DirectUploadResponse>] uploads the uploaded files to attach.
31
29
  # @return [Array<SdrClient::Deposit::FileSet>] the uploads transformed to filesets
@@ -33,7 +31,7 @@ module SdrClient
33
31
  grouped_uploads = grouping_strategy.run(uploads: uploads)
34
32
  grouped_uploads.map.with_index(1) do |upload_group, i|
35
33
  metadata_group = {}
36
- upload_group.each { |upload| metadata_group[upload.filename] = files_metadata.fetch(upload.filename, {}) }
34
+ upload_group.each { |upload| metadata_group[upload.filename] = metadata.for(upload.filename) }
37
35
  FileSet.new(uploads: upload_group, uploads_metadata: metadata_group, label: "Object #{i}")
38
36
  end
39
37
  end
@@ -12,29 +12,27 @@ module SdrClient
12
12
  # @param [String] url the server to send to
13
13
  # @param [String] token the bearer auth token for the server
14
14
  # @param [Array<String>] files a list of file names to upload
15
- # @param [Hash<String, Hash<String, String>>] files_metadata file name, hash of additional file metadata
16
- # Additional metadata includes access, preserve, shelve, md5, sha1
17
15
  # @param [Logger] logger the logger to use
18
16
  # rubocop:disable Metrics/ParameterLists
19
17
  def initialize(metadata:, grouping_strategy: SingleFileGroupingStrategy, url:,
20
- token:, files: [], files_metadata: {}, logger: Logger.new(STDOUT))
18
+ token:, files: [], logger: Logger.new(STDOUT))
21
19
  @files = files
22
20
  @url = url
23
21
  @token = token
24
22
  @metadata = metadata
25
23
  @logger = logger
26
24
  @grouping_strategy = grouping_strategy
27
- @files_metadata = files_metadata
28
25
  end
29
26
  # rubocop:enable Metrics/ParameterLists
30
27
 
31
28
  def run
32
29
  check_files_exist
33
- upload_responses = UploadFiles.new(files: files, logger: logger,
34
- connection: connection, files_metadata: files_metadata).run
30
+ upload_responses = UploadFiles.new(files: files,
31
+ logger: logger,
32
+ connection: connection,
33
+ metadata: metadata).run
35
34
  metadata_builder = MetadataBuilder.new(metadata: metadata,
36
35
  grouping_strategy: grouping_strategy,
37
- files_metadata: files_metadata,
38
36
  logger: logger)
39
37
  request = metadata_builder.with_uploads(upload_responses)
40
38
  upload_metadata(request.as_json)
@@ -42,7 +40,7 @@ module SdrClient
42
40
 
43
41
  private
44
42
 
45
- attr_reader :metadata, :files, :url, :token, :logger, :grouping_strategy, :files_metadata
43
+ attr_reader :metadata, :files, :url, :token, :logger, :grouping_strategy
46
44
 
47
45
  def check_files_exist
48
46
  logger.info('checking to see if files exist')
@@ -76,22 +74,6 @@ module SdrClient
76
74
  conn.adapter :net_http
77
75
  end
78
76
  end
79
-
80
- # @param [Array<SdrClient::Deposit::Files::DirectUploadResponse>] uploads the uploaded files to attach.
81
- # @return [Array<SdrClient::Deposit::FileSet>] the uploads transformed to filesets
82
- def build_filesets(uploads:)
83
- grouped_uploads = grouping_strategy.run(uploads: uploads)
84
- grouped_uploads.map.with_index(1) do |upload_group, i|
85
- metadata_group = {}
86
- upload_group.each { |upload| metadata_group[upload.filename] = file_metadata_for(upload.filename) }
87
- FileSet.new(uploads: upload_group, uploads_metadata: metadata_group, label: "Object #{i}")
88
- end
89
- end
90
-
91
- # @return [Hash<Symbol,String>] the file metadata for this file
92
- def file_metadata_for(filename)
93
- files_metadata.fetch(filename, {})
94
- end
95
77
  end
96
78
  end
97
79
  end
@@ -7,6 +7,8 @@ module SdrClient
7
7
  # @param [String] label the required object label
8
8
  # @param [String] type (http://cocina.sul.stanford.edu/models/object.jsonld) the required object type.
9
9
  # @param [Array<FileSet>] file_sets the file sets to attach.
10
+ # @param [Hash<String, Hash<String, String>>] files_metadata file name, hash of additional file metadata
11
+ # Additional metadata includes access, preserve, shelve, md5, sha1
10
12
  # rubocop:disable Metrics/ParameterLists
11
13
  def initialize(label: nil,
12
14
  apo:,
@@ -14,7 +16,8 @@ module SdrClient
14
16
  source_id:,
15
17
  catkey: nil,
16
18
  type: 'http://cocina.sul.stanford.edu/models/object.jsonld',
17
- file_sets: [])
19
+ file_sets: [],
20
+ files_metadata: {})
18
21
  @label = label
19
22
  @type = type
20
23
  @source_id = source_id
@@ -22,6 +25,7 @@ module SdrClient
22
25
  @catkey = catkey
23
26
  @apo = apo
24
27
  @file_sets = file_sets
28
+ @files_metadata = files_metadata
25
29
  end
26
30
  # rubocop:enable Metrics/ParameterLists
27
31
 
@@ -45,12 +49,20 @@ module SdrClient
45
49
  source_id: source_id,
46
50
  catkey: catkey,
47
51
  type: type,
48
- file_sets: file_sets)
52
+ file_sets: file_sets,
53
+ files_metadata: files_metadata)
54
+ end
55
+
56
+ # @param [String] filename
57
+ # @return [Hash] the metadata for the file
58
+ def for(filename)
59
+ files_metadata.fetch(filename, {})
49
60
  end
50
61
 
51
62
  private
52
63
 
53
- attr_reader :label, :file_sets, :source_id, :catkey, :apo, :collection, :type
64
+ attr_reader :label, :file_sets, :source_id, :catkey, :apo, :collection,
65
+ :type, :files_metadata
54
66
 
55
67
  def administrative
56
68
  {
@@ -10,10 +10,10 @@ module SdrClient
10
10
  # @param [Array<String>] files a list of file names to upload
11
11
  # @param [Logger] logger the logger to use
12
12
  # @param [Faraday::Connection] connection
13
- # @param [Hash<String, Hash<String, String>>] files_metadata file name, hash of additional file metadata
14
- def initialize(files:, files_metadata:, logger:, connection:)
13
+ # @param [Request] metadata information about the object
14
+ def initialize(files:, metadata:, logger:, connection:)
15
15
  @files = files
16
- @files_metadata = files_metadata
16
+ @metadata = metadata
17
17
  @logger = logger
18
18
  @connection = connection
19
19
  end
@@ -28,14 +28,14 @@ module SdrClient
28
28
 
29
29
  private
30
30
 
31
- attr_reader :files, :files_metadata, :logger, :connection
31
+ attr_reader :files, :metadata, :logger, :connection
32
32
 
33
33
  def collect_file_metadata
34
34
  files.each_with_object({}) do |path, obj|
35
35
  file_name = ::File.basename(path)
36
36
  obj[path] = Files::DirectUploadRequest.from_file(path,
37
37
  file_name: file_name,
38
- content_type: file_metadata_for(file_name)[:mime_type])
38
+ content_type: metadata.for(file_name)[:mime_type])
39
39
  end
40
40
  end
41
41
 
@@ -77,11 +77,6 @@ module SdrClient
77
77
 
78
78
  raise "unexpected response: #{upload_response.inspect}" unless upload_response.status == 204
79
79
  end
80
-
81
- # @return [Hash<Symbol,String>] the file metadata for this file
82
- def file_metadata_for(filename)
83
- files_metadata.fetch(filename, {})
84
- end
85
80
  end
86
81
  end
87
82
  end
@@ -1,6 +1,5 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module SdrClient
5
- VERSION = '0.8.1'
4
+ VERSION = '0.9.0'
6
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.8.1
4
+ version: 0.9.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-02-04 00:00:00.000000000 Z
11
+ date: 2020-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads