diff --git a/app/graphql/types/country_type.rb b/app/graphql/types/country_type.rb index fc113f973..2023f22c4 100644 --- a/app/graphql/types/country_type.rb +++ b/app/graphql/types/country_type.rb @@ -3,6 +3,6 @@ class CountryType < BaseObject description "Information about countries" - field :id, String, null: true, description: "Country code" + field :code, String, null: true, description: "Country ISO 3166-1 code" field :name, String, null: true, description: "Country name" end diff --git a/app/graphql/types/funder_type.rb b/app/graphql/types/funder_type.rb index 7f451b8ca..5cd3323c5 100644 --- a/app/graphql/types/funder_type.rb +++ b/app/graphql/types/funder_type.rb @@ -6,7 +6,7 @@ class FunderType < BaseObject field :id, ID, null: false, description: "Crossref Funder ID" field :name, String, null: false, description: "Funder name" field :alternate_name, [String], null: true, description: "Alternate funder names" - field :country, String, null: true, description: "Country where funder is located" + field :country, CountryType, null: true, description: "Country where funder is located" field :date_modified, String, null: false, description: "Date information was last updated" field :datasets, FunderDatasetConnectionWithMetaType, null: false, description: "Funded datasets", connection: true, max_page_size: 100 do argument :first, Int, required: false, default_value: 25 diff --git a/app/graphql/types/label_type.rb b/app/graphql/types/label_type.rb index 3eea65878..24dedc9e4 100644 --- a/app/graphql/types/label_type.rb +++ b/app/graphql/types/label_type.rb @@ -3,6 +3,6 @@ class LabelType < BaseObject description "Information about labels" - field :iso639, ID, null: false, description: "Label language" + field :code, ID, null: false, description: "Label language ISO 639-1 code" field :name, String, null: true, method: :label, description: "Label name" end diff --git a/app/graphql/types/provider_type.rb b/app/graphql/types/provider_type.rb index 46becc91d..9b0dca276 100644 --- a/app/graphql/types/provider_type.rb +++ b/app/graphql/types/provider_type.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true class ProviderType < BaseObject - description "Information about members" + description "Information about providers" - field :id, ID, null: false, hash_key: "uid", description: "Unique identifier for each member" - field :name, String, null: false, description: "Member name" + field :id, ID, null: false, hash_key: "uid", description: "Unique identifier for each provider" + field :name, String, null: false, description: "Provider name" field :ror_id, String, null: false, description: "Research Organization Registry (ROR) identifier" - field :description, String, null: true, description: "Description of the member" - field :website, String, null: true, description: "Website of the member" - field :contact_name, String, null: true, description: "Member contact name" - field :contact_email, String, null: true, description: "Member contact email" - field :logo_url, String, null: true, description: "URL for the member logo" - field :region, String, null: true, description: "Geographic region where the member is located" - field :country, String, null: true, description: "Country where the member is located" + field :description, String, null: true, description: "Description of the provider" + field :website, String, null: true, description: "Website of the provider" + field :contact_name, String, null: true, description: "Provider contact name" + field :contact_email, String, null: true, description: "Provider contact email" + field :logo_url, String, null: true, description: "URL for the provider logo" + field :region, String, null: true, description: "Geographic region where the provider is located" + field :country, CountryType, null: true, description: "Country where the provider is located" field :organization_type, String, null: true, description: "Type of organization" - field :focus_area, String, null: true, description: "Field of science covered by member" + field :focus_area, String, null: true, description: "Field of science covered by provider" field :joined, String, null: true, description: "Date provider joined DataCite" field :prefixes, PrefixConnectionWithMetaType, null: false, description: "Prefixes managed by the provider", connection: true, max_page_size: 100 do argument :query, String, required: false @@ -31,6 +31,14 @@ class ProviderType < BaseObject argument :after, String, required: false end + def country + return {} unless object.country_code.present? + { + code: object.country_code, + name: ISO3166::Country[object.country_code].name + }.compact + end + def prefixes(**args) collection = object.provider_prefixes.joins(:prefix) collection = collection.state(args[:state].underscore.dasherize) if args[:state].present? diff --git a/app/models/funder.rb b/app/models/funder.rb index 9a9595463..8a2971215 100644 --- a/app/models/funder.rb +++ b/app/models/funder.rb @@ -43,18 +43,20 @@ def self.query(query, options={}) def self.parse_message(id: nil, message: nil) if message["location"].present? - location = { - "country" => message["location"] + c = ISO3166::Country.find_country_by_name(message["location"]) + country = { + "code" => c.alpha2, + "name" => message["location"] } else - location = nil + country = nil end { id: id, name: message["name"], alternate_name: message["alt-names"], - country: message["location"], + country: country, date_modified: "2019-04-18T00:00:00Z" }.compact end end diff --git a/app/models/organization.rb b/app/models/organization.rb index 5e4e1b350..11e18eb63 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -40,13 +40,14 @@ def self.query(query, options={}) def self.parse_message(id: nil, message: nil) country = { - id: message.dig("country", "country_code"), + code: message.dig("country", "country_code"), name: message.dig("country", "country_name") }.compact labels = Array.wrap(message["labels"]).map do |label| + code = label["iso639"].present? ? label["iso639"].upcase : nil { - iso639: label["iso639"], - label: label["label"] }.compact + code: code, + name: label["label"] }.compact end { diff --git a/spec/models/funder_spec.rb b/spec/models/funder_spec.rb index 88e1af295..8e7616631 100644 --- a/spec/models/funder_spec.rb +++ b/spec/models/funder_spec.rb @@ -22,7 +22,7 @@ funders = Funder.query(query) expect(funders.dig(:meta, "total")).to eq(19662) expect(funders[:data].size).to eq(100) - expect(funders[:data].first).to eq(id: "https://doi.org/10.13039/100002569", name: "American Association of Endodontists Foundation", alternate_name: ["AAE Foundation for Endodontics", "AAE Foundation", "Foundation for Endodontics", "AAEF"], country: "United States", date_modified: "2019-04-18T00:00:00Z") + expect(funders[:data].first).to eq(id: "https://doi.org/10.13039/100002569", name: "American Association of Endodontists Foundation", alternate_name: ["AAE Foundation for Endodontics", "AAE Foundation", "Foundation for Endodontics", "AAEF"], country: {"code"=>"US", "name"=>"United States"}, date_modified: "2019-04-18T00:00:00Z") end it "limit" do @@ -30,7 +30,7 @@ funders = Funder.query(query, limit: 10) expect(funders.dig(:meta, "total")).to eq(19662) expect(funders[:data].size).to eq(10) - expect(funders[:data].first).to eq(id: "https://doi.org/10.13039/100002569", name: "American Association of Endodontists Foundation", alternate_name: ["AAE Foundation for Endodontics", "AAE Foundation", "Foundation for Endodontics", "AAEF"], country: "United States", date_modified: "2019-04-18T00:00:00Z") + expect(funders[:data].first).to eq(id: "https://doi.org/10.13039/100002569", name: "American Association of Endodontists Foundation", alternate_name: ["AAE Foundation for Endodontics", "AAE Foundation", "Foundation for Endodontics", "AAEF"], country: {"code"=>"US", "name"=>"United States"}, date_modified: "2019-04-18T00:00:00Z") end it "found" do diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index b45b44c11..752111040 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -6,7 +6,7 @@ id = "https://ror.org/0521rfb23" organizations = Organization.find_by_id(id) expect(organizations[:data].size).to eq(1) - expect(organizations[:data].first).to eq(:id=>"https://ror.org/0521rfb23", :name=>"Lincoln University", :aliases=>["Ashmun Institute"], :acronyms=>["LU"], :labels=>[{:iso639=>"es", :label=>"Universidad Lincoln"}], :links=>["http://www.lincoln.edu/"], :wikipedia_url=>"http://en.wikipedia.org/wiki/Lincoln_University_(Pennsylvania)", :country=>{:id=>"US", :name=>"United States"}) + expect(organizations[:data].first).to eq(:id=>"https://ror.org/0521rfb23", :name=>"Lincoln University", :aliases=>["Ashmun Institute"], :acronyms=>["LU"], :labels=>[{:code=>"ES", :name=>"Universidad Lincoln"}], :links=>["http://www.lincoln.edu/"], :wikipedia_url=>"http://en.wikipedia.org/wiki/Lincoln_University_(Pennsylvania)", :country=>{:code=>"US", :name=>"United States"}) end it "not found" do @@ -23,7 +23,7 @@ organizations = Organization.query(query) expect(organizations.dig(:meta, "total")).to eq(91625) expect(organizations[:data].size).to eq(20) - expect(organizations[:data].first).to eq(:id=>"https://ror.org/00xqf8t64", :name=>"Padjadjaran University", :aliases=>["Padjadjaran University"], :acronyms=>["UNPAD"], :labels=> [{:iso639=>"id", :label=>"Universitas Padjadjaran"}], :links=>["http://www.unpad.ac.id/en/"], :wikipedia_url=>"http://en.wikipedia.org/wiki/Padjadjaran_University", :country=>{:id=>"ID", :name=>"Indonesia"}) + expect(organizations[:data].first).to eq(:id=>"https://ror.org/00xqf8t64", :name=>"Padjadjaran University", :aliases=>["Padjadjaran University"], :acronyms=>["UNPAD"], :labels=> [{:code=>"ID", :name=>"Universitas Padjadjaran"}], :links=>["http://www.unpad.ac.id/en/"], :wikipedia_url=>"http://en.wikipedia.org/wiki/Padjadjaran_University", :country=>{:code=>"ID", :name=>"Indonesia"}) end it "found" do @@ -31,7 +31,7 @@ organizations = Organization.query(query) expect(organizations.dig(:meta, "total")).to eq(10475) expect(organizations[:data].size).to eq(20) - expect(organizations[:data].first).to eq(:id=>"https://ror.org/04ps1r162", :name=>"Lincoln University", :aliases=>[], :acronyms=>[], :labels=>[{:iso639=>"mi", :label=>"Te Whare Wanaka o Aoraki"}], :links=>["http://www.lincoln.ac.nz/"], :wikipedia_url=>"http://en.wikipedia.org/wiki/Lincoln_University_(New_Zealand)", :country=>{:id=>"NZ", :name=>"New Zealand"}) + expect(organizations[:data].first).to eq(:id=>"https://ror.org/04ps1r162", :name=>"Lincoln University", :aliases=>[], :acronyms=>[], :labels=>[{:code=>"MI", :name=>"Te Whare Wanaka o Aoraki"}], :links=>["http://www.lincoln.ac.nz/"], :wikipedia_url=>"http://en.wikipedia.org/wiki/Lincoln_University_(New_Zealand)", :country=>{:code=>"NZ", :name=>"New Zealand"}) end it "not found" do