[Trunk | Library]:
1. timeout-interceptor.service.ts: Added whitelist, so that urls included in the list are not cut by this timeout interceptor. 2. services/reports.service.ts & landingPages/htmlProjectReport/htmlProjectReport.service.ts: In calls for CSV and HTML reports, added timeout 10 in seconds. 3. organization.component.ts: Created array "innerReportSubscriptions" where inner request of "downloading research results of a funder" are added - on error, all innerReportSubscriptions are unsubscribed. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@61262 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
8c92a7fcdb
commit
5227f96b3b
|
@ -1,5 +1,6 @@
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {HttpClient} from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
|
import {timeout} from "rxjs/operators";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class HtmlProjectReportService {
|
export class HtmlProjectReportService {
|
||||||
|
@ -12,6 +13,6 @@ export class HtmlProjectReportService {
|
||||||
//'((oaftype exact result) and (resulttypeid exact "'+resultTypeId+'")) and
|
//'((oaftype exact result) and (resulttypeid exact "'+resultTypeId+'")) and
|
||||||
'(relprojectid exact "'+id+'"))';
|
'(relprojectid exact "'+id+'"))';
|
||||||
|
|
||||||
return this.http.get(url,{responseType: 'text'});
|
return this.http.get(url,{responseType: 'text'}).pipe(timeout(10000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ export class OrganizationComponent {
|
||||||
private funderId: string;
|
private funderId: string;
|
||||||
private funderCount: number;
|
private funderCount: number;
|
||||||
subscriptions = [];
|
subscriptions = [];
|
||||||
|
innerReportSubscriptions = [];
|
||||||
properties: EnvProperties;
|
properties: EnvProperties;
|
||||||
public indexUpdateDate: Date;
|
public indexUpdateDate: Date;
|
||||||
public showFeedback: boolean = false;
|
public showFeedback: boolean = false;
|
||||||
|
@ -188,6 +189,12 @@ export class OrganizationComponent {
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.innerReportSubscriptions.forEach(subscription => {
|
||||||
|
if(subscription instanceof Subscriber) {
|
||||||
|
subscription.unsubscribe();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.fetchDatasets.clearSubscriptions();
|
this.fetchDatasets.clearSubscriptions();
|
||||||
this.fetchPublications.clearSubscriptions();
|
this.fetchPublications.clearSubscriptions();
|
||||||
this.fetchSoftware.clearSubscriptions();
|
this.fetchSoftware.clearSubscriptions();
|
||||||
|
@ -390,7 +397,7 @@ export class OrganizationComponent {
|
||||||
data => {
|
data => {
|
||||||
projects = data[1];
|
projects = data[1];
|
||||||
for (let index = 0; index < projects.length; index++) {
|
for (let index = 0; index < projects.length; index++) {
|
||||||
this.subscriptions.push(this._searchResearchResultsService.numOfEntityResults(this.funderContentType, projects[index].id, "project", this.properties).subscribe(
|
this.innerReportSubscriptions.push(this._searchResearchResultsService.numOfEntityResults(this.funderContentType, projects[index].id, "project", this.properties).subscribe(
|
||||||
data => {
|
data => {
|
||||||
//if(data == 0 && title) { // if no publications for this project
|
//if(data == 0 && title) { // if no publications for this project
|
||||||
if (data == 0 && (counter > 1 || title)) { // if no publications for this project
|
if (data == 0 && (counter > 1 || title)) { // if no publications for this project
|
||||||
|
@ -435,7 +442,7 @@ export class OrganizationComponent {
|
||||||
}
|
}
|
||||||
title = true;
|
title = true;
|
||||||
|
|
||||||
this.subscriptions.push(this._reportsService.getCSVResponse(url).subscribe(
|
this.innerReportSubscriptions.push(this._reportsService.getCSVResponse(url).subscribe(
|
||||||
data => {
|
data => {
|
||||||
counter--;
|
counter--;
|
||||||
response[index] = data;
|
response[index] = data;
|
||||||
|
@ -473,6 +480,7 @@ export class OrganizationComponent {
|
||||||
|
|
||||||
this.closeLoading();
|
this.closeLoading();
|
||||||
this.confirmOpenCsvError();
|
this.confirmOpenCsvError();
|
||||||
|
this.innerReportSubscriptions.forEach(subscription => subscription.unsubscribe());
|
||||||
}/*,
|
}/*,
|
||||||
() => console.log('Completed file download.')*/
|
() => console.log('Completed file download.')*/
|
||||||
) );
|
) );
|
||||||
|
@ -481,6 +489,8 @@ export class OrganizationComponent {
|
||||||
err => {
|
err => {
|
||||||
this.handleError("Error getting number of publications for project with id: " + projects[index].id, err);
|
this.handleError("Error getting number of publications for project with id: " + projects[index].id, err);
|
||||||
this.closeLoading();
|
this.closeLoading();
|
||||||
|
this.confirmOpenCsvError();
|
||||||
|
this.innerReportSubscriptions.forEach(subscription => subscription.unsubscribe());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {throwError} from 'rxjs';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import {map, tap} from "rxjs/operators";
|
import {map, tap, timeout} from "rxjs/operators";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ReportsService {
|
export class ReportsService {
|
||||||
|
@ -16,12 +16,15 @@ export class ReportsService {
|
||||||
//var headers = new Headers();
|
//var headers = new Headers();
|
||||||
//headers.append('responseType', 'arraybuffer');
|
//headers.append('responseType', 'arraybuffer');
|
||||||
return this.http.get(url, {responseType: 'text'})
|
return this.http.get(url, {responseType: 'text'})
|
||||||
.pipe(map(res => new Blob([res], { type: 'text/csv' })));
|
.pipe(
|
||||||
|
timeout(10000),
|
||||||
|
map(res => new Blob([res], { type: 'text/csv' })));
|
||||||
}
|
}
|
||||||
getCSVResponse(url: string){
|
getCSVResponse(url: string){
|
||||||
//var headers = new Headers();
|
//var headers = new Headers();
|
||||||
//headers.append('responseType', 'arraybuffer');
|
//headers.append('responseType', 'arraybuffer');
|
||||||
return this.http.get(url, {responseType: 'text'});
|
return this.http.get(url, {responseType: 'text'})
|
||||||
|
.pipe(timeout(10000));
|
||||||
//.pipe(map(res => res));
|
//.pipe(map(res => res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,16 +3,20 @@ import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/c
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { timeout } from 'rxjs/operators';
|
import { timeout } from 'rxjs/operators';
|
||||||
import {isPlatformServer} from "@angular/common";
|
import {isPlatformServer} from "@angular/common";
|
||||||
|
import {properties} from "../../environments/environment";
|
||||||
|
import {isArray} from "util";
|
||||||
|
|
||||||
export const DEFAULT_TIMEOUT = new InjectionToken<number>('defaultTimeout');
|
export const DEFAULT_TIMEOUT = new InjectionToken<number>('defaultTimeout');
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TimeoutInterceptor implements HttpInterceptor {
|
export class TimeoutInterceptor implements HttpInterceptor {
|
||||||
|
private static TIMEOUT_WHITELIST = [properties.csvAPIURL];
|
||||||
|
|
||||||
constructor(@Inject(DEFAULT_TIMEOUT) protected defaultTimeout: number, @Inject(PLATFORM_ID) private platformId: any) {
|
constructor(@Inject(DEFAULT_TIMEOUT) protected defaultTimeout: number, @Inject(PLATFORM_ID) private platformId: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET' || this.isService(req, TimeoutInterceptor.TIMEOUT_WHITELIST)) {
|
||||||
return next.handle(req);
|
return next.handle(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,4 +24,12 @@ export class TimeoutInterceptor implements HttpInterceptor {
|
||||||
const timeoutValueNumeric = Number(timeoutValue);
|
const timeoutValueNumeric = Number(timeoutValue);
|
||||||
return next.handle(req).pipe(timeout(timeoutValueNumeric));
|
return next.handle(req).pipe(timeout(timeoutValueNumeric));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isService(req: HttpRequest<any>, service: string | string[]):boolean {
|
||||||
|
if(isArray(service)) {
|
||||||
|
return !!service.find(element => req.url.indexOf(element) !== -1);
|
||||||
|
} else {
|
||||||
|
return req.url.indexOf(service) !== -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue