uc3-dmp-id 0.1.59 → 0.1.60

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: 791179155f0be964f0cfc186f26de88e9f0774ee9ebb671f7856074b1d40639e
4
+ data.tar.gz: 0bf38f90d0863863362ea4fb5357566d8b262c2036840d78519796e2d55d893a
5
5
  SHA512:
6
- metadata.gz: 90bee71bd0005f49adb736c0ba5fad0d75e40b12815cb46bc0a73352e841bd7b2372e7038282427d7dbfda05fd7f060e04500c4588ce578424a7632bd19510fd
7
- data.tar.gz: 958e3d10549189e8e7d47d950cb27dddb84623f1d8b13d23386b555c773cfe3b8ecbef41d4221a225b84dbcd7f5079701f98218947aff58156fd2e8fe5b18946
6
+ metadata.gz: e938eb3ddaa088e2cc17bb6a4202de8673c5eeb046c47207e1c040eff8775fdede2b835a90758ab8e892490677b93502c205b0244fae3884299498caf27575a8
7
+ data.tar.gz: ae45834944f078ab9e0d3fae1c6b32d2f5015c5b74b46c526c62b457b22e329662c6049ba4dd090e67f4c7f4208d9a1f858cb62b4dc52fa8b1e2bc1b4b17f692
@@ -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
- 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_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
- return _publicly_visible(client:, logger:)
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-9A-Z]{4}-){3}[0-9A-Z]{4}$/
149
+ orcid_regex = /^([0-9a-zA-Z]{4}-){3}[0-9a-zA-Z]{4}$/
137
150
  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:))
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
- 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:))
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
- 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:))
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?
@@ -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.60'
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.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-09 00:00:00.000000000 Z
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json