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
Martin Fenner committed Jan 16, 2020
2 parents cec7530 + 9395f52 commit b56a8d9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 55 deletions.
103 changes: 51 additions & 52 deletions app/controllers/export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def contacts
contacts = Hash.new

add_contact = Proc.new { |contacts, email, id, firstname, lastname, type|
email.downcase
if email
unless contacts.has_key?(email)
contacts[email] = {
Expand Down Expand Up @@ -122,33 +123,31 @@ def organizations

respond_to do |format|
format.csv do
headers = %W(
accountName
fabricaAccountId
parentFabricaAccountId
salesForceId
parentSalesForceId
isActive
accountDescription
accountWebsite
region
focusArea
sector
accountType
generalContactEmail
groupEmail
billingStreet
billingPostalCode
billingCity
billingDepartment
billingOrganization
billingState
billingCountry
twitter
rorId
created
deleted
)
headers = [
"Name",
"fabricaAccountId",
"Parent Organization",
"Is Active",
"Organization Description",
"Website",
"Region",
"Focus Area",
"Sector",
"Member Type",
"Email",
"Group Email",
"billingStreet",
"Billing Zip/Postal Code",
"billingCity",
"Department",
"billingOrganization",
"billingState",
"billingCountry",
"twitter",
"ROR",
"Fabrica Creation Date",
"Fabrica Deletion Date"
]

csv = headers.to_csv

Expand All @@ -157,8 +156,6 @@ def organizations
accountName: provider.name,
fabricaAccountId: provider.symbol,
parentFabricaAccountId: provider.consortium.present? ? provider.consortium.symbol : nil,
salesForceId: provider.salesforce_id,
parentSalesForceId: provider.consortium.present? ? provider.consortium.salesforce_id : nil,
isActive: provider.is_active == "\x01",
accountDescription: provider.description,
accountWebsite: provider.website,
Expand Down Expand Up @@ -199,7 +196,7 @@ def organizations


def repositories
authorize! :export, :repositories
#authorize! :export, :repositories
begin
# Loop through all clients
clients = []
Expand Down Expand Up @@ -235,36 +232,38 @@ def repositories

respond_to do |format|
format.csv do
headers = %W(
accountName
fabricaAccountId
parentFabricaAccountId
salesForceId
parentSalesForceId
isActive
accountDescription
accountWebsite
generalContactEmail
serviceContactEmail
serviceContactGivenName
serviceContactFamilyName
created
deleted
doisCountCurrentYear
doisCountPreviousYear
doisCountTotal
)
headers = [
"Repository Name",
"Repository ID",
"Organization",
"isActive",
"Description",
"Repository URL",
"generalContactEmail",
"serviceContactEmail",
"serviceContactGivenName",
"serviceContactFamilyName",
"Fabrica Creation date",
"Fabrica Deletion date",
"doisCurrentYear",
"doisPreviousYear",
"doisTotal"
]

csv = headers.to_csv

clients.each do |client|
client_id = client.symbol.downcase

# Limit for salesforce default of max 80 chars
name = +client.name.truncate(80)
# Clean the name to remove quotes, which can break csv parsers
name.gsub! /["']/, ''

row = {
accountName: client.name.truncate(80),
accountName: name,
fabricaAccountId: client.symbol,
parentFabricaAccountId: client.provider.present? ? client.provider.symbol : nil,
salesForceId: client.salesforce_id,
parentSalesForceId: client.provider.present? ? client.provider.salesforce_id : nil,
isActive: client.is_active == "\x01",
accountDescription: client.description,
accountWebsite: client.url,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

class PersonCreativeWorkConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: https_to_http(object.parent.id)).results.total
end

def https_to_http(url)
uri = Addressable::URI.parse(url)
uri.scheme = "http" if uri.present?
uri.to_s
end
end
17 changes: 14 additions & 3 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class PersonType < BaseObject
argument :first, Int, required: false, default_value: 25
end

field :creative_works, PersonCreativeWorkConnectionWithMetaType, null: true, description: "Authored creative works", connection: true do
argument :first, Int, required: false, default_value: 25
end

def type
"Person"
end
Expand All @@ -49,22 +53,29 @@ def software_source_codes(**_args)
ElasticsearchLoader.for(Doi).load_many(ids)
end

def creative_works(**_args)
ids = Event.query(nil, obj_id: https_to_http(object[:id])).results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def citation_count(**_args)
dois = Event.query(nil, page: { size: 100 }, obj_id: https_to_http(object[:id])).results.to_a.map do |e|
dois = Event.query(nil, page: { size: 500 }, obj_id: https_to_http(object[:id])).results.to_a.map do |e|
doi_from_url(e.subj_id)
end
EventsQuery.new.citations(dois.join(",")).sum { |h| h[:count] }
end

def view_count(**_args)
dois = Event.query(nil, page: { size: 100 }, obj_id: https_to_http(object[:id])).results.to_a.map do |e|
dois = Event.query(nil, page: { size: 500 }, obj_id: https_to_http(object[:id])).results.to_a.map do |e|
doi_from_url(e.subj_id)
end
EventsQuery.new.views(dois.join(",")).sum { |h| h[:count] }
end

def download_count(**_args)
dois = Event.query(nil, page: { size: 100 }, obj_id: https_to_http(object[:id])).results.to_a.map do |e|
dois = Event.query(nil, page: { size: 500 }, obj_id: https_to_http(object[:id])).results.to_a.map do |e|
doi_from_url(e.subj_id)
end
EventsQuery.new.downloads(dois.join(",")).sum { |h| h[:count] }
Expand Down

0 comments on commit b56a8d9

Please sign in to comment.