dmp-dynamo_adapter 0.2.8 → 0.3.1

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: 1fde969438aa9681c5213d60e441b3187de1ed2141c7b244419ba47a007d39fc
4
- data.tar.gz: a4a9722f607edf91644043c4adbcb3af7bfe81f33d254da104a0223a27fd6c40
3
+ metadata.gz: 80c519bd779bdfc10d50d22b12e61f75a1809c9f54feef84c5f8bf4373bd7665
4
+ data.tar.gz: 9f37c7e34d64b0a5594fef9b0951c89f4d76ddd3478577b4afc3f37d1fd004a5
5
5
  SHA512:
6
- metadata.gz: 0ba67f79d6cdf0b4d29f416301e88b8b4453f85b7381a82280f5389dde4c12bb5446e59bdd21290d04203dbcdaefc73f08c1bd8ffd5221b945a19e514e4f1c2b
7
- data.tar.gz: 8c2a12ccd6b1049a12f254a6ae5f634c63aa2c3b82870778fd541482d6888cd720426ac6cb213d72b6fb3605ad38a3b948abf7393f63b90cc3898fa72f60966e
6
+ metadata.gz: 812e6b3c2e47c7192c352b1c563d047405b8a896fcd115c9f7d3497f9b6c82f21443a828b17c0d62c8b7023a20da4c788664003742be0358b9aa1559142ae474
7
+ data.tar.gz: bfb81e6b453cb83e63c94a939a5dcdba10ca105cd071eb8de1926ff7591e45c043dbc117c11ea463e772090c9bab895e19d8cdcfc959803ff654c9b541c8a011
@@ -10,7 +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']}/"
13
+ ENV['DMP_ID_BASE_URL']&.end_with?('/') ? ENV['DMP_ID_BASE_URL'] : "#{ENV['DMP_ID_BASE_URL']}/"
14
14
  end
15
15
 
16
16
  # Format the DMP ID in the way we want it
@@ -70,7 +70,8 @@ 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[:items].nil? ||
74
+ response[:items].empty?
74
75
 
75
76
  { status: 200, items: [response[:item]] }
76
77
  rescue Aws::Errors::ServiceError => e
@@ -129,11 +130,14 @@ p "PUTTING ITEM:"
129
130
  return_consumed_capacity: @debug_mode ? 'TOTAL' : 'NONE'
130
131
  }
131
132
  )
133
+ # Fetch the newly created record
134
+ response = find_by_pk(p_key: p_key, s_key: Dmp::MetadataHandler::LATEST_VERSION)
135
+ return { status: 500, error: MSG_DEFAULT } unless response[:status] == 200
132
136
 
133
137
  p 'CREATED!?'
134
- pp response.data
138
+ pp response[:items]
135
139
 
136
- { status: 201, items: [response.data] }
140
+ { status: 201, items: response[:items] }
137
141
  rescue Aws::DynamoDB::Errors::DuplicateItemException
138
142
  { status: 405, error: MSG_EXISTS }
139
143
  rescue Aws::Errors::ServiceError => e
@@ -176,7 +180,7 @@ p ''
176
180
 
177
181
  json = splice_json(original_version: version_result[:items].first&.item, new_version: json)
178
182
 
179
- p ''
183
+ # p ''
180
184
  p "AFTER:"
181
185
  pp json
182
186
 
@@ -253,7 +257,8 @@ pp json
253
257
  # Attempt to find the DMP item by its 'is_metadata_for' :dmproadmap_related_identifier
254
258
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
255
259
  def find_by_dmphub_provenance_identifier(json:)
256
- return { status: 400, error: MSG_DEFAULT } if json.nil? || json.fetch('dmp_id', {})['identifier'].nil?
260
+ return { status: 400, error: MSG_DEFAULT } if json.nil? ||
261
+ json.fetch('dmp_id', {})['identifier'].nil?
257
262
 
258
263
  p "FINDING BY PROVENANCE ID: #{json['dmp_id']['identifier']}"
259
264
 
@@ -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.8
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - briri