uc3-dmp-id 0.0.73 → 0.0.75

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 887398e3e0a37412b53474a625428c286279daec1c7a7c2ef6bd809d7fc7c7e7
4
- data.tar.gz: ae415d68ee2443712e08c92328dc2770bfeae68135143afb8bea946d7204939d
3
+ metadata.gz: 445c7ef4554d72339624600ee7e43a0237564e4d45cb9393bd151719bfa5899d
4
+ data.tar.gz: 6f2c315e67f2cd63b570d7815f3bb7d04b9d134b523d17a4a05e293f1c46e7f6
5
5
  SHA512:
6
- metadata.gz: ba0cb83cf68f8d4d30200e628790a9c55c78ed094612e025c70de6f547453ef269612d8ef6ac78c29363e5e9052723b46cded49ca6f20ec235f81e99074fe830
7
- data.tar.gz: 2106286ee96a94ed380c9dea0dcdde7aa629d39bf986efa1cd40c3a8ec6ea150c924ce41c633f8de19b4e6edccc50ffe981112d4495ae35451c6f2dd2932773f
6
+ metadata.gz: 5a3f4ef40605def448cc5128a595b6b2dbfc7a814a652744a63fc8ab386bc57effb4178fddcd78ae380119ed25607e9e2dd7066e89d95e4f5469a001e0e83f6b
7
+ data.tar.gz: '0917410c7c29936e689d192de8c8dff454fa7c15cf891370fa78446c2fb6effdbeb70465f626fb7c3835e2ee34a8a9b9bbdeda2c544ba83701f79eaa4e9cec2a'
@@ -57,9 +57,9 @@ module Uc3DmpId
57
57
  seed_id = json.fetch('dmp', {})['dmproadmap_external_system_identifier']
58
58
 
59
59
  # If we are seeding already registered DMP IDs from the Provenance system, then return the original DMP ID
60
- return seed_id if existing.fetch('type', 'other') == 'url' &&
61
- !seed_id.nil? &&
62
- provenance.fetch('seedingWithLiveDmpIds', false).to_s.downcase == 'true'
60
+ return seed_id.gsub(%r{https?://}, '') if existing.fetch('type', 'other') == 'url' &&
61
+ !seed_id.nil? &&
62
+ provenance.fetch('seedingWithLiveDmpIds', false).to_s.downcase == 'true'
63
63
 
64
64
  #Generate a new DMP ID
65
65
  dmp_id = ''
@@ -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.73'
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.73
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