openaire-library/utils/fetchEntitiesClasses/fetchDataproviders.class.ts

293 lines
12 KiB
TypeScript
Raw Normal View History

import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
import { ErrorCodes} from '../../utils/properties/errorCodes';
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
import{EnvProperties} from '../../utils/properties/env-properties';
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, properties:EnvProperties){
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,[], properties).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, properties:EnvProperties) {
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
if(id != "" && entity != "") {
this._searchDataprovidersService.numOfEntityDataproviders(id, entity, properties).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, properties:EnvProperties) {
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
this._searchDataprovidersService.numOfSearchDataproviders(keyword, properties).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, properties:EnvProperties){
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
if(id != "") {
this._searchDataprovidersService.searchDataprovidersForDeposit(id,type, page, size, properties).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, properties:EnvProperties){
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
this._searchDataprovidersService.searchDataProvidersBySubjects(subject,type, page, size, properties).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, properties:EnvProperties){
//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, properties).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, properties:EnvProperties){
//var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = this.errorCodes.LOADING;
this._searchDataprovidersService.getDataProvidersforEntityRegistry(id, page, size, properties).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;
}
}
);
}
}