uc3-dmp-id 0.1.71 → 0.1.72
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/updater.rb +18 -15
- 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: b90c20a70e3d549ed563b01ac4548f727ff36333e017841fbcc33dd1687e1f9e
|
4
|
+
data.tar.gz: a86589814101e440390ec0c637b2a79ba8f6ee1e454cc2eeb8b51801bdbe4e5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 422bd12145eca2376172a80f8c6c66376ce4c792760d5ba4c99fabab266a7f9463831a89c0743edc76c84576c6cc0330db7c8721c765711b80f05339f4a202ba
|
7
|
+
data.tar.gz: 6f98e2324a6cd7023960dbe641da9d263baed02503645f1e32933feef751117a4de84c13c20056b9fac0d24d79c12e24ea6f1fbfa507db66b22312c3583f7ed8
|
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,48 +28,50 @@ 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
|
-
|
48
|
+
payload = _process_harvester_mods(client:, p_key:, json: payload, logger:)
|
49
|
+
logger&.debug(message: 'Mods after process_harvester_mods', details: payload)
|
48
50
|
|
49
51
|
# Remove the version info because we don't want to save it on the record
|
50
|
-
|
52
|
+
payload.delete('dmphub_versions')
|
51
53
|
|
52
54
|
# Splice the assertions
|
53
|
-
|
54
|
-
logger&.debug(message: 'Mods after process_modifications', details:
|
55
|
+
payload = _process_modifications(owner:, updater:, version:, mods: payload, logger:)
|
56
|
+
logger&.debug(message: 'Mods after process_modifications', details: payload)
|
55
57
|
|
56
58
|
# Set the :modified timestamps
|
57
59
|
now = Time.now.utc
|
58
|
-
|
59
|
-
|
60
|
+
payload['modified'] = now.iso8601
|
61
|
+
payload['dmphub_modification_day'] = now.strftime('%Y-%m-%d')
|
60
62
|
|
61
63
|
# Save the changes
|
62
|
-
resp = client.put_item(json:
|
64
|
+
resp = client.put_item(json: payload, logger:)
|
63
65
|
raise UpdaterError, Helper::MSG_DMP_UNABLE_TO_VERSION if resp.nil?
|
64
66
|
|
65
67
|
# Send the updates to EZID
|
66
|
-
_post_process(provenance:, json:
|
68
|
+
_post_process(provenance:, json: payload, logger:)
|
67
69
|
|
68
70
|
# Return the new version record
|
69
71
|
logger.info(message: "Updated DMP ID: #{p_key}") if logger.respond_to?(:debug)
|
70
72
|
|
71
73
|
# Append the :dmphub_versions Array
|
72
|
-
json = JSON.parse({ dmp:
|
74
|
+
json = JSON.parse({ dmp: payload }.to_json)
|
73
75
|
json = Versioner.append_versions(p_key:, dmp: json, client:, logger:)
|
74
76
|
Helper.cleanse_dmp_json(json:)
|
75
77
|
end
|
@@ -140,11 +142,12 @@ module Uc3DmpId
|
|
140
142
|
logger.debug(message: 'Modifications before merge.', details: mods) if logger.respond_to?(:debug)
|
141
143
|
keys_to_retain = version.keys.select do |key|
|
142
144
|
(key.start_with?('dmphub_') && !%w[dmphub_modifications dmphub_versions].include?(key)) ||
|
143
|
-
key.start_with?('PK') || key.start_with?('
|
145
|
+
key.start_with?('PK') || key.start_with?('dmproadmap_related_identifiers')
|
144
146
|
end
|
145
147
|
keys_to_retain.each do |key|
|
146
148
|
mods[key] = version[key]
|
147
149
|
end
|
150
|
+
mods['SK'] = Helper::DMP_LATEST_VERSION
|
148
151
|
logger.debug(message: 'Modifications after merge.', details: mods) if logger.respond_to?(:debug)
|
149
152
|
mods
|
150
153
|
end
|
@@ -213,7 +216,7 @@ module Uc3DmpId
|
|
213
216
|
|
214
217
|
entry['dmproadmap_related_identifiers'].each do |related|
|
215
218
|
related_id = related.respond_to?(:identifier) ? related.identifier : related['identifier']
|
216
|
-
related_domain = related.respond_to?(:
|
219
|
+
related_domain = related.respond_to?(:domain) ? related.domain : related['domain']
|
217
220
|
key = "#{related_domain.end_with?('/') ? related_domain : "#{related_domain}/"}#{related_id}"
|
218
221
|
key_found = original['related_works'].has_key?(key)
|
219
222
|
logger&.debug(message: "No matching HARVEST_MOD found for #{key}") unless key_found
|
data/lib/uc3-dmp-id/version.rb
CHANGED