Skip to content

Commit

Permalink
Merge branch 'master' into database-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner authored Aug 5, 2020
2 parents 1270617 + 0da527a commit 44971f7
Show file tree
Hide file tree
Showing 184 changed files with 7,174 additions and 2,086 deletions.
2 changes: 1 addition & 1 deletion app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def destroy
def totals
page = { size: 0, number: 1 }
state = current_user.present? && current_user.is_admin_or_staff? && params[:state].present? ? params[:state] : "registered,findable"
response = Doi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: "client")
response = DataciteDoi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: "client")
registrant = response.results.total.positive? ? clients_totals(response.aggregations.clients_totals.buckets) : []

render json: registrant, status: :ok
Expand Down
50 changes: 25 additions & 25 deletions app/controllers/concerns/countable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,63 @@ module Countable
included do
def doi_count(client_id: nil, provider_id: nil, consortium_id: nil, user_id: nil)
if client_id
response = Doi.stats_query(client_id: client_id)
response = DataciteDoi.stats_query(client_id: client_id)
elsif provider_id
response = Doi.stats_query(provider_id: provider_id)
response = DataciteDoi.stats_query(provider_id: provider_id)
elsif consortium_id
response = Doi.stats_query(consortium_id: consortium_id)
response = DataciteDoi.stats_query(consortium_id: consortium_id)
elsif user_id
response = Doi.stats_query(user_id: user_id)
response = DataciteDoi.stats_query(user_id: user_id)
else
response = Doi.stats_query
response = DataciteDoi.stats_query
end

response.results.total.positive? ? facet_by_year(response.aggregations.created.buckets) : []
end

def view_count(client_id: nil, provider_id: nil, consortium_id: nil, user_id: nil, state: nil)
if client_id
response = Doi.query(nil, client_id: client_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, client_id: client_id, page: { number: 1, size: 0 })
elsif provider_id
response = Doi.query(nil, provider_id: provider_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, provider_id: provider_id, page: { number: 1, size: 0 })
elsif consortium_id
response = Doi.query(nil, consortium_id: consortium_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, consortium_id: consortium_id, page: { number: 1, size: 0 })
elsif user_id
response = Doi.query(nil, user_id: user_id, state: state, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, user_id: user_id, state: state, page: { number: 1, size: 0 })
else
response = Doi.query(nil, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, page: { number: 1, size: 0 })
end

response.results.total.positive? ? metric_facet_by_year(response.aggregations.views.buckets) : []
end

def download_count(client_id: nil, provider_id: nil, consortium_id: nil, user_id: nil, state: nil)
if client_id
response = Doi.query(nil, client_id: client_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, client_id: client_id, page: { number: 1, size: 0 })
elsif provider_id
response = Doi.query(nil, provider_id: provider_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, provider_id: provider_id, page: { number: 1, size: 0 })
elsif consortium_id
response = Doi.query(nil, consortium_id: consortium_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, consortium_id: consortium_id, page: { number: 1, size: 0 })
elsif user_id
response = Doi.query(nil, user_id: user_id, state: state, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, user_id: user_id, state: state, page: { number: 1, size: 0 })
else
response = Doi.query(nil, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, page: { number: 1, size: 0 })
end

response.results.total.positive? ? metric_facet_by_year(response.aggregations.downloads.buckets) : []
end

def citation_count(client_id: nil, provider_id: nil, consortium_id: nil, user_id: nil, state: nil)
if client_id
response = Doi.query(nil, client_id: client_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, client_id: client_id, page: { number: 1, size: 0 })
elsif provider_id
response = Doi.query(nil, provider_id: provider_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, provider_id: provider_id, page: { number: 1, size: 0 })
elsif consortium_id
response = Doi.query(nil, consortium_id: consortium_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, consortium_id: consortium_id, page: { number: 1, size: 0 })
elsif user_id
response = Doi.query(nil, user_id: user_id, state: state, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, user_id: user_id, state: state, page: { number: 1, size: 0 })
else
response = Doi.query(nil, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, page: { number: 1, size: 0 })
end

response.results.total.positive? ? metric_facet_by_year(response.aggregations.citations.buckets) : []
Expand Down Expand Up @@ -103,15 +103,15 @@ def provider_count(consortium_id: nil)

def resource_type_count(client_id: nil, provider_id: nil, consortium_id: nil, user_id: nil, state: nil)
if client_id
response = Doi.query(nil, client_id: client_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, client_id: client_id, page: { number: 1, size: 0 })
elsif provider_id
response = Doi.query(nil, provider_id: provider_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, provider_id: provider_id, page: { number: 1, size: 0 })
elsif consortium_id
response = Doi.query(nil, consortium_id: consortium_id, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, consortium_id: consortium_id, page: { number: 1, size: 0 })
elsif user_id
response = Doi.query(nil, user_id: user_id, state: state, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, user_id: user_id, state: state, page: { number: 1, size: 0 })
else
response = Doi.query(nil, page: { number: 1, size: 0 })
response = DataciteDoi.query(nil, page: { number: 1, size: 0 })
end

response.results.total.positive? ? facet_by_combined_key(response.aggregations.resource_types.buckets) : []
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ module Facetable
"cc-by-2.5" => "CC-BY-2.5",
"cc-by-3.0" => "CC-BY-3.0",
"cc-by-4.0" => "CC-BY-4.0",
"cc-by-nc-2.5" => "CC-BY-NC-2.5",
"cc-by-nc-3.0" => "CC-BY-NC-3.0",
"cc-by-nc-4.0" => "CC-BY-NC-4.0",
"cc-by-nc-nd-4.0" => "CC-BY-NC-ND-4.0",
"cc-by-nc-sa-3.0" => "CC-BY-NC-SA-3.0",
"cc-by-nc-sa-4.0" => "CC-BY-NC-SA-4.0",
"cc-by-sa-4.0" => "CC-BY-SA-4.0",
"cc-pddc" => "CC-PDDC",
"cc0-1.0" => "CC0-1.0",
"gpl-3.0" => "GPL-3.0",
Expand Down
1 change: 0 additions & 1 deletion app/controllers/data_centers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def index
response = Client.find_by_id(params[:ids], page: page, sort: sort)
else
response = Client.query(params[:query],
exclude_registration_agencies: true,
year: params[:year],
provider_id: params[:member_id],
fields: params[:fields],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'uri'
require 'base64'

class DoisController < ApplicationController
class DataciteDoisController < ApplicationController
include ActionController::MimeResponds
include Crosscitable

Expand Down Expand Up @@ -43,13 +43,12 @@ def index
params[:state] = "findable" if current_user.nil? || current_user.role_id == "user"

if params[:id].present?
response = Doi.find_by_id(params[:id])
response = DataciteDoi.find_by_id(params[:id])
elsif params[:ids].present?
response = Doi.find_by_ids(params[:ids], page: page, sort: sort)
response = DataciteDoi.find_by_ids(params[:ids], page: page, sort: sort)
else
response = Doi.query(params[:query],
response = DataciteDoi.query(params[:query],
state: params[:state],
exclude_registration_agencies: params[:exclude_registration_agencies],
published: params[:published],
created: params[:created],
registered: params[:registered],
Expand Down Expand Up @@ -150,9 +149,9 @@ def index
# sparse fieldsets
fields = fields_from_params(params)
if fields
render json: DoiSerializer.new(results, options.merge(fields: fields)).serialized_json, status: :ok
render json: DataciteDoiSerializer.new(results, options.merge(fields: fields)).serialized_json, status: :ok
else
render json: DoiSerializer.new(results, options).serialized_json, status: :ok
render json: DataciteDoiSerializer.new(results, options).serialized_json, status: :ok
end
else
states = total.positive? ? facet_by_key(response.aggregations.states.buckets) : nil
Expand Down Expand Up @@ -220,7 +219,6 @@ def index
self: request.original_url,
next: results.size < page[:size] || page[:size] == 0 ? nil : request.base_url + "/dois?" + {
query: params[:query],
"exclude-registration-agencies" => params[:exclude_registration_agencies],
"provider-id" => params[:provider_id],
"consortium-id" => params[:consortium_id],
"client-id" => params[:client_id],
Expand Down Expand Up @@ -264,9 +262,9 @@ def index
# sparse fieldsets
fields = fields_from_params(params)
if fields
render json: DoiSerializer.new(results, options.merge(fields: fields)).serialized_json, status: :ok
render json: DataciteDoiSerializer.new(results, options.merge(fields: fields)).serialized_json, status: :ok
else
render json: DoiSerializer.new(results, options).serialized_json, status: :ok
render json: DataciteDoiSerializer.new(results, options).serialized_json, status: :ok
end
end

Expand All @@ -287,11 +285,11 @@ def index
end

def show
# only show findable DOIs to anonymous users and role user
# only show findable DataCite DOIs to anonymous users and role user
# use current_user role to determine permissions to access draft and registered dois
# instead of using ability
# response = Doi.find_by_id(params[:id])
doi = Doi.where(doi: params[:id]).first
# response = DataciteDoi.find_by_id(params[:id])
doi = DataciteDoi.where(doi: params[:id]).first
fail ActiveRecord::RecordNotFound if not_allowed_by_doi_and_user(doi: doi, user: current_user)

respond_to do |format|
Expand All @@ -309,7 +307,7 @@ def show
affiliation: params[:affiliation],
}

render json: DoiSerializer.new(doi, options).serialized_json, status: :ok
render json: DataciteDoiSerializer.new(doi, options).serialized_json, status: :ok
end

# doi = response.records.first
Expand All @@ -326,7 +324,7 @@ def show
end

def validate
@doi = Doi.new(safe_params.merge(only_validate: true))
@doi = DataciteDoi.new(safe_params.merge(only_validate: true))

authorize! :validate, @doi

Expand All @@ -338,7 +336,7 @@ def validate
:current_ability => current_ability,
}

render json: DoiSerializer.new(@doi, options).serialized_json, status: :ok
render json: DataciteDoiSerializer.new(@doi, options).serialized_json, status: :ok
else
logger.info @doi.errors.messages
render json: serialize_errors(@doi.errors.messages), status: :ok
Expand All @@ -347,7 +345,7 @@ def validate

def create
fail CanCan::AuthorizationNotPerformed if current_user.blank?
@doi = Doi.new(safe_params)
@doi = DataciteDoi.new(safe_params)

# capture username and password for reuse in the handle system
@doi.current_user = current_user
Expand All @@ -364,15 +362,15 @@ def create
affiliation: params[:affiliation]
}

render json: DoiSerializer.new(@doi, options).serialized_json, status: :created, location: @doi
render json: DataciteDoiSerializer.new(@doi, options).serialized_json, status: :created, location: @doi
else
logger.error @doi.errors.inspect
render json: serialize_errors(@doi.errors), include: @include, status: :unprocessable_entity
end
end

def update
@doi = Doi.where(doi: params[:id]).first
@doi = DataciteDoi.where(doi: params[:id]).first
exists = @doi.present?

if exists
Expand All @@ -396,7 +394,7 @@ def update
doi_id = validate_doi(params[:id])
fail ActiveRecord::RecordNotFound unless doi_id.present?

@doi = Doi.new(safe_params.merge(doi: doi_id))
@doi = DataciteDoi.new(safe_params.merge(doi: doi_id))
# capture username and password for reuse in the handle system
@doi.current_user = current_user

Expand All @@ -413,15 +411,15 @@ def update
affiliation: params[:affiliation],
}

render json: DoiSerializer.new(@doi, options).serialized_json, status: exists ? :ok : :created
render json: DataciteDoiSerializer.new(@doi, options).serialized_json, status: exists ? :ok : :created
else
logger.error @doi.errors.messages
render json: serialize_errors(@doi.errors.messages), include: @include, status: :unprocessable_entity
end
end

def undo
@doi = Doi.where(doi: safe_params[:doi]).first
@doi = DataciteDoi.where(doi: safe_params[:doi]).first
fail ActiveRecord::RecordNotFound if @doi.blank?

authorize! :undo, @doi
Expand All @@ -436,15 +434,15 @@ def undo

}

render json: DoiSerializer.new(@doi, options).serialized_json, status: :ok
render json: DataciteDoiSerializer.new(@doi, options).serialized_json, status: :ok
else
logger.error @doi.errors.messages
render json: serialize_errors(@doi.errors.messages), include: @include, status: :unprocessable_entity
end
end

def destroy
@doi = Doi.where(doi: params[:id]).first
@doi = DataciteDoi.where(doi: params[:id]).first
fail ActiveRecord::RecordNotFound if @doi.blank?

authorize! :destroy, @doi
Expand Down Expand Up @@ -472,12 +470,12 @@ def random
end

def get_url
@doi = Doi.where(doi: params[:id]).first
@doi = DataciteDoi.where(doi: params[:id]).first
fail ActiveRecord::RecordNotFound if @doi.blank?

authorize! :get_url, @doi

if !@doi.is_registered_or_findable? || %w(europ).include?(@doi.provider_id) || %w(crossref.citations medra.citations jalc.citations kisti.citations op.citations).include?(@doi.client_id)
if !@doi.is_registered_or_findable? || %w(europ).include?(@doi.provider_id) || @doi.type == "OtherDoi"
url = @doi.url
head :no_content && return if url.blank?
else
Expand Down Expand Up @@ -507,7 +505,7 @@ def get_dois
client_prefix = client.prefixes.first
head :no_content && return if client_prefix.blank?

dois = Doi.get_dois(prefix: client_prefix.uid, username: current_user.uid.upcase, password: current_user.password)
dois = DataciteDoi.get_dois(prefix: client_prefix.uid, username: current_user.uid.upcase, password: current_user.password)
if dois.length.positive?
render json: { dois: dois }.to_json, status: :ok
else
Expand All @@ -517,7 +515,7 @@ def get_dois

def set_url
authorize! :set_url, Doi
Doi.set_url
DataciteDoi.set_url

render json: { message: "Adding missing URLs queued." }.to_json, status: :ok
end
Expand All @@ -533,7 +531,7 @@ def set_include
if params[:include].present?
@include = params[:include].split(",").map { |i| i.downcase.underscore.to_sym }

@include = @include & [:client, :media, :references, :citations, :parts, :part_of, :versions, :version_of]
@include = @include & [:client, :media]
else
@include = []
end
Expand Down
Loading

0 comments on commit 44971f7

Please sign in to comment.