uc3-dmp-id 0.0.42 → 0.0.44

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: a0fef469bbcc71541818da66343150f5f8d836da7fea95e584814676504fc0ab
4
- data.tar.gz: d33e5f4b658a3cc10af320a43712c39dc8876e94d463ca610b1c35f3845c8781
3
+ metadata.gz: 91687cd46faa94794255595d4dfd20df32cf392e569ee8d741dd3229834b4e2f
4
+ data.tar.gz: 355e82dd079620e215065f13781d32db62001674fdaf2a189d654f41e1201b10
5
5
  SHA512:
6
- metadata.gz: e2b2393f62e7a78df241ef998107817fe569c0de4362ca2e2451a471bb8e029717acad65dc48a4c12840885060110f750864d14a2d9ffaf3bd34f1eb78c59a05
7
- data.tar.gz: 76b1ad4c83ebceccea8fdb0932615dfd930b306bfd604d240a39d42b21ffbcb694c17455d1596393f7ff71a00700c2b82c488d31739a07eca340d86c966b2c13
6
+ metadata.gz: 8257dda48d262ab0c29074cc211dd80317637752dcc03ee6b647d3f7cd0d97d7fb6684ccb40c2bcd93e3fe0c738235b95c0031c9004bd531a6cef01612a3d555
7
+ data.tar.gz: 62fda83c1fe587e865dba7eea3a8a6f910d7bd297eb3846690bcf813eda3df1c4ff5164d7b178ed5432f6932f65923075d8e25602c8deec2060ae80b38f09e73
@@ -33,7 +33,8 @@ module Uc3DmpId
33
33
  # raise CreatorError, Uc3DmpId::MSG_DMP_EXISTS if result.is_a?(Hash)
34
34
  raise CreatorError, Uc3DmpId::MSG_DMP_EXISTS unless json['PK'].nil?
35
35
 
36
- 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)
37
38
  raise CreatorError, MSG_UNABLE_TO_MINT if p_key.nil?
38
39
 
39
40
  # Add the DMPHub specific attributes and then save
@@ -42,7 +43,6 @@ module Uc3DmpId
42
43
  puts annotated if debug
43
44
 
44
45
  # Create the item
45
- client = Uc3DmpDynamo::Client.new(debug: debug)
46
46
  resp = client.put_item(json: annotated, debug: debug)
47
47
  raise CreatorError, Uc3DmpId::MSG_DMP_NO_DMP_ID if resp.nil?
48
48
 
@@ -52,18 +52,18 @@ module Uc3DmpId
52
52
 
53
53
  private
54
54
 
55
- def _preregister_dmp_id(json:, debug: false)
55
+ def _preregister_dmp_id(client:, json:, debug: false)
56
56
  # Use the specified DMP ID if the provenance has permission
57
57
  existing = json.fetch('dmp_id', {})
58
58
  id = existing['identifier'].gsub(%r{https?://}, Helper::PK_DMP_PREFIX) if existing.is_a?(Hash) &&
59
59
  !existing['identifier'].nil?
60
- return id if !id.nil? && existing['type'].downcase == 'doi' && !Finder.exists?(p_key: id)
60
+ return id if !id.nil? && existing['type'].downcase == 'doi' && !Finder.exists?(client: client, p_key: id)
61
61
 
62
62
  dmp_id = ''
63
63
  counter = 0
64
64
  while dmp_id == '' && counter <= 10
65
65
  prefix = "#{ENV['DMP_ID_SHOULDER']}#{SecureRandom.hex(2).upcase}#{SecureRandom.hex(2)}"
66
- dmp_id = prefix unless Finder.exists?(p_key: prefix)
66
+ dmp_id = prefix unless Finder.exists?(client: client, p_key: prefix)
67
67
  counter += 1
68
68
  end
69
69
  # Something went wrong and it was unable to identify a unique id
@@ -64,13 +64,14 @@ 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),
73
- SK: s_key
74
+ SK: s_key.nil? ? Helper::DMP_LATEST_VERSION : s_key
74
75
  },
75
76
  projection_expression: 'PK'
76
77
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.0.42'
4
+ VERSION = '0.0.44'
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.42
4
+ version: 0.0.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley