dmp-dynamo_adapter 0.1.5 → 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/dmp_id_handler.rb +1 -1
- data/lib/dmp/dynamo_adapter.rb +19 -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/dmp_id_handler.rb
CHANGED
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 =
|
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,9 @@ 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
|
106
|
+
|
102
107
|
# Try to find it first
|
103
108
|
result = find_by_json(json: json)
|
104
109
|
return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
|
@@ -106,7 +111,7 @@ module Dmp
|
|
106
111
|
return { status: 400, error: MSG_EXISTS } if result[:items].any?
|
107
112
|
|
108
113
|
# allocate a DMP ID
|
109
|
-
p_key = preregister_dmp_id
|
114
|
+
p_key = Dmp::DmpIdHandler.preregister_dmp_id
|
110
115
|
return { status: 500, error: MSG_NO_DMP_ID } if p_key.nil?
|
111
116
|
|
112
117
|
# Add the DMPHub specific attributes and then save
|
@@ -121,8 +126,8 @@ module Dmp
|
|
121
126
|
{ status: 201, items: response.items.map(&:item).compact.uniq }
|
122
127
|
rescue Aws::DynamoDB::Errors::DuplicateItemException
|
123
128
|
{ status: 405, error: MSG_EXISTS }
|
124
|
-
rescue Aws::Errors::ServiceError
|
125
|
-
{ status: 500, error: MSG_DEFAULT }
|
129
|
+
rescue Aws::Errors::ServiceError => e
|
130
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
126
131
|
end
|
127
132
|
# rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
128
133
|
|
@@ -179,8 +184,8 @@ pp json
|
|
179
184
|
{ status: 200, items: response.items.map(&:item).compact.uniq }
|
180
185
|
rescue Aws::DynamoDB::Errors::DuplicateItemException
|
181
186
|
{ status: 405, error: MSG_EXISTS }
|
182
|
-
rescue Aws::Errors::ServiceError
|
183
|
-
{ status: 500, error: MSG_DEFAULT }
|
187
|
+
rescue Aws::Errors::ServiceError => e
|
188
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
184
189
|
end
|
185
190
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
186
191
|
|
@@ -224,8 +229,8 @@ pp json
|
|
224
229
|
}
|
225
230
|
)
|
226
231
|
{ status: 200, items: response.items.map(&:item).compact.uniq }
|
227
|
-
rescue Aws::Errors::ServiceError
|
228
|
-
{ status: 500, error: MSG_DEFAULT }
|
232
|
+
rescue Aws::Errors::ServiceError => e
|
233
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
229
234
|
end
|
230
235
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
231
236
|
|
@@ -240,6 +245,8 @@ pp json
|
|
240
245
|
def find_by_dmphub_provenance_identifier(json:)
|
241
246
|
return { status: 400, error: MSG_DEFAULT } if json.nil? || json.fetch('dmp_id', {})['identifier'].nil?
|
242
247
|
|
248
|
+
p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
|
249
|
+
|
243
250
|
response = @client.query(
|
244
251
|
{
|
245
252
|
table_name: ENV['AWS_DYNAMO_TABLE_NAME'],
|
@@ -261,8 +268,8 @@ pp json
|
|
261
268
|
|
262
269
|
# If we got a hit, fetch the DMP and return it.
|
263
270
|
find_by_pk(p_key: response.items.first.item[:PK])
|
264
|
-
rescue Aws::Errors::ServiceError
|
265
|
-
{ status: 500, error: MSG_DEFAULT }
|
271
|
+
rescue Aws::Errors::ServiceError => e
|
272
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
266
273
|
end
|
267
274
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
268
275
|
|
@@ -291,8 +298,8 @@ pp json
|
|
291
298
|
return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response.items.empty?
|
292
299
|
|
293
300
|
{ status: 200, items: response.items.map(&:item).compact.uniq }
|
294
|
-
rescue Aws::Errors::ServiceError
|
295
|
-
{ status: 500, error: MSG_DEFAULT }
|
301
|
+
rescue Aws::Errors::ServiceError => e
|
302
|
+
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
296
303
|
end
|
297
304
|
# rubocop:enable Metrics/MethodLength
|
298
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
|