uc3-dmp-id 0.1.32 → 0.1.34

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: c916c27dc8eac1cb0ef5b40a5d3fc4e4e07ce34f1bb599f208e919442d6c7f2b
4
- data.tar.gz: 7803e305538f4cce36ca021125ae1161cd201d8db4dd25cf8fe026ae28a53011
3
+ metadata.gz: e8ed82601dab8f040bdef2ca093b8a2c90f81160c5a990533947ff3750a5d97c
4
+ data.tar.gz: 563c25f02e5c85a41960bad34687bdb4376228cce26e00a8c92024ab4f289055
5
5
  SHA512:
6
- metadata.gz: 2738c8c874bd31cef0c6726de4cafb6378c8e1aa374223a478dcfdd42be0a28d1a929e04ec797d5cfe14748bb2a07eb1a1da723b7164b2ec0e12c6942922065a
7
- data.tar.gz: 34e267e65d8db9b497a9673f355a97a21ad92820f6d8e1a98c9102017d8abce21695904bf7a8547568e0b5577364af3f86cc52c7c59ea4d37bfa528c0494d720
6
+ metadata.gz: fdd55f05e2c95cf243e8398070e9d690e4ecf7d2d35ba639f937956298e2dcb6c28e9d5600af8a846b7bc8bc0c507b1456f55a56f82f80c456a885311e64e84b
7
+ data.tar.gz: 0ae5115a0d8856b72f10f86afe311e835e6bf52a950eaf5dd87a3b4af5acae3ad72958c3198485f53ff56184df2034f6c9347d69f745ad71b4d7e9d35e670fd1
@@ -79,7 +79,7 @@ module Uc3DmpId
79
79
  dmp_id = ''
80
80
  counter = 0
81
81
  while dmp_id == '' && counter <= 10
82
- prefix = "#{ENV.fetch('DMP_ID_SHOULDER', nil)}#{SecureRandom.hex(2).upcase}#{SecureRandom.hex(2)}"
82
+ prefix = "#{ENV.fetch('DMP_ID_SHOULDER', nil)}#{SecureRandom.hex(2).upcase}#{SecureRandom.hex(2).upcase}"
83
83
  dmp_id = prefix unless Finder.exists?(client:, p_key: prefix)
84
84
  counter += 1
85
85
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'uc3-dmp-dynamo'
4
+ require 'securerandom'
4
5
 
5
6
  module Uc3DmpId
6
7
  class FinderError < StandardError; end
@@ -75,6 +76,9 @@ module Uc3DmpId
75
76
  dmp = resp['dmp'].nil? ? JSON.parse({ dmp: resp }.to_json) : resp
76
77
  return nil if dmp['dmp']['PK'].nil?
77
78
 
79
+ # Attach any harvester mods to the JSON
80
+ dmp['dmp'] = _attach_harvester_mods(client:, p_key:, json: dmp['dmp'], logger:)
81
+
78
82
  dmp = Versioner.append_versions(p_key: dmp['dmp']['PK'], dmp:, client:, logger:) if cleanse
79
83
  dmp = _remove_narrative_if_private(json: dmp)
80
84
  cleanse ? Helper.cleanse_dmp_json(json: dmp) : dmp
@@ -224,6 +228,46 @@ module Uc3DmpId
224
228
  end
225
229
  json
226
230
  end
231
+
232
+ # Fetch any Harvester modifications and attach them to the JSON in the way the DMPTool expects
233
+ # TODO: eventually just update the rebuilt DMPTool to work with the HARVESTER_MODS records as-is
234
+ def _attach_harvester_mods(client:, p_key:, json:, logger: nil)
235
+ # Fetch the `"SK": "HARVESTER_MODS"` record
236
+ client = Uc3DmpDynamo::Client.new if client.nil?
237
+ resp = client.get_item(
238
+ key: { PK: Helper.append_pk_prefix(p_key:), SK: Helper::SK_HARVESTER_MODS }, logger:
239
+ )
240
+ return json unless resp.is_a?(Hash)
241
+
242
+ mods = []
243
+ resp.fetch('related_works', {}).each do |key, val|
244
+ rec = val.dup
245
+ next if rec['provenance'].nil?
246
+
247
+ # Change the name of the `logic` array to `notes`
248
+ rec['notes'] = rec['logic']
249
+ # For `work-type` that equal `outputmanagementplan`, change it to `output_management_plan`
250
+ rec['work_type'] = 'output_management_plan' if rec['work_type'] == 'outputmanagementplan'
251
+
252
+ # The old `dmphub_modifications` array was grouped by provenance
253
+ prov_array = mods.select { |entry| entry['provenance'] == rec['provenance'] }
254
+ if prov_array.any?
255
+ prov_array << rec
256
+ else
257
+ mods << {
258
+ id: "#{Time.now.utc.strftime('%Y-%m-%d')}-#{SecureRandom.hex(4)}",
259
+ provenance: rec['provenance'],
260
+ augmenter_run_id: SecureRandom.hex(8),
261
+ timestamp: rec['discovered_at'].nil? ? Time.now.utc.iso8601 : rec['discovered_at'],
262
+ dmproadmap_related_identifiers: [rec],
263
+ funding: []
264
+ }
265
+ end
266
+ end
267
+ # Add a `dmphub_modifications` array to the JSON
268
+ json['dmphub_modifications'] = JSON.parse(mods.to_json)
269
+ json
270
+ end
227
271
  end
228
272
  end
229
273
  end
@@ -12,6 +12,8 @@ module Uc3DmpId
12
12
  SK_DMP_PREFIX = 'VERSION#'
13
13
  SK_DMP_REGEX = /VERSION#\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}/
14
14
 
15
+ SK_HARVESTER_MODS = "HARVESTER_MODS"
16
+
15
17
  # TODO: Verify the assumed structure of the DOI is valid
16
18
  DOI_REGEX = %r{[0-9]{2}\.[0-9]{4,}/[a-zA-Z0-9/_.-]+}
17
19
  URL_REGEX = %r{(https?://)?([a-zA-Z0-9\-_]\.)+[a-zA-Z0-9\-_]{2,3}(:[0-9]+)?/?}
@@ -43,6 +43,9 @@ module Uc3DmpId
43
43
  # Bail if the system trying to make the update is not the creator of the DMP ID
44
44
  raise UpdaterError, Helper::MSG_DMP_FORBIDDEN if owner != updater
45
45
 
46
+ # Handle any changes to the dmphub_modifications section
47
+ version = _process_harvester_mods(client:, p_key:, json: version, logger:)
48
+
46
49
  # Remove the version info because we don't want to save it on the record
47
50
  version.delete('dmphub_versions')
48
51
 
@@ -177,6 +180,34 @@ module Uc3DmpId
177
180
  end
178
181
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
179
182
  # rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
183
+
184
+ # Fetch any Harvester modifications to the JSON
185
+ def _process_harvester_mods(client:, p_key:, json:, logger: nil)
186
+ return json if json.fetch('dmphub_modifications', []).empty?
187
+
188
+ # Fetch the `"SK": "HARVESTER_MODS"` record
189
+ client = Uc3DmpDynamo::Client.new if client.nil?
190
+ resp = client.get_item(
191
+ key: { PK: Helper.append_pk_prefix(p_key:), SK: Helper::SK_HARVESTER_MODS }, logger:
192
+ )
193
+ return json unless resp.is_a?(Hash) && resp['related_works'].is_a?(Hash)
194
+
195
+ # The `dmphub_modifications` array will ONLY ever have things the harvester mods know about
196
+ # so just find them and update the status accordingly
197
+ mods = resp.dup
198
+ json['dmphub_modifications'].each do |entry|
199
+ next if entry.fetch('dmproadmap_related_identifiers', []).empty?
200
+
201
+ entry['dmproadmap_related_identifiers'].each do |related|
202
+ next if mods['related_works'][related.identifier].nil?
203
+
204
+ mods['related_works'][related.identifier]['status'] = related['status']
205
+ end
206
+ end
207
+ client.put_item(json: mods, logger:)
208
+ json.delete('dmphub_modifications')
209
+ json
210
+ end
180
211
  end
181
212
  end
182
213
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.1.32'
4
+ VERSION = '0.1.34'
5
5
  end
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.1.32
4
+ version: 0.1.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-02 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json