dmp-dynamo_adapter 0.1.8 → 0.2.1
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 +19 -12
- 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: 4c4c901b97437913b47803234f1f6bd80dfe048e307c452ce80b174f465d6de2
|
4
|
+
data.tar.gz: f5583c6531e487250ba8ccb0acf7e600a9ca46f7e8fee702bbc35bc5085e7198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11246b4c0a980ffd9b4b43b4e9566f1ed29dd4f6db4068a96539cbd5d615bae24a1d720efba00a1bbc54ed3c38fdfa2b0405fd69ce6f1c6a0e2cdd6b73cf4383
|
7
|
+
data.tar.gz: 9fa961d5cf6405334791cebb57713265dccf5856d8bb853cefa37f0d0a2ab2040dfc88d6678718fae15603c82253d37d26df59d721c69edce529076e5ce0557b
|
data/lib/dmp/dynamo_adapter.rb
CHANGED
@@ -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.
|
73
|
+
return { status: 404, error: MSG_NOT_FOUND } if response[:item].nil?
|
72
74
|
|
73
|
-
{ status: 200, items: response
|
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
|
-
|
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
|
-
|
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.
|
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
|