uc3-dmp-id 0.0.4 → 0.0.6
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 +15 -15
- data/lib/uc3-dmp-id/helper.rb +24 -0
- data/lib/uc3-dmp-id/version.rb +1 -1
- data/lib/uc3-dmp-id.rb +8 -1
- 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: ab1c5afc33fa7cf9bafbc4a62a282a0674cdbe81c47566865789db74fc411ea3
|
4
|
+
data.tar.gz: 16521d303406e294953b43108abb65b8e7af94d635a782e8008db91cae6e4c96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbf1707d4052898f39ad30f06979f1218951f02bf24833669ff4743957a4e404278fe8112b791a5bef9f27d99e9081a267ee135a283467e77ea894143607ac43
|
7
|
+
data.tar.gz: bfc2e024b3f73980302f2d8e3a15d945a541129ed02286b6f052371489f48a97e6af4eec31e46669169157035bacc28acd89954db1e5b3ea407647f35c907b5c
|
data/lib/uc3-dmp-id/finder.rb
CHANGED
@@ -23,7 +23,7 @@ module Uc3DmpId
|
|
23
23
|
|
24
24
|
# Find the DMP's versions
|
25
25
|
# -------------------------------------------------------------------------
|
26
|
-
def versions(p_key:)
|
26
|
+
def versions(p_key:, client: nil, log_writer: nil, debug: false)
|
27
27
|
raise Uc3DmpIdFinderError, MSG_MISSING_PK if p_key.nil?
|
28
28
|
|
29
29
|
args = {
|
@@ -33,36 +33,36 @@ module Uc3DmpId
|
|
33
33
|
projection_expression: 'modified',
|
34
34
|
scan_index_forward: false
|
35
35
|
}
|
36
|
-
client = Uc3DmpDynamo::Client.new
|
36
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new(log_writer: log_writer, debug: debug) : client
|
37
37
|
client.query(**args)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Find a DMP based on the contents of the incoming JSON
|
41
41
|
# -------------------------------------------------------------------------
|
42
|
-
def by_json(json:)
|
42
|
+
def by_json(json:, log_writer: nil, debug: false)
|
43
43
|
json = Validator.parse_json(json: json)&.fetch('dmp', {})
|
44
44
|
raise Uc3DmpIdFinderError, MSG_INVALID_ARGS if json.nil? || (json['PK'].nil? && json['dmp_id'].nil?)
|
45
45
|
|
46
46
|
p_key = json['PK']
|
47
47
|
# Translate the incoming :dmp_id into a PK
|
48
48
|
p_key = Helper.dmp_id_to_pk(json: json.fetch('dmp_id', {})) if p_key.nil?
|
49
|
-
|
50
|
-
# find_by_PK
|
51
|
-
resp = by_pk(p_key: p_key, s_key: json['SK']) unless p_key.nil?
|
52
|
-
return resp unless resp.nil?
|
49
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new(log_writer: log_writer, debug: debug) : client
|
53
50
|
|
54
51
|
# find_by_dmphub_provenance_id -> if no PK and no dmp_id result
|
55
|
-
|
52
|
+
return by_provenance_identifier(json: json, client: client, log_writer: log_writer, debug: debug) if p_key.nil?
|
53
|
+
|
54
|
+
# find_by_PK
|
55
|
+
by_pk(p_key: p_key, s_key: json['SK'], client: client, log_writer: log_writer, debug: debug)
|
56
56
|
end
|
57
57
|
|
58
58
|
# Find the DMP by its PK and SK
|
59
59
|
# -------------------------------------------------------------------------
|
60
|
-
def by_pk(p_key:, s_key: Helper::DMP_LATEST_VERSION)
|
60
|
+
def by_pk(p_key:, s_key: Helper::DMP_LATEST_VERSION, client: nil, log_writer: nil, debug: false)
|
61
61
|
raise Uc3DmpIdFinderError, MSG_MISSING_PK if p_key.nil?
|
62
62
|
|
63
63
|
s_key = Helper::DMP_LATEST_VERSION if s_key.nil? || s_key.strip.empty?
|
64
64
|
|
65
|
-
client = Uc3DmpDynamo::Client.new
|
65
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new(log_writer: log_writer, debug: debug) : client
|
66
66
|
resp = client.get_item(
|
67
67
|
key: {
|
68
68
|
PK: Helper.append_pk_prefix(dmp: p_key),
|
@@ -71,13 +71,13 @@ module Uc3DmpId
|
|
71
71
|
)
|
72
72
|
return nil if resp.nil? || resp.fetch('dmp', {})['PK'].nil?
|
73
73
|
|
74
|
-
_append_versions(p_key: resp['dmp']['PK'], dmp: resp)
|
74
|
+
_append_versions(p_key: resp['dmp']['PK'], dmp: resp, client: client)
|
75
75
|
end
|
76
76
|
|
77
77
|
# Attempt to find the DMP item by the provenance system's identifier
|
78
78
|
# -------------------------------------------------------------------------
|
79
79
|
# rubocop:disable Metrics/AbcSize
|
80
|
-
def
|
80
|
+
def by_provenance_identifier(json:, client: nil, log_writer: nil, debug: false)
|
81
81
|
raise Uc3DmpIdFinderError, MSG_MISSING_PROV_ID if json.nil? || json.fetch('dmp_id', {})['identifier'].nil?
|
82
82
|
|
83
83
|
args = {
|
@@ -90,7 +90,7 @@ module Uc3DmpId
|
|
90
90
|
filter_expression: 'SK = :version',
|
91
91
|
expression_attribute_values: { ':version': KeyHelper::DMP_LATEST_VERSION }
|
92
92
|
}
|
93
|
-
client = Uc3DmpDynamo::Client.new
|
93
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new(log_writer: log_writer, debug: debug) : client
|
94
94
|
resp = client.query(**args)
|
95
95
|
return resp if resp.nil? || resp['dmp'].nil?
|
96
96
|
|
@@ -103,10 +103,10 @@ module Uc3DmpId
|
|
103
103
|
|
104
104
|
# Build the dmphub_versions array and attach it to the dmp
|
105
105
|
# rubocop:disable Metrics/AbcSize
|
106
|
-
def _append_versions(p_key:, dmp:)
|
106
|
+
def _append_versions(p_key:, dmp:, client: nil, log_writer: log_writer, debug: false)
|
107
107
|
return dmp if p_key.nil? || !dmp.is_a?(Hash) || dmp['dmp'].nil?
|
108
108
|
|
109
|
-
results =
|
109
|
+
results = versions(p_key: p_key, client: client, log_writer: log_writer, debug: debug)
|
110
110
|
return dmp unless results.length > 1
|
111
111
|
|
112
112
|
versions = results.map do |version|
|
data/lib/uc3-dmp-id/helper.rb
CHANGED
@@ -22,6 +22,30 @@ module Uc3DmpId
|
|
22
22
|
DMP_TOMBSTONE_VERSION = "#{SK_DMP_PREFIX}tombstone"
|
23
23
|
|
24
24
|
class << self
|
25
|
+
# Append the PK prefix for the object
|
26
|
+
# -------------------------------------------------------------------------------------
|
27
|
+
def append_pk_prefix(p_key:)
|
28
|
+
p_key.is_a?(String) ? "#{PK_DMP_PREFIX}#{remove_pk_prefix(p_key: p_key)}" : nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# Strip off the PK prefix
|
32
|
+
# -------------------------------------------------------------------------------------
|
33
|
+
def remove_pk_prefix(p_key:)
|
34
|
+
p_key.is_a?(String) ? p_key.gsub(PK_DMP_PREFIX, '') : p_key
|
35
|
+
end
|
36
|
+
|
37
|
+
# Append the SK prefix for the object
|
38
|
+
# -------------------------------------------------------------------------------------
|
39
|
+
def append_sk_prefix(s_key:)
|
40
|
+
s_key.is_a?(String) ? "#{SK_DMP_PREFIX}#{remove_pk_prefix(s_key: s_key)}" : nil
|
41
|
+
end
|
42
|
+
|
43
|
+
# Strip off the SK prefix
|
44
|
+
# -------------------------------------------------------------------------------------
|
45
|
+
def remove_sk_prefix(s_key:)
|
46
|
+
s_key.is_a?(String) ? s_key.gsub(SK_DMP_PREFIX, '') : s_key
|
47
|
+
end
|
48
|
+
|
25
49
|
# Return the base URL for a DMP ID
|
26
50
|
def dmp_id_base_url
|
27
51
|
url = ENV.fetch('DMP_ID_BASE_URL', 'https://dmptool-dev.cdlib.org/dmps/')
|
data/lib/uc3-dmp-id/version.rb
CHANGED
data/lib/uc3-dmp-id.rb
CHANGED
@@ -13,6 +13,13 @@ require 'uc3-dmp-id/validator'
|
|
13
13
|
require 'uc3-dmp-id/versioner'
|
14
14
|
|
15
15
|
module Uc3DmpId
|
16
|
-
|
16
|
+
MSG_DMP_EXISTS = 'DMP already exists. Try :update instead.'
|
17
|
+
MSG_DMP_UNKNOWN = 'DMP does not exist. Try :create instead.'
|
18
|
+
MSG_DMP_NOT_FOUND = 'DMP does not exist.'
|
19
|
+
MSG_DMP_FORBIDDEN = 'You do not have permission.'
|
20
|
+
MSG_DMP_NO_DMP_ID = 'A DMP ID could not be registered at this time.'
|
21
|
+
MSG_DMP_INVALID_DMP_ID = 'Invalid DMP ID format.'
|
22
|
+
MSG_DMP_NO_HISTORICALS = 'You cannot modify a historical version of the DMP.'
|
23
|
+
MSG_DMP_UNABLE_TO_VERSION = 'Unable to version this DMP.'
|
17
24
|
end
|
18
25
|
# rubocop:enable Naming/FileName
|