dmp-dynamo_adapter 0.2.0 → 0.2.3
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/dmp_id_handler.rb +3 -1
- data/lib/dmp/dynamo_adapter.rb +27 -12
- data/lib/dmp/metadata_handler.rb +2 -0
- 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: 1ca8afd4ec83d2f0b665b3521e0bc9ebe7d1fbd051dea63676d9b4abaadc66ad
|
4
|
+
data.tar.gz: 8dbddd4cd81b89d25561948cf519a1fb27069d9aea10c9ca06956e74b4f7d243
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28e8eb60875cc65bbbbc660a4df24a9848bedb784c20f6b5345686d39e8ceb49235b7e3e2703f37fa68e04317c24d5c06758291d4707987f82095b1d4ba70824
|
7
|
+
data.tar.gz: 6482832fe3c392bd302832bad1722f331890b0b3c4892c913fea2b33fb39f2678cfe4e6e9d8c80ca5cfd9ce7345760db41f93cf2bb7726cfcc0d7edd7728cc31
|
data/lib/dmp/dmp_id_handler.rb
CHANGED
@@ -16,8 +16,10 @@ module Dmp
|
|
16
16
|
# Preassign a DMP ID that will leater be sent to the DOI minting authority (EZID)
|
17
17
|
def preregister_dmp_id
|
18
18
|
dmp_id = ''
|
19
|
-
|
20
19
|
counter = 0
|
20
|
+
|
21
|
+
p 'PREREGISTER DMP ID:'
|
22
|
+
|
21
23
|
while dmp_id == '' && counter <= 10
|
22
24
|
prefix = "#{ENV['DMP_ID_SHOULDER']}.#{SecureRandom.hex(4).upcase}"
|
23
25
|
dmp_id = prefix if find_by_pk(p_key: Dmp::MetadataHandler.append_pk_prefix(dmp: dmp_id)).empty?
|
data/lib/dmp/dynamo_adapter.rb
CHANGED
@@ -70,9 +70,6 @@ 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
|
-
|
74
|
-
pp response.data
|
75
|
-
|
76
73
|
return { status: 404, error: MSG_NOT_FOUND } if response[:item].nil?
|
77
74
|
|
78
75
|
{ status: 200, items: [response[:item]] }
|
@@ -106,21 +103,30 @@ pp response.data
|
|
106
103
|
json = prepare_json(json: json)
|
107
104
|
return { status: 400, error: MSG_DEFAULT } if json.nil? || @provenance.nil?
|
108
105
|
|
109
|
-
p "FINDING BY JSON"
|
110
|
-
pp json
|
111
|
-
|
112
106
|
# Try to find it first
|
113
107
|
result = find_by_json(json: json)
|
114
|
-
|
108
|
+
|
109
|
+
p "RESULT:"
|
110
|
+
pp result
|
111
|
+
|
112
|
+
return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
|
115
113
|
# Abort if found
|
116
114
|
return { status: 400, error: MSG_EXISTS } if result[:items].any?
|
117
115
|
|
118
116
|
# allocate a DMP ID
|
119
117
|
p_key = Dmp::DmpIdHandler.preregister_dmp_id
|
118
|
+
|
119
|
+
p "PRE REGISTERED DMP ID: #{p_key.inspect}"
|
120
|
+
|
120
121
|
return { status: 500, error: MSG_NO_DMP_ID } if p_key.nil?
|
121
122
|
|
122
123
|
# Add the DMPHub specific attributes and then save
|
123
124
|
json = Dmp::MetadataHandler.annotate_json(provenance: @provenance, json: json, p_key: p_key)
|
125
|
+
|
126
|
+
p "ANNOTATED:"
|
127
|
+
pp json
|
128
|
+
|
129
|
+
p "PUTTING ITEM:"
|
124
130
|
response = @client.put_item(
|
125
131
|
{
|
126
132
|
table_name: ENV['AWS_DYNAMO_TABLE_NAME'],
|
@@ -128,7 +134,11 @@ pp json
|
|
128
134
|
return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
|
129
135
|
}
|
130
136
|
)
|
131
|
-
|
137
|
+
|
138
|
+
p 'CREATED!?'
|
139
|
+
pp response.data
|
140
|
+
|
141
|
+
{ status: 201, items: [response.data] }
|
132
142
|
rescue Aws::DynamoDB::Errors::DuplicateItemException
|
133
143
|
{ status: 405, error: MSG_EXISTS }
|
134
144
|
rescue Aws::Errors::ServiceError => e
|
@@ -148,7 +158,7 @@ pp json
|
|
148
158
|
|
149
159
|
# Try to find it first
|
150
160
|
result = find_by_json(json: json)
|
151
|
-
return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
|
161
|
+
return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
|
152
162
|
|
153
163
|
dmp = result[:items].first&.item
|
154
164
|
return { status: 404, error: MSG_NOT_FOUND } if dmp.nil?
|
@@ -206,7 +216,7 @@ pp json
|
|
206
216
|
|
207
217
|
# Try to find it first
|
208
218
|
result = find_by_json(json: json)
|
209
|
-
return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
|
219
|
+
return { status: 500, error: result.fetch(:error, MSG_DEFAULT) } if result[:status] == 500
|
210
220
|
# Abort if NOT found
|
211
221
|
return { status: 404, error: MSG_NOT_FOUND } unless result[:status] == 200 && result.fetch(:items, []).any?
|
212
222
|
|
@@ -269,10 +279,15 @@ p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
|
|
269
279
|
return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
|
270
280
|
}
|
271
281
|
)
|
272
|
-
|
282
|
+
|
283
|
+
p "RESPONSE:"
|
284
|
+
pp response.data
|
285
|
+
|
286
|
+
return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response[:Count] <= 0
|
273
287
|
|
274
288
|
# If we got a hit, fetch the DMP and return it.
|
275
|
-
find_by_pk(p_key: response.
|
289
|
+
find_by_pk(p_key: response.fetch(:LastEvaluatedKey, {})[:HashKeyElement],
|
290
|
+
s_key: response.fetch(:LastEvaluatedKey, {})[:RangeKeyElement])
|
276
291
|
rescue Aws::Errors::ServiceError => e
|
277
292
|
{ status: 500, error: "#{MSG_DEFAULT} - #{e.message}" }
|
278
293
|
end
|
data/lib/dmp/metadata_handler.rb
CHANGED
@@ -60,6 +60,8 @@ module Dmp
|
|
60
60
|
def annotate_json(provenance:, p_key:, json:)
|
61
61
|
return nil if provenance.nil? || p_key.nil? || json.nil?
|
62
62
|
|
63
|
+
p "ANNOTATING METADATA:"
|
64
|
+
|
63
65
|
# Fail if the :PK does not match the :dmp_id if the json has a :PK
|
64
66
|
id = Dmp::DmpIdHandler.dmp_id_to_pk(json: json.fetch('dmp_id', {}))
|
65
67
|
id = nil if id != p_key && !json['PK'].nil?
|