dmp-dynamo_adapter 0.2.4 → 0.2.7

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: 33302af56b5e3b2046ced1ca5b826a0b52abd2c7c57ff1ac738e7f21f58642b6
4
- data.tar.gz: a484cdc69656ce174c7d2319d615b44b7ac1115026f164e027b1cf1e67f04a78
3
+ metadata.gz: 41ac93e31c250106a76873be5e069337fe772387bef81350afdffe231a09ad80
4
+ data.tar.gz: 9998934e79fbdb99639088e64bea3b6a3b516df5b20db4ce8733e7c5bcc7c10c
5
5
  SHA512:
6
- metadata.gz: 7ad5921565684cef3a980ca8b678c2d6a5d753a98dca73f120396d81dfb55c388c55e06f91ad23741f3344537426e4a84ccae4d5aa0af5728fd9c4c2d0e2ff98
7
- data.tar.gz: c1d5f67f064806bb4a002ce11e584d40879868df6ff1037c52706640843297a58f922e140ece87df046d743a857a21da24b10c4bb20f1e34a37432cf9ad3821a
6
+ metadata.gz: 9bdd9d6d4ab79239ca07993ebcb991f3d9298ce01f21058a841921970646b8f08b33ee5239338b95626ca37e19f1272b37da3706425fd985b7a17f2db67fa205
7
+ data.tar.gz: 7d374a240cac71d3cd65d1422fbb983e1b4e10f6d8e1096ad9a4ed973d521229a9bf078db1c7a86e8862c3ad596f95e7f4899e9c0e11751339691e1006cd3dbd
@@ -22,7 +22,10 @@ p 'PREREGISTER DMP ID:'
22
22
 
23
23
  while dmp_id == '' && counter <= 10
24
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?
25
+ result = Dmp::DynamoAdapter.find_by_pk(
26
+ p_key: Dmp::MetadataHandler.append_pk_prefix(dmp: dmp_id)
27
+ )
28
+ dmp_id = prefix unless result[:status] != 404
26
29
  counter += 1
27
30
  end
28
31
  # Something went wrong and it was unable to identify a unique id
@@ -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
 
@@ -283,16 +278,35 @@ p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
283
278
  p "RESPONSE:"
284
279
  pp response.data
285
280
 
286
- return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response[:Count] <= 0
281
+ return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response[:count] <= 0
287
282
 
288
283
  # If we got a hit, fetch the DMP and return it.
289
- find_by_pk(p_key: response.fetch(:LastEvaluatedKey, {})[:HashKeyElement],
290
- s_key: response.fetch(:LastEvaluatedKey, {})[:RangeKeyElement])
284
+ find_by_pk(p_key: response.fetch(:last_evaluated_key, {})[:hash_key_element],
285
+ s_key: response.fetch(:last_evaluated_key, {})[:range_key_element])
291
286
  rescue Aws::Errors::ServiceError => e
292
287
  { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
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_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.4
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri