dor-services 4.23.0 → 4.24.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
  SHA1:
3
- metadata.gz: d050e71f1ce1735d4e070bd9c0691eedd1595a15
4
- data.tar.gz: 82d30bbd2dff8a7f134438d637c5b552ac11e0f0
3
+ metadata.gz: ff429d637d033e04e1198d20958bcbd6a472629c
4
+ data.tar.gz: 4622fda379fcf8ee34a99a5814194dbe27145d52
5
5
  SHA512:
6
- metadata.gz: 9b76b3ab3b360bb28904d6391c0e325694b036be58195dd84d6952a3ef3bd1d723dae7c49bbd18fc9380e05af088297184f6bdaea2e1f896555ab7dd7e657db2
7
- data.tar.gz: 4b29c83f8f57629d9003033e454055114f1abb530c6d5f515081fc71937d158593a30dd5d86b0d712d7907085b27356f3770049c40590bfeaa1d17941815de23
6
+ metadata.gz: ec37f7bc75c22027ccb685ef9addd75845f0e09d943ed829a5aa9a2f1bc5a666672761cb0f8a5eafeda0f30576f41a48eddcb5b00cbce18aa6883423ef85b85b
7
+ data.tar.gz: b6b11408363316db445e6114ebbed7e991d21d44bfcd790060218bb72b41af591ce918b21a8ccde0e53524d32607a80cd24cf7b853b8c1bc87ba3adf5bec442f
@@ -65,3 +65,7 @@
65
65
  :shift_age: weekly
66
66
  :dor_services:
67
67
  :url:
68
+ :indexing_svc:
69
+ :log: 'log/indexing_svc.log'
70
+ :log_date_format_str: '%Y-%m-%d %H:%M:%S.%L'
71
+ :log_rotation_interval: 'daily'
data/lib/dor-services.rb CHANGED
@@ -132,6 +132,7 @@ module Dor
132
132
 
133
133
  # Services
134
134
  autoload :SearchService, 'dor/services/search_service'
135
+ autoload :IndexingService, 'dor/services/indexing_service'
135
136
  autoload :MetadataService, 'dor/services/metadata_service'
136
137
  autoload :RegistrationService, 'dor/services/registration_service'
137
138
  autoload :SuriService, 'dor/services/suri_service'
@@ -143,8 +143,10 @@ module Dor
143
143
  # @return [Nokogiri::XML::Element] the new resource that was added to the contentMetadata
144
144
  #
145
145
  def add_virtual_resource(child_druid, child_resource)
146
+ fail ArgumentError, 'Parent must have existing contentMetadata' if self.ng_xml.nil? || self.ng_xml.root.nil?
147
+
146
148
  # create a virtual resource element with attributes linked to the child and omit label
147
- sequence_max = self.ng_xml.search('//resource').map{ |node| node[:sequence].to_i }.max
149
+ sequence_max = self.ng_xml.search('//resource').map{ |node| node[:sequence].to_i }.max || 0
148
150
  resource = Nokogiri::XML::Element.new('resource', self.ng_xml)
149
151
  resource[:sequence] = sequence_max + 1
150
152
  resource[:id] = "#{self.pid.gsub(/^druid:/, '')}_#{resource[:sequence]}"
@@ -157,7 +159,7 @@ module Dor
157
159
  resource << generate_also_available_as_node(child_druid)
158
160
 
159
161
  # save the virtual resource as a sibling and return
160
- self.ng_xml.root << resource
162
+ self.content = (self.ng_xml.root << resource).to_xml
161
163
  resource
162
164
  end
163
165
 
@@ -0,0 +1,64 @@
1
+ module Dor
2
+ class IndexingService
3
+ ##
4
+ # Returns a Logger instance for recording info about indexing attempts
5
+ # @yield attempt to execute 'entry_id_block' and use the result as an extra identifier for the log
6
+ # entry. a placeholder will be used otherwise. 'request.uuid' might be useful in a Rails app.
7
+ def self.generate_index_logger(&entry_id_block)
8
+ index_logger = Logger.new(Config.indexing_svc.log, Config.indexing_svc.log_rotation_interval)
9
+ index_logger.formatter = proc do |severity, datetime, progname, msg|
10
+ date_format_str = Config.indexing_svc.log_date_format_str
11
+ entry_id = begin entry_id_block.call rescue '---' end
12
+ "[#{entry_id}] [#{datetime.utc.strftime(date_format_str)}] #{msg}\n"
13
+ end
14
+ index_logger
15
+ end
16
+
17
+ # memoize the loggers we create in a hash, init with a nil default logger
18
+ @@loggers = { default: nil }
19
+
20
+ def self.default_index_logger
21
+ @@loggers[:default] ||= generate_index_logger
22
+ end
23
+
24
+ # takes a Dor object and indexes it to solr. doesn't commit automatically.
25
+ def self.reindex_object(obj)
26
+ solr_doc = obj.to_solr
27
+ Dor::SearchService.solr.add(solr_doc)
28
+ solr_doc
29
+ end
30
+
31
+ # retrieves a single Dor object by pid, indexes the object to solr, does some logging
32
+ # (will use a defualt logger if one is not provided). doesn't commit automatically.
33
+ #
34
+ # WARNING/TODO: the tests indicate that the "rescue Exception" block at the end will
35
+ # get skipped, and the thrown exception (e.g. SystemStackError) will not be logged. since
36
+ # that's the only consequence, and the exception bubbles up as we would want anyway, it
37
+ # doesn't seem worth blocking refactoring. see https://github.com/sul-dlss/dor-services/issues/156
38
+ # extra logging in this case would be nice, but centralized indexing that's otherwise
39
+ # fully functional is nicer.
40
+ def self.reindex_pid(pid, index_logger = nil, should_raise_errors = true)
41
+ index_logger ||= default_index_logger
42
+ obj = Dor.load_instance pid
43
+ solr_doc = reindex_object obj
44
+ index_logger.info "updated index for #{pid}"
45
+ solr_doc
46
+ rescue StandardError => se
47
+ if se.is_a? ActiveFedora::ObjectNotFoundError
48
+ index_logger.warn "failed to update index for #{pid}, object not found in Fedora"
49
+ else
50
+ index_logger.warn "failed to update index for #{pid}, unexpected StandardError, see main app log: #{se.backtrace}"
51
+ end
52
+ raise se if should_raise_errors
53
+ rescue Exception => ex
54
+ index_logger.error "failed to update index for #{pid}, unexpected Exception, see main app log: #{ex.backtrace}"
55
+ raise ex # don't swallow anything worse than StandardError
56
+ end
57
+
58
+ # given a list of pids, retrieve those objects from fedora, index each to solr, optionally commit
59
+ def self.reindex_pid_list(pid_list, should_commit = false)
60
+ pid_list.each { |pid| reindex_pid pid, nil, false } # use the default logger, don't let individual errors nuke the rest of the batch
61
+ ActiveFedora.solr.conn.commit if should_commit
62
+ end
63
+ end
64
+ end
data/lib/dor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dor
2
- VERSION = '4.23.0'
2
+ VERSION = '4.24.0'
3
3
  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: 4.23.0
4
+ version: 4.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klein
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-02-08 00:00:00.000000000 Z
15
+ date: 2016-02-19 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: active-fedora
@@ -591,6 +591,7 @@ files:
591
591
  - lib/dor/services/cleanup_reset_service.rb
592
592
  - lib/dor/services/cleanup_service.rb
593
593
  - lib/dor/services/digital_stacks_service.rb
594
+ - lib/dor/services/indexing_service.rb
594
595
  - lib/dor/services/merge_service.rb
595
596
  - lib/dor/services/metadata_handlers/catalog_handler.rb
596
597
  - lib/dor/services/metadata_handlers/mdtoolkit_handler.rb