dmp-dynamo_adapter 0.1.8 → 0.2.1

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 +19 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0bf9a1c860911aa89f60a60dce597a07c6721b5eec655d45b97a8ee394249c8
4
- data.tar.gz: 144963e2c761acbb18285f508648c9940b73ba0c04f18c96102da4530caf86b1
3
+ metadata.gz: 4c4c901b97437913b47803234f1f6bd80dfe048e307c452ce80b174f465d6de2
4
+ data.tar.gz: f5583c6531e487250ba8ccb0acf7e600a9ca46f7e8fee702bbc35bc5085e7198
5
5
  SHA512:
6
- metadata.gz: ad012db60a41f6c3e1ec979df1ce3410de618e8e70efe43897ace24ea0fc5aed6d29e95c7fc2282de840f58b89849883ff4fe738c980c66d878d9c27ba39b5eb
7
- data.tar.gz: 908957cd229392f7d2a3a0d4b127cb80db7bf01cfca9da082fcc1dc12f600e72bfcac89aee21cba6da7296506dc5c13acfbd3a84d4e6a0929f291f0def1db9f2
6
+ metadata.gz: 11246b4c0a980ffd9b4b43b4e9566f1ed29dd4f6db4068a96539cbd5d615bae24a1d720efba00a1bbc54ed3c38fdfa2b0405fd69ce6f1c6a0e2cdd6b73cf4383
7
+ data.tar.gz: 9fa961d5cf6405334791cebb57713265dccf5856d8bb853cefa37f0d0a2ab2040dfc88d6678718fae15603c82253d37d26df59d721c69edce529076e5ce0557b
@@ -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,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
+ s_key = Dmp::MetadataHandler::LATEST_VERSION if s_key.nil? || s_key.strip == ''
62
+
61
63
  p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
62
64
 
63
65
  response = @client.get_item(
@@ -68,11 +70,11 @@ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
68
70
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
69
71
  }
70
72
  )
71
- return { status: 404, error: MSG_NOT_FOUND } if response.items.empty?
73
+ return { status: 404, error: MSG_NOT_FOUND } if response[:item].nil?
72
74
 
73
- { status: 200, items: response.items.map(&:item).compact.uniq }
74
- rescue Aws::Errors::ServiceError
75
- { status: 500, error: MSG_DEFAULT }
75
+ { status: 200, items: [response[:item]] }
76
+ rescue Aws::Errors::ServiceError => e
77
+ { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
76
78
  end
77
79
 
78
80
  # Find a DMP based on the contents of the incoming JSON
@@ -101,9 +103,6 @@ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
101
103
  json = prepare_json(json: json)
102
104
  return { status: 400, error: MSG_DEFAULT } if json.nil? || @provenance.nil?
103
105
 
104
- p "FINDING BY JSON"
105
- pp json
106
-
107
106
  # Try to find it first
108
107
  result = find_by_json(json: json)
109
108
  return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
@@ -123,7 +122,11 @@ pp json
123
122
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
124
123
  }
125
124
  )
126
- { status: 201, items: response.items.map(&:item).compact.uniq }
125
+
126
+ p 'CREATED!?'
127
+ pp response.data
128
+
129
+ { status: 201, items: [response.data] }
127
130
  rescue Aws::DynamoDB::Errors::DuplicateItemException
128
131
  { status: 405, error: MSG_EXISTS }
129
132
  rescue Aws::Errors::ServiceError => e
@@ -264,10 +267,14 @@ p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
264
267
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
265
268
  }
266
269
  )
267
- return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response.items.empty?
270
+
271
+ pp response.data
272
+
273
+ return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response[:Count] <= 0
268
274
 
269
275
  # If we got a hit, fetch the DMP and return it.
270
- find_by_pk(p_key: response.items.first.item[:PK])
276
+ find_by_pk(p_key: response.fetch(:LastEvaluatedKey, {})[:HashKeyElement],
277
+ s_key: response.fetch(:LastEvaluatedKey, {})[:RangeKeyElement])
271
278
  rescue Aws::Errors::ServiceError => e
272
279
  { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
273
280
  end
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.1.8
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri