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);