dmp-dynamo_adapter 0.1.9 → 0.2.2

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 +16 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a38cf33054966d1ad251334ff69c9c120810f574c68366675a3b067c63976518
4
- data.tar.gz: efd50976eedd2b51a7c2a3877fc949b0fb99ce4162ee8f513f8edcf0385a3bd2
3
+ metadata.gz: 482c56531b1bce877f93b66efbdc8aefc4b2c120b5d81eb3713035dfb546149d
4
+ data.tar.gz: bd9680232b0bbfcf92bdeec0b56ec62f335ccefb52acb9d902fc02e00e73659c
5
5
  SHA512:
6
- metadata.gz: a14dea8426ac97c743d420f3952a5d7e56cb6a95749e9f32390ca74791ac085ebdfe90381a0fd990cf3547bb3d5fcae5b78300533871a9d11892f3074ed005f8
7
- data.tar.gz: f35b4a2a51461faf6023ec3a08f973c88f7bd379b13037e7df65cb703368bf39ca09d35ddb289e23d74c0b7dec95e1043cb3f9a85e57880d03e3a253d3a17f83
6
+ metadata.gz: 4a2e6307f60b392621225539e2065633a64859b8dbc60bc83fa1cb559b6960d5f581eace2ada534bbce85d5bf009502642f9065e27fff683d57f967298fe415e
7
+ data.tar.gz: dfd6fdaaf576d91b96fcdb37a7ce6f060a66f8d7ae4511205f08106259eecb6104a65f024cbe4c3ebc07e9221e83c266b627caeef7bc0827fb6f85524d6b082e
@@ -70,9 +70,9 @@ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
70
70
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
71
71
  }
72
72
  )
73
- return { status: 404, error: MSG_NOT_FOUND } if response.items.empty?
73
+ return { status: 404, error: MSG_NOT_FOUND } if response[:item].nil?
74
74
 
75
- { status: 200, items: response.items.map(&:item).compact.uniq }
75
+ { status: 200, items: [response[:item]] }
76
76
  rescue Aws::Errors::ServiceError => e
77
77
  { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
78
78
  end
@@ -103,12 +103,9 @@ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
103
103
  json = prepare_json(json: json)
104
104
  return { status: 400, error: MSG_DEFAULT } if json.nil? || @provenance.nil?
105
105
 
106
- p "FINDING BY JSON"
107
- pp json
108
-
109
106
  # Try to find it first
110
107
  result = find_by_json(json: json)
111
- return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
108
+ return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
112
109
  # Abort if found
113
110
  return { status: 400, error: MSG_EXISTS } if result[:items].any?
114
111
 
@@ -125,7 +122,11 @@ pp json
125
122
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
126
123
  }
127
124
  )
128
- { status: 201, items: response.items.map(&:item).compact.uniq }
125
+
126
+ p 'CREATED!?'
127
+ pp response.data
128
+
129
+ { status: 201, items: [response.data] }
129
130
  rescue Aws::DynamoDB::Errors::DuplicateItemException
130
131
  { status: 405, error: MSG_EXISTS }
131
132
  rescue Aws::Errors::ServiceError => e
@@ -145,7 +146,7 @@ pp json
145
146
 
146
147
  # Try to find it first
147
148
  result = find_by_json(json: json)
148
- return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
149
+ return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
149
150
 
150
151
  dmp = result[:items].first&.item
151
152
  return { status: 404, error: MSG_NOT_FOUND } if dmp.nil?
@@ -203,7 +204,7 @@ pp json
203
204
 
204
205
  # Try to find it first
205
206
  result = find_by_json(json: json)
206
- return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
207
+ return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
207
208
  # Abort if NOT found
208
209
  return { status: 404, error: MSG_NOT_FOUND } unless result[:status] == 200 && result.fetch(:items, []).any?
209
210
 
@@ -266,10 +267,14 @@ p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
266
267
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
267
268
  }
268
269
  )
269
- 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
270
274
 
271
275
  # If we got a hit, fetch the DMP and return it.
272
- 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])
273
278
  rescue Aws::Errors::ServiceError => e
274
279
  { status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
275
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.9
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri