dmp-dynamo_adapter 0.1.7 → 0.2.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dmp/dynamo_adapter.rb +29 -18
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6132be6e3e6a89db5b11dd95f62ed7470516e3b4b7ddb0c54fbe7d70e0b2b51c
4
- data.tar.gz: 1bf763c8a0138b9d262c1fff1c99661f74be833b83de2f6b778f987f183d32c3
3
+ metadata.gz: 9418816d26847581bce0424f326d1b7d65947b2aa3df952c2d8904984229b18c
4
+ data.tar.gz: 3e7a9d4819f987dc3ae51a699b88321182d28705d776e48780aedba1d5995412
5
5
  SHA512:
6
- metadata.gz: bb8e0fdcef792b5bfb86fc8c6dc3883c63088ba3ff35ec312e00a078a58d8bb4044060aafb99e1e48b8d21bccc95b13bf0e505b227427c445e6c86fbc9fbd7f5
7
- data.tar.gz: ceb2ba37d8ef16facf72dced05b2a686d9a55ad0e09ce4b8d825c95e03d79482d2c222f3c6fed21ab08c1a7b33209a14246a9ba322747d80cfc6d23ef891884a
6
+ metadata.gz: 9abe8d680a8dce95cf71d50e14b8fc9c954bb04bdaaa3d080b80dbb639b4f098c7c5b976610a7bff5a37c7ed48c68f330b4e315df93663ec48ffb3a5d2a39119
7
+ data.tar.gz: 1378240d137ae3afd8e089d0337d2322d8a8406fc93d3027b14870c6a2a0f0c15087b7b06bd5dd5f158ef93996e21103f0c4488cf4eae77d6cf3607cc8159931
@@ -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'],
@@ -66,11 +70,14 @@ module Dmp
66
70
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
67
71
  }
68
72
  )
69
- return { status: 404, error: MSG_NOT_FOUND } if response.items.empty?
70
73
 
71
- { status: 200, items: response.items.map(&:item).compact.uniq }
72
- rescue Aws::Errors::ServiceError
73
- { status: 500, error: MSG_DEFAULT }
74
+ pp response.data
75
+
76
+ return { status: 404, error: MSG_NOT_FOUND } if response[:item].nil?
77
+
78
+ { status: 200, items: [response[:item]] }
79
+ rescue Aws::Errors::ServiceError => e
80
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
74
81
  end
75
82
 
76
83
  # Find a DMP based on the contents of the incoming JSON
@@ -81,7 +88,7 @@ module Dmp
81
88
 
82
89
  pk = json['PK']
83
90
  # Translate the incoming :dmp_id into a PK
84
- pk = DmpIdHandler.dmp_id_to_pk(json: json.fetch('dmp_id', {})) if pk.nil?
91
+ pk = Dmp::DmpIdHandler.dmp_id_to_pk(json: json.fetch('dmp_id', {})) if pk.nil?
85
92
 
86
93
  # find_by_PK
87
94
  response = find_by_pk(p_key: pk, s_key: json['SK']) unless pk.nil?
@@ -99,6 +106,8 @@ module Dmp
99
106
  json = prepare_json(json: json)
100
107
  return { status: 400, error: MSG_DEFAULT } if json.nil? || @provenance.nil?
101
108
 
109
+ p "FINDING BY JSON"
110
+ pp json
102
111
 
103
112
  # Try to find it first
104
113
  result = find_by_json(json: json)
@@ -107,7 +116,7 @@ module Dmp
107
116
  return { status: 400, error: MSG_EXISTS } if result[:items].any?
108
117
 
109
118
  # allocate a DMP ID
110
- p_key = preregister_dmp_id
119
+ p_key = Dmp::DmpIdHandler.preregister_dmp_id
111
120
  return { status: 500, error: MSG_NO_DMP_ID } if p_key.nil?
112
121
 
113
122
  # Add the DMPHub specific attributes and then save
@@ -122,8 +131,8 @@ module Dmp
122
131
  { status: 201, items: response.items.map(&:item).compact.uniq }
123
132
  rescue Aws::DynamoDB::Errors::DuplicateItemException
124
133
  { status: 405, error: MSG_EXISTS }
125
- rescue Aws::Errors::ServiceError
126
- { status: 500, error: MSG_DEFAULT }
134
+ rescue Aws::Errors::ServiceError => e
135
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
127
136
  end
128
137
  # rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
129
138
 
@@ -180,8 +189,8 @@ pp json
180
189
  { status: 200, items: response.items.map(&:item).compact.uniq }
181
190
  rescue Aws::DynamoDB::Errors::DuplicateItemException
182
191
  { status: 405, error: MSG_EXISTS }
183
- rescue Aws::Errors::ServiceError
184
- { status: 500, error: MSG_DEFAULT }
192
+ rescue Aws::Errors::ServiceError => e
193
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
185
194
  end
186
195
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
187
196
 
@@ -225,8 +234,8 @@ pp json
225
234
  }
226
235
  )
227
236
  { status: 200, items: response.items.map(&:item).compact.uniq }
228
- rescue Aws::Errors::ServiceError
229
- { status: 500, error: MSG_DEFAULT }
237
+ rescue Aws::Errors::ServiceError => e
238
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
230
239
  end
231
240
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
232
241
 
@@ -241,6 +250,8 @@ pp json
241
250
  def find_by_dmphub_provenance_identifier(json:)
242
251
  return { status: 400, error: MSG_DEFAULT } if json.nil? || json.fetch('dmp_id', {})['identifier'].nil?
243
252
 
253
+ p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
254
+
244
255
  response = @client.query(
245
256
  {
246
257
  table_name: ENV['AWS_DYNAMO_TABLE_NAME'],
@@ -262,8 +273,8 @@ pp json
262
273
 
263
274
  # If we got a hit, fetch the DMP and return it.
264
275
  find_by_pk(p_key: response.items.first.item[:PK])
265
- rescue Aws::Errors::ServiceError
266
- { status: 500, error: MSG_DEFAULT }
276
+ rescue Aws::Errors::ServiceError => e
277
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
267
278
  end
268
279
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
269
280
 
@@ -292,8 +303,8 @@ pp json
292
303
  return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response.items.empty?
293
304
 
294
305
  { status: 200, items: response.items.map(&:item).compact.uniq }
295
- rescue Aws::Errors::ServiceError
296
- { status: 500, error: MSG_DEFAULT }
306
+ rescue Aws::Errors::ServiceError => e
307
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
297
308
  end
298
309
  # rubocop:enable Metrics/MethodLength
299
310
 
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.7
4
+ version: 0.2.0
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