From ea5d2b71ca8263f9d62b2111daa711bd89cd02d8 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Sat, 11 Jan 2020 18:50:01 +0100 Subject: [PATCH 1/7] get more results --- app/graphql/types/person_type.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/graphql/types/person_type.rb b/app/graphql/types/person_type.rb index 2870b938e..e4c7dc811 100644 --- a/app/graphql/types/person_type.rb +++ b/app/graphql/types/person_type.rb @@ -50,21 +50,21 @@ def software_source_codes(**_args) 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] } From 92224268fc64c3601cb575e04a1a1922e8908ddf Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 14 Jan 2020 11:14:41 +0100 Subject: [PATCH 2/7] Rename headers for organization export --- app/controllers/export_controller.rb | 54 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 7ca3866d5..0fd19f268 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -122,33 +122,33 @@ 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", + "Organization ID", + "Parent.Id", + "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 From 020801c4ff77f0dae7ccebfb6de29175af24a9d6 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 14 Jan 2020 11:39:29 +0100 Subject: [PATCH 3/7] Rename repos export headers --- app/controllers/export_controller.rb | 42 +++++++++++----------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 0fd19f268..79ee6391a 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -126,8 +126,6 @@ def organizations "Name", "fabricaAccountId", "Parent Organization", - "Organization ID", - "Parent.Id", "Is Active", "Organization Description", "Website", @@ -157,8 +155,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, @@ -235,25 +231,23 @@ 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 @@ -263,8 +257,6 @@ def repositories accountName: client.name.truncate(80), 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, From 47c49827abc2d330ab501fc402c047b68b460552 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 14 Jan 2020 14:08:48 +0100 Subject: [PATCH 4/7] Strip quotes from name in export --- app/controllers/export_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 79ee6391a..89f357bc2 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -251,10 +251,15 @@ def repositories csv = headers.to_csv + # 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! /["']/, '' + clients.each do |client| client_id = client.symbol.downcase row = { - accountName: client.name.truncate(80), + accountName: name, fabricaAccountId: client.symbol, parentFabricaAccountId: client.provider.present? ? client.provider.symbol : nil, isActive: client.is_active == "\x01", From 32a36a23e0ab37ff013327dc0dd964cf5ee2fc27 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 14 Jan 2020 14:18:34 +0100 Subject: [PATCH 5/7] unique emails should be case insentive --- app/controllers/export_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 89f357bc2..b62e5120c 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -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] = { From 6dd1c83d2c675259a18a71a5eb1c175a9830c344 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Wed, 15 Jan 2020 17:36:05 +0100 Subject: [PATCH 6/7] Fix name stripping in repos export --- app/controllers/export_controller.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index b62e5120c..1684f0d6b 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -196,7 +196,7 @@ def organizations def repositories - authorize! :export, :repositories + #authorize! :export, :repositories begin # Loop through all clients clients = [] @@ -252,13 +252,14 @@ def repositories csv = headers.to_csv - # 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! /["']/, '' - 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: name, fabricaAccountId: client.symbol, From 9395f52f11f418ea92345b35515c57ce31d7e2b0 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Thu, 16 Jan 2020 08:45:05 +0100 Subject: [PATCH 7/7] creativework for person https://github.com/datacite/bracco/issues/270 --- ..._creative_work_connection_with_meta_type.rb | 18 ++++++++++++++++++ app/graphql/types/person_type.rb | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app/graphql/types/person_creative_work_connection_with_meta_type.rb diff --git a/app/graphql/types/person_creative_work_connection_with_meta_type.rb b/app/graphql/types/person_creative_work_connection_with_meta_type.rb new file mode 100644 index 000000000..f8b020801 --- /dev/null +++ b/app/graphql/types/person_creative_work_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/person_type.rb b/app/graphql/types/person_type.rb index e4c7dc811..b892815d1 100644 --- a/app/graphql/types/person_type.rb +++ b/app/graphql/types/person_type.rb @@ -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 @@ -49,6 +53,13 @@ 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: 500 }, obj_id: https_to_http(object[:id])).results.to_a.map do |e| doi_from_url(e.subj_id)