dmp-dynamo_adapter 0.2.6 → 0.2.9
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/dmp/dmp_id_handler.rb +1 -19
- data/lib/dmp/dynamo_adapter.rb +21 -3
- data/lib/dmp/metadata_handler.rb +2 -2
- 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: d66690b743822deb2db2a047370660b2cd7ec3206844534facbaf04f7f98474c
|
4
|
+
data.tar.gz: a2d9f06124324415cb5128d6f9f11b305c70d14656788fc38fe4f72bf9af1bc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaba013e38394e8f547a2002eb7c27b9fc9101f950fb53c0880b71c8cb57815dc2459fc65a262d09f1856af73a6ab7f5a3d1bbe15593985845f58c6f7a5bf85a
|
7
|
+
data.tar.gz: 650f1918d18c4408b25b732a18805b05ff11cb45e41a6aaeaf823d54954fbb4e7805edf60437ef2030348402d77770866787c8a574f9a155f97c77bd9b42a8f6
|
data/lib/dmp/dmp_id_handler.rb
CHANGED
@@ -10,25 +10,7 @@ module Dmp
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
def dmp_id_base_url
|
13
|
-
ENV['DMP_ID_BASE_URL']
|
14
|
-
end
|
15
|
-
|
16
|
-
# Preassign a DMP ID that will leater be sent to the DOI minting authority (EZID)
|
17
|
-
def preregister_dmp_id
|
18
|
-
dmp_id = ''
|
19
|
-
counter = 0
|
20
|
-
|
21
|
-
p 'PREREGISTER DMP ID:'
|
22
|
-
|
23
|
-
while dmp_id == '' && counter <= 10
|
24
|
-
prefix = "#{ENV['DMP_ID_SHOULDER']}.#{SecureRandom.hex(4).upcase}"
|
25
|
-
dmp_id = prefix if find_by_pk(p_key: Dmp::MetadataHandler.append_pk_prefix(dmp: dmp_id)).empty?
|
26
|
-
counter += 1
|
27
|
-
end
|
28
|
-
# Something went wrong and it was unable to identify a unique id
|
29
|
-
return nil if counter >= 10
|
30
|
-
|
31
|
-
"#{Dmp::MetadataHandler::PK_DMP_PREFIX}#{dmp_id_base_url}#{dmp_id}"
|
13
|
+
ENV['DMP_ID_BASE_URL']&.end_with?('/') ? ENV['DMP_ID_BASE_URL'] : "#{ENV['DMP_ID_BASE_URL']}/"
|
32
14
|
end
|
33
15
|
|
34
16
|
# Format the DMP ID in the way we want it
|
data/lib/dmp/dynamo_adapter.rb
CHANGED
@@ -89,8 +89,7 @@ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
|
|
89
89
|
|
90
90
|
# find_by_PK
|
91
91
|
response = find_by_pk(p_key: pk, s_key: json['SK']) unless pk.nil?
|
92
|
-
return response
|
93
|
-
return response unless response[:items].nil? || response[:items].empty?
|
92
|
+
return response unless response[:status] != 404
|
94
93
|
|
95
94
|
# find_by_dmphub_provenance_id -> if no PK and no dmp_id result
|
96
95
|
find_by_dmphub_provenance_identifier(json: json)
|
@@ -110,7 +109,7 @@ p "FINDING BY PK: PK - #{p_key.inspect} / SK - #{s_key.inspect}"
|
|
110
109
|
return { status: 400, error: MSG_EXISTS } if result.fetch(:items, []).any?
|
111
110
|
|
112
111
|
# allocate a DMP ID
|
113
|
-
p_key =
|
112
|
+
p_key = preregister_dmp_id
|
114
113
|
|
115
114
|
p "PRE REGISTERED DMP ID: #{p_key.inspect}"
|
116
115
|
|
@@ -289,6 +288,25 @@ pp response.data
|
|
289
288
|
end
|
290
289
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
291
290
|
|
291
|
+
# Preassign a DMP ID that will leater be sent to the DOI minting authority (EZID)
|
292
|
+
def preregister_dmp_id
|
293
|
+
dmp_id = ''
|
294
|
+
counter = 0
|
295
|
+
|
296
|
+
p 'PREREGISTER DMP ID:'
|
297
|
+
|
298
|
+
while dmp_id == '' && counter <= 10
|
299
|
+
prefix = "#{ENV['DMP_ID_SHOULDER']}.#{SecureRandom.hex(4).upcase}"
|
300
|
+
result = find_by_pk(p_key: Dmp::MetadataHandler.append_pk_prefix(dmp: dmp_id))
|
301
|
+
dmp_id = prefix unless result[:status] != 404
|
302
|
+
counter += 1
|
303
|
+
end
|
304
|
+
# Something went wrong and it was unable to identify a unique id
|
305
|
+
return nil if counter >= 10
|
306
|
+
|
307
|
+
"#{Dmp::MetadataHandler::PK_DMP_PREFIX}#{Dmp::DmpIdHandler.dmp_id_base_url}#{dmp_id}"
|
308
|
+
end
|
309
|
+
|
292
310
|
# Convert the latest version into a historical version
|
293
311
|
# rubocop:disable Metrics/MethodLength
|
294
312
|
def version_it(dmp:)
|
data/lib/dmp/metadata_handler.rb
CHANGED
@@ -74,7 +74,7 @@ p "ANNOTATING METADATA:"
|
|
74
74
|
annotated['dmp_id'] = Dmp::DmpIdHandler.pk_to_dmp_id(p_key: annotated['PK'])
|
75
75
|
|
76
76
|
# Update the modification timestamps
|
77
|
-
annotated['dmphub_modification_day'] = Time.now.strftime('%Y-%
|
77
|
+
annotated['dmphub_modification_day'] = Time.now.strftime('%Y-%m-%d')
|
78
78
|
annotated['dmphub_updated_at'] = Time.now.iso8601
|
79
79
|
# Only add the Creation date if it is blank
|
80
80
|
annotated['dmphub_created_at'] = Time.now.iso8601 if json['dmphub_created_at'].nil?
|
@@ -85,7 +85,7 @@ p "ANNOTATING METADATA:"
|
|
85
85
|
json.fetch('dmp_id', {})['identifier'].nil?
|
86
86
|
|
87
87
|
# Record the original Provenance system's identifier
|
88
|
-
annotated['dmphub_provenance_identifier'] = json
|
88
|
+
annotated['dmphub_provenance_identifier'] = json.fetch('dmp_id', {})['identifier']
|
89
89
|
annotated
|
90
90
|
end
|
91
91
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|