uc3-dmp-id 0.1.59 → 0.1.60
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/uc3-dmp-id/finder.rb +47 -61
- 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: 791179155f0be964f0cfc186f26de88e9f0774ee9ebb671f7856074b1d40639e
|
|
4
|
+
data.tar.gz: 0bf38f90d0863863362ea4fb5357566d8b262c2036840d78519796e2d55d893a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e938eb3ddaa088e2cc17bb6a4202de8673c5eeb046c47207e1c040eff8775fdede2b835a90758ab8e892490677b93502c205b0244fae3884299498caf27575a8
|
|
7
|
+
data.tar.gz: ae45834944f078ab9e0d3fae1c6b32d2f5015c5b74b46c526c62b457b22e329662c6049ba4dd090e67f4c7f4208d9a1f858cb62b4dc52fa8b1e2bc1b4b17f692
|
data/lib/uc3-dmp-id/finder.rb
CHANGED
|
@@ -17,19 +17,32 @@ module Uc3DmpId
|
|
|
17
17
|
MSG_MISSING_PROV_ID = 'No Provenance identifier was provided. \
|
|
18
18
|
Expected: `{ "dmp_id": { "identifier": "value", "type": "value" }`'
|
|
19
19
|
|
|
20
|
-
ORCID_DOMAIN = 'orcid.org'
|
|
21
|
-
ROR_DOMAIN = 'ror.org'
|
|
20
|
+
ORCID_DOMAIN = 'https://orcid.org/'
|
|
21
|
+
ROR_DOMAIN = 'https://ror.org/'
|
|
22
22
|
|
|
23
23
|
class << self
|
|
24
24
|
# TODO: Replace this with ElasticSearch
|
|
25
25
|
def search_dmps(args:, logger: nil)
|
|
26
|
+
# Fetch the DMPs for each of the possible filter options
|
|
26
27
|
client = Uc3DmpDynamo::Client.new(table: ENV['DYNAMO_INDEX_TABLE'])
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return
|
|
28
|
+
owner_pks = _by_owner(owner: args['owner'], client:, logger:) unless args['owner'].nil?
|
|
29
|
+
org_pks = _by_org(org: args['org'], client:, logger:) unless args['org'].nil?
|
|
30
|
+
funder_pks = _by_funder(funder: args['funder'], client:, logger:) unless args['funder'].nil?
|
|
31
|
+
return [] if owner_pks.empty? && org_pks.empty? && funder_pks.empty?
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
# Only use the DMPs that fit all of the filter criteria
|
|
34
|
+
dmps = owner_pks & org_pks & funder_pks
|
|
35
|
+
return [] if dmps.nil? || dmps.empty?
|
|
36
|
+
|
|
37
|
+
# Perfom search operations
|
|
38
|
+
|
|
39
|
+
# Handle sort
|
|
40
|
+
|
|
41
|
+
# Handle pagination
|
|
42
|
+
|
|
43
|
+
# Fetch full DMP records
|
|
44
|
+
client = Uc3DmpDynamo::Client.new(table: ENV['DYNAMO_TABLE'])
|
|
45
|
+
_fetch_dmps(client:, pks: dmps.map { |dmp| dmp['pk'] }, logger:)
|
|
33
46
|
end
|
|
34
47
|
|
|
35
48
|
# Find a DMP based on the contents of the incoming JSON
|
|
@@ -133,73 +146,41 @@ module Uc3DmpId
|
|
|
133
146
|
|
|
134
147
|
# Fetch the DMP IDs for the specified person's ORCID (or email)
|
|
135
148
|
def _by_owner(owner:, client: nil, logger: nil)
|
|
136
|
-
orcid_regex = /^([0-
|
|
149
|
+
orcid_regex = /^([0-9a-zA-Z]{4}-){3}[0-9a-zA-Z]{4}$/
|
|
137
150
|
email_regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
"https://#{ORCID_DOMAIN}/#{owner}"
|
|
148
|
-
]
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
elsif !email.nil?
|
|
152
|
-
args = {
|
|
153
|
-
filter_expression: 'contains(people, :email) AND SK = :sk',
|
|
154
|
-
expression_attribute_values: { ':sk': 'METADATA', ':email': [email.gsub('%40', '@')] }
|
|
155
|
-
}
|
|
156
|
-
else
|
|
157
|
-
# It wasn't an email or ORCID, so return an empty array
|
|
158
|
-
return []
|
|
159
|
-
end
|
|
160
|
-
logger&.debug(message: 'Fetch relevant DMPs _by_owner - scan args', details: args)
|
|
161
|
-
client = Uc3DmpDynamo::Client.new if client.nil?
|
|
162
|
-
_process_search_response(response: client.scan(args:))
|
|
151
|
+
orcid = owner.to_s.strip
|
|
152
|
+
return [] if (orcid =~ orcid_regex).nil? && (orcid =~ email_regex).nil?
|
|
153
|
+
|
|
154
|
+
orcid = "#{ORCID_DOMAIN}#{orcid}" unless (orcid =~ orcid_regex).nil?
|
|
155
|
+
resp = client.get_item(key: { PK: 'PERSON_INDEX', SK: orcid }, logger:)
|
|
156
|
+
return [] unless resp.is_a?(Hash)
|
|
157
|
+
|
|
158
|
+
logger&.debug(message: "DMPs for PERSON #{orcid}", details: resp)
|
|
159
|
+
resp.fetch('dmps', [])
|
|
163
160
|
end
|
|
164
161
|
|
|
165
162
|
# Fetch the DMP IDs for the specified organization/institution
|
|
166
163
|
def _by_org(org:, client: nil, logger: nil)
|
|
167
164
|
regex = /^[a-zA-Z0-9]+$/
|
|
168
|
-
ror = org.strip unless (org.to_s =~ regex).nil?
|
|
165
|
+
ror = "#{ROR_DOMAIN}/#{org.strip}" unless (org.to_s =~ regex).nil?
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
"http://#{ROR_DOMAIN}/#{ror}",
|
|
176
|
-
"https://#{ROR_DOMAIN}/#{ror}"
|
|
177
|
-
]
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
logger&.debug(message: 'Fetch relevant DMPs _by_org - scan args', details: args)
|
|
181
|
-
client = Uc3DmpDynamo::Client.new if client.nil?
|
|
182
|
-
_process_search_response(response: client.scan(args:))
|
|
167
|
+
resp = client.get_item(key: { PK: 'AFFILIATION_INDEX', SK: ror }, logger:)
|
|
168
|
+
return [] unless resp.is_a?(Hash)
|
|
169
|
+
|
|
170
|
+
logger&.debug(message: "DMPs for AFFILIATION #{ror}", details: resp)
|
|
171
|
+
resp.fetch('dmps', [])
|
|
183
172
|
end
|
|
184
173
|
|
|
185
174
|
# Fetch the DMP IDs for the specified funder
|
|
186
175
|
def _by_funder(funder:, client: nil, logger: nil)
|
|
187
176
|
regex = /^[a-zA-Z0-9]+$/
|
|
188
|
-
ror = funder.strip unless (funder.to_s =~ regex).nil?
|
|
177
|
+
ror = "#{ROR_DOMAIN}/#{funder.strip}" unless (funder.to_s =~ regex).nil?
|
|
189
178
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
"http://#{ROR_DOMAIN}/#{ror}",
|
|
196
|
-
"https://#{ROR_DOMAIN}/#{ror}"
|
|
197
|
-
]
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
logger&.debug(message: 'Fetch relevant DMPs _by_funder - scan args', details: args)
|
|
201
|
-
client = Uc3DmpDynamo::Client.new if client.nil?
|
|
202
|
-
_process_search_response(response: client.scan(args:))
|
|
179
|
+
resp = client.get_item(key: { PK: 'FUNDER_INDEX', SK: ror }, logger:)
|
|
180
|
+
return [] unless resp.is_a?(Hash)
|
|
181
|
+
|
|
182
|
+
logger&.debug(message: "DMPs for FUNDER #{ror}", details: resp)
|
|
183
|
+
resp.fetch('dmps', [])
|
|
203
184
|
end
|
|
204
185
|
|
|
205
186
|
# Fetch the DMP IDs that are marked as featured
|
|
@@ -224,6 +205,11 @@ module Uc3DmpId
|
|
|
224
205
|
_process_search_response(response: client.scan(args:))
|
|
225
206
|
end
|
|
226
207
|
|
|
208
|
+
# Fetches all of the DMPs by their PKs
|
|
209
|
+
def _fetch_dmps(client:, pks:, logger: null)
|
|
210
|
+
|
|
211
|
+
end
|
|
212
|
+
|
|
227
213
|
# Transform the search results so that we do not include any of the DMPHub specific metadata
|
|
228
214
|
def _process_search_response(response:)
|
|
229
215
|
return [] unless response.is_a?(Array) && response.any?
|
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.1.
|
|
4
|
+
version: 0.1.60
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Riley
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-07-
|
|
11
|
+
date: 2024-07-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|