uc3-dmp-id 0.1.33 → 0.1.35

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: aa5192435943869c90b3aaeb8c9628f91150ea21605589759c8a8dbd7c9f90e3
4
- data.tar.gz: 14524cbcdf3708c3239e9973227c9516cbdb3cd7e5c40f62bda7de3d2700c894
3
+ metadata.gz: 5828afe1afaf7214cdea0e02ed8b834587068be56f1f1a060050c7768c4d19a8
4
+ data.tar.gz: 10c0bb60320d71414959a9623e435d71ab52b74b758a38fc23cb7fad68f5bd3e
5
5
  SHA512:
6
- metadata.gz: 329763f4160364093199267eec3f6b4d317e35cd8c092030394db9b2c0fdbd74105749e70ee7acf5eece5e1227926d8ef45fca0804e7f5c4e31ad53a8cb90b41
7
- data.tar.gz: df6fb50d5c5249d279411c6023bb299a712d881f4e767a2b0f6ffca6b55d292fbb686cd2e163d93994133c1bf2564ec4cae347c43fed1d852f58376f33e768f4
6
+ metadata.gz: f4195fb80461a995b42d10e41ff6828aa79692d3cf92c7ce942f71f830c74d2544806a4c0ada2924d0aa7bf8c310c8b8f03a63eeacbd8754d4262aeb343f7dba
7
+ data.tar.gz: a1108d2311d8c8331b2b176278ae10d9283bdcbb0f4568c0b7d488e22268293b0356c36a51937857f709c64be89edcf2c8a8f98d74d98a66eda3c08f9ef0dea2
@@ -56,9 +56,7 @@ module Uc3DmpId
56
56
  scoring = []
57
57
  return scoring unless hash.is_a?(Hash) && !hash['title'].nil?
58
58
 
59
- @dmps.each do |entry|
60
- dmp = entry.fetch('_source', {})
61
-
59
+ @dmps.each do |dmp|
62
60
  # Compare the grant ids. If we have a match return the response immediately since that is
63
61
  # a very positive match!
64
62
  response = { confidence: 'None', score: 0, notes: [] }
@@ -79,7 +77,7 @@ module Uc3DmpId
79
77
  next if response[:score] <= 2
80
78
 
81
79
  # Set the confidence level based on the score
82
- response[:dmp_id] = entry['_id']
80
+ response[:dmp_id] = "DMP##{dmp['dmp_id']}"
83
81
  response[:confidence] = if response[:score] > 10
84
82
  'High'
85
83
  else
@@ -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,47 @@ 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
+ rec['score'] = rec['score'].to_s
250
+ # For `work-type` that equal `outputmanagementplan`, change it to `output_management_plan`
251
+ rec['work_type'] = 'output_management_plan' if rec['work_type'] == 'outputmanagementplan'
252
+
253
+ # The old `dmphub_modifications` array was grouped by provenance
254
+ prov_array = mods.select { |entry| entry['provenance'] == rec['provenance'] }
255
+ if prov_array.any?
256
+ prov_array << rec
257
+ else
258
+ mods << {
259
+ id: "#{Time.now.utc.strftime('%Y-%m-%d')}-#{SecureRandom.hex(4)}",
260
+ provenance: rec['provenance'],
261
+ augmenter_run_id: SecureRandom.hex(8),
262
+ timestamp: rec['discovered_at'].nil? ? Time.now.utc.iso8601 : rec['discovered_at'],
263
+ dmproadmap_related_identifiers: [rec],
264
+ funding: []
265
+ }
266
+ end
267
+ end
268
+ # Add a `dmphub_modifications` array to the JSON
269
+ json['dmphub_modifications'] = JSON.parse(mods.to_json)
270
+ json
271
+ end
227
272
  end
228
273
  end
229
274
  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,35 @@ 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
+
208
+ client.put_item(json: mods, logger:)
209
+ json.delete('dmphub_modifications')
210
+ json
211
+ end
180
212
  end
181
213
  end
182
214
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.1.33'
4
+ VERSION = '0.1.35'
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.33
4
+ version: 0.1.35
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-11 00:00:00.000000000 Z
11
+ date: 2024-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json