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.
- checksums.yaml +4 -4
- data/lib/dmp/dynamo_adapter.rb +16 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 482c56531b1bce877f93b66efbdc8aefc4b2c120b5d81eb3713035dfb546149d
|
4
|
+
data.tar.gz: bd9680232b0bbfcf92bdeec0b56ec62f335ccefb52acb9d902fc02e00e73659c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a2e6307f60b392621225539e2065633a64859b8dbc60bc83fa1cb559b6960d5f581eace2ada534bbce85d5bf009502642f9065e27fff683d57f967298fe415e
|
7
|
+
data.tar.gz: dfd6fdaaf576d91b96fcdb37a7ce6f060a66f8d7ae4511205f08106259eecb6104a65f024cbe4c3ebc07e9221e83c266b627caeef7bc0827fb6f85524d6b082e
|
data/lib/dmp/dynamo_adapter.rb
CHANGED
@@ -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.
|
73
|
+
return { status: 404, error: MSG_NOT_FOUND } if response[:item].nil?
|
74
74
|
|
75
|
-
{ status: 200, items: response
|
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
|
-
|
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
|
-
|
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.
|
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
|