uc3-dmp-id 0.0.74 → 0.0.75

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: aafd3e027681cfa713fad3c48471dae7a192cd844546e67a55cec59ae0c2e1d8
4
- data.tar.gz: deda47068b080ccbfddd35091cde8626bde787110ae5a4df6bb204f0b248ff89
3
+ metadata.gz: 445c7ef4554d72339624600ee7e43a0237564e4d45cb9393bd151719bfa5899d
4
+ data.tar.gz: 6f2c315e67f2cd63b570d7815f3bb7d04b9d134b523d17a4a05e293f1c46e7f6
5
5
  SHA512:
6
- metadata.gz: 578c94e8fc0da1b8bb36b163eca0cdd656fc1ae63cbdb02f4be104a6746d137f83b5dc6cd36424549c8f227eba20b69f7058710fb188a400fa546db28a52e08a
7
- data.tar.gz: fc2e39ea16382559b2eac7459528e7cf241623dd9256497088f4c000819dda5d491a80a7f555ed6e357a510d85228884aa842c38b5175e64c15c0666dfb2df26
6
+ metadata.gz: 5a3f4ef40605def448cc5128a595b6b2dbfc7a814a652744a63fc8ab386bc57effb4178fddcd78ae380119ed25607e9e2dd7066e89d95e4f5469a001e0e83f6b
7
+ data.tar.gz: '0917410c7c29936e689d192de8c8dff454fa7c15cf891370fa78446c2fb6effdbeb70465f626fb7c3835e2ee34a8a9b9bbdeda2c544ba83701f79eaa4e9cec2a'
@@ -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
- dmp
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)
@@ -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: debug)
23
+ return _by_owner(owner_org: args['owner_orcid']) unless args['owner_orcid'].nil?
24
+ return _by_owner_org(owner_org: args['owner_org_ror']) unless args['owner_org_ror'].nil?
25
+ return _by_mod_day(day: args['modification_day']) unless args['modification_day'].nil?
19
26
 
20
- # TODO: Need to move this to ElasticSearch!!!
27
+ []
21
28
  end
22
29
  # rubocop:enable Metrics/MethodLength
23
30
 
@@ -104,6 +111,86 @@ 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:)
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
+ client = client.nil? ? Uc3DmpDynamo::Client.new(debug: debug) : client
137
+ _process_search_response(response: client.query(args: args))
138
+ end
139
+
140
+ # Fetch the DMP IDs for the specified organization/institution (the org is the :dmphub_owner_org on the DMP ID record)
141
+ def _by_owner_org(owner_org:)
142
+ regex = %r{^[a-zA-Z0-9]+$}
143
+ raise FinderError, MSG_INVALID_OWNER_ID if owner_org.nil? ||(owner_org.to_s.downcase =~ regex).nil?
144
+
145
+ args = {
146
+ index_name: 'dmphub_owner_org_gsi',
147
+ key_conditions: {
148
+ dmphub_owner_org: {
149
+ attribute_value_list: [
150
+ "http://ror.org/#{owner_org.to_s.downcase}",
151
+ "https://ror.org/#{owner_org.to_s.downcase}"
152
+ ],
153
+ comparison_operator: 'EQ'
154
+ }
155
+ },
156
+ filter_expression: 'SK = :version',
157
+ expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
158
+ }
159
+ client = client.nil? ? Uc3DmpDynamo::Client.new(debug: debug) : client
160
+ _process_search_response(response: client.query(args: args))
161
+ end
162
+
163
+ # Fetch the DMP IDs modified on the specified date (the date is the :dmphub_modification_day on the DMP ID record)
164
+ def _by_mod_day(day:)
165
+ regex = %r{^[0-9]{4}(-[0-9]{2}){2}}
166
+ raise FinderError, MSG_INVALID_OWNER_ID if day.nil? || (day.to_s =~ regex).nil?
167
+
168
+ args = {
169
+ index_name: 'dmphub_modification_day_gsi',
170
+ key_conditions: {
171
+ dmphub_modification_day: {
172
+ attribute_value_list: [day.to_s],
173
+ comparison_operator: 'EQ'
174
+ }
175
+ },
176
+ filter_expression: 'SK = :version',
177
+ expression_attribute_values: { ':version': Helper::DMP_LATEST_VERSION }
178
+ }
179
+ client = client.nil? ? Uc3DmpDynamo::Client.new(debug: debug) : client
180
+ _process_search_response(response: client.query(args: args))
181
+ end
182
+
183
+
184
+ # Transform the search results so that we do not include any of the DMPHub specific metadata
185
+ def _process_search_response(response:)
186
+ return [] unless response.is_a?(Array) && response.any?
187
+
188
+ results = response.each do |item|
189
+ dmp = item['dmp'].nil? ? JSON.parse({ dmp: item }.to_json) : item
190
+ Helper.cleanse_dmp_json(json: dmp)
191
+ end
192
+ results.compact.uniq
193
+ end
107
194
  end
108
195
  end
109
196
  end
@@ -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
- resp
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpId
4
- VERSION = '0.0.74'
4
+ VERSION = '0.0.75'
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.0.74
4
+ version: 0.0.75
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-03 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json