dor-services 7.0.2 → 7.1.0

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: 05abb7b8c6054c86ed4edeeef3baf7d768a7e0c97c3e6bfdedf25d708ba2291a
4
- data.tar.gz: 5955774b7898520df8baf33298697cadf2c2d8b8fa9e41903a1bf9aca2c2cda0
3
+ metadata.gz: 1cf9f20e7028e7252d30de465bbbee5afc837f32793be1612591443dab72170d
4
+ data.tar.gz: 0436dcc7ecf8964b20193603f4219ebfc46a0bedf42566ddcf4a79bd831ed8ff
5
5
  SHA512:
6
- metadata.gz: 99a5e9dffd5f436ae3c2a0059903431b1d8ba59af633d58f3ef6894daa55f1aa32d6b37a7828c2610bc76c8c144806df95e831352d1718fd57fcff1e6008b53e
7
- data.tar.gz: f9cea923019b4ceca95b5516a487683a98dcaeb702956cc082828c6eedb96a4541c478fe08cbc72017344760a5acf212593105069c262e136f6e5ead88ef70a5
6
+ metadata.gz: e48a8d2b2f1f3ccfff30db3def931c14862eb9e108865db26b4d830c170e990db20ca453b5b66b8fdf61fa8b9c5a677f522c124bd294918e682e0ea88693da4e
7
+ data.tar.gz: 1cb0bfa19232319da9d3e47efd241974a91f0e94f21cdc46195804270d02a29be8e2979cbba15c01b5e0c35b53a643f627f5153fb966369b7f74b0100e0132e6
data/lib/dor-services.rb CHANGED
@@ -5,6 +5,7 @@ require 'active_fedora/version'
5
5
  require 'active_support/core_ext/module/attribute_accessors'
6
6
  require 'active_support/core_ext/object/blank'
7
7
  require 'deprecation'
8
+ require 'retries' # Used by Dor::ReleaseTagService
8
9
 
9
10
  module Dor
10
11
  extend ActiveSupport::Autoload
@@ -42,6 +43,7 @@ module Dor
42
43
  require 'dor/utils/ng_tidy'
43
44
  require 'dor/utils/solr_doc_helper'
44
45
  require 'dor/utils/predicate_patch'
46
+ require 'dor/utils/pid_utils'
45
47
 
46
48
  require 'dor/datastreams/datastream_spec_solrizer'
47
49
 
@@ -113,6 +115,7 @@ module Dor
113
115
  autoload :OpenDataLicenseService
114
116
  autoload :PublicDescMetadataService
115
117
  autoload :PublishedRelationshipsFilter
118
+ autoload :PurlClient
116
119
  autoload :ReleaseTagService
117
120
  autoload :SearchService
118
121
  autoload :StatusService
@@ -87,19 +87,21 @@ module Dor
87
87
  def pid_regex
88
88
  /[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{2}[0-9]{4}/
89
89
  end
90
+ deprecation_deprecate pid_regex: 'use PidUtils::PID_REGEX instead'
90
91
 
91
92
  # a regex that can be used to identify a full druid with prefix (e.g. druid:oo000oo0001)
92
93
  # @return [Regex] a regular expression to identify a full druid
93
94
  def druid_regex
94
95
  /druid:#{pid_regex}/
95
96
  end
97
+ deprecation_deprecate druid_regex: 'will be removed without replacement'
96
98
 
97
99
  # Since purl does not use the druid: prefix but much of dor does, use this function to strip the druid: if needed
98
100
  # @return [String] the druid sans the druid: or if there was no druid: prefix, the entire string you passed
99
101
  def remove_druid_prefix(druid = id)
100
- result = druid.match(/#{pid_regex}/)
101
- result.nil? ? druid : result[0] # if no matches, return the string passed in, otherwise return the match
102
+ PidUtils.remove_druid_prefix(druid)
102
103
  end
104
+ deprecation_deprecate remove_druid_prefix: 'use PidUtils.remove_druid_prefix instead'
103
105
 
104
106
  # This is used by Argo and the MergeService
105
107
  # @return [Boolean] true if the object is in a state that allows it to be modified.
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ # Calls the purl service and returns the XML document
5
+ class PurlClient
6
+ def initialize(host:, pid:)
7
+ @host = host
8
+ @pid = pid
9
+ end
10
+
11
+ # Get XML from the purl service
12
+ # Fetches purl xml for a druid
13
+ # @raise [OpenURI::HTTPError]
14
+ # @return [Nokogiri::HTML::Document] parsed XML for the druid or an empty document if no purl is found
15
+ def fetch
16
+ handler = proc do |exception, attempt_number, total_delay|
17
+ # We assume a 404 means the document has never been published before and thus has no purl
18
+ Dor.logger.warn "[Attempt #{attempt_number}] GET #{url} -- #{exception.class}: #{exception.message}; #{total_delay} seconds elapsed."
19
+ raise exception unless exception.is_a? OpenURI::HTTPError
20
+ return Nokogiri::HTML::Document.new if exception.io.status.first == '404' # ["404", "Not Found"] from OpenURI::Meta.status
21
+ end
22
+
23
+ with_retries(max_retries: 3, base_sleep_seconds: 3, max_sleep_seconds: 5, handler: handler) do |attempt|
24
+ # If you change the method used for opening the webpage, you can change the :rescue param to handle the new method's errors
25
+ Dor.logger.debug "[Attempt #{attempt}] GET #{url}"
26
+ return Nokogiri::XML(OpenURI.open_uri(url))
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ # Take the and create the entire purl url that will usable for the open method in open-uri, returns http
33
+ # @return [String] the full url
34
+ def url
35
+ @url ||= "https://#{@host}/#{druid_without_prefix}.xml"
36
+ end
37
+
38
+ def druid_without_prefix
39
+ PidUtils.remove_druid_prefix(@pid)
40
+ end
41
+ end
42
+ end
@@ -11,6 +11,8 @@ module Dor
11
11
 
12
12
  def initialize(item)
13
13
  @item = item
14
+ @purl_client = PurlClient.new(host: Dor::Config.stacks.document_cache_host,
15
+ pid: item.pid)
14
16
  end
15
17
 
16
18
  # Called in Dor::UpdateMarcRecordService (in dor-services-app too)
@@ -189,37 +191,11 @@ module Dor
189
191
  new_tags
190
192
  end
191
193
 
192
- # Get a list of all release nodes found in a purl document
193
- # Fetches purl xml for a druid
194
- # @raise [OpenURI::HTTPError]
195
- # @return [Nokogiri::HTML::Document] parsed XML for the druid or an empty document if no purl is found
196
- def xml_from_purl
197
- url = form_purl_url
198
- handler = proc do |exception, attempt_number, total_delay|
199
- # We assume a 404 means the document has never been published before and thus has no purl
200
- Dor.logger.warn "[Attempt #{attempt_number}] GET #{url} -- #{exception.class}: #{exception.message}; #{total_delay} seconds elapsed."
201
- raise exception unless exception.is_a? OpenURI::HTTPError
202
- return Nokogiri::HTML::Document.new if exception.io.status.first == '404' # ["404", "Not Found"] from OpenURI::Meta.status
203
- end
204
-
205
- with_retries(max_retries: 3, base_sleep_seconds: 3, max_sleep_seconds: 5, handler: handler) do |attempt|
206
- # If you change the method used for opening the webpage, you can change the :rescue param to handle the new method's errors
207
- Dor.logger.info "[Attempt #{attempt}] GET #{url}"
208
- return Nokogiri::HTML(OpenURI.open_uri(url))
209
- end
210
- end
211
-
212
- # Take the and create the entire purl url that will usable for the open method in open-uri, returns http
213
- # @return [String] the full url
214
- def form_purl_url
215
- 'https://' + Dor::Config.stacks.document_cache_host + "/#{item.remove_druid_prefix}.xml"
216
- end
217
-
218
194
  # Pull all release nodes from the public xml obtained via the purl query
219
195
  # @param doc [Nokogiri::HTML::Document] The druid of the object you want
220
196
  # @return [Array] An array containing all the release tags
221
197
  def release_tags_from_purl_xml(doc)
222
- nodes = doc.xpath('//html/body/publicobject/releasedata').children
198
+ nodes = doc.xpath('//publicObject/releaseData').children
223
199
  # We only want the nodes with a name that isn't text
224
200
  nodes.reject { |n| n.name.nil? || n.name.casecmp('text') == 0 }.map { |n| n.attr('to') }.uniq
225
201
  end
@@ -227,7 +203,7 @@ module Dor
227
203
  # Pull all release nodes from the public xml obtained via the purl query
228
204
  # @return [Array] An array containing all the release tags
229
205
  def release_tags_from_purl
230
- release_tags_from_purl_xml(xml_from_purl)
206
+ release_tags_from_purl_xml(@purl_client.fetch)
231
207
  end
232
208
 
233
209
  attr_reader :item
@@ -46,9 +46,9 @@ module Dor
46
46
 
47
47
  # if we find one, return the filename based on whether it is a local file or external file
48
48
  thumb_image = if search_path[:image_type] == 'local'
49
- "#{object.remove_druid_prefix}/#{thumb_files[0]['id']}"
49
+ "#{PidUtils.remove_druid_prefix(object.pid)}/#{thumb_files[0]['id']}"
50
50
  else
51
- "#{object.remove_druid_prefix(thumb_files[0]['objectId'])}/#{thumb_files[0]['fileId']}"
51
+ "#{PidUtils.remove_druid_prefix(thumb_files[0]['objectId'])}/#{thumb_files[0]['fileId']}"
52
52
  end
53
53
  break # break out of the loop so we stop searching
54
54
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ # Utilties for manipulating druids
5
+ class PidUtils
6
+ PID_REGEX = /[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{2}[0-9]{4}/.freeze
7
+ # Since purl does not use the druid: prefix but much of dor does, use this function to strip the druid: if needed
8
+ # @return [String] the druid sans the druid: or if there was no druid: prefix, the entire string you passed
9
+ def self.remove_druid_prefix(druid)
10
+ result = druid.match(PID_REGEX)
11
+ result.nil? ? druid : result[0] # if no matches, return the string passed in, otherwise return the match
12
+ end
13
+ end
14
+ end
data/lib/dor/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dor
4
- VERSION = '7.0.2'
4
+ VERSION = '7.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dor-services
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.2
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klein
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2019-04-24 00:00:00.000000000 Z
17
+ date: 2019-04-25 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: active-fedora
@@ -92,26 +92,6 @@ dependencies:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
94
  version: '1.5'
95
- - !ruby/object:Gem::Dependency
96
- name: equivalent-xml
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: '0.5'
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- version: 0.5.1
105
- type: :runtime
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: '0.5'
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- version: 0.5.1
115
95
  - !ruby/object:Gem::Dependency
116
96
  name: json
117
97
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +174,20 @@ dependencies:
194
174
  - - "<"
195
175
  - !ruby/object:Gem::Version
196
176
  version: '3'
177
+ - !ruby/object:Gem::Dependency
178
+ name: retries
179
+ requirement: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - "~>"
182
+ - !ruby/object:Gem::Version
183
+ version: 0.0.5
184
+ type: :runtime
185
+ prerelease: false
186
+ version_requirements: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - "~>"
189
+ - !ruby/object:Gem::Version
190
+ version: 0.0.5
197
191
  - !ruby/object:Gem::Dependency
198
192
  name: rsolr
199
193
  requirement: !ruby/object:Gem::Requirement
@@ -270,20 +264,6 @@ dependencies:
270
264
  - - "~>"
271
265
  - !ruby/object:Gem::Version
272
266
  version: '2.6'
273
- - !ruby/object:Gem::Dependency
274
- name: retries
275
- requirement: !ruby/object:Gem::Requirement
276
- requirements:
277
- - - ">="
278
- - !ruby/object:Gem::Version
279
- version: '0'
280
- type: :runtime
281
- prerelease: false
282
- version_requirements: !ruby/object:Gem::Requirement
283
- requirements:
284
- - - ">="
285
- - !ruby/object:Gem::Version
286
- version: '0'
287
267
  - !ruby/object:Gem::Dependency
288
268
  name: dor-rights-auth
289
269
  requirement: !ruby/object:Gem::Requirement
@@ -388,6 +368,20 @@ dependencies:
388
368
  - - ">="
389
369
  - !ruby/object:Gem::Version
390
370
  version: '0'
371
+ - !ruby/object:Gem::Dependency
372
+ name: equivalent-xml
373
+ requirement: !ruby/object:Gem::Requirement
374
+ requirements:
375
+ - - "~>"
376
+ - !ruby/object:Gem::Version
377
+ version: '0.6'
378
+ type: :development
379
+ prerelease: false
380
+ version_requirements: !ruby/object:Gem::Requirement
381
+ requirements:
382
+ - - "~>"
383
+ - !ruby/object:Gem::Version
384
+ version: '0.6'
391
385
  - !ruby/object:Gem::Dependency
392
386
  name: jhove-service
393
387
  requirement: !ruby/object:Gem::Requirement
@@ -594,6 +588,7 @@ files:
594
588
  - lib/dor/services/ontology.rb
595
589
  - lib/dor/services/open_data_license_service.rb
596
590
  - lib/dor/services/public_desc_metadata_service.rb
591
+ - lib/dor/services/purl_client.rb
597
592
  - lib/dor/services/release_tag_service.rb
598
593
  - lib/dor/services/search_service.rb
599
594
  - lib/dor/services/status_service.rb
@@ -602,6 +597,7 @@ files:
602
597
  - lib/dor/services/thumbnail_service.rb
603
598
  - lib/dor/utils/hydrus_shims.rb
604
599
  - lib/dor/utils/ng_tidy.rb
600
+ - lib/dor/utils/pid_utils.rb
605
601
  - lib/dor/utils/predicate_patch.rb
606
602
  - lib/dor/utils/solr_doc_helper.rb
607
603
  - lib/dor/version.rb