diff --git a/orcid/orcid.component.ts b/orcid/orcid.component.ts index afe60759..39f0673b 100644 --- a/orcid/orcid.component.ts +++ b/orcid/orcid.component.ts @@ -27,6 +27,8 @@ export class OrcidComponent { public orcidMessage: string = ""; public source: string = ""; + public code: string = ""; + public gotToken: boolean = false; public routerHelper:RouterHelper = new RouterHelper(); @@ -42,9 +44,16 @@ export class OrcidComponent { this.updateUrl( properties.domain + properties.baseLink + this.route.url); this.subscriptions.push(this.route.queryParams.subscribe(params => { + this.gotToken = false; + this.source = params['source']; - if (params['code']) { - this.getToken(params['code']); + this.code = params['code']; + if (this.code) { + if(this.source == "openaire") { + this.getToken(params['code']); + } else { + this.getPersonalDetails(); + } } else if(params['error']) { this.showLoading = false; this.orcidMessage = params['error_description']; @@ -70,6 +79,7 @@ export class OrcidComponent { this.showLoading = true; this.orcidService.getToken(code).subscribe( gotTokens => { + this.gotToken = true; if(gotTokens == null || gotTokens['value'] == false) { this.showLoading = false; this.message = "
An error occured while trying to connect your ORCID iD with OpenAIRE. Please try again!
" + @@ -89,39 +99,14 @@ export class OrcidComponent { this.message = "
Thank you for connecting your ORCID iD with OpenAIRE!
" + "
You will automatically be redirected to our advanced search page where you can link OpenAIRE research results with your ORCID iD.
"; - //get author name - this.subscriptions.push(this.orcidService.getPersonalDetails().subscribe( - details => { - let author: string = ""; - - if(details && details['name']) { - let name: string = details['name']; - if(name['given-names'] && name['given-names']['value']) { - author = name['given-names']['value']; - } - if(name['family-name'] && name['family-name']['value']) { - author += (author ? " " : "") + name['family-name']['value']; - } - } - - let params = this.routerHelper.createQueryParams(['f0', 'fv0'], ['resultauthor', author]); - this._router.navigate([properties.searchLinkToAdvancedResults], {queryParams: params}); - }, - error => { - console.error("Error getting personal details", error); - this._router.navigate([properties.searchLinkToAdvancedResults], {}); - }, - () => { - setTimeout(() => { - this.message += "
If you are not authomatically redirected, please navigate to our search pages.
"; - }, 3000); - } - )); + this.getPersonalDetails(); } // this.message = "Thank you for connecting your ORCID iD with OpenAIRE! Please close this window and continue!"; } }, error => { + this.gotToken = true; + console.error("Error getting token from code: "+code, error); this.message = "An error occured while trying to connect your ORCID iD with OpenAIRE. Please try again!"; }, @@ -131,6 +116,42 @@ export class OrcidComponent { ) } + private getPersonalDetails() { + //get author name + this.subscriptions.push(this.orcidService.getPersonalDetails().subscribe( + details => { + let author: string = ""; + + if(details && details['name']) { + let name: string = details['name']; + if(name['given-names'] && name['given-names']['value']) { + author = name['given-names']['value']; + } + if(name['family-name'] && name['family-name']['value']) { + author += (author ? " " : "") + name['family-name']['value']; + } + } + + let params = this.routerHelper.createQueryParams(['f0', 'fv0'], ['resultauthor', author]); + this._router.navigate([properties.searchLinkToAdvancedResults], {queryParams: params}); + }, + error => { + console.error("Error getting personal details", error); + if(this.gotToken) { + this._router.navigate([properties.searchLinkToAdvancedResults], {}); + } else { + this.getToken(this.code); + } + }, + () => { + if(this.gotToken) { + setTimeout(() => { + this.message += "
If you are not authomatically redirected, please navigate to our search pages.
"; + }, 3000); + } + } + )); + } private updateTitle(title: string) { this._title.setTitle(title); diff --git a/orcid/orcidWork.ts b/orcid/orcidWork.ts index 31be797b..3c0ac586 100644 --- a/orcid/orcidWork.ts +++ b/orcid/orcidWork.ts @@ -62,6 +62,8 @@ export class WorkV3_0 { } public static resultLandingInfoConvert(resultLandingInfo: ResultLandingInfo, putCode: string) : WorkV3_0 { + let description_limit: number = 5000; + let work: WorkV3_0 = {}; // let work = {}; @@ -104,7 +106,7 @@ export class WorkV3_0 { work['journal-title'] = { "value": resultLandingInfo.journal.journal }; } - if(resultLandingInfo.description) { + if(resultLandingInfo.description && resultLandingInfo.description.length < description_limit) { work['short-description'] = resultLandingInfo.description; }