app/models/maestrano/connector/rails/concerns/entity.rb in maestrano-connector-rails-2.3.2 vs app/models/maestrano/connector/rails/concerns/entity.rb in maestrano-connector-rails-2.3.3
- old
+ new
@@ -232,11 +232,11 @@
# Only the first page if batched_fetch
unless batched_fetch
# Fetch subsequent pages
while response_hash['pagination'] && response_hash['pagination']['next']
# ugly way to convert https://api-connec/api/v2/group_id/organizations?next_page_params to /organizations?next_page_params
- next_page = response_hash['pagination']['next'].gsub(/^(.*)\/#{self.class.normalized_connec_entity_name}/, self.class.normalized_connec_entity_name)
+ next_page = response_hash['pagination']['next'].gsub(/\A(.*)\/#{self.class.normalized_connec_entity_name}/, self.class.normalized_connec_entity_name)
response_hash = fetch_connec(next_page)
entities.concat response_hash[self.class.normalized_connec_entity_name]
end
end
@@ -271,10 +271,11 @@
if self.class.currency_check_fields
mapped_external_entities_with_idmaps.each do |mapped_external_entity_with_idmap|
id_map = mapped_external_entity_with_idmap[:idmap]
next unless id_map&.metadata&.dig(:ignore_currency_update)
+
self.class.currency_check_fields.each do |field|
mapped_external_entity_with_idmap[:entity].delete(field)
end
end
end
@@ -300,10 +301,11 @@
# External methods
# ----------------------------------------------
# Wrapper to process options and limitations
def get_external_entities_wrapper(last_synchronization_date = nil, entity_name = self.class.external_entity_name)
return [] if @opts[:__skip_external] || !self.class.can_read_external?
+
get_external_entities(entity_name, last_synchronization_date)
end
# To be implemented in each connector
def get_external_entities(external_entity_name, last_synchronization_date = nil)
@@ -365,10 +367,11 @@
return {idmap: idmap, completed_hash: map_and_complete_hash_with_connec_ids(external_hash, external_entity_name, id_refs_only_connec_entity)}
# Update
else
return nil unless self.class.can_update_external?
+
external_hash = update_external_entity(mapped_connec_entity, idmap.external_id, external_entity_name)
completed_hash = map_and_complete_hash_with_connec_ids(external_hash, external_entity_name, id_refs_only_connec_entity)
# Return the idmap to send it to connec! only if it's the first push of a singleton
@@ -477,9 +480,10 @@
log_info = id_update_only ? 'with only ids' : ''
Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "Sending batch request to Connec! #{log_info} for #{self.class.normalize_connec_entity_name(connec_entity_name)}. Batch_request_size: #{batch_request[:ops].size}. Call_number: #{(start / request_per_call) + 1}")
response = @connec_client.batch(batch_request)
Maestrano::Connector::Rails::ConnectorLogger.log('debug', @organization, "Received batch response from Connec! for #{self.class.normalize_connec_entity_name(connec_entity_name)}: #{response}")
raise "No data received from Connec! when trying to send batch request #{log_info} for #{self.class.connec_entity_name.pluralize}" unless response && response.body.present?
+
response = JSON.parse(response.body)
# Parse batch response
# Update idmaps with either connec_id and timestamps, or a error message
response['results'].each_with_index do |result, index|