app/models/maestrano/connector/rails/concerns/entity.rb in maestrano-connector-rails-2.0.0.pre.RC8 vs app/models/maestrano/connector/rails/concerns/entity.rb in maestrano-connector-rails-2.0.0.pre.RC9

- old
+ new

@@ -235,11 +235,11 @@ page_number += 1 # 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) response_hash = fetch_connec(next_page, page_number) - entities << response_hash[self.class.normalized_connec_entity_name] + entities.concat response_hash[self.class.normalized_connec_entity_name] end end entities.flatten! Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "Received data: Source=Connec!, Entity=#{self.class.connec_entity_name}, Data=#{entities}") @@ -365,11 +365,11 @@ end rescue => e # TODO: improve the flexibility by adding the option for the developer to pass a custom/gem-dependent error if e.class == Maestrano::Connector::Rails::Exceptions::EntityNotFoundError idmap.update!(message: "The #{external_entity_name} record has been deleted in #{Maestrano::Connector::Rails::External.external_name}. Last attempt to sync on #{Time.now}", external_inactive: true) - Rails.logger.info "The #{idmap.external_entity} - #{idmap.external_id} record has been deleted. It is now set to inactive." + Maestrano::Connector::Rails::ConnectorLogger.log('info', @organization, "The #{idmap.external_entity} - #{idmap.external_id} record has been deleted. It is now set to inactive.") else # Store External error Maestrano::Connector::Rails::ConnectorLogger.log('error', @organization, "Error while pushing to #{Maestrano::Connector::Rails::External.external_name}: #{e}") Maestrano::Connector::Rails::ConnectorLogger.log('debug', @organization, "Error while pushing backtrace: #{e.backtrace.join("\n\t")}") idmap.update(message: e.message.truncate(255)) @@ -539,11 +539,11 @@ if result['status'] == 200 batch_entities[index][:idmap].update(connec_id: result['body'][self.class.normalize_connec_entity_name(connec_entity_name)]['id'].find { |id| id['provider'] == 'connec' }['id'], last_push_to_connec: Time.now, message: nil) unless id_update_only # id_update_only only apply for 200 as it's doing PUTs elsif result['status'] == 201 batch_entities[index][:idmap].update(connec_id: result['body'][self.class.normalize_connec_entity_name(connec_entity_name)]['id'].find { |id| id['provider'] == 'connec' }['id'], last_push_to_connec: Time.now, message: nil) else - Maestrano::Connector::Rails::ConnectorLogger.log('error', @organization, "Error while pushing to Connec!: #{result['body']}") + Maestrano::Connector::Rails::ConnectorLogger.log('warn', @organization, "Error while pushing to Connec!: #{result['body']}") # TODO, better error message batch_entities[index][:idmap].update(message: result['body'].to_s.truncate(255)) end end @@ -569,10 +569,10 @@ def is_connec_more_recent?(connec_entity, external_entity) connec_entity['updated_at'] > self.class.last_update_date_from_external_entity_hash(external_entity) end - # This methods try to find a external entity among all the external entities matching the connec one (same id) + # This methods try to find a external entity among all the external entities matching the connec (mapped) one (same id) # If it does not find any, there is no conflict, and it returns the mapped connec entity # If it finds one, the conflict is solved either with options or using the entities timestamps # If the connec entity is kept, it is returned mapped and the matching external entity is discarded (deleted from the array) # Else the method returns nil, meaning the connec entity is discarded def solve_conflict(connec_entity, external_entities, external_entity_name, idmap, id_refs_only_connec_entity)