uc3-dmp-id 0.0.41 → 0.0.43

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: a083adf1ce95bf86fe7775c5c76fa12758f90747502daa8a9f2140cc9b50743b
4
- data.tar.gz: 3fdf9a0f471daa92bcd663892cb4b40f306be417fbab94a0a9bad6a65a600134
3
+ metadata.gz: '00945fc509b066babd974cddaf43c65bfa031abe384515c7ea44daa9af532bda'
4
+ data.tar.gz: 285ccacf79b362c1d75102217f905fd9c0e50c94f9388944a8379c72433ac2bc
5
5
  SHA512:
6
- metadata.gz: 4c7b1e2f15ee9408b07d42902025bfe99f9c8dbf533ad013289147fefe21f6c42ccdff322417ec98ee1473ee424339905d71429a3fb1f2dded7b9cf55d997864
7
- data.tar.gz: 59175eb9fd83d0dea579e030db380ce7fb45a632edcc339739c0c57dd564dde03f93e5274974e3d3a28fd4f6a76172b1fccb6d10dd63d5d937e32ae32904f8e6
6
+ metadata.gz: 163f3b6170b2abbd52e33b44da555e6d079fd1efec50f86fe58b7645cae82e4b2d85aa0db05dc7a93ba3c11e3eec196d5b24371ef88230cfad39262f8f74debf
7
+ data.tar.gz: 1adc6464f455dff57420cd008de1ff42bc0e74f7c999ec29b1db4f5133f537975451864e7b4ec246aff7da69280e7ca70d31e503e1a55a4ef03fca331837448d
@@ -19,7 +19,8 @@ module Uc3DmpId
19
19
  raise DeleterError, MSG_DMP_FORBIDDEN unless provenance.is_a?(Hash) && !provenance['PK'].nil?
20
20
 
21
21
  # Validate the incoming JSON first
22
- errs = Validator.validate(mode: 'author', json: Helper.parse_json(json: json))
22
+ json = Helper.parse_json(json: json)
23
+ errs = Validator.validate(mode: 'author', json: json)
23
24
  raise CreatorError, errs.join(', ') if errs.is_a?(Array) && errs.any? && errs.first != Validator::MSG_VALID_JSON
24
25
 
25
26
  # Fail if the provenance or owner affiliation are not defined
@@ -32,7 +33,8 @@ module Uc3DmpId
32
33
  # raise CreatorError, Uc3DmpId::MSG_DMP_EXISTS if result.is_a?(Hash)
33
34
  raise CreatorError, Uc3DmpId::MSG_DMP_EXISTS unless json['PK'].nil?
34
35
 
35
- p_key = _preregister_dmp_id(json: json, debug: debug)
36
+ client = Uc3DmpDynamo::Client.new(debug: debug)
37
+ p_key = _preregister_dmp_id(client: client, json: json, debug: debug)
36
38
  raise CreatorError, MSG_UNABLE_TO_MINT if p_key.nil?
37
39
 
38
40
  # Add the DMPHub specific attributes and then save
@@ -41,7 +43,6 @@ module Uc3DmpId
41
43
  puts annotated if debug
42
44
 
43
45
  # Create the item
44
- client = Uc3DmpDynamo::Client.new(debug: debug)
45
46
  resp = client.put_item(json: annotated, debug: debug)
46
47
  raise CreatorError, Uc3DmpId::MSG_DMP_NO_DMP_ID if resp.nil?
47
48
 
@@ -51,18 +52,18 @@ module Uc3DmpId
51
52
 
52
53
  private
53
54
 
54
- def _preregister_dmp_id(json:, debug: false)
55
+ def _preregister_dmp_id(client:, json:, debug: false)
55
56
  # Use the specified DMP ID if the provenance has permission
56
57
  existing = json.fetch('dmp_id', {})
57
58
  id = existing['identifier'].gsub(%r{https?://}, Helper::PK_DMP_PREFIX) if existing.is_a?(Hash) &&
58
59
  !existing['identifier'].nil?
59
- return id if existing['type'].downcase == 'doi' && !id.nil? && !Finder.exists?(p_key: id)
60
+ return id if !id.nil? && existing['type'].downcase == 'doi' && !Finder.exists?(client: client, p_key: id)
60
61
 
61
62
  dmp_id = ''
62
63
  counter = 0
63
64
  while dmp_id == '' && counter <= 10
64
65
  prefix = "#{ENV['DMP_ID_SHOULDER']}#{SecureRandom.hex(2).upcase}#{SecureRandom.hex(2)}"
65
- dmp_id = prefix unless Finder.exists?(p_key: prefix)
66
+ dmp_id = prefix unless Finder.exists?(client: client, p_key: prefix)
66
67
  counter += 1
67
68
  end
68
69
  # Something went wrong and it was unable to identify a unique id
@@ -64,9 +64,10 @@ module Uc3DmpId
64
64
 
65
65
  # Fetch just the PK to see if a record exists
66
66
  # -------------------------------------------------------------------------
67
- def exists?(p_key:)
67
+ def exists?(client:, p_key:)
68
68
  raise FinderError, MSG_MISSING_PK if p_key.nil?
69
69
 
70
+ client = client.nil? ? Uc3DmpDynamo::Client.new(debug: debug) : client
70
71
  resp = client.get_item(
71
72
  key: {
72
73
  PK: Helper.append_pk_prefix(p_key: p_key),
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.0.41'
4
+ VERSION = '0.0.43'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc3-dmp-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.41
4
+ version: 0.0.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley