uc3-dmp-id 0.0.93 → 0.0.95
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 +6 -6
- data/lib/uc3-dmp-id/updater.rb +1 -1
- data/lib/uc3-dmp-id/version.rb +1 -1
- data/lib/uc3-dmp-id/versioner.rb +6 -5
- 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: 66da5763a8775630aa772cda55e95ea3a851b0f64e28d0c37c35e2c31d96d57e
|
4
|
+
data.tar.gz: '08ad0dcb0490ac289b674fa9d8a8fdf704a1f9a50020d42fa10d208a34f86771'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a2e0c1288b03cb7457f7bb750a3d44a673059640f2d28c4be8f33be52e2fc2fe10c1c8e4e6fde14f6e478111301236271945312a3b2d3c6b171597dfad035bd
|
7
|
+
data.tar.gz: 86af35a5e87a1bf29b814d0843e06199c351c43605d0cfc84cd2f26728ebcfaee3511766243a9d7c19247cb1be6d9b47873af8cfdb5c1a1650956e45bb6e6d85
|
data/lib/uc3-dmp-id/finder.rb
CHANGED
@@ -30,7 +30,7 @@ module Uc3DmpId
|
|
30
30
|
|
31
31
|
# Find a DMP based on the contents of the incoming JSON
|
32
32
|
# -------------------------------------------------------------------------
|
33
|
-
def by_json(json:, logger: nil)
|
33
|
+
def by_json(json:, cleanse: true, logger: nil)
|
34
34
|
json = Helper.parse_json(json: json)&.fetch('dmp', {})
|
35
35
|
raise FinderError, MSG_INVALID_ARGS if json.nil? || (json['PK'].nil? && json['dmp_id'].nil?)
|
36
36
|
|
@@ -44,12 +44,12 @@ module Uc3DmpId
|
|
44
44
|
# return by_provenance_identifier(json: json, client: client, logger: logger) if p_key.nil?
|
45
45
|
|
46
46
|
# find_by_PK
|
47
|
-
p_key.nil? ? nil : by_pk(p_key: p_key, s_key: json['SK'], client: client, logger: logger)
|
47
|
+
p_key.nil? ? nil : by_pk(p_key: p_key, s_key: json['SK'], client: client, cleanse: cleanse, logger: logger)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Find the DMP by its PK and SK
|
51
51
|
# -------------------------------------------------------------------------
|
52
|
-
def by_pk(p_key:, s_key: Helper::DMP_LATEST_VERSION, client: nil, logger: nil)
|
52
|
+
def by_pk(p_key:, s_key: Helper::DMP_LATEST_VERSION, client: nil, cleanse: true, logger: nil)
|
53
53
|
raise FinderError, MSG_MISSING_PK if p_key.nil?
|
54
54
|
|
55
55
|
s_key = Helper::DMP_LATEST_VERSION if s_key.nil? || s_key.to_s.strip.empty?
|
@@ -67,7 +67,7 @@ module Uc3DmpId
|
|
67
67
|
return nil if dmp['dmp']['PK'].nil?
|
68
68
|
|
69
69
|
dmp = Versioner.append_versions(p_key: dmp['dmp']['PK'], dmp: dmp, client: client, logger: logger)
|
70
|
-
Helper.cleanse_dmp_json(json: dmp)
|
70
|
+
cleanse ? Helper.cleanse_dmp_json(json: dmp) : dmp
|
71
71
|
end
|
72
72
|
|
73
73
|
# Fetch just the PK to see if a record exists
|
@@ -88,7 +88,7 @@ module Uc3DmpId
|
|
88
88
|
# Attempt to find the DMP item by the provenance system's identifier
|
89
89
|
# -------------------------------------------------------------------------
|
90
90
|
# rubocop:disable Metrics/AbcSize
|
91
|
-
def by_provenance_identifier(json:, client: nil, logger: nil)
|
91
|
+
def by_provenance_identifier(json:, client: nil, cleanse: true, logger: nil)
|
92
92
|
raise FinderError, MSG_MISSING_PROV_ID if json.nil? || json.fetch('dmp_id', {})['identifier'].nil?
|
93
93
|
|
94
94
|
args = {
|
@@ -110,7 +110,7 @@ module Uc3DmpId
|
|
110
110
|
return nil if dmp['dmp']['PK'].nil?
|
111
111
|
|
112
112
|
# If we got a hit, fetch the DMP and return it.
|
113
|
-
by_pk(p_key: dmp['dmp']['PK'], s_key: dmp['dmp']['SK'])
|
113
|
+
by_pk(p_key: dmp['dmp']['PK'], s_key: dmp['dmp']['SK'], cleanse: cleanse, logger: logger)
|
114
114
|
end
|
115
115
|
# rubocop:enable Metrics/AbcSize
|
116
116
|
|
data/lib/uc3-dmp-id/updater.rb
CHANGED
@@ -21,7 +21,7 @@ module Uc3DmpId
|
|
21
21
|
|
22
22
|
# fetch the existing latest version of the DMP ID
|
23
23
|
client = Uc3DmpDynamo::Client.new(logger: logger)
|
24
|
-
existing = Finder.by_pk(p_key: p_key, client: client, logger: logger)
|
24
|
+
existing = Finder.by_pk(p_key: p_key, client: client, logger: logger, cleanse: false)
|
25
25
|
logger.debug(message: "Existing latest record", details: existing) if logger.respond_to?(:debug)
|
26
26
|
|
27
27
|
errs = _updateable?(provenance: provenance, p_key: p_key, json: annotated)
|
data/lib/uc3-dmp-id/version.rb
CHANGED
data/lib/uc3-dmp-id/versioner.rb
CHANGED
@@ -36,11 +36,9 @@ module Uc3DmpId
|
|
36
36
|
puts "Provenance: #{provenance}, PK: #{p_key}"
|
37
37
|
puts dmp
|
38
38
|
|
39
|
-
return nil unless p_key.is_a?(String) && !p_key.strip.empty? && _versionable?(dmp:
|
39
|
+
return nil unless p_key.is_a?(String) && !p_key.strip.empty? && _versionable?(p_key: p_key, dmp: latest_version)
|
40
40
|
|
41
41
|
client = Uc3DmpDynamo::Client.new if client.nil?
|
42
|
-
latest_version = Finder.by_p_key(client: client, p_key: p_key) unless latest_version.is_a?(Hash) &&
|
43
|
-
!latest_version['PK'].nil?
|
44
42
|
|
45
43
|
owner = latest_version['dmphub_provenance_id']
|
46
44
|
updater = provenance['PK']
|
@@ -86,8 +84,11 @@ puts dmp
|
|
86
84
|
private
|
87
85
|
|
88
86
|
# Determine whether the specified DMP metadata is versionable - returns boolean
|
89
|
-
def _versionable?(dmp:)
|
90
|
-
|
87
|
+
def _versionable?(p_key:, dmp:)
|
88
|
+
|
89
|
+
puts "PK MATCH? #{dmp['PK'] == p_key}, SK IS LATEST? #{dmp['SK'] == Helper::DMP_LATEST_VERSION}, DMP ID PRESENT? #{!dmp.fetch('dmp_id', {})['identifier'].nil?}"
|
90
|
+
|
91
|
+
return false unless dmp.is_a?(Hash) && dmp['PK'] == p_key && dmp['SK'] == Helper::DMP_LATEST_VERSION
|
91
92
|
|
92
93
|
# It's versionable if it has a DMP ID
|
93
94
|
!dmp.fetch('dmp_id', {})['identifier'].nil?
|