dmp-dynamo_adapter 0.1.7 → 0.1.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 +4 -4
- data/lib/dmp/dynamo_adapter.rb +18 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0bf9a1c860911aa89f60a60dce597a07c6721b5eec655d45b97a8ee394249c8
|
4
|
+
data.tar.gz: 144963e2c761acbb18285f508648c9940b73ba0c04f18c96102da4530caf86b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad012db60a41f6c3e1ec979df1ce3410de618e8e70efe43897ace24ea0fc5aed6d29e95c7fc2282de840f58b89849883ff4fe738c980c66d878d9c27ba39b5eb
|
7
|
+
data.tar.gz: 908957cd229392f7d2a3a0d4b127cb80db7bf01cfca9da082fcc1dc12f600e72bfcac89aee21cba6da7296506dc5c13acfbd3a84d4e6a0929f291f0def1db9f2
|
data/lib/dmp/dynamo_adapter.rb
CHANGED
@@ -58,6 +58,8 @@ 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
|
+
p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
|
62
|
+
|
61
63
|
response = @client.get_item(
|
62
64
|
{
|
63
65
|
table_name: ENV['AWS_DYNAMO_TABLE_NAME'],
|
@@ -81,7 +83,7 @@ module Dmp
|
|
81
83
|
|
82
84
|
pk = json['PK']
|
83
85
|
# Translate the incoming :dmp_id into a PK
|
84
|
-
pk = DmpIdHandler.dmp_id_to_pk(json: json.fetch('dmp_id', {})) if pk.nil?
|
86
|
+
pk = Dmp::DmpIdHandler.dmp_id_to_pk(json: json.fetch('dmp_id', {})) if pk.nil?
|
85
87
|
|
86
88
|
# find_by_PK
|
87
89
|
response = find_by_pk(p_key: pk, s_key: json['SK']) unless pk.nil?
|
@@ -99,6 +101,8 @@ module Dmp
|
|
99
101
|
json = prepare_json(json: json)
|
100
102
|
return { status: 400, error: MSG_DEFAULT } if json.nil? || @provenance.nil?
|
101
103
|
|
104
|
+
p "FINDING BY JSON"
|
105
|
+
pp json
|
102
106
|
|
103
107
|
# Try to find it first
|
104
108
|
result = find_by_json(json: json)
|
@@ -107,7 +111,7 @@ module Dmp
|
|
107
111
|
return { status: 400, error: MSG_EXISTS } if result[:items].any?
|
108
112
|
|
109
113
|
# allocate a DMP ID
|
110
|
-
p_key = preregister_dmp_id
|
114
|
+
p_key = Dmp::DmpIdHandler.preregister_dmp_id
|
111
115
|
return { status: 500, error: MSG_NO_DMP_ID } if p_key.nil?
|
112
116
|
|
113
117
|
# Add the DMPHub specific attributes and then save
|
@@ -122,8 +126,8 @@ module Dmp
|
|
122
126
|
{ status: 201, items: response.items.map(&:item).compact.uniq }
|
123
127
|
rescue Aws::DynamoDB::Errors::DuplicateItemException
|
124
128
|
{ status: 405, error: MSG_EXISTS }
|
125
|
-
rescue Aws::Errors::ServiceError
|
126
|
-
{ status: 500, error: MSG_DEFAULT }
|
129
|
+
rescue Aws::Errors::ServiceError => e
|
130
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
127
131
|
end
|
128
132
|
# rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
129
133
|
|
@@ -180,8 +184,8 @@ pp json
|
|
180
184
|
{ status: 200, items: response.items.map(&:item).compact.uniq }
|
181
185
|
rescue Aws::DynamoDB::Errors::DuplicateItemException
|
182
186
|
{ status: 405, error: MSG_EXISTS }
|
183
|
-
rescue Aws::Errors::ServiceError
|
184
|
-
{ status: 500, error: MSG_DEFAULT }
|
187
|
+
rescue Aws::Errors::ServiceError => e
|
188
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
185
189
|
end
|
186
190
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
187
191
|
|
@@ -225,8 +229,8 @@ pp json
|
|
225
229
|
}
|
226
230
|
)
|
227
231
|
{ status: 200, items: response.items.map(&:item).compact.uniq }
|
228
|
-
rescue Aws::Errors::ServiceError
|
229
|
-
{ status: 500, error: MSG_DEFAULT }
|
232
|
+
rescue Aws::Errors::ServiceError => e
|
233
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
230
234
|
end
|
231
235
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
232
236
|
|
@@ -241,6 +245,8 @@ pp json
|
|
241
245
|
def find_by_dmphub_provenance_identifier(json:)
|
242
246
|
return { status: 400, error: MSG_DEFAULT } if json.nil? || json.fetch('dmp_id', {})['identifier'].nil?
|
243
247
|
|
248
|
+
p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
|
249
|
+
|
244
250
|
response = @client.query(
|
245
251
|
{
|
246
252
|
table_name: ENV['AWS_DYNAMO_TABLE_NAME'],
|
@@ -262,8 +268,8 @@ pp json
|
|
262
268
|
|
263
269
|
# If we got a hit, fetch the DMP and return it.
|
264
270
|
find_by_pk(p_key: response.items.first.item[:PK])
|
265
|
-
rescue Aws::Errors::ServiceError
|
266
|
-
{ status: 500, error: MSG_DEFAULT }
|
271
|
+
rescue Aws::Errors::ServiceError => e
|
272
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
267
273
|
end
|
268
274
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
269
275
|
|
@@ -292,8 +298,8 @@ pp json
|
|
292
298
|
return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response.items.empty?
|
293
299
|
|
294
300
|
{ status: 200, items: response.items.map(&:item).compact.uniq }
|
295
|
-
rescue Aws::Errors::ServiceError
|
296
|
-
{ status: 500, error: MSG_DEFAULT }
|
301
|
+
rescue Aws::Errors::ServiceError => e
|
302
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
297
303
|
end
|
298
304
|
# rubocop:enable Metrics/MethodLength
|
299
305
|
|
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.
|
4
|
+
version: 0.1.8
|
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-
|
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
|