292 lines
11 KiB
TypeScript
292 lines
11 KiB
TypeScript
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
||
|
import { ErrorCodes} from '../../utils/properties/openaireProperties';
|
||
|
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
|
||
|
|
||
|
export class FetchDataproviders {
|
||
|
private errorCodes: ErrorCodes;
|
||
|
|
||
|
public results =[];
|
||
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
||
|
public sub: any; public subResults: any;
|
||
|
public CSV: any = { "columnNames": [ "Title", "Type", "Coutries", "Compatibility" ],
|
||
|
"export":[]
|
||
|
};
|
||
|
public CSVDownloaded = false;
|
||
|
public csvParams: string;
|
||
|
|
||
|
|
||
|
constructor ( private _searchDataprovidersService: SearchDataprovidersService ) {
|
||
|
this.errorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.LOADING;
|
||
|
}
|
||
|
|
||
|
|
||
|
public ngOnDestroy() {
|
||
|
if(this.sub){
|
||
|
this.sub.unsubscribe();
|
||
|
}
|
||
|
if(this.subResults){
|
||
|
this.subResults.unsubscribe();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public getResultsByKeyword(keyword:string, page: number, size: number){
|
||
|
var parameters = "";
|
||
|
if(keyword.length > 0){
|
||
|
parameters = "q=" + keyword;
|
||
|
}
|
||
|
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.LOADING;
|
||
|
|
||
|
|
||
|
this.subResults = this._searchDataprovidersService.searchDataproviders(parameters,null, page, size,[]).subscribe(
|
||
|
data => {
|
||
|
this.searchUtils.totalResults = data[0];
|
||
|
console.info("search Content Providers: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
||
|
this.results = data[1];
|
||
|
|
||
|
//ar errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.DONE;
|
||
|
if(this.searchUtils.totalResults == 0 ){
|
||
|
this.searchUtils.status = this.errorCodes.NONE;
|
||
|
}
|
||
|
},
|
||
|
err => {
|
||
|
console.log(err);
|
||
|
//TODO check erros (service not available, bad request)
|
||
|
// if( ){
|
||
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
||
|
// }
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
//this.searchUtils.status = errorCodes.ERROR;
|
||
|
if(err.status == '404') {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
||
|
} else if(err.status == '500') {
|
||
|
this.searchUtils.status = this.errorCodes.ERROR;
|
||
|
} else {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public getNumForEntity(entity: string, id:string) {
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.LOADING;
|
||
|
|
||
|
if(id != "" && entity != "") {
|
||
|
|
||
|
this._searchDataprovidersService.numOfEntityDataproviders(id, entity).subscribe(
|
||
|
data => {
|
||
|
this.searchUtils.totalResults = data;
|
||
|
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.DONE;
|
||
|
if(this.searchUtils.totalResults == 0 ){
|
||
|
this.searchUtils.status = this.errorCodes.NONE;
|
||
|
}
|
||
|
},
|
||
|
err => {
|
||
|
console.log(err);
|
||
|
//TODO check erros (service not available, bad request)
|
||
|
// if( ){
|
||
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
||
|
// }
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
//this.searchUtils.status = errorCodes.ERROR;
|
||
|
if(err.status == '404') {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
||
|
} else if(err.status == '500') {
|
||
|
this.searchUtils.status = this.errorCodes.ERROR;
|
||
|
} else {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public getNumForSearch(keyword: string) {
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.LOADING;
|
||
|
|
||
|
this._searchDataprovidersService.numOfSearchDataproviders(keyword).subscribe(
|
||
|
data => {
|
||
|
this.searchUtils.totalResults = data;
|
||
|
this.searchUtils.status = this.errorCodes.DONE;
|
||
|
|
||
|
if(this.searchUtils.totalResults == 0) {
|
||
|
this.searchUtils.status = this.errorCodes.NONE;
|
||
|
}
|
||
|
},
|
||
|
err => {
|
||
|
console.log(err);
|
||
|
//TODO check erros (service not available, bad request)
|
||
|
// if( ){
|
||
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
||
|
// }
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
//this.searchUtils.status = errorCodes.ERROR;
|
||
|
if(err.status == '404') {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
||
|
} else if(err.status == '500') {
|
||
|
this.searchUtils.status = this.errorCodes.ERROR;
|
||
|
} else {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public getResultsForDeposit(id:string, type:string, page: number, size: number){
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.LOADING;
|
||
|
|
||
|
if(id != "") {
|
||
|
|
||
|
this._searchDataprovidersService.searchDataprovidersForDeposit(id,type, page, size).subscribe(
|
||
|
data => {
|
||
|
this.searchUtils.totalResults = data[0];
|
||
|
console.info("search Dataproviders forDeposit: [id:"+id+", type:"+type+" ] [total results:"+this.searchUtils.totalResults+"]");
|
||
|
this.results = data[1];
|
||
|
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.DONE;
|
||
|
if(this.searchUtils.totalResults == 0 ){
|
||
|
this.searchUtils.status = this.errorCodes.NONE;
|
||
|
}
|
||
|
},
|
||
|
err => {
|
||
|
console.log(err);
|
||
|
//TODO check erros (service not available, bad request)
|
||
|
// if( ){
|
||
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
||
|
// }
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
//this.searchUtils.status = errorCodes.ERROR;
|
||
|
if(err.status == '404') {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
||
|
} else if(err.status == '500') {
|
||
|
this.searchUtils.status = this.errorCodes.ERROR;
|
||
|
} else {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
public getResultsBySubjectsForDeposit(subject:string, type:string, page: number, size: number){
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.LOADING;
|
||
|
this._searchDataprovidersService.searchDataProvidersBySubjects(subject,type, page, size).subscribe(
|
||
|
data => {
|
||
|
this.searchUtils.totalResults = data[0];
|
||
|
console.info("search Dataproviders forDeposit: [subject:"+subject+", type:"+type+" ] [total results:"+this.searchUtils.totalResults+"]");
|
||
|
this.results = data[1];
|
||
|
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.DONE;
|
||
|
if(this.searchUtils.totalResults == 0 ){
|
||
|
this.searchUtils.status = this.errorCodes.NONE;
|
||
|
}
|
||
|
},
|
||
|
err => {
|
||
|
console.log(err);
|
||
|
//TODO check erros (service not available, bad request)
|
||
|
// if( ){
|
||
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
||
|
// }
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
//this.searchUtils.status = errorCodes.ERROR;
|
||
|
if(err.status == '404') {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
||
|
} else if(err.status == '500') {
|
||
|
this.searchUtils.status = this.errorCodes.ERROR;
|
||
|
} else {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
|
||
|
}
|
||
|
public getResultsForEntity(entity:string, id:string, page: number, size: number){
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.LOADING;
|
||
|
|
||
|
var parameters = "";
|
||
|
|
||
|
if(entity == "organization") {
|
||
|
parameters = "organizations/"+id;
|
||
|
}
|
||
|
|
||
|
if(parameters != "") {
|
||
|
|
||
|
this._searchDataprovidersService.searchDataprovidersForEntity(parameters, page, size).subscribe(
|
||
|
data => {
|
||
|
this.searchUtils.totalResults = data[0];
|
||
|
console.info("search Dataproviders for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
||
|
this.results = data[1];
|
||
|
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.DONE;
|
||
|
if(this.searchUtils.totalResults == 0 ){
|
||
|
this.searchUtils.status = this.errorCodes.NONE;
|
||
|
}
|
||
|
},
|
||
|
err => {
|
||
|
console.log(err);
|
||
|
//TODO check erros (service not available, bad request)
|
||
|
// if( ){
|
||
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
||
|
// }
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
//this.searchUtils.status = errorCodes.ERROR;
|
||
|
if(err.status == '404') {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
||
|
} else if(err.status == '500') {
|
||
|
this.searchUtils.status = this.errorCodes.ERROR;
|
||
|
} else {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public getResultsForDataproviders(id:string, page: number, size: number){
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.LOADING;
|
||
|
|
||
|
this._searchDataprovidersService.getDataProvidersforEntityRegistry(id, page, size).subscribe(
|
||
|
data => {
|
||
|
this.searchUtils.totalResults = data[0];
|
||
|
console.info("search Dataproviders for Entity Registry: [Id:"+id+" ] [total results:"+this.searchUtils.totalResults+"]");
|
||
|
this.results = data[1];
|
||
|
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
this.searchUtils.status = this.errorCodes.DONE;
|
||
|
if(this.searchUtils.totalResults == 0 ){
|
||
|
this.searchUtils.status = this.errorCodes.NONE;
|
||
|
}
|
||
|
},
|
||
|
err => {
|
||
|
console.log(err);
|
||
|
//TODO check erros (service not available, bad request)
|
||
|
// if( ){
|
||
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
||
|
// }
|
||
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
||
|
//this.searchUtils.status = errorCodes.ERROR;
|
||
|
if(err.status == '404') {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
||
|
} else if(err.status == '500') {
|
||
|
this.searchUtils.status = this.errorCodes.ERROR;
|
||
|
} else {
|
||
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|