uc3-dmp-id 0.0.74 → 0.0.76
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/deleter.rb +2 -1
- data/lib/uc3-dmp-id/finder.rb +92 -2
- data/lib/uc3-dmp-id/updater.rb +3 -2
- data/lib/uc3-dmp-id/version.rb +1 -1
- 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: 2f769de6ae77fa371a710f13351629a90092a596131b31f82d7ad5161e792f12
|
4
|
+
data.tar.gz: a3da20ecdce90334053349c726f4d4ed78abe00d5b915366957963be82ccbd40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4a350af34ae4eff82a0c24c2de1e309b62ece8b268d53b23014ed05505dbe646c0a40f126a5a346c88047a30e790e52375cfed3956b879ee2ba5f2b94cf5ccc
|
7
|
+
data.tar.gz: 9cda04030ef741a7f1f66eb62a7124755b572ae9791f8485a5081ac72c0efcd181b36e88f409b472078655bf7c2226f28b2956f16fb31e781ed362165ca4729d
|
data/lib/uc3-dmp-id/deleter.rb
CHANGED
@@ -43,7 +43,8 @@ puts resp.inspect
|
|
43
43
|
|
44
44
|
# Notify EZID about the removal
|
45
45
|
_post_process(json: dmp, debug: debug)
|
46
|
-
|
46
|
+
# Return the tombstoned record
|
47
|
+
Helper.cleanse_dmp_json(json: JSON.parse({ dmp: dmp }.to_json))
|
47
48
|
rescue Aws::Errors::ServiceError => e
|
48
49
|
Responder.log_error(source: source, message: e.message,
|
49
50
|
details: ([@provenance] << e.backtrace).flatten)
|
data/lib/uc3-dmp-id/finder.rb
CHANGED
@@ -9,15 +9,22 @@ module Uc3DmpId
|
|
9
9
|
class Finder
|
10
10
|
MSG_INVALID_ARGS = 'Expected JSON to be structured as `{ "dmp": { "PK": "value"} } OR \
|
11
11
|
{ "dmp": { "dmp_id": { "identifier": "value", "type": "value" } }`'
|
12
|
+
MSG_INVALID_OWNER_ID = 'Invalid :owner_orcid. Expected value to start with `https://orcid.org/`.'
|
13
|
+
MSG_INVALID_OWNER_ORG = 'Invalid :owner_org_ror. Expected value to start with `https://ror.org/`.'
|
14
|
+
MSG_INVALID_MOD_DATE = 'Invalid :modification_day. Expected value to be in the `YYYY-MM-DD` format.'
|
12
15
|
MSG_MISSING_PK = 'No PK was provided'
|
13
16
|
MSG_MISSING_PROV_ID = 'No Provenance identifier was provided. \
|
14
17
|
Expected: `{ "dmp_id": { "identifier": "value", "type": "value" }`'
|
15
18
|
|
19
|
+
|
16
20
|
class << self
|
17
21
|
# TODO: Replace this with ElasticSearch
|
18
|
-
def search_dmps(args:)
|
22
|
+
def search_dmps(args:, debug: false)
|
23
|
+
return _by_owner(owner_org: args['owner_orcid'], debug: debug) unless args['owner_orcid'].nil?
|
24
|
+
return _by_owner_org(owner_org: args['owner_org_ror'], debug: debug) unless args['owner_org_ror'].nil?
|
25
|
+
return _by_mod_day(day: args['modification_day'], debug: debug) unless args['modification_day'].nil?
|
19
26
|
|
20
|
-
|
27
|
+
[]
|
21
28
|
end
|
22
29
|
# rubocop:enable Metrics/MethodLength
|
23
30
|
|
@@ -104,6 +111,89 @@ module Uc3DmpId
|
|
104
111
|
by_pk(p_key: dmp['dmp']['PK'], s_key: dmp['dmp']['SK'])
|
105
112
|
end
|
106
113
|
# rubocop:enable Metrics/AbcSize
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
# 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:, debug: false)
|
119
|
+
regex = %r{^([0-9A-Z]{4}-){3}[0-9A-Z]{4}$}
|
120
|
+
raise FinderError, MSG_INVALID_OWNER_ID if owner_id.nil? || (owner_id.to_s.downcase =~ regex).nil?
|
121
|
+
|
122
|
+
args = {
|
123
|
+
index_name: 'dmphub_owner_id_gsi',
|
124
|
+
key_conditions: {
|
125
|
+
dmphub_owner_id: {
|
126
|
+
attribute_value_list: [
|
127
|
+
"http://orcid.org/#{owner_id.to_s.downcase}",
|
128
|
+
"https://orcid.org/#{owner_id.to_s.downcase}"
|
129
|
+
],
|
130
|
+
comparison_operator: 'EQ'
|
131
|
+
}
|
132
|
+
},
|
133
|
+
filter_expression: 'SK = :version',
|
134
|
+
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
135
|
+
}
|
136
|
+
puts "Querying _by_owner with #{args}" if debug
|
137
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new(debug: debug) : client
|
138
|
+
_process_search_response(response: client.query(args: args))
|
139
|
+
end
|
140
|
+
|
141
|
+
# 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:, debug: false)
|
143
|
+
regex = %r{^[a-zA-Z0-9]+$}
|
144
|
+
raise FinderError, MSG_INVALID_OWNER_ID if owner_org.nil? ||(owner_org.to_s.downcase =~ regex).nil?
|
145
|
+
|
146
|
+
args = {
|
147
|
+
index_name: 'dmphub_owner_org_gsi',
|
148
|
+
key_conditions: {
|
149
|
+
dmphub_owner_org: {
|
150
|
+
attribute_value_list: [
|
151
|
+
"http://ror.org/#{owner_org.to_s.downcase}",
|
152
|
+
"https://ror.org/#{owner_org.to_s.downcase}"
|
153
|
+
],
|
154
|
+
comparison_operator: 'EQ'
|
155
|
+
}
|
156
|
+
},
|
157
|
+
filter_expression: 'SK = :version',
|
158
|
+
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
159
|
+
}
|
160
|
+
puts "Querying _by_owner_org with #{args}" if debug
|
161
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new(debug: debug) : client
|
162
|
+
_process_search_response(response: client.query(args: args))
|
163
|
+
end
|
164
|
+
|
165
|
+
# 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:, debug: false)
|
167
|
+
regex = %r{^[0-9]{4}(-[0-9]{2}){2}}
|
168
|
+
raise FinderError, MSG_INVALID_OWNER_ID if day.nil? || (day.to_s =~ regex).nil?
|
169
|
+
|
170
|
+
args = {
|
171
|
+
index_name: 'dmphub_modification_day_gsi',
|
172
|
+
key_conditions: {
|
173
|
+
dmphub_modification_day: {
|
174
|
+
attribute_value_list: [day.to_s],
|
175
|
+
comparison_operator: 'EQ'
|
176
|
+
}
|
177
|
+
},
|
178
|
+
filter_expression: 'SK = :version',
|
179
|
+
expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
|
180
|
+
}
|
181
|
+
puts "Querying _by_mod_day with #{args}" if debug
|
182
|
+
client = client.nil? ? Uc3DmpDynamo::Client.new(debug: debug) : client
|
183
|
+
_process_search_response(response: client.query(args: args))
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
# Transform the search results so that we do not include any of the DMPHub specific metadata
|
188
|
+
def _process_search_response(response:)
|
189
|
+
return [] unless response.is_a?(Array) && response.any?
|
190
|
+
|
191
|
+
results = response.each do |item|
|
192
|
+
dmp = item['dmp'].nil? ? JSON.parse({ dmp: item }.to_json) : item
|
193
|
+
Helper.cleanse_dmp_json(json: dmp)
|
194
|
+
end
|
195
|
+
results.compact.uniq
|
196
|
+
end
|
107
197
|
end
|
108
198
|
end
|
109
199
|
end
|
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: {}, debug: false)
|
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)
|
@@ -35,7 +35,8 @@ module Uc3DmpId
|
|
35
35
|
|
36
36
|
# Send the updates to EZID, notify the provenance and download the PDF if applicable
|
37
37
|
_post_process(json: dmp, debug: debug)
|
38
|
-
|
38
|
+
# Return the new version record
|
39
|
+
Helper.cleanse_dmp_json(json: JSON.parse({ dmp: new_version }.to_json))
|
39
40
|
end
|
40
41
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
41
42
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
data/lib/uc3-dmp-id/version.rb
CHANGED
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.76
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|