uri_service 0.2.8 → 0.2.9

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
  SHA1:
3
- metadata.gz: 26abbeab1aeb4f9af6f93bd2d12ae38544150881
4
- data.tar.gz: ab29aac65bf065a1795e665e4ba36dee75211a0b
3
+ metadata.gz: 4b458df27c7aeead867b7428323c726280b3665a
4
+ data.tar.gz: a792e2a0d892e8a31769e5f259088cdcf6c4d9b0
5
5
  SHA512:
6
- metadata.gz: 72bedd843f188bdfa169a072aa0fb6abac30b86ac54d3c6b04f52565e118a31102a825c74be5d4330eec35e60151da3f8235ffb60d9e99e04ba3beaade62a013
7
- data.tar.gz: 25aa75d96f0f34f919459bad7bc33c5a38f90844bf0347d45f61d94737fe86100b390f48575ee6360410d322106ae2564a1deb986e83c7e37de485e965d95b33
6
+ metadata.gz: 1c68e9eb488225cdc1756bbf32995c933d0b4884895f52c8c6debb8c402cca1153382fcfa75f9cf8238264fd084021e7a866bcf12c47ff22b1b50bb95e5815d4
7
+ data.tar.gz: 252acdb96ff30482a8f5c21e200dc311b9188a2490c9176cfe00e5a7b03c6addb9f175118a86bacad3162fb7d4005470a2fe8d904ee8c1aa17983fb7193f7d13
@@ -114,6 +114,7 @@ class UriService::Client
114
114
  String :uri, text: true # This needs to be a text field because utf8 strings cannot be our desired 2000 characters long in MySQL. uri_hash will be used to verify uniqueness.
115
115
  String :uri_hash, fixed: true, size: 64, unique: true
116
116
  String :value, text: true
117
+ String :value_hash, fixed: true, size: 64
117
118
  TrueClass :is_local, default: false
118
119
  String :additional_fields, text: true
119
120
  end
@@ -150,11 +151,12 @@ class UriService::Client
150
151
 
151
152
  # Creates a new term.
152
153
  def create_term(vocabulary_string_key, value, term_uri, additional_fields={})
153
- return self.create_term_impl(vocabulary_string_key, value, term_uri, additional_fields, false)
154
+ return self.create_term_impl(vocabulary_string_key, value, term_uri, additional_fields, false, false)
154
155
  end
155
156
 
156
157
  # Creates a new local term, auto-generating a URI
157
- def create_local_term(vocabulary_string_key, value, additional_fields={})
158
+ # By default, if raise_error_if_local_term_value_exists_in_vocabulary param is true, rejects the creation of a local value if that exact value already exists in the specified vocabulary
159
+ def create_local_term(vocabulary_string_key, value, additional_fields={}, raise_error_if_local_term_value_exists_in_vocabulary=true)
158
160
 
159
161
  # Create a new URI for this local term, using the @local_uri_base
160
162
  term_uri = URI(@local_uri_base)
@@ -164,7 +166,7 @@ class UriService::Client
164
166
  # Getting a duplicate UUID from SecureRandom.uuid is EXTREMELY unlikely, but we'll account for it just in case (by making a few more attempts).
165
167
  5.times {
166
168
  begin
167
- return self.create_term_impl(vocabulary_string_key, value, term_uri, additional_fields, true)
169
+ return self.create_term_impl(vocabulary_string_key, value, term_uri, additional_fields, true, raise_error_if_local_term_value_exists_in_vocabulary)
168
170
  rescue UriService::ExistingUriError
169
171
  raise UriService::ExistingUriError, "UriService generated a duplicate random UUID (via SecureRandom.uuid) and will now attempt to create another. This type of problem is EXTREMELY rare."
170
172
  end
@@ -173,7 +175,7 @@ class UriService::Client
173
175
  return nil
174
176
  end
175
177
 
176
- def create_term_impl(vocabulary_string_key, value, term_uri, additional_fields, is_local)
178
+ def create_term_impl(vocabulary_string_key, value, term_uri, additional_fields, is_local, raise_error_if_local_term_value_exists_in_vocabulary)
177
179
  self.handle_database_disconnect do
178
180
 
179
181
  additional_fields.stringify_keys!
@@ -188,12 +190,20 @@ class UriService::Client
188
190
  validate_additional_fields(additional_fields) # This method call raises an error if an invalid additional_field key is supplied
189
191
 
190
192
  @db.transaction do
193
+
194
+ value_hash = Digest::SHA256.hexdigest(value)
195
+
196
+ if raise_error_if_local_term_value_exists_in_vocabulary && @db[UriService::TERMS].where(value_hash: value_hash, vocabulary_string_key: vocabulary_string_key).count > 0
197
+ raise UriService::DisallowedDuplicateLocalTermValueError, "A local term already exists with the value #{value}. This is not allowed when param raise_error_if_local_term_value_exists_in_vocabulary == true."
198
+ end
199
+
191
200
  begin
192
201
  @db[UriService::TERMS].insert(
193
202
  is_local: is_local,
194
203
  uri: term_uri,
195
204
  uri_hash: Digest::SHA256.hexdigest(term_uri),
196
205
  value: value,
206
+ value_hash: value_hash,
197
207
  vocabulary_string_key: vocabulary_string_key,
198
208
  additional_fields: JSON.generate(additional_fields)
199
209
  )
@@ -303,7 +313,12 @@ class UriService::Client
303
313
  end
304
314
 
305
315
  @rsolr_pool.with do |rsolr|
306
- response = rsolr.get('select', params: {:q => '*:*', :fq => fqs })
316
+ response = rsolr.get('select', params: {
317
+ :q => '*:*',
318
+ :fq => fqs,
319
+ :rows => 1,
320
+ :sort => 'score desc, value_ssort asc, uri asc' # For consistent sorting
321
+ })
307
322
  if response['response']['numFound'] == 1
308
323
  return term_solr_doc_to_frozen_term_hash(response['response']['docs'].first)
309
324
  end
@@ -344,7 +359,8 @@ class UriService::Client
344
359
  :q => UriService.solr_escape(value_query),
345
360
  :fq => 'vocabulary_string_key:' + UriService.solr_escape(vocabulary_string_key),
346
361
  :rows => limit,
347
- :start => start
362
+ :start => start,
363
+ :sort => 'score desc, value_ssort asc, uri asc' # For consistent sorting
348
364
  }
349
365
 
350
366
  if value_query.length < 3
@@ -384,9 +400,9 @@ class UriService::Client
384
400
 
385
401
  solr_params = {
386
402
  :fq => 'vocabulary_string_key:' + UriService.solr_escape(vocabulary_string_key),
387
- :sort => 'value_ssort asc',
388
403
  :rows => limit,
389
- :start => start
404
+ :start => start,
405
+ :sort => 'value_ssort asc, uri asc' # Include 'uri asc' as part of sort to ensure consistent sorting
390
406
  }
391
407
 
392
408
  response = rsolr.get('select', params: solr_params)
@@ -458,7 +474,7 @@ class UriService::Client
458
474
  validate_additional_fields(new_additional_fields)
459
475
 
460
476
  @db.transaction do
461
- dataset.update(value: new_value, additional_fields: JSON.generate(new_additional_fields))
477
+ dataset.update(value: new_value, value_hash: Digest::SHA256.hexdigest(new_value), additional_fields: JSON.generate(new_additional_fields))
462
478
  self.send_term_to_solr(term_db_row[:vocabulary_string_key], new_value, term_uri, new_additional_fields, term_db_row[:is_local])
463
479
  end
464
480
 
@@ -493,4 +509,5 @@ class UriService::ExistingVocabularyStringKeyError < StandardError;end
493
509
  class UriService::NonExistentUriError < StandardError;end
494
510
  class UriService::NonExistentVocabularyError < StandardError;end
495
511
  class UriService::UnsupportedObjectTypeError < StandardError;end
496
- class UriService::UnsupportedSearchFieldError < StandardError;end
512
+ class UriService::UnsupportedSearchFieldError < StandardError;end
513
+ class UriService::DisallowedDuplicateLocalTermValueError < StandardError;end
@@ -1,6 +1,6 @@
1
1
  module UriService
2
2
 
3
- VERSION = '0.2.8'
3
+ VERSION = '0.2.9'
4
4
 
5
5
  def self.version
6
6
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric O'Hanlon
@@ -206,4 +206,3 @@ specification_version: 4
206
206
  summary: A service for registering local URIs and performing both local and remote
207
207
  URI lookups.
208
208
  test_files: []
209
- has_rdoc: