223 lines
7.7 KiB
TypeScript
223 lines
7.7 KiB
TypeScript
import {SearchOrpsService} from '../../services/searchOrps.service';
|
|
import { ErrorCodes} from '../../utils/properties/errorCodes';
|
|
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
|
|
import {DOI} from '../../utils/string-utils.class';
|
|
import {Subject} from 'rxjs/Subject';
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
|
|
|
export class FetchOrps{
|
|
private errorCodes: ErrorCodes;
|
|
|
|
public results =[];
|
|
public requestComplete: Subject<void>;
|
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
private sub: any;
|
|
private subResults: any;
|
|
|
|
public csvParams: string;
|
|
|
|
constructor ( private _searchOrpsService: SearchOrpsService ) {
|
|
|
|
this.errorCodes = new ErrorCodes();
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.requestComplete = new Subject<void>();
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
if(this.sub){
|
|
this.sub.unsubscribe();
|
|
}
|
|
if(this.subResults){
|
|
this.subResults.unsubscribe();
|
|
}
|
|
}
|
|
|
|
|
|
public getResultsByKeyword(keyword:string, page: number, size: number, properties:EnvProperties){
|
|
console.info("orps: getResultsByKeyword");
|
|
var parameters = "";
|
|
if(keyword.length > 0){
|
|
var DOIs:string[] = DOI.getDOIsFromString(keyword);
|
|
var doisParams = "";
|
|
|
|
for(var i =0 ;i < DOIs.length; i++){
|
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
|
}
|
|
if(doisParams.length > 0){
|
|
parameters += "&"+doisParams;
|
|
}else{
|
|
parameters = "q=" + StringUtils.URIEncode(keyword);
|
|
}
|
|
}
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.subResults = this._searchOrpsService.searchOrps(parameters,null, page, size, [], properties).subscribe(
|
|
data => {
|
|
this.searchUtils.totalResults = data[0];
|
|
console.info("search Other Research Products: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
|
this.results = data[1];
|
|
|
|
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(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){
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
|
|
if(id != "" && entity != "") {
|
|
this._searchOrpsService.numOfEntityOrps(id, entity, 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(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){
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
var parameters = "";
|
|
|
|
if(entity == "project") {
|
|
parameters = "projects/"+id;
|
|
}
|
|
|
|
if(parameters != "") {
|
|
|
|
this._searchOrpsService.searchOrpsForEntity(parameters, page, size, properties).subscribe(
|
|
data => {
|
|
this.searchUtils.totalResults = data[0];
|
|
console.info("search Other Research Products for "+entity+": [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
|
this.results = data[1];
|
|
|
|
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(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, resultsFrom:string, page: number, size: number, properties:EnvProperties){
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
var parameters;
|
|
if(resultsFrom == "collectedFrom") {
|
|
parameters = "other?fq=collectedfromdatasourceid exact "+'"'+id+'"';
|
|
} else if(resultsFrom == "hostedBy") {
|
|
parameters = "other?fq=resulthostingdatasourceid exact "+'"'+id+'"';
|
|
}
|
|
|
|
if(parameters != "") {
|
|
|
|
this._searchOrpsService.searchOrpsForDataproviders(parameters, page, size, properties).subscribe(
|
|
data => {
|
|
this.searchUtils.totalResults = data[0];
|
|
console.info("search Other Research Products for Dataproviders: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
|
this.results = data[1];
|
|
|
|
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(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 getAggregatorResults(id:string, page: number, size: number, properties:EnvProperties){
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.subResults = this._searchOrpsService.searchAggregators(id, '&fq=collectedfromdatasourceid exact "'+id+'"',"&refine=true&fields=resulthostingdatasource" , page, size, properties).subscribe(
|
|
data => {
|
|
this.results = data;
|
|
this.searchUtils.totalResults = this.results.length;
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
}
|
|
|
|
this.requestComplete.complete();
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
console.info("status: "+err.status);
|
|
//TODO check erros (service not available, bad request)
|
|
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;
|
|
}
|
|
|
|
this.requestComplete.complete();
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|