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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9418816d26847581bce0424f326d1b7d65947b2aa3df952c2d8904984229b18c
4
- data.tar.gz: 3e7a9d4819f987dc3ae51a699b88321182d28705d776e48780aedba1d5995412
3
+ metadata.gz: 1ca8afd4ec83d2f0b665b3521e0bc9ebe7d1fbd051dea63676d9b4abaadc66ad
4
+ data.tar.gz: 8dbddd4cd81b89d25561948cf519a1fb27069d9aea10c9ca06956e74b4f7d243
5
5
  SHA512:
6
- metadata.gz: 9abe8d680a8dce95cf71d50e14b8fc9c954bb04bdaaa3d080b80dbb639b4f098c7c5b976610a7bff5a37c7ed48c68f330b4e315df93663ec48ffb3a5d2a39119
7
- data.tar.gz: 1378240d137ae3afd8e089d0337d2322d8a8406fc93d3027b14870c6a2a0f0c15087b7b06bd5dd5f158ef93996e21103f0c4488cf4eae77d6cf3607cc8159931
6
+ metadata.gz: 28e8eb60875cc65bbbbc660a4df24a9848bedb784c20f6b5345686d39e8ceb49235b7e3e2703f37fa68e04317c24d5c06758291d4707987f82095b1d4ba70824
7
+ data.tar.gz: 6482832fe3c392bd302832bad1722f331890b0b3c4892c913fea2b33fb39f2678cfe4e6e9d8c80ca5cfd9ce7345760db41f93cf2bb7726cfcc0d7edd7728cc31
@@ -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?
@@ -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
- return { status: 500, error: MSG_DEFAULT } if result[:status] == 500
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
- { status: 201, items: response.items.map(&:item).compact.uniq }
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
- return { status: 404, error: MSG_NOT_FOUND } if response.nil? || response.items.empty?
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.items.first.item[:PK])
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
@@ -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?
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.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri