uc3-dmp-id 0.0.63 → 0.0.65
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 +2 -2
- data/lib/uc3-dmp-id/helper.rb +23 -6
- data/lib/uc3-dmp-id/updater.rb +86 -90
- data/lib/uc3-dmp-id/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69ff32208dd9d65b179b6caaf8cb91e7b346733cb487913f7d25b7126fb8a7cd
|
4
|
+
data.tar.gz: d8252a3ee862afc836c4c724f5a64a23287dc35b49d44d0b65bba9fe730d6725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90b610e9567a9cb0d08c5e40cc3909964c868cfec58ffe963c598cf187e715259114a719019c616099ebe243714d29de3b99f52e9e5a701bd900f410fcf923a9
|
7
|
+
data.tar.gz: 134f3d56152ef9b2db4e01bdd79a9ac458a5ee4bde3cc23121148e6be26b3403e38a11b4cf4a4d27ae80a246d9ba8e5601aadb5edb1d97344dca50452c5af9e3
|
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
|
|
@@ -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
|
-
Helper.cleanse_dmp_json(json: annotated)
|
50
|
+
Helper.cleanse_dmp_json(json: JSON.parse({ dmp: annotated }.to_json))
|
51
51
|
end
|
52
52
|
|
53
53
|
private
|
data/lib/uc3-dmp-id/helper.rb
CHANGED
@@ -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:,
|
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['
|
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
|
|
data/lib/uc3-dmp-id/updater.rb
CHANGED
@@ -10,96 +10,92 @@ module Uc3DmpId
|
|
10
10
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
11
11
|
# -------------------------------------------------------------------------
|
12
12
|
def update(provenance:, p_key:, json: {})
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
publisher = Uc3DmpEventBridge::Publisher.new
|
100
|
-
publisher.publish(source: 'DmpUpdater', dmp: json, debug: debug)
|
101
|
-
true
|
102
|
-
end
|
13
|
+
raise UpdaterError, MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
|
14
|
+
|
15
|
+
dmp = Helper.parse_json(json: json)
|
16
|
+
errs = _updateable?(provenance: provenance, p_key: p_key, dmp: dmp)
|
17
|
+
raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
|
18
|
+
|
19
|
+
# Add the DMPHub specific attributes
|
20
|
+
annotated = Helper.annotate_dmp(provenance: provenance, json: dmp['dmp'], p_key: p_key)
|
21
|
+
|
22
|
+
# fetch the existing latest version of the DMP ID
|
23
|
+
client = Uc3DmpDynamo::Client.new(debug: debug)
|
24
|
+
existing = Finder.by_pk(p_key: p_key, client: client, debug: debug)
|
25
|
+
# Don't continue if nothing has changed!
|
26
|
+
raise UpdaterError, MSG_NO_CHANGE if Helper.eql?(dmp_a: existing, dmp_b: annotated)
|
27
|
+
|
28
|
+
# Generate a new version of the DMP. This involves versioning the current latest version
|
29
|
+
new_version = versioner.new_version(p_key: p_key, dmp: json)
|
30
|
+
raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if new_version.nil?
|
31
|
+
|
32
|
+
# Save the changes as the new latest version
|
33
|
+
resp = client.put_item(json: new_version, debug: debug)
|
34
|
+
raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
|
35
|
+
|
36
|
+
# Send the updates to EZID, notify the provenance and download the PDF if applicable
|
37
|
+
_post_process(json: dmp, debug: debug)
|
38
|
+
resp
|
39
|
+
end
|
40
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
41
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
42
|
+
|
43
|
+
def attach_narrative(provenance:, p_key:, url:, debug: false)
|
44
|
+
raise UpdaterError, MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
|
45
|
+
|
46
|
+
# fetch the existing latest version of the DMP ID
|
47
|
+
client = Uc3DmpDynamo::Client.new(debug: debug)
|
48
|
+
dmp = Finder.by_pk(p_key: p_key, client: client, debug: debug)
|
49
|
+
# Don't continue if DMP ID could not be found or the contact has no identifier (should be impossible)
|
50
|
+
raise UpdaterError, MSG_DMP_NOT_FOUND if dmp.nil? || owner_org.nil?
|
51
|
+
|
52
|
+
errs = _updateable?(provenance: provenance, p_key: p_key, json: dmp['dmp'])
|
53
|
+
raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
|
54
|
+
|
55
|
+
# Add the DMPHub specific attributes and then add the download URl for the PDF
|
56
|
+
annotated = Helper.annotate_dmp_json(provenance: provenance, p_key: p_key, json: dmp['dmp'])
|
57
|
+
annotated['dmproadmap_related_identifiers'] = [] if annotated['dmproadmap_related_identifiers'].nil?
|
58
|
+
annotated['dmproadmap_related_identifiers'] << {
|
59
|
+
descriptor: 'is_metadata_for', work_type: 'output_management_plan', type: 'url', identifier: url
|
60
|
+
}
|
61
|
+
|
62
|
+
# Save the changes without creating a new version!
|
63
|
+
resp = client.put_item(json: annotated, debug: debug)
|
64
|
+
raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
|
65
|
+
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Check if the DMP ID is updateable by the provenance
|
72
|
+
def _updateable?(provenance:, p_key:, json:)
|
73
|
+
# Validate the incoming JSON first
|
74
|
+
errs = Validator.validate(mode: 'author', json: json)
|
75
|
+
return errs.join(', ') if errs.is_a?(Array) && errs.any? && errs.first != Validator::MSG_VALID_JSON
|
76
|
+
|
77
|
+
# Fail if the provenance is not defined
|
78
|
+
return [MSG_DMP_FORBIDDEN] unless provenance.is_a?(Hash) && !provenance['PK'].nil?
|
79
|
+
|
80
|
+
# Verify that the JSON is for the same DMP in the PK
|
81
|
+
dmp_id = json.fetch('dmp_id', {})
|
82
|
+
return [MSG_DMP_FORBIDDEN] unless Helper.dmp_id_to_pk(json: dmp_id) == p_key
|
83
|
+
# Make sure they're not trying to update a historical copy of the DMP
|
84
|
+
return [MSG_DMP_NO_HISTORICALS] if json['SK'] != Helper::DMP_LATEST_VERSION
|
85
|
+
end
|
86
|
+
|
87
|
+
# Once the DMP has been updated, we need to register it's DMP ID and download any PDF if applicable
|
88
|
+
# -------------------------------------------------------------------------
|
89
|
+
def _post_process(json:, debug: false)
|
90
|
+
return false unless json.is_a?(Hash)
|
91
|
+
|
92
|
+
# Indicate whether or not the updater is the provenance system
|
93
|
+
json['dmphub_updater_is_provenance'] = @provenance['PK'] == json['dmphub_provenance_id']
|
94
|
+
# Publish the change to the EventBridge
|
95
|
+
publisher = Uc3DmpEventBridge::Publisher.new
|
96
|
+
publisher.publish(source: 'DmpUpdater', dmp: json, debug: debug)
|
97
|
+
true
|
98
|
+
end
|
103
99
|
end
|
104
100
|
end
|
105
101
|
end
|
data/lib/uc3-dmp-id/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uc3-dmp-id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.65
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Riley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|