uc3-dmp-id 0.0.64 → 0.0.66
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uc3-dmp-id/creator.rb +1 -1
- data/lib/uc3-dmp-id/helper.rb +22 -6
- data/lib/uc3-dmp-id/updater.rb +1 -2
- data/lib/uc3-dmp-id/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2d9a4bba715adc0eb2b0101d9484d8a57ea7f3643a3cd63088191fa82da5157
|
4
|
+
data.tar.gz: b42b00fa9a0bfae9c4f69539ebb612f9c2ab063fe20b1d96987a62cbe35cae60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aba3791e3f85c77c3b1fce370e8d4c62e441148c2ea399074ad794505165fb9475488b552001f29613eaf5540e300a3271fe66b83af55bb6410679526828906b
|
7
|
+
data.tar.gz: e5d2470504ff9dbc2d9c61552c69a20229de6ae29d32361df1cf197b4ca97252bfb2d353c3126f42ab2a9b5f601e18a39ef1d6b4ccb6949caa1b2cfdeb7dcdb5
|
data/lib/uc3-dmp-id/creator.rb
CHANGED
@@ -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,
|
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
|
|
data/lib/uc3-dmp-id/helper.rb
CHANGED
@@ -133,16 +133,32 @@ 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
|
+
dmp.fetch('contributor', []).map do { |contributor| contributor.fetch('contact_id', {})['identifier'] }.first
|
144
|
+
end
|
145
|
+
|
136
146
|
# Extract the Contact's affiliaiton ROR ID
|
137
147
|
def extract_owner_org(json: {})
|
138
148
|
return nil unless json.is_a?(Hash)
|
139
149
|
|
140
150
|
dmp = json['dmp'].nil? ? json : json['dmp']
|
141
151
|
owner_org = dmp.fetch('contact', {}).fetch('dmproadmap_affiliation', {}).fetch('affiliation_id', {})['identifier']
|
152
|
+
return owner_org unless owner_org.nil?
|
153
|
+
|
154
|
+
orgs = dmp.fetch('contributor', []).map do |contributor|
|
155
|
+
contributor.fetch('dmproadmap_affiliation', {}).fetch('affiliation_id', {})['identifier']
|
156
|
+
end
|
157
|
+
orgs.compact.max_by { |i| orgs.count(i) }
|
142
158
|
end
|
143
159
|
|
144
160
|
# Add DMPHub specific fields to the DMP ID JSON
|
145
|
-
def annotate_dmp_json(provenance:,
|
161
|
+
def annotate_dmp_json(provenance:, p_key:, json:)
|
146
162
|
json = parse_json(json: json)
|
147
163
|
return json if provenance.nil? || owner_org.nil? || p_key.nil? || !json.is_a?(Hash)
|
148
164
|
|
@@ -157,9 +173,13 @@ module Uc3DmpId
|
|
157
173
|
# Ensure that the :dmp_id matches the :PK
|
158
174
|
annotated['dmp_id'] = pk_to_dmp_id(p_key: remove_pk_prefix(p_key: annotated['PK']))
|
159
175
|
|
176
|
+
owner_id = extract_owner_id(json: json)
|
177
|
+
owner_org = extract_owner_org(json: json)
|
178
|
+
|
160
179
|
# Update the modification timestamps
|
161
180
|
annotated['dmphub_modification_day'] = Time.now.strftime('%Y-%m-%d')
|
162
|
-
annotated['
|
181
|
+
annotated['dmphub_owner_id'] = owner_id unless owner_id.nil?
|
182
|
+
annotated['dmphub_owner_org'] = owner_org unless owner_org.nil?
|
163
183
|
annotated['dmphub_updated_at'] = Time.now.iso8601
|
164
184
|
# Only add the Creation date if it is blank
|
165
185
|
annotated['dmphub_created_at'] = Time.now.iso8601 if json['dmphub_created_at'].nil?
|
@@ -181,10 +201,6 @@ module Uc3DmpId
|
|
181
201
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
182
202
|
def cleanse_dmp_json(json:)
|
183
203
|
return json unless json.is_a?(Hash) || json.is_a?(Array)
|
184
|
-
|
185
|
-
puts "Cleansing DMP JSON:"
|
186
|
-
puts json
|
187
|
-
|
188
204
|
# If it's an array clean each of the objects individually
|
189
205
|
return json.map { |obj| cleanse_dmp_json(json: obj) }.compact if json.is_a?(Array)
|
190
206
|
|
data/lib/uc3-dmp-id/updater.rb
CHANGED
@@ -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,
|
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
|
data/lib/uc3-dmp-id/version.rb
CHANGED