dmp-dynamo_adapter 0.2.5 → 0.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0b673c5ab8af1a4ada8c4f14be3c2543c7af6e16ad3fbe34a31552451fea8a3
4
- data.tar.gz: 77484e5b3f58fd9088b635ab2e9fcd47b493aeb4fefc46618daec56a6dd993aa
3
+ metadata.gz: 1fde969438aa9681c5213d60e441b3187de1ed2141c7b244419ba47a007d39fc
4
+ data.tar.gz: a4a9722f607edf91644043c4adbcb3af7bfe81f33d254da104a0223a27fd6c40
5
5
  SHA512:
6
- metadata.gz: b81abb15e34a2e6ca1d5dc0405b98bdae243b6099cca1f2c83735ea3b540c293059cb5d652d77095b899e2ac04b374f319dcdd6842f32a4b5dd76681b8bff083
7
- data.tar.gz: 29a757ae20c3888e0f9c5dd8fdd17b2b77b20c2af5c1b9c0a14e003bf55054d371c57a484730088d4d50decc5e95e9f090135070bc3a6d6d8f6df495bc4c5bf2
6
+ metadata.gz: 0ba67f79d6cdf0b4d29f416301e88b8b4453f85b7381a82280f5389dde4c12bb5446e59bdd21290d04203dbcdaefc73f08c1bd8ffd5221b945a19e514e4f1c2b
7
+ data.tar.gz: 8c2a12ccd6b1049a12f254a6ae5f634c63aa2c3b82870778fd541482d6888cd720426ac6cb213d72b6fb3605ad38a3b948abf7393f63b90cc3898fa72f60966e
@@ -13,24 +13,6 @@ module Dmp
13
13
  ENV['DMP_ID_BASE_URL'].end_with?('/') ? ENV['DMP_ID_BASE_URL'] : "#{ENV['DMP_ID_BASE_URL']}/"
14
14
  end
15
15
 
16
- # Preassign a DMP ID that will leater be sent to the DOI minting authority (EZID)
17
- def preregister_dmp_id
18
- dmp_id = ''
19
- counter = 0
20
-
21
- p 'PREREGISTER DMP ID:'
22
-
23
- while dmp_id == '' && counter <= 10
24
- prefix = "#{ENV['DMP_ID_SHOULDER']}.#{SecureRandom.hex(4).upcase}"
25
- dmp_id = prefix if find_by_pk(p_key: Dmp::MetadataHandler.append_pk_prefix(dmp: dmp_id)).empty?
26
- counter += 1
27
- end
28
- # Something went wrong and it was unable to identify a unique id
29
- return nil if counter >= 10
30
-
31
- "#{Dmp::MetadataHandler::PK_DMP_PREFIX}#{dmp_id_base_url}#{dmp_id}"
32
- end
33
-
34
16
  # Format the DMP ID in the way we want it
35
17
  def format_dmp_id(value:)
36
18
  dmp_id = value.match(DOI_REGEX).to_s
@@ -89,8 +89,7 @@ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
89
89
 
90
90
  # find_by_PK
91
91
  response = find_by_pk(p_key: pk, s_key: json['SK']) unless pk.nil?
92
- return response if response[:status] == 500
93
- return response unless response[:items].nil? || response[:items].empty?
92
+ return response unless response[:status] != 404
94
93
 
95
94
  # find_by_dmphub_provenance_id -> if no PK and no dmp_id result
96
95
  find_by_dmphub_provenance_identifier(json: json)
@@ -105,16 +104,12 @@ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
105
104
 
106
105
  # Try to find it first
107
106
  result = find_by_json(json: json)
108
-
109
- p "RESULT:"
110
- pp result
111
-
112
107
  return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
113
108
  # Abort if found
114
- return { status: 400, error: MSG_EXISTS } if result[:items].any?
109
+ return { status: 400, error: MSG_EXISTS } if result.fetch(:items, []).any?
115
110
 
116
111
  # allocate a DMP ID
117
- p_key = Dmp::DmpIdHandler.preregister_dmp_id
112
+ p_key = preregister_dmp_id
118
113
 
119
114
  p "PRE REGISTERED DMP ID: #{p_key.inspect}"
120
115
 
@@ -293,6 +288,25 @@ pp response.data
293
288
  end
294
289
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
295
290
 
291
+ # Preassign a DMP ID that will leater be sent to the DOI minting authority (EZID)
292
+ def preregister_dmp_id
293
+ dmp_id = ''
294
+ counter = 0
295
+
296
+ p 'PREREGISTER DMP ID:'
297
+
298
+ while dmp_id == '' && counter <= 10
299
+ prefix = "#{ENV['DMP_ID_SHOULDER']}.#{SecureRandom.hex(4).upcase}"
300
+ result = find_by_pk(p_key: Dmp::MetadataHandler.append_pk_prefix(dmp: dmp_id))
301
+ dmp_id = prefix unless result[:status] != 404
302
+ counter += 1
303
+ end
304
+ # Something went wrong and it was unable to identify a unique id
305
+ return nil if counter >= 10
306
+
307
+ "#{Dmp::MetadataHandler::PK_DMP_PREFIX}#{Dmp::DmpIdHandler.dmp_id_base_url}#{dmp_id}"
308
+ end
309
+
296
310
  # Convert the latest version into a historical version
297
311
  # rubocop:disable Metrics/MethodLength
298
312
  def version_it(dmp:)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmp-dynamo_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri