uc3-dmp-id 0.1.0 → 0.1.1
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/README.md +9 -0
- data/lib/uc3-dmp-id/asserter.rb +7 -7
- data/lib/uc3-dmp-id/creator.rb +10 -10
- data/lib/uc3-dmp-id/deleter.rb +5 -5
- data/lib/uc3-dmp-id/finder.rb +26 -26
- data/lib/uc3-dmp-id/helper.rb +16 -16
- data/lib/uc3-dmp-id/updater.rb +25 -24
- data/lib/uc3-dmp-id/validator.rb +2 -2
- data/lib/uc3-dmp-id/version.rb +1 -1
- data/lib/uc3-dmp-id/versioner.rb +7 -7
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d78c65551789e0b3e96488bb2c3689999a301c76a8434f945f7b855dd62d57d
|
4
|
+
data.tar.gz: 73fe134b92ebe24bf9595610f3ef9e7f8dc744a3494152d9e7a6e7e73675b075
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fb32754f0e36c6292860e35327a9af48b566bae061eb0d08a8e4f94b9976144acae3b948837f7b1835e918d20d06971085091db81d5483ba494c51fd5279d68
|
7
|
+
data.tar.gz: 889bd0b3cbe91b95a534930b267625b38fe988381cf7b76e6fd73e53d4d73796b5abe3af8bd81ae322b1c7f1e17c9b9f3ea0f59ba00f3b9deeaecb3a15a131ed
|
data/README.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
1
|
# Uc3DmpId
|
2
2
|
|
3
3
|
Helper methods for working with DMP ID JSON records
|
4
|
+
|
5
|
+
After you have made changes, be sure to increment the version number in `lib/uc3-dmp-id/version.rb`.
|
6
|
+
|
7
|
+
To build and push this gem to RubyGems:
|
8
|
+
- Make sure you are logged into RubyGems in your terminal window (see their docs)
|
9
|
+
- Run `gem build uc3-dmp-id.gemspec` to build the gem
|
10
|
+
- Run `gem push uc3-dmp-id-[version].gem` to publish to RubyGems
|
11
|
+
|
12
|
+
After you have pushed a new version to RubyGems, you should rebuild and redeploy the AWS SAM application.
|
data/lib/uc3-dmp-id/asserter.rb
CHANGED
@@ -28,13 +28,13 @@ module Uc3DmpId
|
|
28
28
|
related_works = modified_version.fetch('dmproadmap_related_identifiers', [])
|
29
29
|
|
30
30
|
if related_works.any?
|
31
|
-
latest_version = _add_related_identifier(updater
|
32
|
-
identifiers: related_works, note
|
31
|
+
latest_version = _add_related_identifier(updater:, latest_version:,
|
32
|
+
identifiers: related_works, note:, logger:)
|
33
33
|
end
|
34
34
|
return latest_version unless !funding.nil? && funding.any?
|
35
35
|
|
36
|
-
_add_funding_mod(updater
|
37
|
-
note
|
36
|
+
_add_funding_mod(updater:, latest_version:, funding:,
|
37
|
+
note:, logger:)
|
38
38
|
end
|
39
39
|
# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
40
40
|
|
@@ -106,7 +106,7 @@ module Uc3DmpId
|
|
106
106
|
end
|
107
107
|
|
108
108
|
latest_version['dmproadmap_related_identifiers'] = [] if latest_version['dmproadmap_related_identifiers'].nil?
|
109
|
-
assertion = _generate_assertion(updater
|
109
|
+
assertion = _generate_assertion(updater:, note:,
|
110
110
|
mods: JSON.parse({ dmproadmap_related_identifiers: additions }.to_json))
|
111
111
|
if logger.respond_to?(:debug)
|
112
112
|
logger.debug(message: 'Adding change to :dmphub_modifications.',
|
@@ -151,7 +151,7 @@ module Uc3DmpId
|
|
151
151
|
latest_version['dmphub_modifications'] = [] if latest_version['dmphub_modifications'].nil?
|
152
152
|
mod = JSON.parse({ funding: fund }.to_json)
|
153
153
|
mod['funding']['funding_status'] = 'granted'
|
154
|
-
assertion = _generate_assertion(updater
|
154
|
+
assertion = _generate_assertion(updater:, mods: mod, note:)
|
155
155
|
if logger.respond_to?(:debug)
|
156
156
|
logger.debug(message: 'Adding change to :dmphub_modifications.',
|
157
157
|
details: assertion)
|
@@ -200,7 +200,7 @@ module Uc3DmpId
|
|
200
200
|
provenance: updater.gsub('PROVENANCE#', ''),
|
201
201
|
timestamp: Time.now.utc.iso8601,
|
202
202
|
status: 'pending',
|
203
|
-
note:
|
203
|
+
note:
|
204
204
|
}
|
205
205
|
mods.each_pair { |key, val| assertion[key] = val }
|
206
206
|
JSON.parse(assertion.to_json)
|
data/lib/uc3-dmp-id/creator.rb
CHANGED
@@ -23,23 +23,23 @@ module Uc3DmpId
|
|
23
23
|
raise CreatorError, Helper::MSG_DMP_FORBIDDEN unless provenance.is_a?(Hash) && !provenance['PK'].nil?
|
24
24
|
|
25
25
|
# Validate the incoming JSON first
|
26
|
-
json = Helper.parse_json(json:
|
27
|
-
errs = Validator.validate(mode: 'author', json:
|
26
|
+
json = Helper.parse_json(json:)
|
27
|
+
errs = Validator.validate(mode: 'author', json:)
|
28
28
|
raise CreatorError, errs.join(', ') if errs.is_a?(Array) && errs.any? && errs.first != Validator::MSG_VALID_JSON
|
29
29
|
|
30
30
|
# Try to find it by the :dmp_id first and Fail if found
|
31
31
|
dmp_id = Helper.dmp_id_to_pk(json: json.fetch('dmp', {})['dmp_id'])
|
32
|
-
result = Finder.exists?(p_key: dmp_id, logger:
|
32
|
+
result = Finder.exists?(p_key: dmp_id, logger:) unless dmp_id.nil?
|
33
33
|
raise CreatorError, Helper::MSG_DMP_EXISTS if result.is_a?(Hash)
|
34
34
|
|
35
35
|
# raise CreatorError, Uc3DmpId::MSG_DMP_EXISTS unless json['PK'].nil?
|
36
36
|
|
37
37
|
client = Uc3DmpDynamo::Client.new
|
38
|
-
p_key = _preregister_dmp_id(client
|
38
|
+
p_key = _preregister_dmp_id(client:, provenance:, json:, logger:)
|
39
39
|
raise CreatorError, MSG_UNABLE_TO_MINT if p_key.nil?
|
40
40
|
|
41
41
|
# Add the DMPHub specific attributes and then save
|
42
|
-
annotated = Helper.annotate_dmp_json(provenance
|
42
|
+
annotated = Helper.annotate_dmp_json(provenance:, p_key:, json: json['dmp'])
|
43
43
|
logger.info(message: "Creating DMP ID: #{p_key}") if logger.respond_to?(:debug)
|
44
44
|
|
45
45
|
# Set the :created and :modified timestamps
|
@@ -48,10 +48,10 @@ module Uc3DmpId
|
|
48
48
|
annotated['modified'] = now
|
49
49
|
|
50
50
|
# Create the item
|
51
|
-
resp = client.put_item(json: annotated, logger:
|
51
|
+
resp = client.put_item(json: annotated, logger:)
|
52
52
|
raise CreatorError, Helper::MSG_DMP_NO_DMP_ID if resp.nil?
|
53
53
|
|
54
|
-
_post_process(json: annotated, logger:
|
54
|
+
_post_process(json: annotated, logger:)
|
55
55
|
Helper.cleanse_dmp_json(json: JSON.parse({ dmp: annotated }.to_json))
|
56
56
|
end
|
57
57
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
@@ -75,7 +75,7 @@ module Uc3DmpId
|
|
75
75
|
counter = 0
|
76
76
|
while dmp_id == '' && counter <= 10
|
77
77
|
prefix = "#{ENV.fetch('DMP_ID_SHOULDER', nil)}#{SecureRandom.hex(2).upcase}#{SecureRandom.hex(2)}"
|
78
|
-
dmp_id = prefix unless Finder.exists?(client
|
78
|
+
dmp_id = prefix unless Finder.exists?(client:, p_key: prefix)
|
79
79
|
counter += 1
|
80
80
|
end
|
81
81
|
# Something went wrong and it was unable to identify a unique id
|
@@ -94,7 +94,7 @@ module Uc3DmpId
|
|
94
94
|
|
95
95
|
# Publish the change to the EventBridge
|
96
96
|
publisher = Uc3DmpEventBridge::Publisher.new
|
97
|
-
publisher.publish(source: 'DmpCreator', event_type: 'EZID update', dmp: json, logger:
|
97
|
+
publisher.publish(source: 'DmpCreator', event_type: 'EZID update', dmp: json, logger:)
|
98
98
|
|
99
99
|
# Determine if there are any related identifiers that we should try to fetch a citation for
|
100
100
|
citable_identifiers = Helper.citable_related_identifiers(dmp: json)
|
@@ -108,7 +108,7 @@ module Uc3DmpId
|
|
108
108
|
}
|
109
109
|
logger.debug(message: 'Fetching citations', details: citable_identifiers) if logger.respond_to?(:debug)
|
110
110
|
publisher.publish(source: 'DmpCreator', dmp: json, event_type: 'Citation Fetch', detail: citer_detail,
|
111
|
-
logger:
|
111
|
+
logger:)
|
112
112
|
true
|
113
113
|
end
|
114
114
|
end
|
data/lib/uc3-dmp-id/deleter.rb
CHANGED
@@ -19,7 +19,7 @@ module Uc3DmpId
|
|
19
19
|
|
20
20
|
# Fetch the latest version of the DMP ID by it's PK
|
21
21
|
client = Uc3DmpDynamo::Client.new
|
22
|
-
dmp = Finder.by_pk(p_key
|
22
|
+
dmp = Finder.by_pk(p_key:, client:, cleanse: false, logger:)
|
23
23
|
raise DeleterError, Helper::MSG_DMP_NOT_FOUND unless dmp.is_a?(Hash) && !dmp['dmp'].nil?
|
24
24
|
|
25
25
|
# Only allow this if the provenance is the owner of the DMP!
|
@@ -38,16 +38,16 @@ module Uc3DmpId
|
|
38
38
|
dmp['dmp']['dmphub_tombstoned_at'] = now
|
39
39
|
|
40
40
|
# Create the Tombstone version
|
41
|
-
resp = client.put_item(json: dmp['dmp'], logger:
|
41
|
+
resp = client.put_item(json: dmp['dmp'], logger:)
|
42
42
|
raise DeleterError, Helper::MSG_DMP_NO_TOMBSTONE if resp.nil?
|
43
43
|
|
44
44
|
# Delete the Latest version
|
45
|
-
client.delete_item(p_key
|
45
|
+
client.delete_item(p_key:, s_key: Helper::DMP_LATEST_VERSION, logger:)
|
46
46
|
|
47
47
|
# TODO: We should do a check here to see if it was successful!
|
48
48
|
|
49
49
|
# Notify EZID about the removal
|
50
|
-
_post_process(json: dmp, logger:
|
50
|
+
_post_process(json: dmp, logger:)
|
51
51
|
|
52
52
|
# Return the tombstoned record
|
53
53
|
Helper.cleanse_dmp_json(json: dmp)
|
@@ -66,7 +66,7 @@ module Uc3DmpId
|
|
66
66
|
|
67
67
|
# Publish the change to the EventBridge
|
68
68
|
publisher = Uc3DmpEventBridge::Publisher.new
|
69
|
-
publisher.publish(source: 'DmpDeleter', event_type: 'EZID update', dmp: json, logger:
|
69
|
+
publisher.publish(source: 'DmpDeleter', event_type: 'EZID update', dmp: json, logger:)
|
70
70
|
true
|
71
71
|
end
|
72
72
|
end
|
data/lib/uc3-dmp-id/finder.rb
CHANGED
@@ -20,15 +20,15 @@ module Uc3DmpId
|
|
20
20
|
# TODO: Replace this with ElasticSearch
|
21
21
|
def search_dmps(args:, logger: nil)
|
22
22
|
client = Uc3DmpDynamo::Client.new
|
23
|
-
return _by_owner(owner_org: args['owner_orcid'], client
|
23
|
+
return _by_owner(owner_org: args['owner_orcid'], client:, logger:) unless args['owner_orcid'].nil?
|
24
24
|
|
25
25
|
unless args['owner_org_ror'].nil?
|
26
|
-
return _by_owner_org(owner_org: args['owner_org_ror'], client
|
27
|
-
logger:
|
26
|
+
return _by_owner_org(owner_org: args['owner_org_ror'], client:,
|
27
|
+
logger:)
|
28
28
|
end
|
29
29
|
unless args['modification_day'].nil?
|
30
|
-
return _by_mod_day(day: args['modification_day'], client
|
31
|
-
logger:
|
30
|
+
return _by_mod_day(day: args['modification_day'], client:,
|
31
|
+
logger:)
|
32
32
|
end
|
33
33
|
|
34
34
|
[]
|
@@ -38,20 +38,20 @@ module Uc3DmpId
|
|
38
38
|
# -------------------------------------------------------------------------
|
39
39
|
# rubocop:disable Metrics/AbcSize
|
40
40
|
def by_json(json:, client: nil, cleanse: true, logger: nil)
|
41
|
-
json = Helper.parse_json(json:
|
41
|
+
json = Helper.parse_json(json:)&.fetch('dmp', {})
|
42
42
|
raise FinderError, MSG_INVALID_ARGS if !json.is_a?(Hash) || (json['PK'].nil? && json['dmp_id'].nil?)
|
43
43
|
|
44
44
|
p_key = json['PK']
|
45
45
|
# Translate the incoming :dmp_id into a PK
|
46
46
|
p_key = Helper.dmp_id_to_pk(json: json.fetch('dmp_id', {})) if p_key.nil?
|
47
|
-
client =
|
47
|
+
client = Uc3DmpDynamo::Client.new if client.nil?
|
48
48
|
|
49
49
|
# TODO: Re-enable this once we figure out Dynamo indexes
|
50
50
|
# find_by_dmphub_provenance_id -> if no PK and no dmp_id result
|
51
51
|
# return by_provenance_identifier(json: json, client: client, logger: logger) if p_key.nil?
|
52
52
|
|
53
53
|
# find_by_PK
|
54
|
-
p_key.nil? ? nil : by_pk(p_key
|
54
|
+
p_key.nil? ? nil : by_pk(p_key:, s_key: json['SK'], client:, cleanse:, logger:)
|
55
55
|
end
|
56
56
|
# rubocop:enable Metrics/AbcSize
|
57
57
|
|
@@ -62,20 +62,20 @@ module Uc3DmpId
|
|
62
62
|
raise FinderError, MSG_MISSING_PK if p_key.nil?
|
63
63
|
|
64
64
|
s_key = Helper::DMP_LATEST_VERSION if s_key.nil? || s_key.to_s.strip.empty?
|
65
|
-
client =
|
65
|
+
client = Uc3DmpDynamo::Client.new if client.nil?
|
66
66
|
resp = client.get_item(
|
67
67
|
key: {
|
68
|
-
PK: Helper.append_pk_prefix(p_key:
|
69
|
-
SK: Helper.append_sk_prefix(s_key:
|
68
|
+
PK: Helper.append_pk_prefix(p_key:),
|
69
|
+
SK: Helper.append_sk_prefix(s_key:)
|
70
70
|
},
|
71
|
-
logger:
|
71
|
+
logger:
|
72
72
|
)
|
73
73
|
return resp unless resp.is_a?(Hash)
|
74
74
|
|
75
75
|
dmp = resp['dmp'].nil? ? JSON.parse({ dmp: resp }.to_json) : resp
|
76
76
|
return nil if dmp['dmp']['PK'].nil?
|
77
77
|
|
78
|
-
dmp = Versioner.append_versions(p_key: dmp['dmp']['PK'], dmp
|
78
|
+
dmp = Versioner.append_versions(p_key: dmp['dmp']['PK'], dmp:, client:, logger:) if cleanse
|
79
79
|
cleanse ? Helper.cleanse_dmp_json(json: dmp) : dmp
|
80
80
|
end
|
81
81
|
# rubocop:enable Metrics/AbcSize
|
@@ -85,13 +85,13 @@ module Uc3DmpId
|
|
85
85
|
def exists?(p_key:, s_key: Helper::DMP_LATEST_VERSION, client: nil, logger: nil)
|
86
86
|
raise FinderError, MSG_MISSING_PK if p_key.nil?
|
87
87
|
|
88
|
-
client =
|
88
|
+
client = Uc3DmpDynamo::Client.new if client.nil?
|
89
89
|
client.pk_exists?(
|
90
90
|
key: {
|
91
|
-
PK: Helper.append_pk_prefix(p_key:
|
92
|
-
SK: Helper.append_sk_prefix(s_key:
|
91
|
+
PK: Helper.append_pk_prefix(p_key:),
|
92
|
+
SK: Helper.append_sk_prefix(s_key:)
|
93
93
|
},
|
94
|
-
logger:
|
94
|
+
logger:
|
95
95
|
)
|
96
96
|
end
|
97
97
|
|
@@ -115,15 +115,15 @@ module Uc3DmpId
|
|
115
115
|
filter_expression: 'SK = :version',
|
116
116
|
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
117
117
|
}
|
118
|
-
client =
|
119
|
-
resp = client.query(args
|
118
|
+
client = Uc3DmpDynamo::Client.new if client.nil?
|
119
|
+
resp = client.query(args:, logger:)
|
120
120
|
return resp unless resp.is_a?(Hash)
|
121
121
|
|
122
122
|
dmp = resp['dmp'].nil? ? JSON.parse({ dmp: resp }.to_json) : resp
|
123
123
|
return nil if dmp['dmp']['PK'].nil?
|
124
124
|
|
125
125
|
# If we got a hit, fetch the DMP and return it.
|
126
|
-
by_pk(p_key: dmp['dmp']['PK'], s_key: dmp['dmp']['SK'], cleanse
|
126
|
+
by_pk(p_key: dmp['dmp']['PK'], s_key: dmp['dmp']['SK'], cleanse:, logger:)
|
127
127
|
end
|
128
128
|
# rubocop:enable Metrics/AbcSize
|
129
129
|
|
@@ -149,8 +149,8 @@ module Uc3DmpId
|
|
149
149
|
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
150
150
|
}
|
151
151
|
logger.info(message: "Querying _by_owner with #{args}") if logger.respond_to?(:info)
|
152
|
-
client =
|
153
|
-
_process_search_response(response: client.query(args
|
152
|
+
client = Uc3DmpDynamo::Client.new if client.nil?
|
153
|
+
_process_search_response(response: client.query(args:, logger:))
|
154
154
|
end
|
155
155
|
|
156
156
|
# Fetch the DMP IDs for the specified organization/institution (the org is the :dmphub_owner_org
|
@@ -174,8 +174,8 @@ module Uc3DmpId
|
|
174
174
|
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
175
175
|
}
|
176
176
|
logger.info(message: "Querying _by_owner_org with #{args}") if logger.respond_to?(:info)
|
177
|
-
client =
|
178
|
-
_process_search_response(response: client.query(args
|
177
|
+
client = Uc3DmpDynamo::Client.new if client.nil?
|
178
|
+
_process_search_response(response: client.query(args:, logger:))
|
179
179
|
end
|
180
180
|
|
181
181
|
# Fetch the DMP IDs modified on the specified date (the date is the :dmphub_modification_day on the DMP ID record)
|
@@ -195,8 +195,8 @@ module Uc3DmpId
|
|
195
195
|
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
196
196
|
}
|
197
197
|
logger.info(message: "Querying _by_mod_day with #{args}") if logger.respond_to?(:info)
|
198
|
-
client =
|
199
|
-
_process_search_response(response: client.query(args
|
198
|
+
client = Uc3DmpDynamo::Client.new if client.nil?
|
199
|
+
_process_search_response(response: client.query(args:, logger:))
|
200
200
|
end
|
201
201
|
|
202
202
|
# Transform the search results so that we do not include any of the DMPHub specific metadata
|
data/lib/uc3-dmp-id/helper.rb
CHANGED
@@ -7,17 +7,17 @@ module Uc3DmpId
|
|
7
7
|
# Helper functions for working with DMP IDs
|
8
8
|
class Helper
|
9
9
|
PK_DMP_PREFIX = 'DMP#'
|
10
|
-
PK_DMP_REGEX = %r{DMP#[a-zA-Z0-9\-_.]+/[a-zA-Z0-9]{2}\.[a-zA-Z0-9./:]+}
|
10
|
+
PK_DMP_REGEX = %r{DMP#[a-zA-Z0-9\-_.]+/[a-zA-Z0-9]{2}\.[a-zA-Z0-9./:]+}
|
11
11
|
|
12
12
|
SK_DMP_PREFIX = 'VERSION#'
|
13
|
-
SK_DMP_REGEX = /VERSION#\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}
|
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
15
|
# TODO: Verify the assumed structure of the DOI is valid
|
16
|
-
DOI_REGEX = %r{[0-9]{2}\.[0-9]{4,}/[a-zA-Z0-9/_.-]+}
|
17
|
-
URL_REGEX = %r{(https?://)?([a-zA-Z0-9\-_]\.)+[a-zA-Z0-9\-_]{2,3}(:[0-9]+)?/?}
|
16
|
+
DOI_REGEX = %r{[0-9]{2}\.[0-9]{4,}/[a-zA-Z0-9/_.-]+}
|
17
|
+
URL_REGEX = %r{(https?://)?([a-zA-Z0-9\-_]\.)+[a-zA-Z0-9\-_]{2,3}(:[0-9]+)?/?}
|
18
18
|
|
19
|
-
DMP_LATEST_VERSION = "#{SK_DMP_PREFIX}latest"
|
20
|
-
DMP_TOMBSTONE_VERSION = "#{SK_DMP_PREFIX}tombstone"
|
19
|
+
DMP_LATEST_VERSION = "#{SK_DMP_PREFIX}latest".freeze
|
20
|
+
DMP_TOMBSTONE_VERSION = "#{SK_DMP_PREFIX}tombstone".freeze
|
21
21
|
|
22
22
|
DEFAULT_API_URL = 'https://api.dmphub.uc3dev.cdlib.net/dmps/'
|
23
23
|
DEFAULT_LANDING_PAGE_URL = 'https://dmphub.uc3dev.cdlib.net/dmps/'
|
@@ -41,7 +41,7 @@ module Uc3DmpId
|
|
41
41
|
# Append the PK prefix for the object
|
42
42
|
# -------------------------------------------------------------------------------------
|
43
43
|
def append_pk_prefix(p_key:)
|
44
|
-
p_key.is_a?(String) ? "#{PK_DMP_PREFIX}#{remove_pk_prefix(p_key:
|
44
|
+
p_key.is_a?(String) ? "#{PK_DMP_PREFIX}#{remove_pk_prefix(p_key:)}" : nil
|
45
45
|
end
|
46
46
|
|
47
47
|
# Strip off the PK prefix
|
@@ -53,7 +53,7 @@ module Uc3DmpId
|
|
53
53
|
# Append the SK prefix for the object
|
54
54
|
# -------------------------------------------------------------------------------------
|
55
55
|
def append_sk_prefix(s_key:)
|
56
|
-
s_key.is_a?(String) ? "#{SK_DMP_PREFIX}#{remove_sk_prefix(s_key:
|
56
|
+
s_key.is_a?(String) ? "#{SK_DMP_PREFIX}#{remove_sk_prefix(s_key:)}" : nil
|
57
57
|
end
|
58
58
|
|
59
59
|
# Strip off the SK prefix
|
@@ -82,7 +82,7 @@ module Uc3DmpId
|
|
82
82
|
return with_protocol ? value : value.gsub(%r{https?://}, '') if value.start_with?('http')
|
83
83
|
|
84
84
|
dmp_id = dmp_id.gsub('doi:', '')
|
85
|
-
dmp_id = dmp_id
|
85
|
+
dmp_id = dmp_id[1..dmp_id.length] if dmp_id.start_with?('/')
|
86
86
|
base_domain = with_protocol ? dmp_id_base_url : dmp_id_base_url.gsub(%r{https?://}, '')
|
87
87
|
"#{base_domain}#{dmp_id}"
|
88
88
|
end
|
@@ -95,7 +95,7 @@ module Uc3DmpId
|
|
95
95
|
p_key = param if param.start_with?(dmp_id_base_url) || param.start_with?(base_domain)
|
96
96
|
p_key = CGI.unescape(p_key.nil? ? param : p_key)
|
97
97
|
p_key = format_dmp_id(value: p_key)
|
98
|
-
append_pk_prefix(p_key:
|
98
|
+
append_pk_prefix(p_key:)
|
99
99
|
end
|
100
100
|
|
101
101
|
# Append the :PK prefix to the :dmp_id
|
@@ -115,7 +115,7 @@ module Uc3DmpId
|
|
115
115
|
|
116
116
|
{
|
117
117
|
type: 'doi',
|
118
|
-
identifier: format_dmp_id(value: remove_pk_prefix(p_key:
|
118
|
+
identifier: format_dmp_id(value: remove_pk_prefix(p_key:), with_protocol: true)
|
119
119
|
}
|
120
120
|
end
|
121
121
|
|
@@ -180,7 +180,7 @@ module Uc3DmpId
|
|
180
180
|
# Add DMPHub specific fields to the DMP ID JSON
|
181
181
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
182
182
|
def annotate_dmp_json(provenance:, p_key:, json:)
|
183
|
-
json = parse_json(json:
|
183
|
+
json = parse_json(json:)
|
184
184
|
bool_vals = [1, '1', true, 'true', 'yes']
|
185
185
|
return json if provenance.nil? || p_key.nil? || !json.is_a?(Hash)
|
186
186
|
|
@@ -189,14 +189,14 @@ module Uc3DmpId
|
|
189
189
|
return json if id != p_key && !json['PK'].nil?
|
190
190
|
|
191
191
|
annotated = deep_copy_dmp(obj: json)
|
192
|
-
annotated['PK'] = json['PK'] || append_pk_prefix(p_key:
|
192
|
+
annotated['PK'] = json['PK'] || append_pk_prefix(p_key:)
|
193
193
|
annotated['SK'] = DMP_LATEST_VERSION
|
194
194
|
|
195
195
|
# Ensure that the :dmp_id matches the :PK
|
196
196
|
annotated['dmp_id'] = JSON.parse(pk_to_dmp_id(p_key: remove_pk_prefix(p_key: annotated['PK'])).to_json)
|
197
197
|
|
198
|
-
owner_id = extract_owner_id(json:
|
199
|
-
owner_org = extract_owner_org(json:
|
198
|
+
owner_id = extract_owner_id(json:)
|
199
|
+
owner_org = extract_owner_org(json:)
|
200
200
|
|
201
201
|
# Set the :dmproadmap_featured flag appropriately
|
202
202
|
featured = annotated.fetch('dmproadmap_featured', 'no')
|
@@ -219,7 +219,7 @@ module Uc3DmpId
|
|
219
219
|
annotated['dmphub_provenance_identifier'] = annotated.fetch('dmproadmap_links', {})['get']
|
220
220
|
else
|
221
221
|
annotated['dmphub_provenance_identifier'] = format_provenance_id(
|
222
|
-
provenance
|
222
|
+
provenance:, value: json.fetch('dmp_id', {})['identifier']
|
223
223
|
)
|
224
224
|
end
|
225
225
|
annotated
|
data/lib/uc3-dmp-id/updater.rb
CHANGED
@@ -16,18 +16,18 @@ module Uc3DmpId
|
|
16
16
|
def update(provenance:, p_key:, json: {}, note: nil, 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:
|
20
|
-
p_key = Helper.append_pk_prefix(p_key:
|
19
|
+
mods = Helper.parse_json(json:).fetch('dmp', {})
|
20
|
+
p_key = Helper.append_pk_prefix(p_key:)
|
21
21
|
logger.debug(message: "Incoming modifications for PK #{p_key}", details: mods) if logger.respond_to?(:debug)
|
22
22
|
|
23
23
|
# Fetch the latest version of the DMP ID
|
24
24
|
client = Uc3DmpDynamo::Client.new
|
25
|
-
latest_version = Finder.by_pk(p_key
|
26
|
-
latest_version = latest_version
|
25
|
+
latest_version = Finder.by_pk(p_key:, client:, logger:, cleanse: false)
|
26
|
+
latest_version = latest_version.fetch('dmp', {}) unless latest_version['dmp'].nil?
|
27
27
|
logger.debug(message: "Latest version for PK #{p_key}", details: latest_version) if logger.respond_to?(:debug)
|
28
28
|
|
29
29
|
# Verify that the DMP ID is updateable with the info passed in
|
30
|
-
errs = _updateable?(provenance
|
30
|
+
errs = _updateable?(provenance:, p_key:, latest_version: latest_version['dmp'],
|
31
31
|
mods: mods['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?
|
@@ -37,35 +37,35 @@ module Uc3DmpId
|
|
37
37
|
# Version the DMP ID record (if applicable).
|
38
38
|
owner = latest_version['dmphub_provenance_id']
|
39
39
|
updater = provenance['PK']
|
40
|
-
version = Versioner.generate_version(client
|
41
|
-
updater
|
40
|
+
version = Versioner.generate_version(client:, latest_version:, owner:,
|
41
|
+
updater:, logger:)
|
42
42
|
raise UpdaterError, Helper::MSG_DMP_UNABLE_TO_VERSION if version.nil?
|
43
43
|
|
44
44
|
# Remove the version info because we don't want to save it on the record
|
45
45
|
version.delete('dmphub_versions')
|
46
46
|
|
47
47
|
# Splice the assertions
|
48
|
-
version = _process_modifications(owner
|
49
|
-
logger:
|
48
|
+
version = _process_modifications(owner:, updater:, version:, mods:, note:,
|
49
|
+
logger:)
|
50
50
|
# Set the :modified timestamps
|
51
51
|
now = Time.now.utc
|
52
52
|
version['modified'] = now.iso8601
|
53
53
|
version['dmphub_modification_day'] = now.strftime('%Y-%m-%d')
|
54
54
|
|
55
55
|
# Save the changes
|
56
|
-
resp = client.put_item(json: version, logger:
|
56
|
+
resp = client.put_item(json: version, logger:)
|
57
57
|
raise UpdaterError, Helper::MSG_DMP_UNABLE_TO_VERSION if resp.nil?
|
58
58
|
|
59
59
|
# Send the updates to EZID
|
60
|
-
_post_process(provenance
|
60
|
+
_post_process(provenance:, json: version, logger:)
|
61
61
|
|
62
62
|
# Return the new version record
|
63
63
|
logger.info(message: "Updated DMP ID: #{p_key}") if logger.respond_to?(:debug)
|
64
64
|
|
65
65
|
# Append the :dmphub_versions Array
|
66
66
|
json = JSON.parse({ dmp: version }.to_json)
|
67
|
-
json = Versioner.append_versions(p_key
|
68
|
-
Helper.cleanse_dmp_json(json:
|
67
|
+
json = Versioner.append_versions(p_key:, dmp: json, client:, logger:)
|
68
|
+
Helper.cleanse_dmp_json(json:)
|
69
69
|
end
|
70
70
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
71
71
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
@@ -77,21 +77,21 @@ module Uc3DmpId
|
|
77
77
|
raise UpdaterError, Helper::MSG_DMP_INVALID_DMP_ID unless p_key.is_a?(String) && !p_key.strip.empty?
|
78
78
|
|
79
79
|
# fetch the existing latest version of the DMP ID
|
80
|
-
client = Uc3DmpDynamo::Client.new(logger:
|
81
|
-
dmp = Finder.by_pk(p_key
|
80
|
+
client = Uc3DmpDynamo::Client.new(logger:)
|
81
|
+
dmp = Finder.by_pk(p_key:, client:, logger:, cleanse: false)
|
82
82
|
logger.info(message: 'Existing latest record', details: dmp) if logger.respond_to?(:debug)
|
83
83
|
raise UpdaterError, Helper::MSG_DMP_FORBIDDEN unless provenance.is_a?(Hash) && !provenance['PK'].nil? &&
|
84
84
|
provenance['PK'] == dmp['dmp']['dmphub_provenance_id']
|
85
85
|
|
86
86
|
# Add the download URl for the PDF as a related identifier on the DMP ID record
|
87
|
-
annotated = Helper.annotate_dmp_json(provenance
|
87
|
+
annotated = Helper.annotate_dmp_json(provenance:, p_key:, json: dmp['dmp'])
|
88
88
|
annotated['dmproadmap_related_identifiers'] = [] if annotated['dmproadmap_related_identifiers'].nil?
|
89
89
|
annotated['dmproadmap_related_identifiers'] << JSON.parse({
|
90
90
|
descriptor: 'is_metadata_for', work_type: 'output_management_plan', type: 'url', identifier: url
|
91
91
|
}.to_json)
|
92
92
|
|
93
93
|
# Save the changes without creating a new version!
|
94
|
-
resp = client.put_item(json: annotated, logger:
|
94
|
+
resp = client.put_item(json: annotated, logger:)
|
95
95
|
raise UpdaterError, Helper::MSG_DMP_UNABLE_TO_VERSION if resp.nil?
|
96
96
|
|
97
97
|
logger.info(message: "Added DMP ID narrative for PK: #{p_key}, Narrative: #{url}") if logger.respond_to?(:debug)
|
@@ -111,8 +111,9 @@ module Uc3DmpId
|
|
111
111
|
return [Helper::MSG_DMP_FORBIDDEN] unless provenance.is_a?(Hash) && !provenance['PK'].nil?
|
112
112
|
# Verify that the JSON is for the same DMP in the PK
|
113
113
|
return [Helper::MSG_DMP_FORBIDDEN] unless Helper.dmp_id_to_pk(json: mods.fetch('dmp_id', {})) == p_key
|
114
|
+
|
114
115
|
# Bail out if the DMP ID could not be found or the PKs do not match for some reason
|
115
|
-
|
116
|
+
[Helper::MSG_DMP_UNKNOWN] unless latest_version.is_a?(Hash) && latest_version['PK'] == p_key
|
116
117
|
end
|
117
118
|
# rubocop:enable Metrics/AbcSize
|
118
119
|
|
@@ -123,14 +124,14 @@ module Uc3DmpId
|
|
123
124
|
|
124
125
|
updated = if owner == updater
|
125
126
|
# Splice together any assertions that may have been made while the user was editing the DMP ID
|
126
|
-
Asserter.splice(latest_version: version, modified_version: mods, logger:
|
127
|
+
Asserter.splice(latest_version: version, modified_version: mods, logger:)
|
127
128
|
else
|
128
129
|
# Attach the incoming changes as an assertion to the DMP ID since the updater is NOT the owner
|
129
|
-
Asserter.add(updater
|
130
|
-
logger:
|
130
|
+
Asserter.add(updater:, latest_version: version, modified_version: mods, note:,
|
131
|
+
logger:)
|
131
132
|
end
|
132
133
|
|
133
|
-
_merge_versions(latest_version: version, mods: updated, logger:
|
134
|
+
_merge_versions(latest_version: version, mods: updated, logger:)
|
134
135
|
end
|
135
136
|
# rubocop:enable Metrics/ParameterLists
|
136
137
|
|
@@ -172,7 +173,7 @@ module Uc3DmpId
|
|
172
173
|
logger.debug(message: 'Sending event for EZID publication',
|
173
174
|
details: json)
|
174
175
|
end
|
175
|
-
publisher.publish(source: 'DmpUpdater', event_type: 'EZID update', dmp: json, logger:
|
176
|
+
publisher.publish(source: 'DmpUpdater', event_type: 'EZID update', dmp: json, logger:) if publishable
|
176
177
|
|
177
178
|
# Determine if there are any related identifiers that we should try to fetch a citation for
|
178
179
|
citable_identifiers = Helper.citable_related_identifiers(dmp: json)
|
@@ -189,7 +190,7 @@ module Uc3DmpId
|
|
189
190
|
details: citable_identifiers)
|
190
191
|
end
|
191
192
|
publisher.publish(source: 'DmpUpdater', dmp: json, event_type: 'Citation Fetch', detail: citer_detail,
|
192
|
-
logger:
|
193
|
+
logger:)
|
193
194
|
true
|
194
195
|
end
|
195
196
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
data/lib/uc3-dmp-id/validator.rb
CHANGED
@@ -23,11 +23,11 @@ module Uc3DmpId
|
|
23
23
|
# Validate the specified DMP's :json against the schema for the specified :mode
|
24
24
|
# rubocop:disable Metrics/AbcSize
|
25
25
|
def validate(mode:, json:)
|
26
|
-
json = Helper.parse_json(json:
|
26
|
+
json = Helper.parse_json(json:)
|
27
27
|
return [MSG_EMPTY_JSON] if json.nil? || !VALIDATION_MODES.include?(mode)
|
28
28
|
|
29
29
|
# Load the appropriate JSON schema for the mode
|
30
|
-
schema = _load_schema(mode:
|
30
|
+
schema = _load_schema(mode:)
|
31
31
|
return [MSG_NO_SCHEMA] if schema.nil?
|
32
32
|
|
33
33
|
# Validate the JSON
|
data/lib/uc3-dmp-id/version.rb
CHANGED
data/lib/uc3-dmp-id/versioner.rb
CHANGED
@@ -18,13 +18,13 @@ module Uc3DmpId
|
|
18
18
|
|
19
19
|
args = {
|
20
20
|
key_conditions: {
|
21
|
-
PK: { attribute_value_list: [Helper.append_pk_prefix(p_key:
|
21
|
+
PK: { attribute_value_list: [Helper.append_pk_prefix(p_key:)], comparison_operator: 'EQ' }
|
22
22
|
},
|
23
23
|
projection_expression: 'modified',
|
24
24
|
scan_index_forward: false
|
25
25
|
}
|
26
|
-
client =
|
27
|
-
client.query(args
|
26
|
+
client = Uc3DmpDynamo::Client.new if client.nil?
|
27
|
+
client.query(args:, logger:)
|
28
28
|
end
|
29
29
|
|
30
30
|
# Generate a snapshot of the current latest version of the DMP ID using the existing :modified as
|
@@ -57,8 +57,8 @@ module Uc3DmpId
|
|
57
57
|
prior['SK'] = "#{Helper::SK_DMP_PREFIX}#{latest_version['modified'] || Time.now.utc.iso8601}"
|
58
58
|
|
59
59
|
# Create the prior version record ()
|
60
|
-
client =
|
61
|
-
resp = client.put_item(json: prior, logger:
|
60
|
+
client = Uc3DmpDynamo::Client.new if client.nil?
|
61
|
+
resp = client.put_item(json: prior, logger:)
|
62
62
|
return nil if resp.nil?
|
63
63
|
|
64
64
|
msg = "#{SOURCE} created version PK: #{prior['PK']} SK: #{prior['SK']}"
|
@@ -74,7 +74,7 @@ module Uc3DmpId
|
|
74
74
|
json = Helper.parse_json(json: dmp)
|
75
75
|
return json unless p_key.is_a?(String) && !p_key.strip.empty? && json.is_a?(Hash) && !json['dmp'].nil?
|
76
76
|
|
77
|
-
results = get_versions(p_key
|
77
|
+
results = get_versions(p_key:, client:, logger:)
|
78
78
|
return json unless results.length > 1
|
79
79
|
|
80
80
|
# TODO: we may want to include milliseconds in the future if we get increased volume so that
|
@@ -82,7 +82,7 @@ module Uc3DmpId
|
|
82
82
|
versions = results.map do |ver|
|
83
83
|
next if ver['modified'].nil?
|
84
84
|
|
85
|
-
base_url = "#{Helper.landing_page_url}#{Helper.remove_pk_prefix(p_key:
|
85
|
+
base_url = "#{Helper.landing_page_url}#{Helper.remove_pk_prefix(p_key:)}"
|
86
86
|
{
|
87
87
|
timestamp: ver['modified'],
|
88
88
|
url: dmp['dmp']['modified'] == ver['modified'] ? base_url : "#{base_url}?version=#{ver['modified']}"
|
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Riley
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -91,7 +91,7 @@ licenses:
|
|
91
91
|
- MIT
|
92
92
|
metadata:
|
93
93
|
rubygems_mfa_required: 'false'
|
94
|
-
post_install_message:
|
94
|
+
post_install_message:
|
95
95
|
rdoc_options: []
|
96
96
|
require_paths:
|
97
97
|
- lib
|
@@ -100,15 +100,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '2
|
103
|
+
version: '3.2'
|
104
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
106
|
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
111
|
-
signing_key:
|
110
|
+
rubygems_version: 3.4.10
|
111
|
+
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: DMPTool gem that provides support for DMP ID records
|
114
114
|
test_files: []
|