uc3-dmp-id 0.1.59 → 0.1.61

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59344bea0d31538592f45cc51bda5971e9834ba66ba6b75b99f25bc188307782
4
- data.tar.gz: b57a971d2734b20cda13bd67df9f8c1e1f14f3c80d17eb6dc92d0a00ac28e3e0
3
+ metadata.gz: bb07288c4e1b21217a2ca9ed4df6a8c7243968c2cea3dbd0474796b6399d2a09
4
+ data.tar.gz: 665c7eb28c3fd99e73c50f06b9bd95be7f96bb95b0a0c551634c6b5c941fd9db
5
5
  SHA512:
6
- metadata.gz: 90bee71bd0005f49adb736c0ba5fad0d75e40b12815cb46bc0a73352e841bd7b2372e7038282427d7dbfda05fd7f060e04500c4588ce578424a7632bd19510fd
7
- data.tar.gz: 958e3d10549189e8e7d47d950cb27dddb84623f1d8b13d23386b555c773cfe3b8ecbef41d4221a225b84dbcd7f5079701f98218947aff58156fd2e8fe5b18946
6
+ metadata.gz: 8f196c1f061e5fcbd9085f5d483936797b3fe97bdb3e74b9bb8e2fc83effdefc4ecffbb28a0f0b478418fff6e8b6edd21b35cb2e103e6d7db1696e33e94d9d2f
7
+ data.tar.gz: b4adad6f533baff187391f415123134b93ffc0c01a93771f6519d8e935f91966c32c0d2ff2c051a98b09a596a615c86226b1f7ba6eeda72092b34b127edac403
@@ -17,19 +17,36 @@ 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
- return _by_owner(owner: args['owner'], client:, logger:) unless args['owner'].nil?
28
- return _by_org(org: args['org'], client:, logger:) unless args['org'].nil?
29
- return _by_funder(funder: args['funder'], client:, logger:) unless args['funder'].nil?
30
- return _by_featured(client:, logger:) if args.fetch('featured', 'false').to_s.downcase == 'true'
28
+ owner = args['owner']
29
+ org = args['org']
30
+ funder = args['funder']
31
31
 
32
- return _publicly_visible(client:, logger:)
32
+ owner_pks = owner.nil? ? [] : _by_owner(owner: owner, client:, logger:)
33
+ org_pks = org.nil? ? [] : _by_org(org: org, client:, logger:)
34
+ funder_pks = funder.nil? ? [] : _by_funder(funder: funder, client:, logger:)
35
+ return [] if owner_pks.empty? && org_pks.empty? && funder_pks.empty?
36
+
37
+ # Only use the DMPs that fit all of the filter criteria
38
+ dmps = owner_pks & org_pks & funder_pks
39
+ return [] if dmps.nil? || dmps.empty?
40
+
41
+ # Perfom search operations
42
+
43
+ # Handle sort
44
+
45
+ # Handle pagination
46
+
47
+ # Fetch full DMP records
48
+ client = Uc3DmpDynamo::Client.new(table: ENV['DYNAMO_TABLE'])
49
+ _fetch_dmps(client:, pks: dmps.map { |dmp| dmp['pk'] }, logger:)
33
50
  end
34
51
 
35
52
  # Find a DMP based on the contents of the incoming JSON
@@ -133,73 +150,41 @@ module Uc3DmpId
133
150
 
134
151
  # Fetch the DMP IDs for the specified person's ORCID (or email)
135
152
  def _by_owner(owner:, client: nil, logger: nil)
136
- orcid_regex = /^([0-9A-Z]{4}-){3}[0-9A-Z]{4}$/
153
+ orcid_regex = /^([0-9a-zA-Z]{4}-){3}[0-9a-zA-Z]{4}$/
137
154
  email_regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
138
- email = owner.strip unless (owner.to_s.strip.gsub('%40', '@') =~ email_regex).nil?
139
-
140
- if !(owner.to_s.strip =~ orcid_regex).nil?
141
- args = {
142
- filter_expression: 'contains(people_ids, :orcids) AND SK = :sk',
143
- expression_attribute_values: {
144
- ':sk': 'METADATA',
145
- ':orcids': [
146
- "http://#{ORCID_DOMAIN}/#{owner}",
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:))
155
+ orcid = owner.to_s.strip
156
+ return [] if (orcid =~ orcid_regex).nil? && (orcid =~ email_regex).nil?
157
+
158
+ orcid = "#{ORCID_DOMAIN}#{orcid}" unless (orcid =~ orcid_regex).nil?
159
+ resp = client.get_item(key: { PK: 'PERSON_INDEX', SK: orcid }, logger:)
160
+ return [] unless resp.is_a?(Hash)
161
+
162
+ logger&.debug(message: "DMPs for PERSON #{orcid}", details: resp)
163
+ resp.fetch('dmps', [])
163
164
  end
164
165
 
165
166
  # Fetch the DMP IDs for the specified organization/institution
166
167
  def _by_org(org:, client: nil, logger: nil)
167
168
  regex = /^[a-zA-Z0-9]+$/
168
- ror = org.strip unless (org.to_s =~ regex).nil?
169
+ ror = "#{ROR_DOMAIN}/#{org.strip}" unless (org.to_s =~ regex).nil?
169
170
 
170
- args = {
171
- filter_expression: 'contains(affiliation_ids, :rors) AND SK = :sk',
172
- expression_attribute_values: {
173
- ':sk': 'METADATA',
174
- ':rors': [
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:))
171
+ resp = client.get_item(key: { PK: 'AFFILIATION_INDEX', SK: ror }, logger:)
172
+ return [] unless resp.is_a?(Hash)
173
+
174
+ logger&.debug(message: "DMPs for AFFILIATION #{ror}", details: resp)
175
+ resp.fetch('dmps', [])
183
176
  end
184
177
 
185
178
  # Fetch the DMP IDs for the specified funder
186
179
  def _by_funder(funder:, client: nil, logger: nil)
187
180
  regex = /^[a-zA-Z0-9]+$/
188
- ror = funder.strip unless (funder.to_s =~ regex).nil?
181
+ ror = "#{ROR_DOMAIN}/#{funder.strip}" unless (funder.to_s =~ regex).nil?
189
182
 
190
- args = {
191
- filter_expression: 'contains(funder_ids, :rors) AND SK = :sk',
192
- expression_attribute_values: {
193
- ':sk': 'METADATA',
194
- ':rors': [
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:))
183
+ resp = client.get_item(key: { PK: 'FUNDER_INDEX', SK: ror }, logger:)
184
+ return [] unless resp.is_a?(Hash)
185
+
186
+ logger&.debug(message: "DMPs for FUNDER #{ror}", details: resp)
187
+ resp.fetch('dmps', [])
203
188
  end
204
189
 
205
190
  # Fetch the DMP IDs that are marked as featured
@@ -224,6 +209,11 @@ module Uc3DmpId
224
209
  _process_search_response(response: client.scan(args:))
225
210
  end
226
211
 
212
+ # Fetches all of the DMPs by their PKs
213
+ def _fetch_dmps(client:, pks:, logger: null)
214
+
215
+ end
216
+
227
217
  # Transform the search results so that we do not include any of the DMPHub specific metadata
228
218
  def _process_search_response(response:)
229
219
  return [] unless response.is_a?(Array) && response.any?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.1.59'
4
+ VERSION = '0.1.61'
5
5
  end
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.59
4
+ version: 0.1.61
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-09 00:00:00.000000000 Z
11
+ date: 2024-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json