dmp-dynamo_adapter 0.2.1 → 0.2.4

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: 4c4c901b97437913b47803234f1f6bd80dfe048e307c452ce80b174f465d6de2
4
- data.tar.gz: f5583c6531e487250ba8ccb0acf7e600a9ca46f7e8fee702bbc35bc5085e7198
3
+ metadata.gz: 33302af56b5e3b2046ced1ca5b826a0b52abd2c7c57ff1ac738e7f21f58642b6
4
+ data.tar.gz: a484cdc69656ce174c7d2319d615b44b7ac1115026f164e027b1cf1e67f04a78
5
5
  SHA512:
6
- metadata.gz: 11246b4c0a980ffd9b4b43b4e9566f1ed29dd4f6db4068a96539cbd5d615bae24a1d720efba00a1bbc54ed3c38fdfa2b0405fd69ce6f1c6a0e2cdd6b73cf4383
7
- data.tar.gz: 9fa961d5cf6405334791cebb57713265dccf5856d8bb853cefa37f0d0a2ab2040dfc88d6678718fae15603c82253d37d26df59d721c69edce529076e5ce0557b
6
+ metadata.gz: 7ad5921565684cef3a980ca8b678c2d6a5d753a98dca73f120396d81dfb55c388c55e06f91ad23741f3344537426e4a84ccae4d5aa0af5728fd9c4c2d0e2ff98
7
+ data.tar.gz: c1d5f67f064806bb4a002ce11e584d40879868df6ff1037c52706640843297a58f922e140ece87df046d743a857a21da24b10c4bb20f1e34a37432cf9ad3821a
@@ -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
- return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
108
+
109
+ p "RESULT:"
110
+ pp result
111
+
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'],
@@ -146,7 +158,7 @@ pp response.data
146
158
 
147
159
  # Try to find it first
148
160
  result = find_by_json(json: json)
149
- return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
161
+ return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
150
162
 
151
163
  dmp = result[:items].first&.item
152
164
  return { status: 404, error: MSG_NOT_FOUND } if dmp.nil?
@@ -204,7 +216,7 @@ pp json
204
216
 
205
217
  # Try to find it first
206
218
  result = find_by_json(json: json)
207
- return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
219
+ return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
208
220
  # Abort if NOT found
209
221
  return { status: 404, error: MSG_NOT_FOUND } unless result[:status] == 200 && result.fetch(:items, []).any?
210
222
 
@@ -262,12 +274,13 @@ 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
286
  return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response[:Count] <= 0
@@ -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.1
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri