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
This commit is contained in:
konstantina.galouni 2017-06-16 15:03:30 +00:00
parent ff7fc02161
commit 5012261491
10 changed files with 147 additions and 151 deletions

View File

@ -260,7 +260,7 @@ export class OrganizationComponent {
{ {
projects = data[1]; projects = data[1];
for(let index=0; index < projects.length; index++) { 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 => data =>
{ {
// let index: number = this.organizationInfo.projects.get(funder).indexOf(project); // let index: number = this.organizationInfo.projects.get(funder).indexOf(project);

View File

@ -82,18 +82,20 @@ export class SearchDataprovidersComponent {
} }
public getNumForEntity(entity: string, id:string) { public getNumForEntity(entity: string, id:string) {
console.info("getNumForEntity : Dataproviders Component"); var errorCodes:ErrorCodes = new ErrorCodes();
var parameters=""; this.searchUtils.status = errorCodes.LOADING;
if(entity == "organization") { if(id != "" && entity != "") {
parameters = "organizations/"+id+"/datasources/count";
}
if(parameters != "") { this._searchDataprovidersService.numOfEntityDataproviders(id, entity).subscribe(
this._searchDataprovidersService.numOfDataproviders(parameters).subscribe(
data => { data => {
this.searchUtils.totalResults = 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 => { err => {
console.log(err); console.log(err);
@ -109,13 +111,18 @@ export class SearchDataprovidersComponent {
} }
public getNumForSearch(keyword: string) { public getNumForSearch(keyword: string) {
var parameters="datasources/count"; var errorCodes:ErrorCodes = new ErrorCodes();
if(keyword != "") { this.searchUtils.status = errorCodes.LOADING;
parameters += "?q="+keyword;
} this._searchDataprovidersService.numOfDataproviders(keyword).subscribe(
this._searchDataprovidersService.numOfDataproviders(parameters).subscribe(
data => { data => {
this.searchUtils.totalResults = 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 => { err => {
console.log(err); console.log(err);

View File

@ -449,8 +449,8 @@ export class SearchDataprovidersService {
return results; return results;
} }
numOfDataproviders(params: string):any { numOfDataproviders(url: string):any {
let url = OpenaireProperties. getSearchAPIURLLast()+params+(params.indexOf("?") == -1 ?"?":"&")+"format=json"; //let url = OpenaireProperties. getSearchAPIURLLast()+params+(params.indexOf("?") == -1 ?"?":"&")+"format=json";
let key = url; let key = url;
if (this._cache.has(key)) { if (this._cache.has(key)) {
return Observable.of(this._cache.get(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 { private quote(word: any): string {
return '"'+word+'"'; return '"'+word+'"';
} }

View File

@ -303,37 +303,37 @@ export class SearchDatasetsService {
return results; 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 => <any> res.json())
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
//OpenaireProperties.getSearchAPIURLLast() numOfEntityDatasets(id: string, entity: string):any {
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" var parameters = "";
let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"/datasets/count"+"?format=json";
let key = url; if(entity == "project") {
if (this._cache.has(key)) { parameters = "projects/"+id+"/datasets/count";
return Observable.of(this._cache.get(key)); } else if(entity == "person") {
parameters = "people/"+id+"/datasets/count";
} }
return this.http.get(url)
.map(res => <any> res.json()) let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json";
.map(res => res.total) return this.numOfDatasets(url);
.do(res => {
this._cache.set(key, res);
});
} }
numOfSearchDatasets(params: string):any { numOfSearchDatasets(params: string):any {
let url = OpenaireProperties.getSearchAPIURLLast()+"datasets/count?format=json";
//OpenaireProperties.getSearchAPIURLLast() if(params != "") {
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" url += "&q=" + params;
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));
} }
return this.http.get(url) return this.numOfDatasets(url);
.map(res => <any> res.json())
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
} }
} }

View File

@ -173,38 +173,35 @@ export class SearchOrganizationsService {
return results; 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 => <any> res.json())
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
//OpenaireProperties.getSearchAPIURLLast() numOfEntityOrganizations(id: string, entity: string):any {
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" // currently not used - if used fix entity comparison below
let url = OpenaireProperties.getSearchAPIURLLast()+entity+id+"/organizations/count"+ "?format=json"; var parameters: string = "";
let key = url; if(entity == "organization") {
if (this._cache.has(key)) { parameters = "organizations/"+id+"/organizations/count";
return Observable.of(this._cache.get(key));
} }
return this.http.get(url)
.map(res => <any> res.json()) let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json";
.map(res => res.total) return this.numOfOrganizations(url);
.do(res => {
this._cache.set(key, res);
});
} }
numOfSearchOrganizations(params: string):any { numOfSearchOrganizations(params: string):any {
let url = OpenaireProperties.getSearchAPIURLLast()+"organizations/count?format=json";
//OpenaireProperties.getSearchAPIURLLast() if(params != "") {
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" url += "&q=" + params;
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));
} }
return this.http.get(url) return this.numOfOrganizations(url);
.map(res => <any> res.json())
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
} }
} }

View File

@ -243,37 +243,36 @@ export class SearchProjectsService {
return results; 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 => <any> res.json())
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
//OpenaireProperties.getSearchAPIURLLast() numOfEntityProjects(id: string, entity: string):any {
//"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 url = OpenaireProperties.getSearchAPIURLLast()+params+(params.indexOf("?") == -1 ?"?":"&")+"format=json"; var parameters: string = "";
let key = url; if(entity == "organization") {
if (this._cache.has(key)) { parameters = "organizations/"+id+"/projects/count";
return Observable.of(this._cache.get(key));
} }
return this.http.get(url)
.map(res => <any> res.json()) let url = OpenaireProperties.getSearchAPIURLLast()+parameters+ "?format=json";
.map(res => res.total)
.do(res => { return this.numOfProjects(url);
this._cache.set(key, res);
});
} }
numOfSearchProjects(params: string):any { numOfSearchProjects(params: string):any {
let url = OpenaireProperties.getSearchAPIURLLast()+"projects/count?format=json";
//OpenaireProperties.getSearchAPIURLLast() if(params != "") {
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" url += "&q=" + params;
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));
} }
return this.http.get(url) return this.numOfProjects(url);
.map(res => <any> res.json())
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
} }
} }

View File

@ -423,37 +423,34 @@ export class SearchPublicationsService {
return results; 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 => <any> res.json())
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
}
//OpenaireProperties.getSearchAPIURLLast() numOfEntityPublications(id: string, entity: string):any {
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" var parameters: string = "";
let url = OpenaireProperties.getSearchAPIURLLast()+entity+id+"/publications/count"+ "?format=json"; if(entity == "project") {
let key = url; parameters = "projects/"+id+"/publications/count";
if (this._cache.has(key)) {
return Observable.of(this._cache.get(key));
} }
return this.http.get(url) let url = OpenaireProperties.getSearchAPIURLLast()+parameters+"?format=json";
.map(res => <any> res.json()) return this.numOfPublications(url);
.map(res => res.total)
.do(res => {
this._cache.set(key, res);
});
} }
numOfSearchPublications(params: string):any { numOfSearchPublications(params: string):any {
let url = OpenaireProperties.getSearchAPIURLLast()+"publications/count?format=json";
//OpenaireProperties.getSearchAPIURLLast() if(params != "") {
//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-2.0.0-SNAPSHOT/rest/v2/api/" url += "&q=" + params;
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));
} }
return this.http.get(url) return this.numOfPublications(url);
.map(res => <any> res.json())
.map(res => res.total).do(res => {
this._cache.set(key, res);
});
} }
private quote(word: any): string { private quote(word: any): string {

View File

@ -64,18 +64,12 @@ export class FetchDataproviders {
} }
public getNumForEntity(entity: string, id:string) { public getNumForEntity(entity: string, id:string) {
var parameters="";
if(entity == "organization") {
parameters = "organizations/"+id+"/datasources/count";
}
var errorCodes:ErrorCodes = new ErrorCodes(); var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.LOADING; this.searchUtils.status = errorCodes.LOADING;
if(parameters != "") { if(id != "" && entity != "") {
this._searchDataprovidersService.numOfDataproviders(parameters).subscribe( this._searchDataprovidersService.numOfEntityDataproviders(id, entity).subscribe(
data => { data => {
this.searchUtils.totalResults = data; this.searchUtils.totalResults = data;
@ -101,11 +95,8 @@ export class FetchDataproviders {
public getNumForSearch(keyword: string) { public getNumForSearch(keyword: string) {
var errorCodes:ErrorCodes = new ErrorCodes(); var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.LOADING; this.searchUtils.status = errorCodes.LOADING;
var parameters="datasources/count";
if(keyword != "") { this._searchDataprovidersService.numOfDataproviders(keyword).subscribe(
parameters += "?q=" +keyword ;
}
this._searchDataprovidersService.numOfDataproviders(parameters).subscribe(
data => { data => {
this.searchUtils.totalResults = data; this.searchUtils.totalResults = data;
this.searchUtils.status = errorCodes.DONE; this.searchUtils.status = errorCodes.DONE;

View File

@ -78,17 +78,9 @@ public getNumForEntity(entity:string, id:string){
var errorCodes:ErrorCodes = new ErrorCodes(); var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.LOADING; this.searchUtils.status = errorCodes.LOADING;
var parameters = ""; if(id != "" && entity != "") {
if(entity == "project") { this._searchDatasetsService.numOfEntityDatasets(id, entity).subscribe(
parameters = "projects/"+id;
} else if(entity == "person") {
parameters = "people/"+id;
}
if(parameters != "") {
this._searchDatasetsService.numOfEntityDatasets(parameters).subscribe(
data => { data => {
this.searchUtils.totalResults = data; this.searchUtils.totalResults = data;

View File

@ -91,18 +91,12 @@ export class FetchProjects{
} }
public getNumForEntity(entity: string, id:string) { public getNumForEntity(entity: string, id:string) {
var parameters="";
if(entity == "organization") {
parameters = "organizations/"+id+"/projects/count";
}
var errorCodes:ErrorCodes = new ErrorCodes(); var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.LOADING; this.searchUtils.status = errorCodes.LOADING;
if(parameters != "") { if(id != "" && entity != "") {
this._searchProjectsService.numOfProjects(parameters).subscribe( this._searchProjectsService.numOfEntityProjects(id, entity).subscribe(
data => { data => {
this.searchUtils.totalResults = data; this.searchUtils.totalResults = data;