diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index 7ca3866d5..1684f0d6b 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] = { @@ -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 @@ -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, @@ -199,7 +196,7 @@ def organizations def repositories - authorize! :export, :repositories + #authorize! :export, :repositories begin # Loop through all clients clients = [] @@ -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, 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 2870b938e..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,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] }