uc3-dmp-id 0.1.79 → 0.1.80
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/finder.rb +3 -1
- data/lib/uc3-dmp-id/updater.rb +57 -40
- 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: 9e69e96c9dc20009c9a8ae00a332cff2348e529ffbfce306418a781977bf13b0
|
4
|
+
data.tar.gz: c3d4e37d7fefef7d98aa6606e5063a6539270c31d7916af1f964b99065b80724
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92b6adb8619e99a00dcd61876c429d55757a6bb79841ffb5ddffbf04c0cc2fe10003464a8a3274b0886c639c2f527e241ca3b714c1b9e31c16d2fc125938d559
|
7
|
+
data.tar.gz: 6f6519e59f7c708be73fe721a7b68013e17dd523ebd42e33d5b6aedc7755a5364d3dafbf4df4534a10d3d34c320aa79b17e122e15eea0c3a8477032b3c454e89
|
data/lib/uc3-dmp-id/finder.rb
CHANGED
@@ -172,6 +172,7 @@ module Uc3DmpId
|
|
172
172
|
def _by_org(org:, client: nil, logger: nil)
|
173
173
|
regex = /^[a-zA-Z0-9]+$/
|
174
174
|
id = "#{ROR_DOMAIN}#{org.strip}" unless (org.to_s =~ regex).nil?
|
175
|
+
return [] if id.nil?
|
175
176
|
|
176
177
|
resp = client.get_item(key: { PK: 'AFFILIATION_INDEX', SK: id }, logger:)
|
177
178
|
return [] unless resp.is_a?(Hash)
|
@@ -184,7 +185,8 @@ module Uc3DmpId
|
|
184
185
|
def _by_funder(funder:, client: nil, logger: nil)
|
185
186
|
regex = /^[a-zA-Z0-9]+$/
|
186
187
|
id = "#{ROR_DOMAIN}/#{funder.strip}" unless (funder.to_s =~ regex).nil?
|
187
|
-
id = "#{DOI_DOMAIN}#{
|
188
|
+
id = "#{DOI_DOMAIN}#{funder.strip}" if id.nil? && !(funder.to_s =~ Helper::DOI_REGEX).nil?
|
189
|
+
return [] if id.nil?
|
188
190
|
|
189
191
|
resp = client.get_item(key: { PK: 'FUNDER_INDEX', SK: id }, logger:)
|
190
192
|
return [] unless resp.is_a?(Hash)
|
data/lib/uc3-dmp-id/updater.rb
CHANGED
@@ -16,9 +16,9 @@ module Uc3DmpId
|
|
16
16
|
def update(provenance:, p_key:, json: {}, logger: nil)
|
17
17
|
raise UpdaterError, Helper::MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
|
18
18
|
|
19
|
-
|
19
|
+
payload = Helper.parse_json(json:).fetch('dmp', {})
|
20
20
|
p_key = Helper.append_pk_prefix(p_key:)
|
21
|
-
logger.debug(message: "Incoming modifications for PK #{p_key}", details:
|
21
|
+
logger.debug(message: "Incoming modifications for PK #{p_key}", details: payload) if logger.respond_to?(:debug)
|
22
22
|
|
23
23
|
# Fetch the latest version of the DMP ID
|
24
24
|
client = Uc3DmpDynamo::Client.new
|
@@ -28,29 +28,31 @@ module Uc3DmpId
|
|
28
28
|
|
29
29
|
# Verify that the DMP ID is updateable with the info passed in
|
30
30
|
errs = _updateable?(provenance:, p_key:, latest_version: latest_version['dmp'],
|
31
|
-
mods:
|
31
|
+
mods: payload['dmp'])
|
32
32
|
logger.error(message: errs.join(', ')) if logger.respond_to?(:error) && errs.is_a?(Array) && errs.any?
|
33
33
|
raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
|
34
34
|
# Don't continue if nothing has changed!
|
35
|
-
raise UpdaterError, Helper::MSG_NO_CHANGE if Helper.eql?(dmp_a: latest_version, dmp_b:
|
35
|
+
raise UpdaterError, Helper::MSG_NO_CHANGE if Helper.eql?(dmp_a: latest_version, dmp_b: payload)
|
36
36
|
|
37
37
|
# Version the DMP ID record (if applicable).
|
38
38
|
owner = latest_version['dmphub_provenance_id']
|
39
39
|
updater = provenance['PK']
|
40
40
|
version = Versioner.generate_version(client:, latest_version:, owner:,
|
41
41
|
updater:, logger:)
|
42
|
+
logger&.debug(message: 'New Version', details: version)
|
42
43
|
raise UpdaterError, Helper::MSG_DMP_UNABLE_TO_VERSION if version.nil?
|
43
44
|
# Bail if the system trying to make the update is not the creator of the DMP ID
|
44
45
|
raise UpdaterError, Helper::MSG_DMP_FORBIDDEN if owner != updater
|
45
46
|
|
46
47
|
# Handle any changes to the dmphub_modifications section
|
47
|
-
version = _process_harvester_mods(client:, p_key:, json:
|
48
|
+
version = _process_harvester_mods(client:, p_key:, json: payload, version:, logger:)
|
49
|
+
logger&.debug(message: 'Version after process_harvester_mods', details: version)
|
50
|
+
raise UpdaterError, Helper::MSG_SERVER_ERROR if version.nil?
|
48
51
|
|
49
|
-
# Remove the version info
|
52
|
+
# Remove the version info any any lingering modification blocks
|
50
53
|
version.delete('dmphub_versions')
|
54
|
+
version.delete('dmphub_modifications')
|
51
55
|
|
52
|
-
# Splice the assertions
|
53
|
-
version = _process_modifications(owner:, updater:, version:, mods:, logger:)
|
54
56
|
# Set the :modified timestamps
|
55
57
|
now = Time.now.utc
|
56
58
|
version['modified'] = now.iso8601
|
@@ -67,9 +69,9 @@ module Uc3DmpId
|
|
67
69
|
logger.info(message: "Updated DMP ID: #{p_key}") if logger.respond_to?(:debug)
|
68
70
|
|
69
71
|
# Append the :dmphub_versions Array
|
70
|
-
|
71
|
-
|
72
|
-
Helper.cleanse_dmp_json(json:)
|
72
|
+
out = JSON.parse({ dmp: version }.to_json)
|
73
|
+
out = Versioner.append_versions(p_key:, dmp: out, client:, logger:)
|
74
|
+
Helper.cleanse_dmp_json(json: out)
|
73
75
|
end
|
74
76
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
75
77
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
@@ -130,24 +132,6 @@ module Uc3DmpId
|
|
130
132
|
end
|
131
133
|
# rubocop:enable Metrics/AbcSize
|
132
134
|
|
133
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
134
|
-
def _process_modifications(owner:, updater:, version:, mods:, logger: nil)
|
135
|
-
return version unless mods.is_a?(Hash) && !updater.nil?
|
136
|
-
return mods unless version.is_a?(Hash) && !owner.nil?
|
137
|
-
|
138
|
-
logger.debug(message: 'Modifications before merge.', details: mods) if logger.respond_to?(:debug)
|
139
|
-
keys_to_retain = version.keys.select do |key|
|
140
|
-
(key.start_with?('dmphub_') && !%w[dmphub_modifications dmphub_versions].include?(key)) ||
|
141
|
-
key.start_with?('PK') || key.start_with?('SK') || key.start_with?('dmproadmap_related_identifiers')
|
142
|
-
end
|
143
|
-
keys_to_retain.each do |key|
|
144
|
-
mods[key] = version[key]
|
145
|
-
end
|
146
|
-
logger.debug(message: 'Modifications after merge.', details: mods) if logger.respond_to?(:debug)
|
147
|
-
mods
|
148
|
-
end
|
149
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
150
|
-
|
151
135
|
# Once the DMP has been updated, we need to update it's DOI metadata
|
152
136
|
# -------------------------------------------------------------------------
|
153
137
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
@@ -191,32 +175,65 @@ module Uc3DmpId
|
|
191
175
|
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
192
176
|
|
193
177
|
# Fetch any Harvester modifications to the JSON
|
194
|
-
def _process_harvester_mods(client:, p_key:, json:, logger: nil)
|
195
|
-
|
178
|
+
def _process_harvester_mods(client:, p_key:, json:, version:, logger: nil)
|
179
|
+
logger&.debug(message: 'Incoming modifications', details: json)
|
180
|
+
return version if json.fetch('dmphub_modifications', []).empty?
|
196
181
|
|
197
182
|
# Fetch the `"SK": "HARVESTER_MODS"` record
|
198
183
|
client = Uc3DmpDynamo::Client.new if client.nil?
|
199
184
|
resp = client.get_item(
|
200
185
|
key: { PK: Helper.append_pk_prefix(p_key:), SK: Helper::SK_HARVESTER_MODS }, logger:
|
201
186
|
)
|
202
|
-
return
|
187
|
+
return version unless resp.is_a?(Hash) && resp['related_works'].is_a?(Hash)
|
203
188
|
|
189
|
+
logger&.debug(message: 'Original HARVESTER_MODS record', details: resp)
|
204
190
|
# The `dmphub_modifications` array will ONLY ever have things the harvester mods know about
|
205
191
|
# so just find them and update the status accordingly
|
206
|
-
|
192
|
+
original = resp.dup
|
193
|
+
json['dmproadmap_related_identifiers'] = [] if json['dmproadmap_related_identifiers'].nil?
|
194
|
+
|
207
195
|
json['dmphub_modifications'].each do |entry|
|
208
|
-
next if entry.fetch('dmproadmap_related_identifiers', []).empty?
|
196
|
+
next if entry.is_a?(Hash) && entry.fetch('dmproadmap_related_identifiers', []).empty?
|
209
197
|
|
210
198
|
entry['dmproadmap_related_identifiers'].each do |related|
|
211
|
-
|
212
|
-
|
213
|
-
|
199
|
+
# Detrmine if the HARVESTER_MODS record even knows about the mod
|
200
|
+
related_id = related.respond_to?(:identifier) ? related.identifier : related['identifier']
|
201
|
+
related_domain = related.respond_to?(:domain) ? related.domain : related['domain']
|
202
|
+
key = "#{related_domain.end_with?('/') ? related_domain : "#{related_domain}/"}#{related_id}"
|
203
|
+
key_found = original['related_works'].has_key?(key)
|
204
|
+
logger&.debug(message: "No matching HARVEST_MOD found for #{key}") unless key_found
|
205
|
+
next unless key_found
|
206
|
+
|
207
|
+
# Update the status in the HARVESTER_MODS record
|
208
|
+
logger&.debug(message: "Updating status for #{key} from #{original['related_works'][key]['status']} to #{related['status']}")
|
209
|
+
original['related_works'][key]['status'] = related['status']
|
210
|
+
|
211
|
+
existing = version['dmproadmap_related_identifiers'].select do |ri|
|
212
|
+
ri['identifier'] == key
|
213
|
+
end
|
214
|
+
|
215
|
+
# Add it if it was approved and doesn't exist in dmproadmap_related_identifiers
|
216
|
+
if related['status'] == 'approved' && existing.empty?
|
217
|
+
version['dmproadmap_related_identifiers'] << JSON.parse({
|
218
|
+
identifier: key,
|
219
|
+
work_type: related['work_type'],
|
220
|
+
type: related['type'],
|
221
|
+
descriptor: related['descriptor'],
|
222
|
+
citation: related['citation']
|
223
|
+
}.to_json)
|
224
|
+
elsif related['status'] == 'rejected' && existing.any?
|
225
|
+
# otherwise remove it
|
226
|
+
version['dmproadmap_related_identifiers'] = version['dmproadmap_related_identifiers'].reject { |ri| ri == existing.first }
|
227
|
+
end
|
214
228
|
end
|
215
229
|
end
|
216
230
|
|
217
|
-
|
218
|
-
|
219
|
-
|
231
|
+
logger&.debug(message: 'Updating HARVESTER_MODS with:', details: original)
|
232
|
+
resp = client.put_item(json: original, logger:)
|
233
|
+
logger&.error(message: 'Unable to update HARVESTER_MODS', details: original) if resp.nil?
|
234
|
+
|
235
|
+
logger&.debug(message: 'Returning updated VERSION:', details: version)
|
236
|
+
version
|
220
237
|
end
|
221
238
|
end
|
222
239
|
end
|
data/lib/uc3-dmp-id/version.rb
CHANGED