dmp-dynamo_adapter 0.2.2 → 0.2.5

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: 482c56531b1bce877f93b66efbdc8aefc4b2c120b5d81eb3713035dfb546149d
4
- data.tar.gz: bd9680232b0bbfcf92bdeec0b56ec62f335ccefb52acb9d902fc02e00e73659c
3
+ metadata.gz: d0b673c5ab8af1a4ada8c4f14be3c2543c7af6e16ad3fbe34a31552451fea8a3
4
+ data.tar.gz: 77484e5b3f58fd9088b635ab2e9fcd47b493aeb4fefc46618daec56a6dd993aa
5
5
  SHA512:
6
- metadata.gz: 4a2e6307f60b392621225539e2065633a64859b8dbc60bc83fa1cb559b6960d5f581eace2ada534bbce85d5bf009502642f9065e27fff683d57f967298fe415e
7
- data.tar.gz: dfd6fdaaf576d91b96fcdb37a7ce6f060a66f8d7ae4511205f08106259eecb6104a65f024cbe4c3ebc07e9221e83c266b627caeef7bc0827fb6f85524d6b082e
6
+ metadata.gz: b81abb15e34a2e6ca1d5dc0405b98bdae243b6099cca1f2c83735ea3b540c293059cb5d652d77095b899e2ac04b374f319dcdd6842f32a4b5dd76681b8bff083
7
+ data.tar.gz: 29a757ae20c3888e0f9c5dd8fdd17b2b77b20c2af5c1b9c0a14e003bf55054d371c57a484730088d4d50decc5e95e9f090135070bc3a6d6d8f6df495bc4c5bf2
@@ -16,8 +16,10 @@ module Dmp
16
16
  # Preassign a DMP ID that will leater be sent to the DOI minting authority (EZID)
17
17
  def preregister_dmp_id
18
18
  dmp_id = ''
19
-
20
19
  counter = 0
20
+
21
+ p 'PREREGISTER DMP ID:'
22
+
21
23
  while dmp_id == '' && counter <= 10
22
24
  prefix = "#{ENV['DMP_ID_SHOULDER']}.#{SecureRandom.hex(4).upcase}"
23
25
  dmp_id = prefix if find_by_pk(p_key: Dmp::MetadataHandler.append_pk_prefix(dmp: dmp_id)).empty?
@@ -105,16 +105,28 @@ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
105
105
 
106
106
  # Try to find it first
107
107
  result = find_by_json(json: json)
108
+
109
+ p "RESULT:"
110
+ pp result
111
+
108
112
  return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
109
113
  # Abort if found
110
114
  return { status: 400, error: MSG_EXISTS } if result[:items].any?
111
115
 
112
116
  # allocate a DMP ID
113
117
  p_key = Dmp::DmpIdHandler.preregister_dmp_id
118
+
119
+ p "PRE REGISTERED DMP ID: #{p_key.inspect}"
120
+
114
121
  return { status: 500, error: MSG_NO_DMP_ID } if p_key.nil?
115
122
 
116
123
  # Add the DMPHub specific attributes and then save
117
124
  json = Dmp::MetadataHandler.annotate_json(provenance: @provenance, json: json, p_key: p_key)
125
+
126
+ p "ANNOTATED:"
127
+ pp json
128
+
129
+ p "PUTTING ITEM:"
118
130
  response = @client.put_item(
119
131
  {
120
132
  table_name: ENV['AWS_DYNAMO_TABLE_NAME'],
@@ -262,19 +274,20 @@ p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
262
274
  },
263
275
  filter_expression: 'SK = :version',
264
276
  expression_attribute_values: {
265
- ':SK': Dmp::MetadataHandler::LATEST_VERSION
277
+ ':version': Dmp::MetadataHandler::LATEST_VERSION
266
278
  },
267
279
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
268
280
  }
269
281
  )
270
282
 
283
+ p "RESPONSE:"
271
284
  pp response.data
272
285
 
273
- return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response[:Count] <= 0
286
+ return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response[:count] <= 0
274
287
 
275
288
  # If we got a hit, fetch the DMP and return it.
276
- find_by_pk(p_key: response.fetch(:LastEvaluatedKey, {})[:HashKeyElement],
277
- s_key: response.fetch(:LastEvaluatedKey, {})[:RangeKeyElement])
289
+ find_by_pk(p_key: response.fetch(:last_evaluated_key, {})[:hash_key_element],
290
+ s_key: response.fetch(:last_evaluated_key, {})[:range_key_element])
278
291
  rescue Aws::Errors::ServiceError => e
279
292
  { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
280
293
  end
@@ -60,6 +60,8 @@ module Dmp
60
60
  def annotate_json(provenance:, p_key:, json:)
61
61
  return nil if provenance.nil? || p_key.nil? || json.nil?
62
62
 
63
+ p "ANNOTATING METADATA:"
64
+
63
65
  # Fail if the :PK does not match the :dmp_id if the json has a :PK
64
66
  id = Dmp::DmpIdHandler.dmp_id_to_pk(json: json.fetch('dmp_id', {}))
65
67
  id = nil if id != p_key && !json['PK'].nil?
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.2
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri