dmp-dynamo_adapter 0.1.6 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dmp/dynamo_adapter.rb +25 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fe879d1aefc8db1c3b1a8160171c2f3cd8f6ee1986d494abf69083af19a6133
4
- data.tar.gz: 58fd4512a6c72bfaee714cfb19be7c9dd3f9a81b2df1742f5a7a35ff6b5fa045
3
+ metadata.gz: a38cf33054966d1ad251334ff69c9c120810f574c68366675a3b067c63976518
4
+ data.tar.gz: efd50976eedd2b51a7c2a3877fc949b0fb99ce4162ee8f513f8edcf0385a3bd2
5
5
  SHA512:
6
- metadata.gz: 52c93f6323e77810246cceeba743a71866872931716f82b1dfe482ff613d1361ef596deed64ff8f22eec32ea38c7679d0c64916c7e1941d076eed1357537ac37
7
- data.tar.gz: 01f5d12e5227007fc434520e135b82edbbb4601a517c6a9898cf510fe2dcca9163900145fb50b19d69a40cdc8e3bf81fd345c0e0361d24df2a650ab15a9bf2cb
6
+ metadata.gz: a14dea8426ac97c743d420f3952a5d7e56cb6a95749e9f32390ca74791ac085ebdfe90381a0fd990cf3547bb3d5fcae5b78300533871a9d11892f3074ed005f8
7
+ data.tar.gz: f35b4a2a51461faf6023ec3a08f973c88f7bd379b13037e7df65cb703368bf39ca09d35ddb289e23d74c0b7dec95e1043cb3f9a85e57880d03e3a253d3a17f83
@@ -49,8 +49,8 @@ module Dmp
49
49
  }
50
50
  )
51
51
  { status: 200, items: response.items.map(&:item).compact.uniq }
52
- rescue Aws::Errors::ServiceError
53
- { status: 500, error: MSG_DEFAULT }
52
+ rescue Aws::Errors::ServiceError => e
53
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
54
54
  end
55
55
  # rubocop:enable Metrics/MethodLength
56
56
 
@@ -58,6 +58,10 @@ module Dmp
58
58
  def find_by_pk(p_key:, s_key: Dmp::MetadataHandler::LATEST_VERSION)
59
59
  return { status: 404, error: MSG_NOT_FOUND } if p_key.nil?
60
60
 
61
+ s_key = Dmp::MetadataHandler::LATEST_VERSION if s_key.nil? || s_key.strip == ''
62
+
63
+ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
64
+
61
65
  response = @client.get_item(
62
66
  {
63
67
  table_name: ENV['AWS_DYNAMO_TABLE_NAME'],
@@ -69,8 +73,8 @@ module Dmp
69
73
  return { status: 404, error: MSG_NOT_FOUND } if response.items.empty?
70
74
 
71
75
  { status: 200, items: response.items.map(&:item).compact.uniq }
72
- rescue Aws::Errors::ServiceError
73
- { status: 500, error: MSG_DEFAULT }
76
+ rescue Aws::Errors::ServiceError => e
77
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
74
78
  end
75
79
 
76
80
  # Find a DMP based on the contents of the incoming JSON
@@ -81,7 +85,7 @@ module Dmp
81
85
 
82
86
  pk = json['PK']
83
87
  # Translate the incoming :dmp_id into a PK
84
- pk = pk_from_dmp_id(json: json.fetch('dmp_id', {})) if pk.nil?
88
+ pk = Dmp::DmpIdHandler.dmp_id_to_pk(json: json.fetch('dmp_id', {})) if pk.nil?
85
89
 
86
90
  # find_by_PK
87
91
  response = find_by_pk(p_key: pk, s_key: json['SK']) unless pk.nil?
@@ -99,6 +103,9 @@ module Dmp
99
103
  json = prepare_json(json: json)
100
104
  return { status: 400, error: MSG_DEFAULT } if json.nil? || @provenance.nil?
101
105
 
106
+ p "FINDING BY JSON"
107
+ pp json
108
+
102
109
  # Try to find it first
103
110
  result = find_by_json(json: json)
104
111
  return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
@@ -106,7 +113,7 @@ module Dmp
106
113
  return { status: 400, error: MSG_EXISTS } if result[:items].any?
107
114
 
108
115
  # allocate a DMP ID
109
- p_key = preregister_dmp_id
116
+ p_key = Dmp::DmpIdHandler.preregister_dmp_id
110
117
  return { status: 500, error: MSG_NO_DMP_ID } if p_key.nil?
111
118
 
112
119
  # Add the DMPHub specific attributes and then save
@@ -121,8 +128,8 @@ module Dmp
121
128
  { status: 201, items: response.items.map(&:item).compact.uniq }
122
129
  rescue Aws::DynamoDB::Errors::DuplicateItemException
123
130
  { status: 405, error: MSG_EXISTS }
124
- rescue Aws::Errors::ServiceError
125
- { status: 500, error: MSG_DEFAULT }
131
+ rescue Aws::Errors::ServiceError => e
132
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
126
133
  end
127
134
  # rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
128
135
 
@@ -179,8 +186,8 @@ pp json
179
186
  { status: 200, items: response.items.map(&:item).compact.uniq }
180
187
  rescue Aws::DynamoDB::Errors::DuplicateItemException
181
188
  { status: 405, error: MSG_EXISTS }
182
- rescue Aws::Errors::ServiceError
183
- { status: 500, error: MSG_DEFAULT }
189
+ rescue Aws::Errors::ServiceError => e
190
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
184
191
  end
185
192
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
186
193
 
@@ -224,8 +231,8 @@ pp json
224
231
  }
225
232
  )
226
233
  { status: 200, items: response.items.map(&:item).compact.uniq }
227
- rescue Aws::Errors::ServiceError
228
- { status: 500, error: MSG_DEFAULT }
234
+ rescue Aws::Errors::ServiceError => e
235
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
229
236
  end
230
237
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
231
238
 
@@ -240,6 +247,8 @@ pp json
240
247
  def find_by_dmphub_provenance_identifier(json:)
241
248
  return { status: 400, error: MSG_DEFAULT } if json.nil? || json.fetch('dmp_id', {})['identifier'].nil?
242
249
 
250
+ p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
251
+
243
252
  response = @client.query(
244
253
  {
245
254
  table_name: ENV['AWS_DYNAMO_TABLE_NAME'],
@@ -261,8 +270,8 @@ pp json
261
270
 
262
271
  # If we got a hit, fetch the DMP and return it.
263
272
  find_by_pk(p_key: response.items.first.item[:PK])
264
- rescue Aws::Errors::ServiceError
265
- { status: 500, error: MSG_DEFAULT }
273
+ rescue Aws::Errors::ServiceError => e
274
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
266
275
  end
267
276
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
268
277
 
@@ -291,8 +300,8 @@ pp json
291
300
  return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response.items.empty?
292
301
 
293
302
  { status: 200, items: response.items.map(&:item).compact.uniq }
294
- rescue Aws::Errors::ServiceError
295
- { status: 500, error: MSG_DEFAULT }
303
+ rescue Aws::Errors::ServiceError => e
304
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
296
305
  end
297
306
  # rubocop:enable Metrics/MethodLength
298
307
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmp-dynamo_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-22 00:00:00.000000000 Z
11
+ date: 2022-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb