From d9f4b93f48d52db2b37df4b70e359b3a7ce0d815 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 16 Mar 2021 15:04:38 +0000 Subject: [PATCH] Fixes #3436 - Unable to sync Exchange contracts (if one contact is unable to process). --- .../import/common/sub_sequence/mixin/base.rb | 38 +++++++++++++++---- .../import/exchange/attribute_examples.rb | 11 +++++- .../exchange/folder_contacts/sub_sequence.rb | 25 +++++++----- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/lib/sequencer/unit/import/common/sub_sequence/mixin/base.rb b/lib/sequencer/unit/import/common/sub_sequence/mixin/base.rb index 656ffb765..780b3af76 100644 --- a/lib/sequencer/unit/import/common/sub_sequence/mixin/base.rb +++ b/lib/sequencer/unit/import/common/sub_sequence/mixin/base.rb @@ -23,16 +23,38 @@ class Sequencer @default_parameter ||= default_params end - def sequence_resource(resource) - sequence_parameter = default_parameter.dup - sequence_parameter[:resource] = resource - - sequence_parameter = yield(sequence_parameter) if block_given? - - sequence_parameter[:resource] = sequence_parameter[:resource].to_h.with_indifferent_access + def sequence_resource(resource = nil, &block) + parameters = sanitized_sequence_parameters!(resource, &block) + return if parameters.blank? ::Sequencer.process(sequence_name, - parameters: sequence_parameter) + parameters: parameters) + end + + def sanitized_sequence_parameters!(resource, &block) + parameters = sequence_parameters(resource, &block) + + if parameters.nil? + logger.debug { "Skipping processing of Sub-Sequence '#{sequence_name}'. `sequence_resource` block returned `nil` in '#{self.class.name}'." } + return + end + + if parameters[:resource].blank? + raise '`resource` parameter missing. It is required as an argument to `sequence_resource` or as `:resource` key value of the block result.' + end + + parameters.tap do |result| + result[:resource] = result[:resource].to_h.with_indifferent_access + end + end + + def sequence_parameters(resource) + # creates a dup/copy of `default_parameter` + parameters = default_parameter.merge(resource: resource) + + return parameters if !block_given? + + yield(parameters) end def sequence_resources(resources, &block) diff --git a/lib/sequencer/unit/import/exchange/attribute_examples.rb b/lib/sequencer/unit/import/exchange/attribute_examples.rb index 5559ed6d6..a23aee4f6 100644 --- a/lib/sequencer/unit/import/exchange/attribute_examples.rb +++ b/lib/sequencer/unit/import/exchange/attribute_examples.rb @@ -14,10 +14,17 @@ class Sequencer ews_folder_ids.collect do |folder_id| - ews_folder.find(folder_id).items.each do |resource| - attributes = ::Import::Exchange::ItemAttributes.extract(resource) + ews_folder.find(folder_id).items.each do |item| + + attributes = ::Import::Exchange::ItemAttributes.extract(item) extractor.extract(attributes) + break if extractor.enough + rescue => e + Rails.logger.error 'Unable to process Exchange folder item' + Rails.logger.debug { item.inspect } + Rails.logger.error e + nil end rescue NoMethodError => e raise if e.message.exclude?('Viewpoint::EWS::') diff --git a/lib/sequencer/unit/import/exchange/folder_contacts/sub_sequence.rb b/lib/sequencer/unit/import/exchange/folder_contacts/sub_sequence.rb index 0ce073575..97e2d427e 100644 --- a/lib/sequencer/unit/import/exchange/folder_contacts/sub_sequence.rb +++ b/lib/sequencer/unit/import/exchange/folder_contacts/sub_sequence.rb @@ -41,19 +41,26 @@ class Sequencer logger.debug { "Fetching and processing #{per_page} items (page: #{page}, offset: #{offset}) from Exchange folder '#{display_path}' (total: #{total})" } - folder.items(opts).each do |item| + process_folders(folder, display_path, opts) + end + end - sequence_resource(item) do |parameters| + def process_folders(folder, display_path, opts) + folder.items(opts).each do |item| - item = parameters[:resource] + sequence_resource do |parameters| - logger.debug { "Extracting attributes from Exchange item: #{item.get_all_properties!.inspect}" } + logger.debug { "Extracting attributes from Exchange item: #{item.get_all_properties!.inspect}" } - parameters.merge( - resource: ::Import::Exchange::ItemAttributes.extract(item), - ews_folder_name: display_path, - ) - end + parameters.merge( + resource: ::Import::Exchange::ItemAttributes.extract(item), + ews_folder_name: display_path, + ) + rescue => e + Rails.logger.error 'Unable to process Exchange folder item' + Rails.logger.debug { item.inspect } + Rails.logger.error e + nil end end end