uc3-dmp-id 0.0.119 → 0.0.121
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/asserter.rb +6 -4
- data/lib/uc3-dmp-id/creator.rb +6 -0
- data/lib/uc3-dmp-id/deleter.rb +7 -1
- data/lib/uc3-dmp-id/helper.rb +6 -5
- data/lib/uc3-dmp-id/updater.rb +5 -0
- data/lib/uc3-dmp-id/version.rb +1 -1
- data/lib/uc3-dmp-id/versioner.rb +9 -11
- 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: 6a7b18e8a03e8b1fec669c319659352f4cee0fc5d726c92a45c178ea37116375
|
4
|
+
data.tar.gz: 4239900d4abfe0c89126ba713d135b55ede35b05db53671390fabab773372933
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e2d9142e4adcc5604ee23d35d16f3f06c48f872476d049223293c6779c89ec5cdb5b5db80a0ad27ded0c46110d105ed41351b55b4dcc655b9eec698b56ddb1a
|
7
|
+
data.tar.gz: 93393c6f351ceef8afdf2f59213f58ac8a908bde9511d67e263e780b1bc2d0120ed0d9de02a6a93e9151e5289176162473929afc7de65952aa1cab354ee781a6
|
data/lib/uc3-dmp-id/asserter.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'time'
|
4
|
+
|
3
5
|
module Uc3DmpId
|
4
6
|
class AsserterError < StandardError; end
|
5
7
|
|
@@ -38,7 +40,7 @@ puts "MODIFIED_VERSION ASSERTIONS: #{modified_version['dmphub_assertions']}"
|
|
38
40
|
|
39
41
|
# Return the modified_version if the timestamps are the same (meaning no new assertions were made while the
|
40
42
|
# user was working on the DMP ID) OR neither version has assertions
|
41
|
-
return modified_version if latest_version['
|
43
|
+
return modified_version if latest_version['modified'] == modified_version['modified'] ||
|
42
44
|
(latest_version.fetch('dmphub_assertions', []).empty? &&
|
43
45
|
modified_version.fetch('dmphub_assertions', []).empty?)
|
44
46
|
|
@@ -48,9 +50,9 @@ puts "MODIFIED_VERSION ASSERTIONS: #{modified_version['dmphub_assertions']}"
|
|
48
50
|
logger.debug(message: "Existing assertions", details: existing_assertions) if logger.respond_to?(:debug)
|
49
51
|
logger.debug(message: "Incoming modifications", details: incoming_assertions) if logger.respond_to?(:debug)
|
50
52
|
|
51
|
-
# Keep any assetions that were made after the
|
53
|
+
# Keep any assetions that were made after the modified on the incoming changes
|
52
54
|
modified_version['dmphub_assertions'] = existing_assertions.select do |entry|
|
53
|
-
!entry['timestamp'].nil? && Time.parse(entry['timestamp']) > Time.parse(modified_version['
|
55
|
+
!entry['timestamp'].nil? && Time.parse(entry['timestamp']) > Time.parse(modified_version['modified'])
|
54
56
|
end
|
55
57
|
return modified_version unless incoming_assertions.any?
|
56
58
|
|
@@ -105,7 +107,7 @@ puts "MODIFIED_VERSION ASSERTIONS: #{modified_version['dmphub_assertions']}"
|
|
105
107
|
JSON.parse({
|
106
108
|
id: SecureRandom.hex(4).upcase,
|
107
109
|
provenance: updater.gsub('PROVENANCE#', ''),
|
108
|
-
timestamp: Time.now.iso8601,
|
110
|
+
timestamp: Time.now.utc.iso8601,
|
109
111
|
status: 'new',
|
110
112
|
note: note,
|
111
113
|
assertions: mods
|
data/lib/uc3-dmp-id/creator.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
|
+
require 'time'
|
4
5
|
|
5
6
|
module Uc3DmpId
|
6
7
|
class CreatorError < StandardError; end
|
@@ -40,6 +41,11 @@ module Uc3DmpId
|
|
40
41
|
annotated = Helper.annotate_dmp_json(provenance: provenance, p_key: p_key, json: json['dmp'])
|
41
42
|
logger.info(message: "Creating DMP ID: #{p_key}") if logger.respond_to?(:debug)
|
42
43
|
|
44
|
+
# Set the :created and :modified timestamps
|
45
|
+
now = Time.now.utc.iso8601
|
46
|
+
annotated['created'] = now
|
47
|
+
annotated['modified'] = now
|
48
|
+
|
43
49
|
# Create the item
|
44
50
|
resp = client.put_item(json: annotated, logger: logger)
|
45
51
|
raise CreatorError, Uc3DmpId::MSG_DMP_NO_DMP_ID if resp.nil?
|
data/lib/uc3-dmp-id/deleter.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'time'
|
4
|
+
|
3
5
|
module Uc3DmpId
|
4
6
|
class DeleterError < StandardError; end
|
5
7
|
|
@@ -27,10 +29,14 @@ module Uc3DmpId
|
|
27
29
|
|
28
30
|
# Annotate the DMP ID
|
29
31
|
dmp['dmp']['SK'] = Helper::DMP_TOMBSTONE_VERSION
|
30
|
-
dmp['dmp']['dmphub_tombstoned_at'] = Time.now.iso8601
|
32
|
+
dmp['dmp']['dmphub_tombstoned_at'] = Time.now.utc.iso8601
|
31
33
|
dmp['dmp']['title'] = "OBSOLETE: #{dmp['title']}"
|
32
34
|
logger.info(message: "Tomstoning DMP ID: #{p_key}") if logger.respond_to?(:debug)
|
33
35
|
|
36
|
+
# Set the :modified timestamps
|
37
|
+
now = Time.now.utc.iso8601
|
38
|
+
dmp['modified'] = now
|
39
|
+
|
34
40
|
# Create the Tombstone version
|
35
41
|
resp = client.put_item(json: dmp, logger: logger)
|
36
42
|
raise DeleterError, MSG_DMP_NO_TOMBSTONE if resp.nil?
|
data/lib/uc3-dmp-id/helper.rb
CHANGED
@@ -132,7 +132,7 @@ module Uc3DmpId
|
|
132
132
|
b = deep_copy_dmp(obj: dmp_b)
|
133
133
|
|
134
134
|
# ignore some of the attributes before comparing
|
135
|
-
%w[SK dmphub_modification_day
|
135
|
+
%w[SK dmphub_modification_day modified created dmphub_assertions].each do |key|
|
136
136
|
a['dmp'].delete(key) unless a['dmp'][key].nil?
|
137
137
|
b['dmp'].delete(key) unless b['dmp'][key].nil?
|
138
138
|
end
|
@@ -167,6 +167,7 @@ module Uc3DmpId
|
|
167
167
|
# Add DMPHub specific fields to the DMP ID JSON
|
168
168
|
def annotate_dmp_json(provenance:, p_key:, json:)
|
169
169
|
json = parse_json(json: json)
|
170
|
+
bool_vals = [1, '1', true, 'true', 'yes']
|
170
171
|
return json if provenance.nil? || p_key.nil? || !json.is_a?(Hash)
|
171
172
|
|
172
173
|
# Fail the json as is if the :PK does not match the :dmp_id if the json has a :PK
|
@@ -183,13 +184,13 @@ module Uc3DmpId
|
|
183
184
|
owner_id = extract_owner_id(json: json)
|
184
185
|
owner_org = extract_owner_org(json: json)
|
185
186
|
|
187
|
+
# Set the :dmproadmap_featured flag appropriately
|
188
|
+
annotated['dmproadmap_featured'] = bool_vals.include?(annotated['dmproadmap_featured']&.downcase) ? 1 : 0
|
189
|
+
|
186
190
|
# Update the modification timestamps
|
187
191
|
annotated['dmphub_modification_day'] = Time.now.strftime('%Y-%m-%d')
|
188
192
|
annotated['dmphub_owner_id'] = owner_id unless owner_id.nil?
|
189
193
|
annotated['dmphub_owner_org'] = owner_org unless owner_org.nil?
|
190
|
-
annotated['dmphub_updated_at'] = Time.now.iso8601 if annotated['dmphub_updated_at'].nil?
|
191
|
-
# Only add the Creation date if it is blank
|
192
|
-
annotated['dmphub_created_at'] = Time.now.iso8601 if json['dmphub_created_at'].nil?
|
193
194
|
return annotated unless json['dmphub_provenance_id'].nil?
|
194
195
|
|
195
196
|
annotated['dmphub_provenance_id'] = provenance.fetch('PK', '')
|
@@ -218,7 +219,7 @@ module Uc3DmpId
|
|
218
219
|
return json.map { |obj| cleanse_dmp_json(json: obj) }.compact if json.is_a?(Array)
|
219
220
|
|
220
221
|
cleansed = {}
|
221
|
-
allowable = %w[
|
222
|
+
allowable = %w[dmphub_versions]
|
222
223
|
json.each_key do |key|
|
223
224
|
next if (key.to_s.start_with?('dmphub') && !allowable.include?(key)) || %w[PK SK].include?(key.to_s)
|
224
225
|
|
data/lib/uc3-dmp-id/updater.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
|
+
require 'time'
|
4
5
|
|
5
6
|
module Uc3DmpId
|
6
7
|
class UpdaterError < StandardError; end
|
@@ -42,6 +43,10 @@ module Uc3DmpId
|
|
42
43
|
version = _process_modifications(owner: owner, updater: updater, version: version, mods: mods, note: note,
|
43
44
|
logger: logger)
|
44
45
|
|
46
|
+
# Set the :modified timestamps
|
47
|
+
now = Time.now.utc.iso8601
|
48
|
+
version['modified'] = now
|
49
|
+
|
45
50
|
# Save the changes
|
46
51
|
resp = client.put_item(json: version, logger: logger)
|
47
52
|
raise UpdaterError, MSG_DMP_UNABLE_TO_VERSION if resp.nil?
|
data/lib/uc3-dmp-id/version.rb
CHANGED
data/lib/uc3-dmp-id/versioner.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'uc3-dmp-dynamo'
|
4
|
+
require 'time'
|
4
5
|
|
5
6
|
module Uc3DmpId
|
6
7
|
class VersionerError < StandardError; end
|
@@ -19,19 +20,19 @@ module Uc3DmpId
|
|
19
20
|
key_conditions: {
|
20
21
|
PK: { attribute_value_list: [Helper.append_pk_prefix(p_key: p_key)], comparison_operator: 'EQ' }
|
21
22
|
},
|
22
|
-
projection_expression: '
|
23
|
+
projection_expression: 'modified',
|
23
24
|
scan_index_forward: false
|
24
25
|
}
|
25
26
|
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
26
27
|
client.query(args: args, logger: logger)
|
27
28
|
end
|
28
29
|
|
29
|
-
# Generate a snapshot of the current latest version of the DMP ID using the existing :
|
30
|
+
# Generate a snapshot of the current latest version of the DMP ID using the existing :modified as
|
30
31
|
# the new SK.
|
31
32
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
32
33
|
def generate_version(client:, latest_version:, owner:, updater:, logger: nil)
|
33
34
|
# Only create a version if the Updater is not the Owner OR the changes have happened on a different day
|
34
|
-
mod_time = Time.parse(latest_version.fetch('
|
35
|
+
mod_time = Time.parse(latest_version.fetch('modified', Time.now.utc.iso8601))
|
35
36
|
now = Time.now
|
36
37
|
if mod_time.nil? || !(now - mod_time).is_a?(Float)
|
37
38
|
logger.error(message: "#{SOURCE} unable to determine mod time: #{mod_time}") if logger.respond_to?(:debug)
|
@@ -47,10 +48,10 @@ module Uc3DmpId
|
|
47
48
|
return latest_version
|
48
49
|
end
|
49
50
|
|
50
|
-
# Make a copy of the latest_version and then update it's SK to the :
|
51
|
+
# Make a copy of the latest_version and then update it's SK to the :modified to mark it in a point of time
|
51
52
|
# We essentially make a snapshot of the record before making changes
|
52
53
|
prior = Helper.deep_copy_dmp(obj: latest_version)
|
53
|
-
prior['SK'] = "#{Helper::SK_DMP_PREFIX}#{latest_version['
|
54
|
+
prior['SK'] = "#{Helper::SK_DMP_PREFIX}#{latest_version['modified'] || Time.now.utc.iso8601}"
|
54
55
|
# Create the prior version record ()
|
55
56
|
client = client.nil? ? Uc3DmpDynamo::Client.new : client
|
56
57
|
resp = client.put_item(json: prior, logger: logger)
|
@@ -58,9 +59,6 @@ module Uc3DmpId
|
|
58
59
|
|
59
60
|
msg = "#{SOURCE} created version PK: #{prior['PK']} SK: #{prior['SK']}"
|
60
61
|
logger.info(message: msg, details: prior) if logger.respond_to?(:debug)
|
61
|
-
|
62
|
-
# Set the modification dates to now and then return the latest version
|
63
|
-
latest_version['dmphub_updated_at'] = Time.now.iso8601
|
64
62
|
latest_version
|
65
63
|
end
|
66
64
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
@@ -75,10 +73,10 @@ module Uc3DmpId
|
|
75
73
|
return json unless results.length > 1
|
76
74
|
|
77
75
|
versions = results.map do |ver|
|
78
|
-
next if ver['
|
76
|
+
next if ver['modified'].nil?
|
79
77
|
{
|
80
|
-
timestamp: ver['
|
81
|
-
url: "#{Helper.landing_page_url}#{Helper.remove_pk_prefix(p_key: p_key)}?version=#{ver['
|
78
|
+
timestamp: ver['modified'],
|
79
|
+
url: "#{Helper.landing_page_url}#{Helper.remove_pk_prefix(p_key: p_key)}?version=#{ver['modified']}"
|
82
80
|
}
|
83
81
|
end
|
84
82
|
json['dmp']['dmphub_versions'] = JSON.parse(versions.to_json)
|
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.121
|
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-08-
|
11
|
+
date: 2023-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|