uc3-dmp-id 0.0.61 → 0.0.63

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: f57c20b88aa66fde624307bb92a176682f83058929d36c54f5bc8f3930a98b2d
4
- data.tar.gz: 2dc28c07fc2fc766904b3360b043cd6c3b3af7a772765f5681e9dd29040d0a39
3
+ metadata.gz: f83d0a009fdbffc97f8725896fb33492c6444ac2f12d798a5b221f879f4d0d32
4
+ data.tar.gz: 49287ecaa021b356bf48eafbe79135b4dbcc5172b7ddb918d837fdfb8aea0856
5
5
  SHA512:
6
- metadata.gz: 9896f63e4d891d16bd97d5293516bf3dc4694ae9dcb8490431433d1061e03dca23c5f99a5d0b6959e7316e6eec19cd5c16aaa7ec93d3fd156b6d877097aec8c9
7
- data.tar.gz: fe9a16d6cf9cfad66eb1547137fa5a43583b59c3198476809249a311a01ee91a3086802108a9196dfeb0a95f48620e992505f03d4fe178b434059cf7722b2809
6
+ metadata.gz: 318c39772d51a114597438aef45e84d9a627f3132b6ac2d091254fa5e674bc0bc133701829cec11b667e92e367cc07f83e925c5f07cf2332defe7c6e7163eb27
7
+ data.tar.gz: b987744fdbb5aa0dce30538be6d58e68b9b0e00b03de5b58fb817906fdcbed9a5c47f62a49092ec21e736e67dc1d1f5451a13b13136c50f3a08328e24c8b34e6
@@ -47,7 +47,7 @@ module Uc3DmpId
47
47
  raise CreatorError, Uc3DmpId::MSG_DMP_NO_DMP_ID if resp.nil?
48
48
 
49
49
  _post_process(json: annotated, debug: debug)
50
- annotated
50
+ Helper.cleanse_dmp_json(json: annotated)
51
51
  end
52
52
 
53
53
  private
@@ -133,27 +133,29 @@ module Uc3DmpId
133
133
  a == b
134
134
  end
135
135
 
136
+ # Extract the Contact's affiliaiton ROR ID
137
+ def extract_owner_org(json: {})
138
+ return nil unless json.is_a?(Hash)
139
+
140
+ dmp = json['dmp'].nil? ? json : json['dmp']
141
+ owner_org = dmp.fetch('contact', {}).fetch('dmproadmap_affiliation', {}).fetch('affiliation_id', {})['identifier']
142
+ end
143
+
136
144
  # Add DMPHub specific fields to the DMP ID JSON
137
145
  def annotate_dmp_json(provenance:, owner_org:, p_key:, json:)
138
146
  json = parse_json(json: json)
139
-
140
- puts "annotate - prov: #{provenance['PK']}, owner_org: #{owner_org}, p_key: #{p_key}, Hash? #{json.is_a?(Hash)} ::: #{provenance.nil? || owner_org.nil? || p_key.nil? || !json.is_a?(Hash)}"
141
-
142
147
  return json if provenance.nil? || owner_org.nil? || p_key.nil? || !json.is_a?(Hash)
143
148
 
144
149
  # Fail the json as is if the :PK does not match the :dmp_id if the json has a :PK
145
150
  id = dmp_id_to_pk(json: json.fetch('dmp_id', {}))
146
-
147
- puts "annotate - id: #{id}, PK exist? #{json['PK']} ::: #{id != p_key && !json['PK'].nil?}"
148
-
149
151
  return json if id != p_key && !json['PK'].nil?
150
152
 
151
153
  annotated = deep_copy_dmp(obj: json)
152
- annotated['PK'] = json['PK'] || p_key
154
+ annotated['PK'] = json['PK'] || append_pk_prefix(p_key: p_key)
153
155
  annotated['SK'] = DMP_LATEST_VERSION
154
156
 
155
157
  # Ensure that the :dmp_id matches the :PK
156
- annotated['dmp_id'] = pk_to_dmp_id(p_key: annotated['PK'])
158
+ annotated['dmp_id'] = pk_to_dmp_id(p_key: remove_pk_prefix(p_key: annotated['PK']))
157
159
 
158
160
  # Update the modification timestamps
159
161
  annotated['dmphub_modification_day'] = Time.now.strftime('%Y-%m-%d')
@@ -180,6 +182,9 @@ puts "annotate - id: #{id}, PK exist? #{json['PK']} ::: #{id != p_key && !json['
180
182
  def cleanse_dmp_json(json:)
181
183
  return json unless json.is_a?(Hash) || json.is_a?(Array)
182
184
 
185
+ puts "Cleansing DMP JSON:"
186
+ puts json
187
+
183
188
  # If it's an array clean each of the objects individually
184
189
  return json.map { |obj| cleanse_dmp_json(json: obj) }.compact if json.is_a?(Array)
185
190
 
@@ -46,11 +46,7 @@ module Uc3DmpId
46
46
  # fetch the existing latest version of the DMP ID
47
47
  client = Uc3DmpDynamo::Client.new(debug: debug)
48
48
  dmp = Finder.by_pk(p_key: p_key, client: client, debug: debug)
49
- owner_org = dmp['dmp'].fetch('contact', {}).fetch('dmproadmap_affiliation', {}) unless dmp.nil?
50
- owner_org = owner_org.fetch('affiliation_id', {})['identifier'] unless owner_org.nil?
51
-
52
- puts "OWNER ORG: #{owner_org}"
53
-
49
+ owner_org = Helper.extract_owner_org(json: dmp)
54
50
  # Don't continue if DMP ID could not be found or the contact has no identifier (should be impossible)
55
51
  raise UpdaterError, MSG_DMP_NOT_FOUND if dmp.nil? || owner_org.nil?
56
52
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.0.61'
4
+ VERSION = '0.0.63'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc3-dmp-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.61
4
+ version: 0.0.63
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley