From 501226149127fad1f67499378b71e6bb89efbca5 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Fri, 16 Jun 2017 15:03:30 +0000 Subject: [PATCH] Functions for count results of an entity better structured in search services git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@47541 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../organization/organization.component.ts | 2 +- .../simple/searchDataproviders.component.ts | 33 +++++++----- .../services/searchDataproviders.service.ts | 23 +++++++- .../app/services/searchDatasets.service.ts | 52 +++++++++---------- .../services/searchOrganizations.service.ts | 51 +++++++++--------- .../app/services/searchProjects.service.ts | 51 +++++++++--------- .../services/searchPublications.service.ts | 47 ++++++++--------- .../fetchDataproviders.class.ts | 17 ++---- .../fetchDatasets.class.ts | 12 +---- .../fetchProjects.class.ts | 10 +--- 10 files changed, 147 insertions(+), 151 deletions(-) diff --git a/portal-2/src/app/landingPages/organization/organization.component.ts b/portal-2/src/app/landingPages/organization/organization.component.ts index 37b86440..7841ac8c 100644 --- a/portal-2/src/app/landingPages/organization/organization.component.ts +++ b/portal-2/src/app/landingPages/organization/organization.component.ts @@ -260,7 +260,7 @@ export class OrganizationComponent { { projects = data[1]; for(let index=0; index < projects.length; index++) { - this._searchPublicationsService.numOfEntityPublications(projects[index].id, "projects/").subscribe( + this._searchPublicationsService.numOfEntityPublications(projects[index].id, "project").subscribe( data => { // let index: number = this.organizationInfo.projects.get(funder).indexOf(project); diff --git a/portal-2/src/app/searchPages/simple/searchDataproviders.component.ts b/portal-2/src/app/searchPages/simple/searchDataproviders.component.ts index 58022650..6317d758 100644 --- a/portal-2/src/app/searchPages/simple/searchDataproviders.component.ts +++ b/portal-2/src/app/searchPages/simple/searchDataproviders.component.ts @@ -82,18 +82,20 @@ export class SearchDataprovidersComponent { } public getNumForEntity(entity: string, id:string) { - console.info("getNumForEntity : Dataproviders Component"); - var parameters=""; + var errorCodes:ErrorCodes = new ErrorCodes(); + this.searchUtils.status = errorCodes.LOADING; - if(entity == "organization") { - parameters = "organizations/"+id+"/datasources/count"; - } + if(id != "" && entity != "") { - if(parameters != "") { - - this._searchDataprovidersService.numOfDataproviders(parameters).subscribe( + this._searchDataprovidersService.numOfEntityDataproviders(id, entity).subscribe( data => { this.searchUtils.totalResults = data; + + var errorCodes:ErrorCodes = new ErrorCodes(); + this.searchUtils.status = errorCodes.DONE; + if(this.searchUtils.totalResults == 0 ){ + this.searchUtils.status = errorCodes.NONE; + } }, err => { console.log(err); @@ -109,13 +111,18 @@ export class SearchDataprovidersComponent { } public getNumForSearch(keyword: string) { - var parameters="datasources/count"; - if(keyword != "") { - parameters += "?q="+keyword; - } - this._searchDataprovidersService.numOfDataproviders(parameters).subscribe( + var errorCodes:ErrorCodes = new ErrorCodes(); + this.searchUtils.status = errorCodes.LOADING; + + this._searchDataprovidersService.numOfDataproviders(keyword).subscribe( data => { this.searchUtils.totalResults = data; + + var errorCodes:ErrorCodes = new ErrorCodes(); + this.searchUtils.status = errorCodes.DONE; + if(this.searchUtils.totalResults == 0 ){ + this.searchUtils.status = errorCodes.NONE; + } }, err => { console.log(err); diff --git a/portal-2/src/app/services/searchDataproviders.service.ts b/portal-2/src/app/services/searchDataproviders.service.ts index 9f225b71..7e8eeff0 100644 --- a/portal-2/src/app/services/searchDataproviders.service.ts +++ b/portal-2/src/app/services/searchDataproviders.service.ts @@ -449,8 +449,8 @@ export class SearchDataprovidersService { return results; } - numOfDataproviders(params: string):any { - let url = OpenaireProperties. getSearchAPIURLLast()+params+(params.indexOf("?") == -1 ?"?":"&")+"format=json"; + numOfDataproviders(url: string):any { + //let url = OpenaireProperties. getSearchAPIURLLast()+params+(params.indexOf("?") == -1 ?"?":"&")+"format=json"; let key = url; if (this._cache.has(key)) { return Observable.of(this._cache.get(key)); @@ -463,6 +463,25 @@ export class SearchDataprovidersService { }); } + numOfEntityDataproviders(id: string, entity: string):any { + var parameters = ""; + if(entity == "organization") { + parameters = "organizations/"+id+"/datasources/count"; + } + + let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json"; + return this.numOfDataproviders(url); + } + + numOfSearchDataproviders(params: string):any { + let url: string = OpenaireProperties.getSearchAPIURLLast()+"datasources/count?format=json"; + if(params != "") { + url += "&q=" + params; + } + + return this.numOfDataproviders(url); + } + private quote(word: any): string { return '"'+word+'"'; } diff --git a/portal-2/src/app/services/searchDatasets.service.ts b/portal-2/src/app/services/searchDatasets.service.ts index 0eacb41e..0060d4a1 100644 --- a/portal-2/src/app/services/searchDatasets.service.ts +++ b/portal-2/src/app/services/searchDatasets.service.ts @@ -303,37 +303,37 @@ export class SearchDatasetsService { return results; } - numOfEntityDatasets(parameters: string):any { + numOfDatasets(url: string):any { + let key = url; + if (this._cache.has(key)) { + return Observable.of(this._cache.get(key)); + } + return this.http.get(url) + .map(res => res.json()) + .map(res => res.total) + .do(res => { + this._cache.set(key, res); + }); + } - //OpenaireProperties.getSearchAPIURLLast() - //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"/datasets/count"+"?format=json"; - let key = url; - if (this._cache.has(key)) { - return Observable.of(this._cache.get(key)); + numOfEntityDatasets(id: string, entity: string):any { + var parameters = ""; + + if(entity == "project") { + parameters = "projects/"+id+"/datasets/count"; + } else if(entity == "person") { + parameters = "people/"+id+"/datasets/count"; } - return this.http.get(url) - .map(res => res.json()) - .map(res => res.total) - .do(res => { - this._cache.set(key, res); - }); + + let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json"; + return this.numOfDatasets(url); } numOfSearchDatasets(params: string):any { - - //OpenaireProperties.getSearchAPIURLLast() - //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+"datasets/count?q=" + params + "&format=json"; - let key = url; - if (this._cache.has(key)) { - return Observable.of(this._cache.get(key)); + let url = OpenaireProperties.getSearchAPIURLLast()+"datasets/count?format=json"; + if(params != "") { + url += "&q=" + params; } - return this.http.get(url) - .map(res => res.json()) - .map(res => res.total) - .do(res => { - this._cache.set(key, res); - }); + return this.numOfDatasets(url); } } diff --git a/portal-2/src/app/services/searchOrganizations.service.ts b/portal-2/src/app/services/searchOrganizations.service.ts index a5007d77..6d55ab47 100644 --- a/portal-2/src/app/services/searchOrganizations.service.ts +++ b/portal-2/src/app/services/searchOrganizations.service.ts @@ -173,38 +173,35 @@ export class SearchOrganizationsService { return results; } - numOfEntityOrganizations(id: string, entity: string):any { + numOfOrganizations(url: string): any { + let key = url; + if (this._cache.has(key)) { + return Observable.of(this._cache.get(key)); + } + return this.http.get(url) + .map(res => res.json()) + .map(res => res.total) + .do(res => { + this._cache.set(key, res); + }); + } - //OpenaireProperties.getSearchAPIURLLast() - //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+entity+id+"/organizations/count"+ "?format=json"; - let key = url; - if (this._cache.has(key)) { - return Observable.of(this._cache.get(key)); + numOfEntityOrganizations(id: string, entity: string):any { + // currently not used - if used fix entity comparison below + var parameters: string = ""; + if(entity == "organization") { + parameters = "organizations/"+id+"/organizations/count"; } - return this.http.get(url) - .map(res => res.json()) - .map(res => res.total) - .do(res => { - this._cache.set(key, res); - }); + + let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json"; + return this.numOfOrganizations(url); } numOfSearchOrganizations(params: string):any { - - //OpenaireProperties.getSearchAPIURLLast() - //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+"organizations/count?q=" + params + "&format=json"; - - let key = url; - if (this._cache.has(key)) { - return Observable.of(this._cache.get(key)); + let url = OpenaireProperties.getSearchAPIURLLast()+"organizations/count?format=json"; + if(params != "") { + url += "&q=" + params; } - return this.http.get(url) - .map(res => res.json()) - .map(res => res.total) - .do(res => { - this._cache.set(key, res); - }); + return this.numOfOrganizations(url); } } diff --git a/portal-2/src/app/services/searchProjects.service.ts b/portal-2/src/app/services/searchProjects.service.ts index ff0ffc98..67995607 100644 --- a/portal-2/src/app/services/searchProjects.service.ts +++ b/portal-2/src/app/services/searchProjects.service.ts @@ -243,37 +243,36 @@ export class SearchProjectsService { return results; } - numOfProjects(params: string):any { + numOfProjects(url: string):any { + let key = url; + if (this._cache.has(key)) { + return Observable.of(this._cache.get(key)); + } + return this.http.get(url) + .map(res => res.json()) + .map(res => res.total) + .do(res => { + this._cache.set(key, res); + }); + } - //OpenaireProperties.getSearchAPIURLLast() - //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+params+(params.indexOf("?") == -1 ?"?":"&")+"format=json"; - let key = url; - if (this._cache.has(key)) { - return Observable.of(this._cache.get(key)); + numOfEntityProjects(id: string, entity: string):any { + //let url = OpenaireProperties.getSearchAPIURLLast()+params+(params.indexOf("?") == -1 ?"?":"&")+"format=json"; + var parameters: string = ""; + if(entity == "organization") { + parameters = "organizations/"+id+"/projects/count"; } - return this.http.get(url) - .map(res => res.json()) - .map(res => res.total) - .do(res => { - this._cache.set(key, res); - }); + + let url = OpenaireProperties.getSearchAPIURLLast()+parameters+ "?format=json"; + + return this.numOfProjects(url); } numOfSearchProjects(params: string):any { - - //OpenaireProperties.getSearchAPIURLLast() - //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+"projects/count?q=" + params + "&format=json"; - let key = url; - if (this._cache.has(key)) { - return Observable.of(this._cache.get(key)); + let url = OpenaireProperties.getSearchAPIURLLast()+"projects/count?format=json"; + if(params != "") { + url += "&q=" + params; } - return this.http.get(url) - .map(res => res.json()) - .map(res => res.total) - .do(res => { - this._cache.set(key, res); - }); + return this.numOfProjects(url); } } diff --git a/portal-2/src/app/services/searchPublications.service.ts b/portal-2/src/app/services/searchPublications.service.ts index 4a8a8eae..2d105943 100644 --- a/portal-2/src/app/services/searchPublications.service.ts +++ b/portal-2/src/app/services/searchPublications.service.ts @@ -423,37 +423,34 @@ export class SearchPublicationsService { return results; } - numOfEntityPublications(id: string, entity: string):any { + numOfPublications(url: string): any { + let key = url; + if (this._cache.has(key)) { + return Observable.of(this._cache.get(key)); + } + return this.http.get(url) + .map(res => res.json()) + .map(res => res.total) + .do(res => { + this._cache.set(key, res); + }); + } - //OpenaireProperties.getSearchAPIURLLast() - //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+entity+id+"/publications/count"+ "?format=json"; - let key = url; - if (this._cache.has(key)) { - return Observable.of(this._cache.get(key)); + numOfEntityPublications(id: string, entity: string):any { + var parameters: string = ""; + if(entity == "project") { + parameters = "projects/"+id+"/publications/count"; } - return this.http.get(url) - .map(res => res.json()) - .map(res => res.total) - .do(res => { - this._cache.set(key, res); - }); + let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json"; + return this.numOfPublications(url); } numOfSearchPublications(params: string):any { - - //OpenaireProperties.getSearchAPIURLLast() - //"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" - let url = OpenaireProperties.getSearchAPIURLLast()+"publications/count?q="+ params +"&format=json"; - let key = url; - if (this._cache.has(key)) { - return Observable.of(this._cache.get(key)); + let url = OpenaireProperties.getSearchAPIURLLast()+"publications/count?format=json"; + if(params != "") { + url += "&q=" + params; } - return this.http.get(url) - .map(res => res.json()) - .map(res => res.total).do(res => { - this._cache.set(key, res); - }); + return this.numOfPublications(url); } private quote(word: any): string { diff --git a/portal-2/src/app/utils/fetchEntitiesClasses/fetchDataproviders.class.ts b/portal-2/src/app/utils/fetchEntitiesClasses/fetchDataproviders.class.ts index 30fd634d..30c3c6bd 100644 --- a/portal-2/src/app/utils/fetchEntitiesClasses/fetchDataproviders.class.ts +++ b/portal-2/src/app/utils/fetchEntitiesClasses/fetchDataproviders.class.ts @@ -64,18 +64,12 @@ export class FetchDataproviders { } public getNumForEntity(entity: string, id:string) { - var parameters=""; - - if(entity == "organization") { - parameters = "organizations/"+id+"/datasources/count"; - } - var errorCodes:ErrorCodes = new ErrorCodes(); this.searchUtils.status = errorCodes.LOADING; - if(parameters != "") { + if(id != "" && entity != "") { - this._searchDataprovidersService.numOfDataproviders(parameters).subscribe( + this._searchDataprovidersService.numOfEntityDataproviders(id, entity).subscribe( data => { this.searchUtils.totalResults = data; @@ -101,11 +95,8 @@ export class FetchDataproviders { public getNumForSearch(keyword: string) { var errorCodes:ErrorCodes = new ErrorCodes(); this.searchUtils.status = errorCodes.LOADING; - var parameters="datasources/count"; - if(keyword != "") { - parameters += "?q=" +keyword ; - } - this._searchDataprovidersService.numOfDataproviders(parameters).subscribe( + + this._searchDataprovidersService.numOfDataproviders(keyword).subscribe( data => { this.searchUtils.totalResults = data; this.searchUtils.status = errorCodes.DONE; diff --git a/portal-2/src/app/utils/fetchEntitiesClasses/fetchDatasets.class.ts b/portal-2/src/app/utils/fetchEntitiesClasses/fetchDatasets.class.ts index 09a1a3be..d132821a 100644 --- a/portal-2/src/app/utils/fetchEntitiesClasses/fetchDatasets.class.ts +++ b/portal-2/src/app/utils/fetchEntitiesClasses/fetchDatasets.class.ts @@ -78,17 +78,9 @@ public getNumForEntity(entity:string, id:string){ var errorCodes:ErrorCodes = new ErrorCodes(); this.searchUtils.status = errorCodes.LOADING; - var parameters = ""; + if(id != "" && entity != "") { - if(entity == "project") { - parameters = "projects/"+id; - } else if(entity == "person") { - parameters = "people/"+id; - } - - if(parameters != "") { - - this._searchDatasetsService.numOfEntityDatasets(parameters).subscribe( + this._searchDatasetsService.numOfEntityDatasets(id, entity).subscribe( data => { this.searchUtils.totalResults = data; diff --git a/portal-2/src/app/utils/fetchEntitiesClasses/fetchProjects.class.ts b/portal-2/src/app/utils/fetchEntitiesClasses/fetchProjects.class.ts index 7e419d0b..99467328 100644 --- a/portal-2/src/app/utils/fetchEntitiesClasses/fetchProjects.class.ts +++ b/portal-2/src/app/utils/fetchEntitiesClasses/fetchProjects.class.ts @@ -91,18 +91,12 @@ export class FetchProjects{ } public getNumForEntity(entity: string, id:string) { - var parameters=""; - - if(entity == "organization") { - parameters = "organizations/"+id+"/projects/count"; - } - var errorCodes:ErrorCodes = new ErrorCodes(); this.searchUtils.status = errorCodes.LOADING; - if(parameters != "") { + if(id != "" && entity != "") { - this._searchProjectsService.numOfProjects(parameters).subscribe( + this._searchProjectsService.numOfEntityProjects(id, entity).subscribe( data => { this.searchUtils.totalResults = data;