From 2f6f5f99d0b70babdf29d6e4a9e81711e6dbbed9 Mon Sep 17 00:00:00 2001 From: Jori Niemi <3295718+tahme@users.noreply.github.com> Date: Fri, 30 Apr 2021 12:35:21 +0300 Subject: [PATCH] =?UTF-8?q?CSCFAIRMETA-906:=20[FIX]=C2=A0Citation=20fixes?= =?UTF-8?q?=20(#809)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * List also top organization if publisher is a suborganization * Trim whitespace before determining parts of name --- .../frontend/__tests__/utils/cite.test.js | 40 +++++++++++++++++++ .../components/dataset/citation/cite/utils.js | 15 +++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/etsin_finder/frontend/__tests__/utils/cite.test.js b/etsin_finder/frontend/__tests__/utils/cite.test.js index 0f446ba4a..b30647b5f 100644 --- a/etsin_finder/frontend/__tests__/utils/cite.test.js +++ b/etsin_finder/frontend/__tests__/utils/cite.test.js @@ -42,6 +42,24 @@ const organizationDataset = { identifier: 'metax_identifier_for_this_dataset', } +const publisherSuborganizationDataset = { + research_dataset: { + creator: [{ name: { en: 'Creator', fi: 'Creator' } }], + publisher: { + name: { en: 'Suborganization', fi: 'Joku aliorganisaatio' }, + '@type': 'Organization', + is_part_of: { + name: { en: 'Top organization', fi: 'Pääorganisaatio' }, + '@type': 'Organization', + }, + }, + issued: '2021-02-23', + title: { fi: 'Julkaisun nimi', en: 'Publication title' }, + preferred_identifier: 'urn:nbn:fi:att:feedc0de', + }, + identifier: 'metax_identifier_for_this_dataset', +} + const doiDataset = { research_dataset: { ...organizationDataset.research_dataset, @@ -165,6 +183,12 @@ describe('Citation styles', () => { '(2021). Publication title. Publisher. http://urn.fi/urn:nbn:fi:att:feedc0de' ) }) + + it('should render citation for dataset published by a suborganization', () => { + c(publisherSuborganizationDataset).should.eq( + 'Creator. (2021). Publication title. Top organization, Suborganization. http://urn.fi/urn:nbn:fi:att:feedc0de' + ) + }) }) describe('Chicago', () => { @@ -222,6 +246,12 @@ describe('Citation styles', () => { 'Eka, Tyyppi, Tyyppi Toka, Tyyppi Kolmas, Tyyppi Neljäs, Tyyppi Viides, Tyyppi Kuudes, Tyyppi Seitsemäs, et al. 2021. ”Publication title”. Publisher. http://urn.fi/urn:nbn:fi:att:feedc0de' ) }) + + it('should render citation for dataset published by a suborganization', () => { + c(publisherSuborganizationDataset).should.eq( + 'Creator. 2021. ”Publication title”. Top organization, Suborganization. http://urn.fi/urn:nbn:fi:att:feedc0de' + ) + }) }) describe('MLA', () => { @@ -279,6 +309,12 @@ describe('Citation styles', () => { 'Eka, Tyyppi, et al. ”Publication title”. Publisher, 2021. http://urn.fi/urn:nbn:fi:att:feedc0de' ) }) + + it('should render citation for dataset published by a suborganization', () => { + c(publisherSuborganizationDataset).should.eq( + 'Creator. ”Publication title”. Top organization, Suborganization, 2021. http://urn.fi/urn:nbn:fi:att:feedc0de' + ) + }) }) }) @@ -292,6 +328,10 @@ describe('Utils', () => { getNameInitials('Mauri Antero Numminen').should.eq('Numminen, M. A.') }) + it('should ignore whitespace around name', () => { + getNameInitials(' Mauri Antero Numminen ').should.eq('Numminen, M. A.') + }) + it('should leave multi-part last name unchanged', () => { getNameInitials('Johannes Diderik van der Waals').should.eq('van der Waals, J. D.') }) diff --git a/etsin_finder/frontend/js/components/dataset/citation/cite/utils.js b/etsin_finder/frontend/js/components/dataset/citation/cite/utils.js index 000bf0cd0..5ae7e4e14 100644 --- a/etsin_finder/frontend/js/components/dataset/citation/cite/utils.js +++ b/etsin_finder/frontend/js/components/dataset/citation/cite/utils.js @@ -22,7 +22,7 @@ const romanNumeralMatch = /^(((IX|IV|V)I{0,3})|I{1,3})$/ const toInitial = name => `${name[0]}.` export const getNameParts = name => { - const parts = name.split(' ') + const parts = name.trim().split(' ') if (parts.length === 1) { return { first: [], last: [parts[0]], suffixes: [] } } @@ -182,5 +182,14 @@ export const getIdentifier = dataset => { return identifier } -export const getPublisher = (dataset, getTranslation) => - getTranslation(dataset.research_dataset.publisher?.name) +export const getPublisher = (dataset, getTranslation) => { + const pub = dataset.research_dataset.publisher + if (pub) { + const top = topOrg(pub) + if (top !== pub) { + return `${getTranslation(top.name)}, ${getTranslation(pub.name)}` + } + return getTranslation(pub.name) + } + return undefined +}