uc3-dmp-id 0.0.89 → 0.0.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/uc3-dmp-id/creator.rb +11 -12
- data/lib/uc3-dmp-id/deleter.rb +11 -11
- data/lib/uc3-dmp-id/finder.rb +29 -27
- data/lib/uc3-dmp-id/splicer.rb +4 -8
- data/lib/uc3-dmp-id/updater.rb +19 -19
- data/lib/uc3-dmp-id/version.rb +1 -1
- data/lib/uc3-dmp-id/versioner.rb +20 -20
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 13c2a01e8e979f1cc3a4e9fe003cb8429d742c0e5b9d217d78e2d93bd36c276c
|
|
4
|
+
data.tar.gz: 5541be19755ac0850166d14fd4e02408d02db1e35caf83cddab527729c061a54
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d9e65edacb5d45bef33510718f50023fb14abf271859ca07910bd2b60941ebb7219e662efcead0a818141e7e2349f5e57c81e705162685dbe7cd6d736c60238
|
|
7
|
+
data.tar.gz: f5e2103aa8360d25a73ec5af6415a3087c73afdfc63c03983cbdf798e107e1bb086f0effc7c00ca3ddd71e4859e48832e03d441a2d092ff11ab4c0f0db053fcc
|
data/lib/uc3-dmp-id/creator.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Uc3DmpId
|
|
|
11
11
|
MSG_UNABLE_TO_MINT = 'Unable to mint a unique DMP ID.'
|
|
12
12
|
|
|
13
13
|
class << self
|
|
14
|
-
def create(provenance:, json:,
|
|
14
|
+
def create(provenance:, json:, logger: nil)
|
|
15
15
|
raise CreatorError, MSG_NO_SHOULDER if ENV['DMP_ID_SHOULDER'].nil?
|
|
16
16
|
raise CreatorError, MSG_NO_BASE_URL if ENV['DMP_ID_BASE_URL'].nil?
|
|
17
17
|
|
|
@@ -28,30 +28,29 @@ module Uc3DmpId
|
|
|
28
28
|
|
|
29
29
|
# TODO: Swap this out with the Finder search once the Dynamo indexes are working
|
|
30
30
|
# Try to find it first and Fail if found
|
|
31
|
-
result = Finder.by_json(json: json,
|
|
31
|
+
result = Finder.by_json(json: json, logger: logger)
|
|
32
32
|
raise CreatorError, Uc3DmpId::MSG_DMP_EXISTS if result.is_a?(Hash)
|
|
33
33
|
# raise CreatorError, Uc3DmpId::MSG_DMP_EXISTS unless json['PK'].nil?
|
|
34
34
|
|
|
35
|
-
client = Uc3DmpDynamo::Client.new
|
|
36
|
-
p_key = _preregister_dmp_id(client: client, provenance: provenance, json: json,
|
|
35
|
+
client = Uc3DmpDynamo::Client.new
|
|
36
|
+
p_key = _preregister_dmp_id(client: client, provenance: provenance, json: json, logger: logger)
|
|
37
37
|
raise CreatorError, MSG_UNABLE_TO_MINT if p_key.nil?
|
|
38
38
|
|
|
39
39
|
# Add the DMPHub specific attributes and then save
|
|
40
40
|
annotated = Helper.annotate_dmp_json(provenance: provenance, p_key: p_key, json: json['dmp'])
|
|
41
|
-
|
|
42
|
-
puts annotated if debug
|
|
41
|
+
logger.info(message: "Creating DMP ID: #{p_key}") if logger.respond_to?(:debug)
|
|
43
42
|
|
|
44
43
|
# Create the item
|
|
45
|
-
resp = client.put_item(json: annotated,
|
|
44
|
+
resp = client.put_item(json: annotated, logger: logger)
|
|
46
45
|
raise CreatorError, Uc3DmpId::MSG_DMP_NO_DMP_ID if resp.nil?
|
|
47
46
|
|
|
48
|
-
_post_process(json: annotated,
|
|
47
|
+
_post_process(json: annotated, logger: logger)
|
|
49
48
|
Helper.cleanse_dmp_json(json: JSON.parse({ dmp: annotated }.to_json))
|
|
50
49
|
end
|
|
51
50
|
|
|
52
51
|
private
|
|
53
52
|
|
|
54
|
-
def _preregister_dmp_id(client:, provenance:, json:,
|
|
53
|
+
def _preregister_dmp_id(client:, provenance:, json:, logger: nil)
|
|
55
54
|
# Use the specified DMP ID if the provenance has permission
|
|
56
55
|
existing = json.fetch('dmp', {}).fetch('dmp_id', {})
|
|
57
56
|
seed_id = json.fetch('dmp', {})['dmproadmap_external_system_identifier']
|
|
@@ -72,7 +71,7 @@ module Uc3DmpId
|
|
|
72
71
|
# Something went wrong and it was unable to identify a unique id
|
|
73
72
|
raise CreatorError, MSG_UNABLE_TO_MINT if counter >= 10
|
|
74
73
|
|
|
75
|
-
|
|
74
|
+
logger.debug(message: "Preregistration DMP ID: #{dmp_id}") if logger.respond_to?(:debug)
|
|
76
75
|
url = ENV['DMP_ID_BASE_URL'].gsub(%r{https?://}, '')
|
|
77
76
|
"#{Helper::PK_DMP_PREFIX}#{url.end_with?('/') ? url : "#{url}/"}#{dmp_id}"
|
|
78
77
|
end
|
|
@@ -81,14 +80,14 @@ module Uc3DmpId
|
|
|
81
80
|
# Once the DMP has been created, we need to register it's DMP ID and download any
|
|
82
81
|
# PDF if applicable
|
|
83
82
|
# -------------------------------------------------------------------------
|
|
84
|
-
def _post_process(json:,
|
|
83
|
+
def _post_process(json:, logger: nil)
|
|
85
84
|
return false unless json.is_a?(Hash)
|
|
86
85
|
|
|
87
86
|
# We are creating, so this is always true
|
|
88
87
|
json['dmphub_updater_is_provenance'] = true
|
|
89
88
|
# Publish the change to the EventBridge
|
|
90
89
|
publisher = Uc3DmpEventBridge::Publisher.new
|
|
91
|
-
publisher.publish(source: 'DmpCreator', dmp: json,
|
|
90
|
+
publisher.publish(source: 'DmpCreator', dmp: json, logger: logger)
|
|
92
91
|
true
|
|
93
92
|
end
|
|
94
93
|
end
|
data/lib/uc3-dmp-id/deleter.rb
CHANGED
|
@@ -9,15 +9,15 @@ module Uc3DmpId
|
|
|
9
9
|
# Delete/Tombstone a record in the table
|
|
10
10
|
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
11
11
|
# -------------------------------------------------------------------------
|
|
12
|
-
def tombstone(provenance:, p_key:,
|
|
12
|
+
def tombstone(provenance:, p_key:, logger: nil)
|
|
13
13
|
raise DeleterError, MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
|
|
14
14
|
|
|
15
15
|
# Fail if the provenance is not defined
|
|
16
16
|
raise DeleterError, MSG_DMP_FORBIDDEN unless provenance.is_a?(Hash) && !provenance['PK'].nil?
|
|
17
17
|
|
|
18
18
|
# Fetch the latest version of the DMP ID by it's PK
|
|
19
|
-
client = Uc3DmpDynamo::Client.new
|
|
20
|
-
dmp = Finder.by_pk(p_key: p_key, client: client,
|
|
19
|
+
client = Uc3DmpDynamo::Client.new
|
|
20
|
+
dmp = Finder.by_pk(p_key: p_key, client: client, logger: logger)
|
|
21
21
|
raise DeleterError, MSG_DMP_NOT_FOUND unless dmp.is_a?(Hash) && !dmp['dmp'].nil?
|
|
22
22
|
|
|
23
23
|
# Only allow this if the provenance is the owner of the DMP!
|
|
@@ -29,25 +29,25 @@ module Uc3DmpId
|
|
|
29
29
|
dmp['dmp']['SK'] = Helper::DMP_TOMBSTONE_VERSION
|
|
30
30
|
dmp['dmp']['dmphub_tombstoned_at'] = Time.now.iso8601
|
|
31
31
|
dmp['dmp']['title'] = "OBSOLETE: #{dmp['title']}"
|
|
32
|
-
|
|
32
|
+
logger.info(message: "Tomstoning DMP ID: #{p_key}") if logger.respond_to?(:debug)
|
|
33
33
|
|
|
34
34
|
# Create the Tombstone version
|
|
35
|
-
resp = client.put_item(json: dmp,
|
|
35
|
+
resp = client.put_item(json: dmp, logger: logger)
|
|
36
36
|
raise DeleterError, MSG_DMP_NO_TOMBSTONE if resp.nil?
|
|
37
37
|
|
|
38
38
|
# Delete the Latest version
|
|
39
|
-
resp = client.delete_item(p_key: p_key, s_key: Helper::SK_DMP_PREFIX,
|
|
39
|
+
resp = client.delete_item(p_key: p_key, s_key: Helper::SK_DMP_PREFIX, logger: logger)
|
|
40
40
|
|
|
41
41
|
# TODO: We should do a check here to see if it was successful!
|
|
42
42
|
puts resp.inspect
|
|
43
43
|
|
|
44
44
|
# Notify EZID about the removal
|
|
45
|
-
_post_process(json: dmp,
|
|
45
|
+
_post_process(json: dmp, logger: logger)
|
|
46
46
|
# Return the tombstoned record
|
|
47
47
|
Helper.cleanse_dmp_json(json: JSON.parse({ dmp: dmp }.to_json))
|
|
48
48
|
rescue Aws::Errors::ServiceError => e
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
puts "ERROR in Uc3DmpId::Deleter - #{e.message}"
|
|
50
|
+
puts e.backtrace
|
|
51
51
|
{ status: 500, error: Messages::MSG_SERVER_ERROR }
|
|
52
52
|
end
|
|
53
53
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
@@ -56,14 +56,14 @@ puts resp.inspect
|
|
|
56
56
|
|
|
57
57
|
# Once the DMP has been tombstoned, we need to notify EZID
|
|
58
58
|
# -------------------------------------------------------------------------
|
|
59
|
-
def _post_process(json:,
|
|
59
|
+
def _post_process(json:, logger: nil)
|
|
60
60
|
return false unless json.is_a?(Hash)
|
|
61
61
|
|
|
62
62
|
# Indicate whether or not the updater is the provenance system
|
|
63
63
|
json['dmphub_updater_is_provenance'] = true
|
|
64
64
|
# Publish the change to the EventBridge
|
|
65
65
|
publisher = Uc3DmpEventBridge::Publisher.new
|
|
66
|
-
publisher.publish(source: 'DmpDeleter', dmp: json,
|
|
66
|
+
publisher.publish(source: 'DmpDeleter', dmp: json, logger: logger)
|
|
67
67
|
true
|
|
68
68
|
end
|
|
69
69
|
end
|
data/lib/uc3-dmp-id/finder.rb
CHANGED
|
@@ -19,10 +19,10 @@ module Uc3DmpId
|
|
|
19
19
|
|
|
20
20
|
class << self
|
|
21
21
|
# TODO: Replace this with ElasticSearch
|
|
22
|
-
def search_dmps(args:,
|
|
23
|
-
return _by_owner(owner_org: args['owner_orcid'],
|
|
24
|
-
return _by_owner_org(owner_org: args['owner_org_ror'],
|
|
25
|
-
return _by_mod_day(day: args['modification_day'],
|
|
22
|
+
def search_dmps(args:, logger: nil)
|
|
23
|
+
return _by_owner(owner_org: args['owner_orcid'], logger: logger) unless args['owner_orcid'].nil?
|
|
24
|
+
return _by_owner_org(owner_org: args['owner_org_ror'], logger: logger) unless args['owner_org_ror'].nil?
|
|
25
|
+
return _by_mod_day(day: args['modification_day'], logger: logger) unless args['modification_day'].nil?
|
|
26
26
|
|
|
27
27
|
[]
|
|
28
28
|
end
|
|
@@ -30,63 +30,65 @@ module Uc3DmpId
|
|
|
30
30
|
|
|
31
31
|
# Find a DMP based on the contents of the incoming JSON
|
|
32
32
|
# -------------------------------------------------------------------------
|
|
33
|
-
def by_json(json:,
|
|
33
|
+
def by_json(json:, 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
|
|
|
37
37
|
p_key = json['PK']
|
|
38
38
|
# Translate the incoming :dmp_id into a PK
|
|
39
39
|
p_key = Helper.dmp_id_to_pk(json: json.fetch('dmp_id', {})) if p_key.nil?
|
|
40
|
-
client = client.nil? ? Uc3DmpDynamo::Client.new
|
|
40
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
|
41
41
|
|
|
42
42
|
# TODO: Re-enable this once we figure out Dynamo indexes
|
|
43
43
|
# find_by_dmphub_provenance_id -> if no PK and no dmp_id result
|
|
44
|
-
# return by_provenance_identifier(json: json, client: client,
|
|
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,
|
|
47
|
+
p_key.nil? ? nil : by_pk(p_key: p_key, s_key: json['SK'], client: client, 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,
|
|
52
|
+
def by_pk(p_key:, s_key: Helper::DMP_LATEST_VERSION, client: nil, 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?
|
|
56
|
-
client = client.nil? ? Uc3DmpDynamo::Client.new
|
|
56
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
|
57
57
|
resp = client.get_item(
|
|
58
58
|
key: {
|
|
59
59
|
PK: Helper.append_pk_prefix(p_key: p_key),
|
|
60
60
|
SK: s_key
|
|
61
|
-
}
|
|
61
|
+
},
|
|
62
|
+
logger: logger
|
|
62
63
|
)
|
|
63
64
|
return resp unless resp.is_a?(Hash)
|
|
64
65
|
|
|
65
66
|
dmp = resp['dmp'].nil? ? JSON.parse({ dmp: resp }.to_json) : resp
|
|
66
67
|
return nil if dmp['dmp']['PK'].nil?
|
|
67
68
|
|
|
68
|
-
dmp = Versioner.append_versions(p_key: dmp['dmp']['PK'], dmp: dmp, client: client,
|
|
69
|
+
dmp = Versioner.append_versions(p_key: dmp['dmp']['PK'], dmp: dmp, client: client, logger: logger)
|
|
69
70
|
Helper.cleanse_dmp_json(json: dmp)
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
# Fetch just the PK to see if a record exists
|
|
73
74
|
# -------------------------------------------------------------------------
|
|
74
|
-
def exists?(p_key:, s_key: Helper::DMP_LATEST_VERSION, client: nil)
|
|
75
|
+
def exists?(p_key:, s_key: Helper::DMP_LATEST_VERSION, client: nil, logger: nil)
|
|
75
76
|
raise FinderError, MSG_MISSING_PK if p_key.nil?
|
|
76
77
|
|
|
77
|
-
client = client.nil? ? Uc3DmpDynamo::Client.new
|
|
78
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
|
78
79
|
client.pk_exists?(
|
|
79
80
|
key: {
|
|
80
81
|
PK: Helper.append_pk_prefix(p_key: p_key),
|
|
81
82
|
SK: s_key
|
|
82
|
-
}
|
|
83
|
+
},
|
|
84
|
+
logger: logger
|
|
83
85
|
)
|
|
84
86
|
end
|
|
85
87
|
|
|
86
88
|
# Attempt to find the DMP item by the provenance system's identifier
|
|
87
89
|
# -------------------------------------------------------------------------
|
|
88
90
|
# rubocop:disable Metrics/AbcSize
|
|
89
|
-
def by_provenance_identifier(json:, client: nil,
|
|
91
|
+
def by_provenance_identifier(json:, client: nil, logger: nil)
|
|
90
92
|
raise FinderError, MSG_MISSING_PROV_ID if json.nil? || json.fetch('dmp_id', {})['identifier'].nil?
|
|
91
93
|
|
|
92
94
|
args = {
|
|
@@ -100,8 +102,8 @@ module Uc3DmpId
|
|
|
100
102
|
filter_expression: 'SK = :version',
|
|
101
103
|
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
|
102
104
|
}
|
|
103
|
-
client = client.nil? ? Uc3DmpDynamo::Client.new
|
|
104
|
-
resp = client.query(args: args)
|
|
105
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
|
106
|
+
resp = client.query(args: args, logger: logger)
|
|
105
107
|
return resp unless resp.is_a?(Hash)
|
|
106
108
|
|
|
107
109
|
dmp = resp['dmp'].nil? ? JSON.parse({ dmp: resp }.to_json) : resp
|
|
@@ -115,7 +117,7 @@ module Uc3DmpId
|
|
|
115
117
|
private
|
|
116
118
|
|
|
117
119
|
# Fetch the DMP IDs for the specified owner's ORCID (the owner is the :dmphub_owner_id on the DMP ID record)
|
|
118
|
-
def _by_owner(owner_id:,
|
|
120
|
+
def _by_owner(owner_id:, logger: nil)
|
|
119
121
|
regex = %r{^([0-9A-Z]{4}-){3}[0-9A-Z]{4}$}
|
|
120
122
|
raise FinderError, MSG_INVALID_OWNER_ID if owner_id.nil? || (owner_id.to_s.downcase =~ regex).nil?
|
|
121
123
|
|
|
@@ -134,12 +136,12 @@ module Uc3DmpId
|
|
|
134
136
|
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
|
135
137
|
}
|
|
136
138
|
puts "Querying _by_owner with #{args}" if debug
|
|
137
|
-
client = client.nil? ? Uc3DmpDynamo::Client.new
|
|
138
|
-
_process_search_response(response: client.query(args: args))
|
|
139
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
|
140
|
+
_process_search_response(response: client.query(args: args, logger: logger))
|
|
139
141
|
end
|
|
140
142
|
|
|
141
143
|
# Fetch the DMP IDs for the specified organization/institution (the org is the :dmphub_owner_org on the DMP ID record)
|
|
142
|
-
def _by_owner_org(owner_org:,
|
|
144
|
+
def _by_owner_org(owner_org:, logger: nil)
|
|
143
145
|
regex = %r{^[a-zA-Z0-9]+$}
|
|
144
146
|
raise FinderError, MSG_INVALID_OWNER_ID if owner_org.nil? ||(owner_org.to_s.downcase =~ regex).nil?
|
|
145
147
|
|
|
@@ -158,12 +160,12 @@ module Uc3DmpId
|
|
|
158
160
|
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
|
159
161
|
}
|
|
160
162
|
puts "Querying _by_owner_org with #{args}" if debug
|
|
161
|
-
client = client.nil? ? Uc3DmpDynamo::Client.new
|
|
162
|
-
_process_search_response(response: client.query(args: args))
|
|
163
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
|
164
|
+
_process_search_response(response: client.query(args: args, logger: logger))
|
|
163
165
|
end
|
|
164
166
|
|
|
165
167
|
# Fetch the DMP IDs modified on the specified date (the date is the :dmphub_modification_day on the DMP ID record)
|
|
166
|
-
def _by_mod_day(day:,
|
|
168
|
+
def _by_mod_day(day:, logger: nil)
|
|
167
169
|
regex = %r{^[0-9]{4}(-[0-9]{2}){2}}
|
|
168
170
|
raise FinderError, MSG_INVALID_OWNER_ID if day.nil? || (day.to_s =~ regex).nil?
|
|
169
171
|
|
|
@@ -179,8 +181,8 @@ module Uc3DmpId
|
|
|
179
181
|
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
|
180
182
|
}
|
|
181
183
|
puts "Querying _by_mod_day with #{args}" if debug
|
|
182
|
-
client = client.nil? ? Uc3DmpDynamo::Client.new
|
|
183
|
-
_process_search_response(response: client.query(args: args))
|
|
184
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
|
185
|
+
_process_search_response(response: client.query(args: args, logger: logger))
|
|
184
186
|
end
|
|
185
187
|
|
|
186
188
|
|
data/lib/uc3-dmp-id/splicer.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Uc3DmpId
|
|
|
9
9
|
# --------------------------------------------------------------
|
|
10
10
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
11
11
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
12
|
-
def splice_for_owner(owner:, updater:, base:, mods:,
|
|
12
|
+
def splice_for_owner(owner:, updater:, base:, mods:, logger: nil)
|
|
13
13
|
return base if owner.nil? || updater.nil? || mods.nil?
|
|
14
14
|
return mods if base.nil?
|
|
15
15
|
|
|
@@ -39,9 +39,7 @@ module Uc3DmpId
|
|
|
39
39
|
spliced['dmproadmap_related_identifiers'] = mod_relateds
|
|
40
40
|
spliced['dmproadmap_related_identifiers'] << other_relateds if other_relateds.any?
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
puts spliced if debug
|
|
44
|
-
|
|
42
|
+
logger.debug(message: "JSON after splicing in changes from provenance", details: spliced) if logger.respond_to?(:debug)
|
|
45
43
|
spliced
|
|
46
44
|
end
|
|
47
45
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
@@ -50,7 +48,7 @@ module Uc3DmpId
|
|
|
50
48
|
# Splice changes from the other system onto the system of provenance and other system's changes
|
|
51
49
|
# --------------------------------------------------------------
|
|
52
50
|
# rubocop:disable Metrics/AbcSize
|
|
53
|
-
def splice_for_others(owner:, updater:, base:, mods:,
|
|
51
|
+
def splice_for_others(owner:, updater:, base:, mods:, logger: nil)
|
|
54
52
|
return base if owner.nil? || updater.nil? || base.nil? || mods.nil?
|
|
55
53
|
|
|
56
54
|
spliced = Helper.deep_copy_dmp(obj: base)
|
|
@@ -71,9 +69,7 @@ module Uc3DmpId
|
|
|
71
69
|
updater: updater, base: base_relateds, mods: mod_relateds
|
|
72
70
|
)
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
puts spliced if debug
|
|
76
|
-
|
|
72
|
+
logger.debug(message: "JSON after splicing in changes from non-provenance", details: spliced) if logger.respond_to?(:debug)
|
|
77
73
|
spliced
|
|
78
74
|
end
|
|
79
75
|
# rubocop:enable Metrics/AbcSize
|
data/lib/uc3-dmp-id/updater.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Uc3DmpId
|
|
|
9
9
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
10
10
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
11
11
|
# -------------------------------------------------------------------------
|
|
12
|
-
def update(provenance:, p_key:, json: {},
|
|
12
|
+
def update(provenance:, p_key:, json: {}, logger: nil)
|
|
13
13
|
raise UpdaterError, MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
|
|
14
14
|
|
|
15
15
|
dmp = Helper.parse_json(json: json)
|
|
@@ -17,45 +17,44 @@ module Uc3DmpId
|
|
|
17
17
|
|
|
18
18
|
# Add the DMPHub specific attributes
|
|
19
19
|
annotated = Helper.annotate_dmp_json(provenance: provenance, p_key: p_key, json: dmp['dmp'])
|
|
20
|
-
|
|
21
|
-
puts 'Annotated:'
|
|
22
|
-
puts annotated
|
|
20
|
+
logger.debug(message: "Incoming JSON after annotation", details: annotated) if logger.respond_to?(:debug)
|
|
23
21
|
|
|
24
22
|
# fetch the existing latest version of the DMP ID
|
|
25
|
-
client = Uc3DmpDynamo::Client.new(
|
|
26
|
-
existing = Finder.by_pk(p_key: p_key, client: client,
|
|
23
|
+
client = Uc3DmpDynamo::Client.new(logger: logger)
|
|
24
|
+
existing = Finder.by_pk(p_key: p_key, client: client, logger: logger)
|
|
25
|
+
logger.debug(message: "Existing latest record", details: existing) if logger.respond_to?(:debug)
|
|
26
|
+
|
|
27
27
|
errs = _updateable?(provenance: provenance, p_key: p_key, json: annotated)
|
|
28
28
|
raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
|
|
29
29
|
# Don't continue if nothing has changed!
|
|
30
30
|
raise UpdaterError, MSG_NO_CHANGE if Helper.eql?(dmp_a: existing, dmp_b: dmp)
|
|
31
31
|
|
|
32
32
|
# Generate a new version of the DMP. This involves versioning the current latest version
|
|
33
|
-
new_version = Versioner.new_version(provenance: provenance, p_key: p_key, client: client,
|
|
33
|
+
new_version = Versioner.new_version(provenance: provenance, p_key: p_key, client: client, logger: logger,
|
|
34
34
|
dmp: dmp, latest_version: existing)
|
|
35
|
-
|
|
36
|
-
puts 'New version:'
|
|
37
|
-
puts new_version
|
|
38
|
-
|
|
35
|
+
logger.debug(message: "New version", details: new_version) if logger.respond_to?(:debug)
|
|
39
36
|
raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if new_version.nil?
|
|
40
37
|
|
|
41
38
|
# Save the changes as the new latest version
|
|
42
|
-
resp = client.put_item(json: new_version,
|
|
39
|
+
resp = client.put_item(json: new_version, logger: logger)
|
|
43
40
|
raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
|
|
44
41
|
|
|
45
42
|
# Send the updates to EZID, notify the provenance and download the PDF if applicable
|
|
46
|
-
_post_process(json: dmp,
|
|
43
|
+
_post_process(json: dmp, logger: logger)
|
|
47
44
|
# Return the new version record
|
|
45
|
+
logger.info(message: "Updated DMP ID: #{p_key}") if logger.respond_to?(:debug)
|
|
48
46
|
Helper.cleanse_dmp_json(json: JSON.parse({ dmp: new_version }.to_json))
|
|
49
47
|
end
|
|
50
48
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
51
49
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
52
50
|
|
|
53
|
-
def attach_narrative(provenance:, p_key:, url:,
|
|
51
|
+
def attach_narrative(provenance:, p_key:, url:, logger: nil)
|
|
54
52
|
raise UpdaterError, MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
|
|
55
53
|
|
|
56
54
|
# fetch the existing latest version of the DMP ID
|
|
57
|
-
client = Uc3DmpDynamo::Client.new(
|
|
58
|
-
dmp = Finder.by_pk(p_key: p_key, client: client,
|
|
55
|
+
client = Uc3DmpDynamo::Client.new(logger: logger)
|
|
56
|
+
dmp = Finder.by_pk(p_key: p_key, client: client, logger: logger)
|
|
57
|
+
logger.info(message: "Existing latest record", details: dmp) if logger.respond_to?(:debug)
|
|
59
58
|
|
|
60
59
|
errs = _updateable?(provenance: provenance, p_key: p_key, json: dmp['dmp'])
|
|
61
60
|
raise UpdaterError, errs if errs.is_a?(Array) && errs.any?
|
|
@@ -68,9 +67,10 @@ puts new_version
|
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
# Save the changes without creating a new version!
|
|
71
|
-
resp = client.put_item(json: annotated,
|
|
70
|
+
resp = client.put_item(json: annotated, logger: logger)
|
|
72
71
|
raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
|
|
73
72
|
|
|
73
|
+
logger.info(message: "Added DMP ID narrative for PK: #{p_key}, Narrative: #{url}") if logger.respond_to?(:debug)
|
|
74
74
|
true
|
|
75
75
|
end
|
|
76
76
|
|
|
@@ -90,14 +90,14 @@ puts new_version
|
|
|
90
90
|
|
|
91
91
|
# Once the DMP has been updated, we need to register it's DMP ID and download any PDF if applicable
|
|
92
92
|
# -------------------------------------------------------------------------
|
|
93
|
-
def _post_process(json:,
|
|
93
|
+
def _post_process(json:, logger: nil)
|
|
94
94
|
return false unless json.is_a?(Hash)
|
|
95
95
|
|
|
96
96
|
# Indicate whether or not the updater is the provenance system
|
|
97
97
|
json['dmphub_updater_is_provenance'] = @provenance['PK'] == json['dmphub_provenance_id']
|
|
98
98
|
# Publish the change to the EventBridge
|
|
99
99
|
publisher = Uc3DmpEventBridge::Publisher.new
|
|
100
|
-
publisher.publish(source: 'DmpUpdater', dmp: json,
|
|
100
|
+
publisher.publish(source: 'DmpUpdater', dmp: json, logger: logger)
|
|
101
101
|
true
|
|
102
102
|
end
|
|
103
103
|
end
|
data/lib/uc3-dmp-id/version.rb
CHANGED
data/lib/uc3-dmp-id/versioner.rb
CHANGED
|
@@ -6,11 +6,13 @@ module Uc3DmpId
|
|
|
6
6
|
class VersionerError < StandardError; end
|
|
7
7
|
|
|
8
8
|
class Versioner
|
|
9
|
+
SOURCE = 'Uc3DmpId::Versioner'
|
|
10
|
+
|
|
9
11
|
class << self
|
|
10
12
|
|
|
11
13
|
# Find the DMP ID's versions
|
|
12
14
|
# -------------------------------------------------------------------------
|
|
13
|
-
def get_versions(p_key:, client: nil,
|
|
15
|
+
def get_versions(p_key:, client: nil, logger: nil)
|
|
14
16
|
return [] unless p_key.is_a?(String) && !p_key.strip.empty?
|
|
15
17
|
|
|
16
18
|
args = {
|
|
@@ -20,8 +22,8 @@ module Uc3DmpId
|
|
|
20
22
|
projection_expression: 'modified',
|
|
21
23
|
scan_index_forward: false
|
|
22
24
|
}
|
|
23
|
-
client = client.nil? ? Uc3DmpDynamo::Client.new
|
|
24
|
-
client.query(args: args,
|
|
25
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
|
26
|
+
client.query(args: args, logger: logger)
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
# Create a new version of the DMP. This involves:
|
|
@@ -29,10 +31,10 @@ module Uc3DmpId
|
|
|
29
31
|
# - Saving the new `VERSION=yyyy-mm-ddThh:mm:ss+zz:zz` item
|
|
30
32
|
# - Splicing in the current changes onto the existing `VERSION#latest` item
|
|
31
33
|
# - Returning the spliced `VERSION#latest` back to this method
|
|
32
|
-
def new_version(provenance:, p_key:, client: nil, dmp:, latest_version: {},
|
|
34
|
+
def new_version(provenance:, p_key:, client: nil, dmp:, latest_version: {}, logger: nil)
|
|
33
35
|
return nil unless p_key.is_a?(String) && !p_key.strip.empty? && _versionable?(dmp: dmp)
|
|
34
36
|
|
|
35
|
-
client = Uc3DmpDynamo::Client.new(
|
|
37
|
+
client = Uc3DmpDynamo::Client.new(logger: logger) if client.nil?
|
|
36
38
|
latest_version = Finder.by_p_key(client: client, p_key: p_key) unless latest_version.is_a?(Hash) &&
|
|
37
39
|
!latest_version['PK'].nil?
|
|
38
40
|
|
|
@@ -44,11 +46,9 @@ module Uc3DmpId
|
|
|
44
46
|
prior = _generate_version(client: client, latest_version: latest, owner: owner, updater: updater)
|
|
45
47
|
return nil if prior.nil?
|
|
46
48
|
|
|
47
|
-
args = { owner: owner, updater: updater, base: prior, mods: dmp,
|
|
48
|
-
|
|
49
|
-
puts dmp if debug
|
|
49
|
+
args = { owner: owner, updater: updater, base: prior, mods: dmp, logger: logger }
|
|
50
|
+
logger.debug(message: "#{SOURCE} record prior to splicing", details: dmp) if logger.respond_to?(:debug)
|
|
50
51
|
|
|
51
|
-
args = { owner: owner, updater: updater, base: prior, mods: dmp, debug: debug }
|
|
52
52
|
# If the system of provenance is making the change then just use the
|
|
53
53
|
# new version as the base and then splice in any mods made by others
|
|
54
54
|
# args = args.merge({ base: new_version, mods: original_version })
|
|
@@ -56,16 +56,18 @@ module Uc3DmpId
|
|
|
56
56
|
# Otherwise use the original version as the base and then update the
|
|
57
57
|
# metadata owned by the updater system
|
|
58
58
|
new_version = Splicer.splice_for_others(args) if new_version.nil?
|
|
59
|
+
|
|
60
|
+
logger.debug(message: "#{SOURCE} record after splicing", details: new_version) if logger.respond_to?(:debug)
|
|
59
61
|
new_version
|
|
60
62
|
end
|
|
61
63
|
|
|
62
64
|
# Build the :dmphub_versions array and attach it to the DMP JSON
|
|
63
65
|
# rubocop:disable Metrics/AbcSize
|
|
64
|
-
def append_versions(p_key:, dmp:, client: nil,
|
|
66
|
+
def append_versions(p_key:, dmp:, client: nil, logger: nil)
|
|
65
67
|
json = Helper.parse_json(json: dmp)
|
|
66
68
|
return json unless p_key.is_a?(String) && !p_key.strip.empty? && json.is_a?(Hash) && !json['dmp'].nil?
|
|
67
69
|
|
|
68
|
-
results = get_versions(p_key: p_key, client: client,
|
|
70
|
+
results = get_versions(p_key: p_key, client: client, logger: logger)
|
|
69
71
|
return json unless results.length > 1
|
|
70
72
|
|
|
71
73
|
versions = results.map do |ver|
|
|
@@ -92,28 +94,26 @@ module Uc3DmpId
|
|
|
92
94
|
|
|
93
95
|
# Generate a version
|
|
94
96
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
95
|
-
def _generate_version(client:, latest_version:, owner:, updater:,
|
|
97
|
+
def _generate_version(client:, latest_version:, owner:, updater:, logger: nil)
|
|
96
98
|
# Only create a version if the Updater is not the Owner OR the changes have happened on a different day
|
|
97
99
|
mod_time = Time.parse(latest_version.fetch('dmphub_updated_at', Time.now.iso8601))
|
|
98
100
|
now = Time.now
|
|
99
|
-
|
|
100
|
-
puts "_generate_version -- mod_time: #{mod_time} --> !(now - mod_time).is_a?(Float)"
|
|
101
|
-
|
|
101
|
+
logger.debug(message: "#{SOURCE} generating version - mod_time: #{mod_time}") if logger.respond_to?(:debug)
|
|
102
102
|
return latest_version if mod_time.nil? || !(now - mod_time).is_a?(Float)
|
|
103
103
|
|
|
104
104
|
same_hour = (now - mod_time).round <= 3600
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
logger.debug(message: "#{SOURCE} same owner and updater? #{owner == updater}") if logger.respond_to?(:debug)
|
|
106
|
+
logger.debug(message: "#{SOURCE} already updated within the past hour? #{same_hour}") if logger.respond_to?(:debug)
|
|
108
107
|
return latest_version if owner != updater || (owner == updater && same_hour)
|
|
109
108
|
|
|
110
109
|
latest_version['SK'] = "#{Helper::SK_DMP_PREFIX}#{latest_version['dmphub_updated_at'] || Time.now.iso8601}"
|
|
111
|
-
|
|
112
110
|
# Create the prior version record
|
|
113
|
-
resp = client.put_item(json: latest_version,
|
|
111
|
+
resp = client.put_item(json: latest_version, logger: logger)
|
|
114
112
|
return nil if resp.nil?
|
|
115
113
|
|
|
116
114
|
puts "Created new version #{latest_version['PK']} - #{latest_version['SK']}" if debug
|
|
115
|
+
msg = "#{SOURCE} created version PK: #{latest_version['PK']} SK: #{latest_version['SK']}"
|
|
116
|
+
logger.info(message: msg, details: latest_version) if logger.respond_to?(:debug)
|
|
117
117
|
latest_version
|
|
118
118
|
end
|
|
119
119
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
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.0.
|
|
4
|
+
version: 0.0.90
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Riley
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-07-
|
|
11
|
+
date: 2023-07-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|