From a1c223bd78b80c2b531363a8937b08fe09efa520 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Thu, 3 May 2018 09:58:30 +0000 Subject: [PATCH] Claim Search: add parse method(optionally) in all search services for claim search(orcid, datacite, crossref), use common response as an array of ClaimResult | use common component to show those results | transform openaire results to ClaimResult class | enhance Orcid result with DOI with info got from crossref git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51910 d315682c-612b-4755-9ff5-7f18f6832af3 --- claims/claim-utils/claim.ts | 1 + claims/claim-utils/claimEntities.class.ts | 67 +------ .../claimResultSearchForm.component.html | 96 +--------- .../claimResultSearchForm.component.ts | 177 +++++++++--------- .../claimResultSearchForm.module.ts | 5 +- claims/claim-utils/claimResults.component.ts | 66 +++++++ .../service/searchCrossref.service.ts | 49 ++++- .../service/searchDatacite.service.ts | 41 +++- .../service/searchOrcid.service.ts | 57 +++++- .../linking/bulkClaim/bulkClaim.component.ts | 16 +- .../selected/selectedResults.component.ts | 18 +- 11 files changed, 320 insertions(+), 273 deletions(-) create mode 100644 claims/claim-utils/claimResults.component.ts diff --git a/claims/claim-utils/claim.ts b/claims/claim-utils/claim.ts index b5378c5f..183b888b 100644 --- a/claims/claim-utils/claim.ts +++ b/claims/claim-utils/claim.ts @@ -13,3 +13,4 @@ export class Claim { export class Project{ } + diff --git a/claims/claim-utils/claimEntities.class.ts b/claims/claim-utils/claimEntities.class.ts index 7d866cea..03ce92f0 100644 --- a/claims/claim-utils/claimEntities.class.ts +++ b/claims/claim-utils/claimEntities.class.ts @@ -13,69 +13,10 @@ export class ClaimResult{ public publisher: string; public description: string; public resourceType:string; - - public static generateResult(item, itemId,itemSource,itemType, itemUrl, itemTitle, date, accessmode){ - - var result: ClaimResult = new ClaimResult(); - result.id = itemId; - result.type = itemType; - result.source = itemSource; - - result.title = (Array.isArray(itemTitle) && itemTitle.length > 0 )?itemTitle[0]:itemTitle; - result.url = itemUrl; - result.accessRights = 'OPEN'; - result.date = date; - result.result = item; - if(item.publisher){ - result.publisher = item.publisher; - } - - if(itemSource == 'datacite'){ - - result.publisher = item.attributes['container-title']; - if(item.attributes.author){ - result.authors =[] - for(var i=0; i< item.attributes.author.length; i++){ - result.authors.push((item.attributes.author[i].family)?item.attributes.author[i].family+', '+item.attributes.author[i].given:item.attributes.author[i].literal); - } - } - - // result = {id: itemId, type :itemType, source : itemSource, title: itemTitle,url: itemUrl, result: item, accessRights: 'OPEN', embargoEndDate: this.nextDate, date : date}; - }else if (itemSource == 'openaire'){ - //TODO put right access rights - // result = {id:itemId, type :itemType, source : itemSource, title: itemTitle,url: itemUrl, result: item, accessRights: accessMode, embargoEndDate: this.nextDate, date: date}; - // result = {id:itemId, type :itemType, source : itemSource, title: itemTitle,url: itemUrl, result: item, accessRights: accessmode, embargoEndDate: this.nextDate, date : date}; - result.embargoEndDate = accessmode; - - }else if(itemSource == 'crossref'){ - date = (date == null) ? null : date.substring(0,10); - result.date = date; - result.resourceType = item.type; - result.description = item.abstract; - if(item.author){ - result.authors =[] - for(var i=0; i< item.author.length; i++){ - result.authors.push(item.author[i].family +" "+ item.author[i].given ); - } - } - // result = {id: itemId, type :itemType, source : itemSource, title: itemTitle,url: itemUrl, result: item, accessRights: 'OPEN', embargoEndDate: this.nextDate, date: date}; - }else if (itemSource == 'orcid'){ - date = (date == null) ? null : date + "-01.-01" - result.date = date; - if(item['work-type']){ - result.resourceType = item.type; - - } - if(item.contributors){ - result.authors =[] - for(var i=0; i< item.contributors.length; i++){ - result.authors.push(item.contributors[i]); - } - } - - } - return result; - } + DOI: string; + editors=[]; + journal: string; + } export class ClaimProject{ public funderId: string; diff --git a/claims/claim-utils/claimResultSearchForm.component.html b/claims/claim-utils/claimResultSearchForm.component.html index a5d4da7d..8920fe71 100644 --- a/claims/claim-utils/claimResultSearchForm.component.html +++ b/claims/claim-utils/claimResultSearchForm.component.html @@ -39,18 +39,8 @@
- + +
@@ -66,19 +56,7 @@
- +
@@ -103,34 +81,20 @@ - -
-
- +
No results found
- +
@@ -143,21 +107,7 @@
- - +
@@ -173,23 +123,7 @@
- +
@@ -205,22 +139,8 @@
- +
diff --git a/claims/claim-utils/claimResultSearchForm.component.ts b/claims/claim-utils/claimResultSearchForm.component.ts index cd7a29c5..aa31051c 100644 --- a/claims/claim-utils/claimResultSearchForm.component.ts +++ b/claims/claim-utils/claimResultSearchForm.component.ts @@ -158,12 +158,12 @@ private getCrossrefResults (term: string, size : number, page : number) { this.crossrefPage=page; this.crossrefResultsNum = data['total-results']; if(data.items == 0){ - this._searchCrossrefService.searchCrossrefResults(term, size, page, this.properties.searchCrossrefAPIURL).subscribe( + this._searchCrossrefService.searchCrossrefResults(term, size, page, this.properties.searchCrossrefAPIURL, true).subscribe( data => { if(data != null) { - this.crossrefResults = data.items; + this.crossrefResults = data; this.crossrefPage=page; - this.crossrefResultsNum = data['total-results']; + this.crossrefResultsNum = data.length; this.crossrefStatus = this.errorCodes.DONE; }else{ @@ -182,11 +182,11 @@ private getCrossrefResults (term: string, size : number, page : number) { } }, err => { - this._searchCrossrefService.searchCrossrefResults(term, size, page, this.properties.searchCrossrefAPIURL).subscribe( + this._searchCrossrefService.searchCrossrefResults(term, size, page, this.properties.searchCrossrefAPIURL, true).subscribe( data => { - this.crossrefResults = data.items; + this.crossrefResults = data; this.crossrefPage=page; - this.crossrefResultsNum = data['total-results']; + this.crossrefResultsNum = data.length; this.crossrefStatus = this.errorCodes.DONE; }, @@ -202,12 +202,12 @@ private getCrossrefResults (term: string, size : number, page : number) { }else{ - this._searchCrossrefService.searchCrossrefResults(term, size, page, this.properties.searchCrossrefAPIURL).subscribe( + this._searchCrossrefService.searchCrossrefResults(term, size, page, this.properties.searchCrossrefAPIURL, true).subscribe( data => { if(data != null) { - this.crossrefResults = data.items; + this.crossrefResults = data; this.crossrefPage=page; - this.crossrefResultsNum = data['total-results']; + this.crossrefResultsNum = data.length; this.crossrefStatus = this.errorCodes.DONE; }else{ @@ -231,7 +231,7 @@ private getCrossrefResults (term: string, size : number, page : number) { if(data != null) { this.openairePubsPage=page; this.openairePubsNum = data[0]; - this.openairePubs = data[1]; + this.openairePubs = this.openaire2ClaimResults(data[1],"publication"); this.openairePubsStatus = this.errorCodes.DONE; if(this.openairePubsNum == 0){ this.openairePubsStatus = this.errorCodes.NONE; @@ -252,7 +252,7 @@ private getCrossrefResults (term: string, size : number, page : number) { if(data != null) { this.openairePubsPage=page; this.openairePubsNum = data[0]; - this.openairePubs = data[1]; + this.openairePubs = this.openaire2ClaimResults(data[1],"publication"); this.openairePubsStatus = this.errorCodes.DONE; if(this.openairePubsNum == 0){ this.openairePubsStatus = this.errorCodes.NONE; @@ -364,7 +364,7 @@ private getCrossrefResults (term: string, size : number, page : number) { this.authorFamilyName = this.authors[index].authorFamilyName; this.authorId = this.authors[index].id; this.orcidStatus = this.errorCodes.LOADING; - this._searchOrcidService.searchOrcidPublications(this.authors[index].id, this.properties).subscribe( + this._searchOrcidService.searchOrcidPublications(this.authors[index].id, this.properties, true).subscribe( data => { if(data != null) { this.orcidResults=data; @@ -382,6 +382,13 @@ private getCrossrefResults (term: string, size : number, page : number) { if(this.orcidResultsNum == 0){ this.orcidStatus = this.errorCodes.NONE; } + for(var i=0;i { + if(data != null || data.length > 0 ) { + var crossrefResult = data[0]; + if(result['title'] == null ||result['title'] == ""){ + result['title'] = crossrefResult['title']; + } + if(crossrefResult['authors'].length > 0){ + result['authors'] = []; + for(var i =0; i { + + } + + ); + } +} /* Is it USED??? private remove(item){ @@ -453,34 +495,6 @@ openaireSoftwarePageChange($event) { } - private isSelected(id:string){ - - var found:boolean = false; - this.warningMessage = ""; - for (var _i = 0; _i < this.selectedResults.length; _i++) { - let item = this.selectedResults[_i]; - if(item.id == id){ - found=true; - this.warningMessage = "Publication already in selected list"; - } - } - return found; - - - } - // isSelected(id:string){ - // - // var found:boolean = false; - // this.warningMessage = ""; - // for (var _i = 0; _i < this.selectedResults.length; _i++) { - // let item = this.selectedResults[_i]; - // if(item.id == id){ - // found=true; - // break; - // } - // } - // return found; - // } private searchDatacite (term: string, size : number, page : number) { this.getDataciteResults(term,size,page); this.warningMessage = ""; @@ -495,7 +509,7 @@ openaireSoftwarePageChange($event) { if(data != null) { this.openaireDataPage=page; this.openaireDataNum = data[0]; - this.openaireData = data[1]; + this.openaireData = this.openaire2ClaimResults(data[1],"dataset"); this.openaireDataStatus = this.errorCodes.DONE; if(this.openaireDataNum == 0){ this.openaireDataStatus = this.errorCodes.NONE; @@ -513,7 +527,7 @@ openaireSoftwarePageChange($event) { if(data != null) { this.openaireDataPage=page; this.openaireDataNum = data[0]; - this.openaireData = data[1]; + this.openaireData = this.openaire2ClaimResults(data[1],"dataset"); this.openaireDataStatus = this.errorCodes.DONE; if(this.openaireDataNum == 0){ this.openaireDataStatus = this.errorCodes.NONE; @@ -538,7 +552,7 @@ openaireSoftwarePageChange($event) { if(data != null) { this.openaireSoftwarePage=page; this.openaireSoftwareNum = data[0]; - this.openaireSoftware = data[1]; + this.openaireSoftware = this.openaire2ClaimResults(data[1],"software"); this.openaireSoftwareStatus = this.errorCodes.DONE; if(this.openaireSoftwareNum == 0){ this.openaireSoftwareStatus = this.errorCodes.NONE; @@ -556,7 +570,8 @@ openaireSoftwarePageChange($event) { if(data != null) { this.openaireSoftwarePage=page; this.openaireSoftwareNum = data[0]; - this.openaireSoftware = data[1]; + this.openaireSoftware = this.openaire2ClaimResults(data[1],"software"); + this.openaireSoftwareStatus = this.errorCodes.DONE; if(this.openaireSoftwareNum == 0){ this.openaireSoftwareStatus = this.errorCodes.NONE; @@ -573,13 +588,44 @@ openaireSoftwarePageChange($event) { this.infoMessage = ""; } + + private openaire2ClaimResults(data,type):ClaimResult[]{ + var claimResults = []; + for(var i=0; i< data.length; i++){ + var item = data[i]; + var result: ClaimResult = new ClaimResult(); + result.publisher = null; + result.journal = null; + result.DOI = null; + result.id = item.id; + result.title = item.title.name; + result.url = item.title.url; + result.source = "openaire"; + result.date = item.year; + result.accessRights = item.title.accessMode; + console.log(item); + result.type = type; + + result.publisher = item.publisher; + result.result = item; + if(item.authors){ + for(var j=0; j { - this.dataciteResults = data.data; + this.dataciteResults = data; this.datacitePage=page; - this.dataciteResultsNum = data.meta.total; + this.dataciteResultsNum = data.length; this.dataciteStatus = this.errorCodes.DONE; @@ -592,43 +638,6 @@ openaireSoftwarePageChange($event) { ); } - add(item, itemId,itemSource,itemType, itemUrl, itemTitle, date, accessmode){ - - console.log(' adding ' + itemType + " From " + itemSource+" "+ itemTitle); - var result: ClaimResult = ClaimResult.generateResult(item, itemId,itemSource,itemType, itemUrl, itemTitle, date, accessmode); - - - if (itemSource == 'orcid'){ - if(result.authors.length ==0 ){ - result.authors.push(this.authorGivenName + ', '+ this.authorFamilyName); - } - } - var found:boolean = this.isSelected( result.id); - - this.warningMessage = ""; - if (!found) { - this.selectedResults.push(result); - - UIkit.notification({ - message : 'A new research result is selected.', - status : 'primary', - timeout : 1000, - pos : 'top-center' - }); - - - }else{ - this.warningMessage = "Research Data already in selected list"; - UIkit.notification({ - message : 'The research result is already on your list.', - status : 'warning', - timeout : 1000, - pos : 'top-center' - }); - } - - } - public searchSourceChanged(source){ this.searchSource = source; this.activeTab = (source == "openaire" || source == "all")?"openairePub":source; diff --git a/claims/claim-utils/claimResultSearchForm.module.ts b/claims/claim-utils/claimResultSearchForm.module.ts index c547654d..0a7af73f 100644 --- a/claims/claim-utils/claimResultSearchForm.module.ts +++ b/claims/claim-utils/claimResultSearchForm.module.ts @@ -3,6 +3,7 @@ import { NgModule } from '@angular/core'; import { SharedModule } from '../../shared/shared.module'; import { CommonModule } from '@angular/common'; import {ClaimResultSearchFormComponent} from './claimResultSearchForm.component'; +import {ClaimResultsComponent} from './claimResults.component'; import {SearchDataciteServiceModule} from './service/searchDataciteService.module'; @@ -22,9 +23,9 @@ import {HelperModule} from '../../utils/helper/helper.module'; SearchOrcidService ], declarations: [ - ClaimResultSearchFormComponent + ClaimResultSearchFormComponent, ClaimResultsComponent ], - exports: [ClaimResultSearchFormComponent ] + exports: [ClaimResultSearchFormComponent, ClaimResultsComponent ] }) export class ClaimResultSearchFormModule { } diff --git a/claims/claim-utils/claimResults.component.ts b/claims/claim-utils/claimResults.component.ts new file mode 100644 index 00000000..b121fdf7 --- /dev/null +++ b/claims/claim-utils/claimResults.component.ts @@ -0,0 +1,66 @@ +import {Component, Input, Output, EventEmitter} from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; + +import {ClaimResult} from '../claim-utils/claimEntities.class'; + +declare var UIkit:any; + +@Component({ + selector: 'claim-results', + template:` + +
    +
  • +
    + {{result.title?result.title:'[No title available]'}} + {{result.title?result.title:'[No title available]'}} + + +
    + + + + +
  • `, + +}) +export class ClaimResultsComponent { + @Input() results; + @Input() selectedResults; + private isSelected(id:string){ + + var found:boolean = false; + for (var _i = 0; _i < this.selectedResults.length; _i++) { + let item = this.selectedResults[_i]; + if(item.id == id){ + found=true; + } + } + return found; + + + } + add(item){ + var found:boolean = this.isSelected( item.id); + if (!found) { + this.selectedResults.push(item); + + UIkit.notification({ + message : 'A new research result is selected.', + status : 'primary', + timeout : 1000, + pos : 'top-center' + }); + + }else{ + UIkit.notification({ + message : 'The research result is already on your list.', + status : 'warning', + timeout : 1000, + pos : 'top-center' + }); + } + + } +} diff --git a/claims/claim-utils/service/searchCrossref.service.ts b/claims/claim-utils/service/searchCrossref.service.ts index 38000e3a..d14b9c8d 100644 --- a/claims/claim-utils/service/searchCrossref.service.ts +++ b/claims/claim-utils/service/searchCrossref.service.ts @@ -4,22 +4,23 @@ import {Observable} from 'rxjs/Observable'; import 'rxjs/add/observable/of'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/share'; +import { ClaimResult} from '../claimEntities.class'; @Injectable() export class SearchCrossrefService { constructor( private http: Http ) {} - searchCrossrefResults (term: string, size : number, page : number, apiUrl:string):any { + searchCrossrefResults (term: string, size : number, page : number, apiUrl:string, parse:boolean = false):any { let url = apiUrl+'?query='+term+'&rows='+size+'&offset='+(size*(page-1)); let key = url; return this.http.get(url) .map(request => request.json().message) - .do(items => console.log("Crossref Results: total results = "+items['total-results']+" keyword = "+term)); + .map(request => (parse?this.parse(request.items):request)) //.catch(this.handleError); } - searchCrossrefByDOIs(DOIs: string[], apiUrl:string):any { + searchCrossrefByDOIs(DOIs: string[], apiUrl:string, parse:boolean = false):any { var doisParams = ""; for(var i =0 ;i < DOIs.length; i++){ @@ -31,11 +32,11 @@ export class SearchCrossrefService { return this.http.get(url) .map(request => request.json().message) - .do(items => console.log("Crossref Results: total results = "+items['total-results']+" for doi = "+doisParams)); + .map(request => (parse?this.parse(request.items):request)) //.catch(this.handleError); } - searchCrossrefByMultipleDOIs(dois: string[], apiUrl:string):any { + searchCrossrefByMultipleDOIs(dois: string[], apiUrl:string, parse:boolean = false):any { let url = apiUrl+'?filter=doi:'; for(var i=0; i request.json().message) - .do(items => console.log("Crossref Results: total results = "+items['total-results'])); + .map(request => (parse?this.parse(request.items):request)) //.catch(this.handleError); } @@ -57,5 +58,41 @@ export class SearchCrossrefService { console.log(error); return Observable.throw(error || 'Server error'); } + parse(response):ClaimResult[]{ + var results:ClaimResult[] = []; + for(var i=0; i request.json()) + .map(request => (parse?this.parse(request.data):request)) .do(items => console.info(items)) - .do(items => console.log("Datacite Results: total results = "+items.meta.total+" keyword = "+term)); - //.catch(this.handleError); + //.catch(this.handleError); } - getDataciteResultByDOI (doi: string, properties:EnvProperties):any { + getDataciteResultByDOI (doi: string, properties:EnvProperties, parse:boolean = false):any { console.info("Fetch datacite resultt by DOI: "+doi); let url = properties.searchDataciteAPIURL+'/'+doi; let key = url; return this.http.get( (properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(request => request.json()) + .map(request => (parse?this.parse(request.data):request)) .do(items => console.info(items)); + // .do(items => console.log("Datacite Results: total results = "+items.meta.total+" doi = "+doi)) //.catch(this.handleError); @@ -48,4 +51,34 @@ export class SearchDataciteService { let body = res.json(); return body.data || { }; } + parse(response):ClaimResult[]{ + var results:ClaimResult[] = []; + for(var i=0; i res.json()['group']); + .map(res => res.json()['group']) + .do(res => console.log(res)) + .map(request => (parse?this.parse(request):request)); //.map(res => res['orcid-work']); } @@ -125,4 +128,54 @@ export class SearchOrcidService { } return ret; } + parse(response):ClaimResult[]{ + var results:ClaimResult[] = []; + for(var i=0; i 0){ + item = item['work-summary'][0]; + }else{ + item['work-summary']; + } + if(item['external-ids'] && item['external-ids']['external-id']){ + for(var j =0; j< item['external-ids']['external-id'].length; j++){ + var id = item['external-ids']['external-id'][j]; + if(id['external-id-type'] == "doi"){ + result.DOI = id['external-id-value']; + result.url = "http://dx.doi.org/" + result.DOI; + break; + } + } + } + result.id = item['put-code']; + if(item.title && item.title.title){ + result.title = item['title']['title'].value; + } + result.journal = item['journal-title']; + result.source = 'orcid'; + result.type = 'publication'; + if(item['publication-date'] && item['publication-date']['year']){ + result.date = item['publication-date']['year'].value + } + + result.accessRights = "OPEN"; + if(item.publisher){ + result.publisher = item.publisher; + } + result.result = item; + + results.push(result); + } + + return results; + + } + + + } diff --git a/claims/linking/bulkClaim/bulkClaim.component.ts b/claims/linking/bulkClaim/bulkClaim.component.ts index e1791d97..034c3b75 100644 --- a/claims/linking/bulkClaim/bulkClaim.component.ts +++ b/claims/linking/bulkClaim/bulkClaim.component.ts @@ -175,13 +175,12 @@ export class BulkClaimComponent { } fetchResult(id:string,accessMode:string,date:string){ - this._searchCrossrefService.searchCrossrefByDOIs([id], this.properties.searchCrossrefAPIURL).subscribe( + this._searchCrossrefService.searchCrossrefByDOIs([id], this.properties.searchCrossrefAPIURL, true).subscribe( data => { - var crossrefResult = data.items[0]; - if(data.items.length > 0){ + var result = data[0]; + if(data.length > 0){ this.foundIds.push(id); - var result: ClaimResult = ClaimResult.generateResult(crossrefResult, id,"crossref","publication", crossrefResult.URL, crossrefResult.title, crossrefResult.created['date-time'], accessMode); result.embargoEndDate = date; this.results.push(result); this.endOfFetching(); @@ -198,14 +197,13 @@ export class BulkClaimComponent { ); } searchInDatacite(id:string,accessMode:string,date:string){ - this._searchDataciteService.getDataciteResultByDOI(id,this.properties).subscribe( - item => { - var dataciteResult = item.data; + this._searchDataciteService.getDataciteResultByDOI(id,this.properties,true).subscribe( + items => { - if(dataciteResult != null && dataciteResult.attributes!= null ){ + if(items.length > 0){ + var result = items[0]; this.foundIds.push(id); - var result: ClaimResult = ClaimResult.generateResult(dataciteResult, id,"datacite","dataset", 'http://dx.doi.org/'+dataciteResult.attributes.doi, dataciteResult.attributes.title, dataciteResult.attributes.published, accessMode); result.embargoEndDate = date; this.results.push(result); }else{ diff --git a/claims/linking/selected/selectedResults.component.ts b/claims/linking/selected/selectedResults.component.ts index a115e11c..98f30f83 100644 --- a/claims/linking/selected/selectedResults.component.ts +++ b/claims/linking/selected/selectedResults.component.ts @@ -36,26 +36,14 @@ import {Dates} from '../../../utils/string-utils.class'; Publisher: {{pub.publisher}} - Journal: {{pub.result['journal-title'].value}} - ({{pub.date.substring(0,4)}}) + Journal: {{pub.journal}} + ({{pub.date}})
    Authors: {{author}}{{(i < (pub.authors.slice(0,10).length-1))?"; ":""}}{{(i == pub.authors.slice(0,10).length-1 && pub.authors.length > 10)?"...":""}}
    - - -
    Editors: {{author.family}} {{author.given}}{{(i < (pub.result.editor.slice(0,10).length-1))?"; ":""}}{{(i == pub.result.editor.slice(0,10).length-1 && pub.result.editor.length > 10)?"...":""}}
    +
    Editors: {{author}} {{(i < (pub.editors.slice(0,10).length-1))?"; ":""}}{{(i == pub.editors.slice(0,10).length-1 && pub.editors.length > 10)?"...":""}}
    - -
    Authors: {{author}}{{(i < (pub.result.authors.slice(0,10).length-1))?"; ":""}}{{(i == pub.result.authors.slice(0,10).length-1 && pub.result.authors.length > 10)?"...":""}}
    - - - - -
    {{pub.source}} {{pub.accessRights}} {{pub.type}}