dmp-dynamo_adapter 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41ac93e31c250106a76873be5e069337fe772387bef81350afdffe231a09ad80
4
- data.tar.gz: 9998934e79fbdb99639088e64bea3b6a3b516df5b20db4ce8733e7c5bcc7c10c
3
+ metadata.gz: 1df64725fca2ba042c200d8615e9d304503836f48bd04451cb08a034773b4ad9
4
+ data.tar.gz: ce3dc12d41f2b48f7106d390cb0ef7d7b61f5ea3d77337adba094e8604f59575
5
5
  SHA512:
6
- metadata.gz: 9bdd9d6d4ab79239ca07993ebcb991f3d9298ce01f21058a841921970646b8f08b33ee5239338b95626ca37e19f1272b37da3706425fd985b7a17f2db67fa205
7
- data.tar.gz: 7d374a240cac71d3cd65d1422fbb983e1b4e10f6d8e1096ad9a4ed973d521229a9bf078db1c7a86e8862c3ad596f95e7f4899e9c0e11751339691e1006cd3dbd
6
+ metadata.gz: b0393c336cc05254ae08dc757f449fda523f6caaaff7a65241b466d468af7ef9e595a95ea56d2b6a3934dc406bf9414b0da2bc2c06ea77c8e7d89c61abb87331
7
+ data.tar.gz: d2ac537a78af198168ff50006a8d74ed880f0103f2cce91045c48578dbbd7e44815205f37d7167c206c8cd468ee92bad35caca6d4af96700aaf2b66950e07ff0
@@ -10,28 +10,7 @@ module Dmp
10
10
 
11
11
  class << self
12
12
  def dmp_id_base_url
13
- ENV['DMP_ID_BASE_URL'].end_with?('/') ? ENV['DMP_ID_BASE_URL'] : "#{ENV['DMP_ID_BASE_URL']}/"
14
- end
15
-
16
- # Preassign a DMP ID that will leater be sent to the DOI minting authority (EZID)
17
- def preregister_dmp_id
18
- dmp_id = ''
19
- counter = 0
20
-
21
- p 'PREREGISTER DMP ID:'
22
-
23
- while dmp_id == '' && counter <= 10
24
- prefix = "#{ENV['DMP_ID_SHOULDER']}.#{SecureRandom.hex(4).upcase}"
25
- result = Dmp::DynamoAdapter.find_by_pk(
26
- p_key: Dmp::MetadataHandler.append_pk_prefix(dmp: dmp_id)
27
- )
28
- dmp_id = prefix unless result[:status] != 404
29
- counter += 1
30
- end
31
- # Something went wrong and it was unable to identify a unique id
32
- return nil if counter >= 10
33
-
34
- "#{Dmp::MetadataHandler::PK_DMP_PREFIX}#{dmp_id_base_url}#{dmp_id}"
13
+ ENV['DMP_ID_BASE_URL']&.end_with?('/') ? ENV['DMP_ID_BASE_URL'] : "#{ENV['DMP_ID_BASE_URL']}/"
35
14
  end
36
15
 
37
16
  # Format the DMP ID in the way we want it
@@ -70,7 +70,7 @@ 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[:item].nil?
73
+ return { status: 404, error: MSG_NOT_FOUND } if response.fetch(:item, []).empty?
74
74
 
75
75
  { status: 200, items: [response[:item]] }
76
76
  rescue Aws::Errors::ServiceError => e
@@ -129,11 +129,14 @@ p "PUTTING ITEM:"
129
129
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
130
130
  }
131
131
  )
132
+ # Fetch the newly created record
133
+ response = find_by_pk(p_key: p_key, s_key: Dmp::MetadataHandler::LATEST_VERSION)
134
+ return { status: 500, error: MSG_DEFAULT } unless response[:status] == 200
132
135
 
133
136
  p 'CREATED!?'
134
- pp response.data
137
+ pp response[:items]
135
138
 
136
- { status: 201, items: [response.data] }
139
+ { status: 201, items: response[:items] }
137
140
  rescue Aws::DynamoDB::Errors::DuplicateItemException
138
141
  { status: 405, error: MSG_EXISTS }
139
142
  rescue Aws::Errors::ServiceError => e
@@ -176,7 +179,7 @@ p ''
176
179
 
177
180
  json = splice_json(original_version: version_result[:items].first&.item, new_version: json)
178
181
 
179
- p ''
182
+ # p ''
180
183
  p "AFTER:"
181
184
  pp json
182
185
 
@@ -253,7 +256,8 @@ pp json
253
256
  # Attempt to find the DMP item by its 'is_metadata_for' :dmproadmap_related_identifier
254
257
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
255
258
  def find_by_dmphub_provenance_identifier(json:)
256
- return { status: 400, error: MSG_DEFAULT } if json.nil? || json.fetch('dmp_id', {})['identifier'].nil?
259
+ return { status: 400, error: MSG_DEFAULT } if json.nil? ||
260
+ json.fetch('dmp_id', {})['identifier'].nil?
257
261
 
258
262
  p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
259
263
 
@@ -304,7 +308,7 @@ p 'PREREGISTER DMP ID:'
304
308
  # Something went wrong and it was unable to identify a unique id
305
309
  return nil if counter >= 10
306
310
 
307
- "#{Dmp::MetadataHandler::PK_DMP_PREFIX}#{dmp_id_base_url}#{dmp_id}"
311
+ "#{Dmp::MetadataHandler::PK_DMP_PREFIX}#{Dmp::DmpIdHandler.dmp_id_base_url}#{dmp_id}"
308
312
  end
309
313
 
310
314
  # Convert the latest version into a historical version
@@ -74,7 +74,7 @@ p "ANNOTATING METADATA:"
74
74
  annotated['dmp_id'] = Dmp::DmpIdHandler.pk_to_dmp_id(p_key: annotated['PK'])
75
75
 
76
76
  # Update the modification timestamps
77
- annotated['dmphub_modification_day'] = Time.now.strftime('%Y-%M-%d')
77
+ annotated['dmphub_modification_day'] = Time.now.strftime('%Y-%m-%d')
78
78
  annotated['dmphub_updated_at'] = Time.now.iso8601
79
79
  # Only add the Creation date if it is blank
80
80
  annotated['dmphub_created_at'] = Time.now.iso8601 if json['dmphub_created_at'].nil?
@@ -85,7 +85,7 @@ p "ANNOTATING METADATA:"
85
85
  json.fetch('dmp_id', {})['identifier'].nil?
86
86
 
87
87
  # Record the original Provenance system's identifier
88
- annotated['dmphub_provenance_identifier'] = json['dmp_id']
88
+ annotated['dmphub_provenance_identifier'] = json.fetch('dmp_id', {})['identifier']
89
89
  annotated
90
90
  end
91
91
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
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.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri