From d635949909468cf3f1d8c33c91c2c54e6e62b45f Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Thu, 11 Nov 2021 12:13:25 +0200 Subject: [PATCH] [Library]: searchDatacite.service.ts & searchCrossref.service.ts: [Bug fix] Extra checks added in author parsing | In Crossref parse author.name if author.family and/or author.given is missing. --- .../service/searchCrossref.service.ts | 29 +++++++++++++++++-- .../service/searchDatacite.service.ts | 4 ++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/claims/claim-utils/service/searchCrossref.service.ts b/claims/claim-utils/service/searchCrossref.service.ts index 526a5f96..16372b61 100644 --- a/claims/claim-utils/service/searchCrossref.service.ts +++ b/claims/claim-utils/service/searchCrossref.service.ts @@ -78,12 +78,18 @@ export class SearchCrossrefService { if (item.author) { entity.result.authors = []; for (let j = 0; j < item.author.length; j++) { - entity.result.authors.push(item.author[j].family + ", " + item.author[j].given); + let author = this.parseName(item.author[j]); + if(author) { + entity.result.authors.push(author); + } } } if (item.editor) { for (let j = 0; j < item.editor.length; j++) { - entity.result.editors.push(item.editor[j].family + ", " + item.editor[j].given); + let editor = this.parseName(item.editor[j]); + if(editor) { + entity.result.authors.push(editor); + } } } results.push(entity); @@ -93,4 +99,23 @@ export class SearchCrossrefService { } + private parseName(authorObj) : string { + let author: string = ""; + if(authorObj.hasOwnProperty("family")) { + author += authorObj.family; + } + if(authorObj.hasOwnProperty("family") && authorObj.hasOwnProperty("given")) { + author += ", "; + } + if(authorObj.hasOwnProperty("given")) { + author += authorObj.given; + } + + if(!author && authorObj.hasOwnProperty("name")) { + author += authorObj.name; + } + + return author; + } + } diff --git a/claims/claim-utils/service/searchDatacite.service.ts b/claims/claim-utils/service/searchDatacite.service.ts index 887b6a7e..fa8dfbae 100644 --- a/claims/claim-utils/service/searchDatacite.service.ts +++ b/claims/claim-utils/service/searchDatacite.service.ts @@ -68,7 +68,9 @@ export class SearchDataciteService { entity.result.authors = []; for (let j = 0; j < item.attributes.author.length; j++) { const author = item.attributes.author[j]; - entity.result.authors.push((author.family) ? author.family + ', ' + author.given : author.literal); + if(author.family || author.literal) { + entity.result.authors.push((author.family) ? author.family + (author.given ? ', ' + author.given : '') : author.literal); + } } } results.push(entity);