uc3-dmp-id 0.0.64 → 0.0.65

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: 9a0c6efaee7727ad373bdccdc9184e12d1abefafe3834768c210d949d854c669
4
- data.tar.gz: 0c771250b7459256822a87dc99bdbc720ebca8cc2f4d5a5c53ccfcf5a8a0d0aa
3
+ metadata.gz: 69ff32208dd9d65b179b6caaf8cb91e7b346733cb487913f7d25b7126fb8a7cd
4
+ data.tar.gz: d8252a3ee862afc836c4c724f5a64a23287dc35b49d44d0b65bba9fe730d6725
5
5
  SHA512:
6
- metadata.gz: 98025dcd7ccdd69b284b910d8391a715c2b2b72799398cf432bf1688efc25b22caf7f25e5b5ca0eb2d528b7256703304f287fa15b92cc9df6ce96d4aa4e7c738
7
- data.tar.gz: bdc3d64ec36a853aca5ec44d32a415b65dc868b83c3bd48ce4054aae2a546a8005b3f25400d6bd759ef8fb6085e1f0bdfea16c1b4b6e178e1861e443a9a1cb3e
6
+ metadata.gz: 90b610e9567a9cb0d08c5e40cc3909964c868cfec58ffe963c598cf187e715259114a719019c616099ebe243714d29de3b99f52e9e5a701bd900f410fcf923a9
7
+ data.tar.gz: 134f3d56152ef9b2db4e01bdd79a9ac458a5ee4bde3cc23121148e6be26b3403e38a11b4cf4a4d27ae80a246d9ba8e5601aadb5edb1d97344dca50452c5af9e3
@@ -38,7 +38,7 @@ module Uc3DmpId
38
38
  raise CreatorError, MSG_UNABLE_TO_MINT if p_key.nil?
39
39
 
40
40
  # Add the DMPHub specific attributes and then save
41
- annotated = Helper.annotate_dmp_json(provenance: provenance, owner_org: owner_org, p_key: p_key, json: json['dmp'])
41
+ annotated = Helper.annotate_dmp_json(provenance: provenance, p_key: p_key, json: json['dmp'])
42
42
  puts "CREATING DMP ID:" if debug
43
43
  puts annotated if debug
44
44
 
@@ -133,16 +133,33 @@ module Uc3DmpId
133
133
  a == b
134
134
  end
135
135
 
136
+ # Extract the Contact's ORCID id
137
+ def extract_owner_id(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('contact_id', {})['identifier']
142
+
143
+ orgs = dmp.fetch('contributor').map do { |contributor| contributor.fetch('contact_id', {})['identifier'] }
144
+ orgs.first
145
+ end
146
+
136
147
  # Extract the Contact's affiliaiton ROR ID
137
148
  def extract_owner_org(json: {})
138
149
  return nil unless json.is_a?(Hash)
139
150
 
140
151
  dmp = json['dmp'].nil? ? json : json['dmp']
141
152
  owner_org = dmp.fetch('contact', {}).fetch('dmproadmap_affiliation', {}).fetch('affiliation_id', {})['identifier']
153
+ return owner_org unless owner_org.nil?
154
+
155
+ orgs = dmp.fetch('contributor').map do |contributor|
156
+ contributor.fetch('dmproadmap_affiliation', {}).fetch('affiliation_id', {})['identifier']
157
+ end
158
+ orgs.compact.max_by { |i| orgs.count(i) }
142
159
  end
143
160
 
144
161
  # Add DMPHub specific fields to the DMP ID JSON
145
- def annotate_dmp_json(provenance:, owner_org:, p_key:, json:)
162
+ def annotate_dmp_json(provenance:, p_key:, json:)
146
163
  json = parse_json(json: json)
147
164
  return json if provenance.nil? || owner_org.nil? || p_key.nil? || !json.is_a?(Hash)
148
165
 
@@ -157,9 +174,13 @@ module Uc3DmpId
157
174
  # Ensure that the :dmp_id matches the :PK
158
175
  annotated['dmp_id'] = pk_to_dmp_id(p_key: remove_pk_prefix(p_key: annotated['PK']))
159
176
 
177
+ owner_id = extract_owner_id(json: json)
178
+ owner_org = extract_owner_org(json: json)
179
+
160
180
  # Update the modification timestamps
161
181
  annotated['dmphub_modification_day'] = Time.now.strftime('%Y-%m-%d')
162
- annotated['dmphub_owner_org'] = owner_org.to_s
182
+ annotated['dmphub_owner_id'] = owner_id unless owner_id.nil?
183
+ annotated['dmphub_owner_org'] = owner_org unless owner_org.nil?
163
184
  annotated['dmphub_updated_at'] = Time.now.iso8601
164
185
  # Only add the Creation date if it is blank
165
186
  annotated['dmphub_created_at'] = Time.now.iso8601 if json['dmphub_created_at'].nil?
@@ -181,10 +202,6 @@ module Uc3DmpId
181
202
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
182
203
  def cleanse_dmp_json(json:)
183
204
  return json unless json.is_a?(Hash) || json.is_a?(Array)
184
-
185
- puts "Cleansing DMP JSON:"
186
- puts json
187
-
188
205
  # If it's an array clean each of the objects individually
189
206
  return json.map { |obj| cleanse_dmp_json(json: obj) }.compact if json.is_a?(Array)
190
207
 
@@ -46,7 +46,6 @@ 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 = Helper.extract_owner_org(json: dmp)
50
49
  # Don't continue if DMP ID could not be found or the contact has no identifier (should be impossible)
51
50
  raise UpdaterError, MSG_DMP_NOT_FOUND if dmp.nil? || owner_org.nil?
52
51
 
@@ -54,7 +53,7 @@ module Uc3DmpId
54
53
  raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
55
54
 
56
55
  # Add the DMPHub specific attributes and then add the download URl for the PDF
57
- annotated = Helper.annotate_dmp_json(provenance: provenance, owner_org: owner_org, p_key: p_key, json: dmp['dmp'])
56
+ annotated = Helper.annotate_dmp_json(provenance: provenance, p_key: p_key, json: dmp['dmp'])
58
57
  annotated['dmproadmap_related_identifiers'] = [] if annotated['dmproadmap_related_identifiers'].nil?
59
58
  annotated['dmproadmap_related_identifiers'] << {
60
59
  descriptor: 'is_metadata_for', work_type: 'output_management_plan', type: 'url', identifier: url
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.0.64'
4
+ VERSION = '0.0.65'
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.64
4
+ version: 0.0.65
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley