uc3-dmp-id 0.1.71 → 0.1.73

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: 06d836115caac7a07306686448df2e596b9d77f54368e4fb5f1e1f921e8c7ad6
4
- data.tar.gz: afd13d10029262be80f08cc86516292567162bbd87679fe467b0dd23c1b5d72a
3
+ metadata.gz: 30470f9547ebdbc1a5e8928be0fad068d5c3f1b485d78a4b12fc76eae53cfe67
4
+ data.tar.gz: 19a4aed6a4f3c3cd8ac29b2b8a719b4a0829d22c0b4a1cf1320640ad5868bbb7
5
5
  SHA512:
6
- metadata.gz: aef2a4c77b3ee99d13f4aac02f544b978e5f7c84495e7fedcf0588f0ffa8efe495be8dc05e984487873620b292da3f9f1bf3e33a6119bbdce26c845df3161ac0
7
- data.tar.gz: 87b47716904176310c6add2c3c7d376077ec462edfa6063b1f7f295b557c78ad4852e6bb3174a68c053b088ee1f8eefe2d43ea80f8d62ee10521fb0c83086a9c
6
+ metadata.gz: 3e7cee4b2f06b160c1a350a6d47aba1fcd0402800e6ed8a9a884dc1a6a8b6cedb7d8dacc3186c6cf51ad7e39eeff9d80e85f161c7e0662dd159457a94257d33c
7
+ data.tar.gz: 5c6d819af9a1be470da73fa98df34412a44f5f203260a5287d5c5131bc4e25478836047e5c421f19d736717495b980d88dacf13241d2e06824ae36bb9cc913fe
@@ -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
- mods = Helper.parse_json(json:).fetch('dmp', {})
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: mods) if logger.respond_to?(:debug)
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: mods['dmp'])
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: mods)
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: mods, logger:)
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
- version.delete('dmphub_versions')
52
+ payload.delete('dmphub_versions')
51
53
 
52
54
  # Splice the assertions
53
- version = _process_modifications(owner:, updater:, version:, mods:, logger:)
54
- logger&.debug(message: 'Mods after process_modifications', details: version)
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
- version['modified'] = now.iso8601
59
- version['dmphub_modification_day'] = now.strftime('%Y-%m-%d')
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: version, logger:)
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: version, logger:)
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: version }.to_json)
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?('SK') || key.start_with?('dmproadmap_related_identifiers')
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
@@ -208,19 +211,41 @@ module Uc3DmpId
208
211
  # The `dmphub_modifications` array will ONLY ever have things the harvester mods know about
209
212
  # so just find them and update the status accordingly
210
213
  original = resp.dup
214
+ json['dmproadmap_related_identifiers'] = [] if json['dmproadmap_related_identifiers'].nil?
215
+
211
216
  json['dmphub_modifications'].each do |entry|
212
217
  next if entry.fetch('dmproadmap_related_identifiers', []).empty?
213
218
 
214
219
  entry['dmproadmap_related_identifiers'].each do |related|
220
+ # Detrmine if the HARVESTER_MODS record even knows about the mod
215
221
  related_id = related.respond_to?(:identifier) ? related.identifier : related['identifier']
216
- related_domain = related.respond_to?(:identifier) ? related.domain : related['domain']
222
+ related_domain = related.respond_to?(:domain) ? related.domain : related['domain']
217
223
  key = "#{related_domain.end_with?('/') ? related_domain : "#{related_domain}/"}#{related_id}"
218
224
  key_found = original['related_works'].has_key?(key)
219
225
  logger&.debug(message: "No matching HARVEST_MOD found for #{key}") unless key_found
220
226
  next unless key_found
221
227
 
228
+ # Update the status in the HARVESTER_MODS record
222
229
  logger&.debug(message: "Updating status for #{key} from #{original['related_works'][key]['status']} to #{related['status']}")
223
230
  original['related_works'][key]['status'] = related['status']
231
+
232
+ existing = json['dmproadmap_related_identifiers'].select do |ri|
233
+ ri['identifier'] == key
234
+ end
235
+
236
+ # Add it if it was approved and doesn't exist in dmproadmap_related_identifiers
237
+ if related['status'] == 'approved' && existing.empty?
238
+ json['dmproadmap_related_identifiers'] << {
239
+ identifier: key,
240
+ work_type: related['work_type'],
241
+ type: related['type'],
242
+ descriptor: related['descriptor'],
243
+ citation: related['citation']
244
+ }.to_json
245
+ elsif exists
246
+ # otherwise remove it
247
+ json['dmproadmap_related_identifiers'] = json['dmproadmap_related_identifiers'].reject { |ri| ri == existing.first }
248
+ end
224
249
  end
225
250
  end
226
251
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.1.71'
4
+ VERSION = '0.1.73'
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.1.71
4
+ version: 0.1.73
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley