From 7fa56eb8e0a1461a32016bc950a3234ada79c822 Mon Sep 17 00:00:00 2001 From: Ramon Granell Date: Tue, 26 Nov 2024 11:30:29 +0000 Subject: [PATCH] modifying code to run with ROR V2 --- .../Editor/Organisations/LinkOverlay.vue | 45 ++++++++++----- src/lib/Client/ExternalClients.js | 3 +- .../Editor/Organisations/LinkOverlay.spec.js | 55 ++++++++++++------- 3 files changed, 68 insertions(+), 35 deletions(-) diff --git a/src/components/Editor/Organisations/LinkOverlay.vue b/src/components/Editor/Organisations/LinkOverlay.vue index 0f98de0b7d..7253dccb73 100644 --- a/src/components/Editor/Organisations/LinkOverlay.vue +++ b/src/components/Editor/Organisations/LinkOverlay.vue @@ -687,6 +687,15 @@ this.enterName = false this.importROR = true this.validName = true + data.items.forEach( it => { + it.names.every(e => { + if (e.types.includes('ror_display')){ + it.name = e.value + return false + } else { + return true + }}) + }) this.organisationsList = data.items this.organisationsNameList = data.items.map(item => item.name) } else { @@ -702,21 +711,24 @@ /************ Organisation Name ************/ this.menus.newOrganisation.data.name = this.menus.newOrganisation.selectOrganisation.name /************** Homepage Link **************/ - this.menus.newOrganisation.data.homepage = this.menus.newOrganisation.selectOrganisation.links[0] + this.menus.newOrganisation.data.homepage = this.menus.newOrganisation.selectOrganisation.links.filter(link => link.type === 'website')[0].value + //his.menus.newOrganisation.data.homepage = this.menus.newOrganisation.selectOrganisation.links[0] /*************** ROR Link ***************/ this.menus.newOrganisation.data.ror_link = this.menus.newOrganisation.selectOrganisation.id /*************** Alternative Names ***************/ - this.menus.newOrganisation.data.alternative_names = - this.menus.newOrganisation.selectOrganisation.aliases.concat( - this.menus.newOrganisation.selectOrganisation.acronyms - ) + this.menus.newOrganisation.data.alternative_names = [] + this.menus.newOrganisation.selectOrganisation.names.forEach( it =>{ + if (!it.types.includes('ror_display')){ + this.menus.newOrganisation.data.alternative_names.push(it.value) + } + }) /*************** Type Select ***************/ this.selectTypes() /************* Country Select *************/ - this.menus.newOrganisation.data.country_ids = this.countries.filter(country => country.name === this.menus.newOrganisation.selectOrganisation.country["country_name"]) + this.menus.newOrganisation.data.country_ids = this.countries.filter(country => country.name === this.menus.newOrganisation.selectOrganisation.locations[0].geonames_details["country_name"]) /************* Parent ror relationship *************/ - this.menus.newOrganisation.data.parent_ror_links = this.menus.newOrganisation.selectOrganisation.relationships.filter(obj => obj.type === "Parent") - this.menus.newOrganisation.data.child_ror_links = this.menus.newOrganisation.selectOrganisation.relationships.filter(obj => obj.type === "Child") + this.menus.newOrganisation.data.parent_ror_links = this.menus.newOrganisation.selectOrganisation.relationships.filter(obj => obj.type === "parent") + this.menus.newOrganisation.data.child_ror_links = this.menus.newOrganisation.selectOrganisation.relationships.filter(obj => obj.type === "child") } }, @@ -727,19 +739,22 @@ this.menus.newOrganisation.data.organisation_type_ids = matchedType } else{ switch (selectedType) { - case 'Government': + case 'government': this.menus.newOrganisation.data.organisation_type_ids = [this.organisationsTypes[0]] break - case 'Nonprofit': + case 'nonprofit': this.menus.newOrganisation.data.organisation_type_ids = [this.organisationsTypes[1]] break - case 'Education': + case 'education': this.menus.newOrganisation.data.organisation_type_ids = [this.organisationsTypes[2]] break - case 'Healthcare': - case 'Archive': - case 'Facility': - case 'Other': + case 'company': + this.menus.newOrganisation.data.organisation_type_ids = [this.organisationsTypes[5]] + break + case 'healthcare': + case 'archive': + case 'facility': + case 'other': default: this.menus.newOrganisation.data.organisation_type_ids = [this.organisationsTypes[8]] } diff --git a/src/lib/Client/ExternalClients.js b/src/lib/Client/ExternalClients.js index 67bf437d8c..38bccf0589 100644 --- a/src/lib/Client/ExternalClients.js +++ b/src/lib/Client/ExternalClients.js @@ -18,7 +18,8 @@ class ExternalRESTClients { this.pmidBaseURL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&retmode=json&id="; this.tessBaseURL = "https://tess.elixir-europe.org/materials.json?q="; this.orcidBaseURL = "https://pub.orcid.org/v2.0/"; - this.rorOrganisationsBaseURL = "https://api.ror.org/organizations?query="; + //this.rorOrganisationsBaseURL = "https://api.ror.org/organizations?query="; + this.rorOrganisationsBaseURL = "https://api.ror.org/v2/organizations?query="; } async getDOI(doi){ diff --git a/tests/unit/components/Editor/Organisations/LinkOverlay.spec.js b/tests/unit/components/Editor/Organisations/LinkOverlay.spec.js index 112d1249a5..a19691ad2f 100644 --- a/tests/unit/components/Editor/Organisations/LinkOverlay.spec.js +++ b/tests/unit/components/Editor/Organisations/LinkOverlay.spec.js @@ -39,18 +39,26 @@ const formValidation = { }; const organisation = { - "items":[{ - "country":{ - "country_code": "GB", - "country_name": "Great Britain" - }, - "links":["http://www.obsmedical.com/"], - "name":"OBS Medical (United Kingdom)", - "types":["Company"], - "ror_link": "https:rororere.rere", - "parent_ror_links": ["https:rororere.rere1", "https:rororere.rere2"], - "child_ror_links": ["https:rororere.rere3", "https:rororere.rere4"] - }], + "items": [{ + "locations":[{ + "geonames_details": { + "country_code": "GB", + "country_name": "Great Britain" + } + }], + "links":[{ + "type": "website", + "value": "http://www.obsmedical.com/" + }], + "names":[{ + "types": ["ror_display"], + "value": "OBS Medical (United Kingdom)" + }], + "ror_link": "https:rororere.rere", + "types":["company"], + "parent_ror_links": ["https:rororere.rere1", "https:rororere.rere2"], + "child_ror_links": ["https:rororere.rere3", "https:rororere.rere4"] + }], }; describe("Edit -> LinkOverlay.vue", function() { @@ -237,14 +245,23 @@ describe("Edit -> LinkOverlay.vue", function() { fetchStub = sinon.stub(ExternalClient.prototype, "executeQuery"); fetchStub.returns({data:organisation}); const expectedOrganisation = [{ - "country":{ - "country_code": "GB", - "country_name": "Great Britain" - }, - "links":["http://www.obsmedical.com/"], - "name":"OBS Medical (United Kingdom)", + "locations":[{ + "geonames_details": { + "country_code": "GB", + "country_name": "Great Britain" + } + }], + "links":[{ + "type": "website", + "value": "http://www.obsmedical.com/" + }], + "names":[{ + "types": ["ror_display"], + "value": "OBS Medical (United Kingdom)" + }], + "name": "OBS Medical (United Kingdom)", "ror_link": "https:rororere.rere", - "types":["Company"], + "types":["company"], "parent_ror_links": ["https:rororere.rere1", "https:rororere.rere2"], "child_ror_links": ["https:rororere.rere3", "https:rororere.rere4"] }]