Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Jan 31, 2020
2 parents 193995b + 6697045 commit b6c2ef4
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 118 deletions.
2 changes: 1 addition & 1 deletion app/controllers/client_prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def create

render json: ClientPrefixSerializer.new(@client_prefix, options).serialized_json, status: :created
else
logger.error @client_prefix.errors.inspect
Rails.logger.error @client_prefix.errors.inspect
render json: serialize_errors(@client_prefix.errors), status: :unprocessable_entity
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def create

render json: ClientSerializer.new(@client, options).serialized_json, status: :created
else
logger.error @client.errors.inspect
Rails.logger.error @client.errors.inspect
render json: serialize_errors(@client.errors), status: :unprocessable_entity
end
end
Expand All @@ -129,7 +129,7 @@ def update

render json: ClientSerializer.new(@client, options).serialized_json, status: :ok
else
logger.error @client.errors.inspect
Rails.logger.error @client.errors.inspect
render json: serialize_errors(@client.errors), status: :unprocessable_entity
end
end
Expand All @@ -140,13 +140,13 @@ def destroy
if @client.dois.present?
message = "Can't delete client that has DOIs."
status = 400
logger.warn message
Rails.logger.warn message
render json: { errors: [{ status: status.to_s, title: message }] }.to_json, status: status
elsif @client.update(is_active: nil, deleted_at: Time.zone.now)
@client.send_delete_email unless Rails.env.test?
head :no_content
else
logger.error @client.errors.inspect
Rails.logger.error @client.errors.inspect
render json: serialize_errors(@client.errors), status: :unprocessable_entity
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/graphql_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def ensure_hash(ambiguous_param)
end

def handle_error_in_development(e)
logger.error e.message
logger.error e.backtrace.join("\n")
Rails.logger.error e.message
Rails.logger.error e.backtrace.join("\n")

render json: { error: { message: e.message, backtrace: e.backtrace }, data: {} }, status: 500
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create

render json: MediaSerializer.new(@media, options).serialized_json, status: :created
else
logger.error @media.errors.inspect
Rails.logger.error @media.errors.inspect
render json: serialize_errors(@media.errors), status: :unprocessable_entity
end
end
Expand All @@ -75,7 +75,7 @@ def update

render json: MediaSerializer.new(@media, options).serialized_json, status: :ok
else
logger.error @media.errors.inspect
Rails.logger.error @media.errors.inspect
render json: serialize_errors(@media.errors), status: :unprocessable_entity
end
end
Expand All @@ -86,7 +86,7 @@ def destroy
if @media.destroy
head :no_content
else
logger.error @media.errors.inspect
Rails.logger.error @media.errors.inspect
render json: serialize_errors(@media.errors), status: :unprocessable_entity
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/metadata_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create

render json: MetadataSerializer.new(@metadata, options).serialized_json, status: :created
else
logger.error @metadata.errors.inspect
Rails.logger.error @metadata.errors.inspect
render json: serialize_errors(@metadata.errors), status: :unprocessable_entity
end
end
Expand All @@ -77,7 +77,7 @@ def destroy
if @metadata.destroy
head :no_content
else
logger.error @metadata.errors.inspect
Rails.logger.error @metadata.errors.inspect
render json: serialize_errors(@metadata.errors), status: :unprocessable_entity
end
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/provider_prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def create

render json: ProviderPrefixSerializer.new(@provider_prefix, options).serialized_json, status: :created
else
logger.error @provider_prefix.errors.inspect
Rails.logger.error @provider_prefix.errors.inspect
render json: serialize_errors(@provider_prefix.errors), status: :unprocessable_entity
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def create

render json: ProviderSerializer.new(@provider, options).serialized_json, status: :ok
else
logger.error @provider.errors.inspect
Rails.logger.error @provider.errors.inspect
render json: serialize_errors(@provider.errors), status: :unprocessable_entity
end
end
Expand Down Expand Up @@ -243,7 +243,7 @@ def update

render json: ProviderSerializer.new(@provider, options).serialized_json, status: :ok
else
logger.error @provider.errors.inspect
Rails.logger.error @provider.errors.inspect
render json: serialize_errors(@provider.errors), status: :unprocessable_entity
end
end
Expand All @@ -254,13 +254,13 @@ def destroy
if active_client_count(provider_id: @provider.symbol).positive?
message = "Can't delete provider that has active clients."
status = 400
logger.warn message
Rails.logger.warn message
render json: { errors: [{ status: status.to_s, title: message }] }.to_json, status: status
elsif @provider.update_attributes(is_active: nil, deleted_at: Time.zone.now)
@provider.send_delete_email unless Rails.env.test?
head :no_content
else
logger.error @provider.errors.inspect
Rails.logger.error @provider.errors.inspect
render json: serialize_errors(@provider.errors), status: :unprocessable_entity
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def create

render json: RepositorySerializer.new(@client, options).serialized_json, status: :created
else
logger.error @client.errors.inspect
Rails.logger.error @client.errors.inspect
render json: serialize_errors(@client.errors), status: :unprocessable_entity
end
end
Expand All @@ -155,7 +155,7 @@ def update

render json: RepositorySerializer.new(@client, options).serialized_json, status: :ok
else
logger.error @client.errors.inspect
Rails.logger.error @client.errors.inspect
render json: serialize_errors(@client.errors), status: :unprocessable_entity
end
end
Expand All @@ -166,13 +166,13 @@ def destroy
if @client.dois.present?
message = "Can't delete repository that has DOIs."
status = 400
logger.warn message
Rails.logger.warn message
render json: { errors: [{ status: status.to_s, title: message }] }.to_json, status: status
elsif @client.update_attributes(is_active: nil, deleted_at: Time.zone.now)
@client.send_delete_email unless Rails.env.test?
head :no_content
else
logger.error @client.errors.inspect
Rails.logger.error @client.errors.inspect
render json: serialize_errors(@client.errors), status: :unprocessable_entity
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/repository_prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def create

render json: RepositoryPrefixSerializer.new(@client_prefix, options).serialized_json, status: :created
else
logger.error @client_prefix.errors.inspect
Rails.logger.error @client_prefix.errors.inspect
render json: serialize_errors(@client_prefix.errors), status: :unprocessable_entity
end
end
Expand Down
14 changes: 7 additions & 7 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,21 @@ def self.import_by_id(options={})
# log errors
errors += response['items'].map { |k, v| k.values.first['error'] }.compact.length
response['items'].select { |k, v| k.values.first['error'].present? }.each do |err|
logger.error "[Elasticsearch] " + err.inspect
Rails.logger.error "[Elasticsearch] " + err.inspect
end

count += activities.length
end

if errors > 1
logger.error "[Elasticsearch] #{errors} errors importing #{count} activities with IDs #{id} - #{(id + 499)}."
Rails.logger.error "[Elasticsearch] #{errors} errors importing #{count} activities with IDs #{id} - #{(id + 499)}."
elsif count > 0
logger.info "[Elasticsearch] Imported #{count} activities with IDs #{id} - #{(id + 499)}."
Rails.logger.info "[Elasticsearch] Imported #{count} activities with IDs #{id} - #{(id + 499)}."
end

count
rescue Elasticsearch::Transport::Transport::Errors::RequestEntityTooLarge, Faraday::ConnectionFailed, ActiveRecord::LockWaitTimeout => error
logger.error "[Elasticsearch] Error #{error.message} importing activities with IDs #{id} - #{(id + 499)}."
Rails.logger.error "[Elasticsearch] Error #{error.message} importing activities with IDs #{id} - #{(id + 499)}."

count = 0

Expand All @@ -243,7 +243,7 @@ def self.import_by_id(options={})
count += 1
end

logger.info "[Elasticsearch] Imported #{count} activities with IDs #{id} - #{(id + 499)}."
Rails.logger.info "[Elasticsearch] Imported #{count} activities with IDs #{id} - #{(id + 499)}."

count
end
Expand Down Expand Up @@ -315,11 +315,11 @@ def self.convert_affiliation_by_id(options={})
end
end

logger.info "[Elasticsearch] Converted affiliations for #{count} activities with IDs #{id} - #{(id + 499)}." if count > 0
Rails.logger.info "[Elasticsearch] Converted affiliations for #{count} activities with IDs #{id} - #{(id + 499)}." if count > 0

count
rescue Elasticsearch::Transport::Transport::Errors::RequestEntityTooLarge, Faraday::ConnectionFailed, ActiveRecord::LockWaitTimeout => error
logger.info "[Elasticsearch] Error #{error.message} converting affiliations for DOIs with IDs #{id} - #{(id + 499)}."
Rails.logger.info "[Elasticsearch] Error #{error.message} converting affiliations for DOIs with IDs #{id} - #{(id + 499)}."
end

def uid
Expand Down
8 changes: 4 additions & 4 deletions app/models/concerns/crosscitable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def parse_xml(input, options={})
rescue NoMethodError, ArgumentError => exception
Raven.capture_exception(exception)

logger.error "Error " + exception.message + " for doi " + @doi + "."
logger.error exception
Rails.logger.error "Error " + exception.message + " for doi " + @doi + "."
Rails.logger.error exception

{}
end
Expand Down Expand Up @@ -117,8 +117,8 @@ def clean_xml(string)
doc = Nokogiri::XML(string) { |config| config.strict.noblanks }
doc.to_xml
rescue ArgumentError, Encoding::CompatibilityError => exception
logger.error "Error " + exception.message + "."
logger.error exception
Rails.logger.error "Error " + exception.message + "."
Rails.logger.error exception

nil
end
Expand Down
18 changes: 9 additions & 9 deletions app/models/concerns/helpable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module Helpable

def register_url
unless url.present?
logger.error "[Handle] Error updating DOI " + doi + ": url missing."
Rails.logger.error "[Handle] Error updating DOI " + doi + ": url missing."
return OpenStruct.new(body: { "errors" => [{ "title" => "URL missing." }] })
end

unless client_id.present?
logger.error "[Handle] Error updating DOI " + doi + ": client ID missing."
Rails.logger.error "[Handle] Error updating DOI " + doi + ": client ID missing."
return OpenStruct.new(body: { "errors" => [{ "title" => "Client ID missing." }] })
end

Expand Down Expand Up @@ -56,11 +56,11 @@ def register_url
if [200, 201].include?(response.status)
# update minted column after first successful registration in handle system
self.update_attributes(minted: Time.zone.now, updated: Time.zone.now) if minted.blank?
logger.info "[Handle] URL for DOI " + doi + " updated to " + url + "." unless Rails.env.test?
Rails.logger.info "[Handle] URL for DOI " + doi + " updated to " + url + "." unless Rails.env.test?

self.__elasticsearch__.index_document
else
logger.error "[Handle] Error updating URL for DOI " + doi + ": " + response.body.inspect unless Rails.env.test?
Rails.logger.error "[Handle] Error updating URL for DOI " + doi + ": " + response.body.inspect unless Rails.env.test?
end

response
Expand All @@ -71,7 +71,7 @@ def get_url
response = Maremma.get(url, ssl_self_signed: true, timeout: 10)

if response.status != 200
logger.error "[Handle] Error fetching URL for DOI " + doi + ": " + response.body.inspect unless Rails.env.test?
Rails.logger.error "[Handle] Error fetching URL for DOI " + doi + ": " + response.body.inspect unless Rails.env.test?
end

response
Expand Down Expand Up @@ -142,13 +142,13 @@ def get_dois(options={})
else
text = "Error " + response.body["errors"].inspect

logger.error "[Handle] " + text
Rails.logger.error "[Handle] " + text
User.send_notification_to_slack(text, title: "Error #{response.status.to_s}", level: "danger") unless Rails.env.test?
end
end
end

logger.info "#{total} DOIs found."
Rails.logger.info "#{total} DOIs found."

dois
end
Expand All @@ -163,7 +163,7 @@ def get_doi(options={})
if response.status != 200
text = "Error " + response.body["errors"].inspect

logger.error "[Handle] " + text
Rails.logger.error "[Handle] " + text
User.send_notification_to_slack(text, title: "Error #{response.status.to_s}", level: "danger") unless Rails.env.test?
end

Expand All @@ -182,7 +182,7 @@ def delete_doi(options={})
else
text = "Error " + response.body["errors"].inspect

logger.error "[Handle] " + text
Rails.logger.error "[Handle] " + text
User.send_notification_to_slack(text, title: "Error #{response.status.to_s}", level: "danger") unless Rails.env.test?
response
end
Expand Down
Loading

0 comments on commit b6c2ef4

Please sign in to comment.