[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:
konstantina.galouni 2021-06-22 08:04:38 +00:00
parent 8c92a7fcdb
commit 5227f96b3b
4 changed files with 33 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {timeout} from "rxjs/operators";
@Injectable()
export class HtmlProjectReportService {
@ -12,6 +13,6 @@ export class HtmlProjectReportService {
//'((oaftype exact result) and (resulttypeid exact "'+resultTypeId+'")) and
'(relprojectid exact "'+id+'"))';
return this.http.get(url,{responseType: 'text'});
return this.http.get(url,{responseType: 'text'}).pipe(timeout(10000));
}
}

View File

@ -92,6 +92,7 @@ export class OrganizationComponent {
private funderId: string;
private funderCount: number;
subscriptions = [];
innerReportSubscriptions = [];
properties: EnvProperties;
public indexUpdateDate: Date;
public showFeedback: boolean = false;
@ -188,6 +189,12 @@ export class OrganizationComponent {
subscription.unsubscribe();
}
});
this.innerReportSubscriptions.forEach(subscription => {
if(subscription instanceof Subscriber) {
subscription.unsubscribe();
}
});
this.fetchDatasets.clearSubscriptions();
this.fetchPublications.clearSubscriptions();
this.fetchSoftware.clearSubscriptions();
@ -390,7 +397,7 @@ export class OrganizationComponent {
data => {
projects = data[1];
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 => {
//if(data == 0 && 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;
this.subscriptions.push(this._reportsService.getCSVResponse(url).subscribe(
this.innerReportSubscriptions.push(this._reportsService.getCSVResponse(url).subscribe(
data => {
counter--;
response[index] = data;
@ -473,6 +480,7 @@ export class OrganizationComponent {
this.closeLoading();
this.confirmOpenCsvError();
this.innerReportSubscriptions.forEach(subscription => subscription.unsubscribe());
}/*,
() => console.log('Completed file download.')*/
) );
@ -481,6 +489,8 @@ export class OrganizationComponent {
err => {
this.handleError("Error getting number of publications for project with id: " + projects[index].id, err);
this.closeLoading();
this.confirmOpenCsvError();
this.innerReportSubscriptions.forEach(subscription => subscription.unsubscribe());
}));
}
},

View File

@ -4,7 +4,7 @@ import {throwError} from 'rxjs';
import {map, tap} from "rxjs/operators";
import {map, tap, timeout} from "rxjs/operators";
@Injectable()
export class ReportsService {
@ -16,12 +16,15 @@ export class ReportsService {
//var headers = new Headers();
//headers.append('responseType', 'arraybuffer');
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){
//var headers = new Headers();
//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));
}

View File

@ -3,16 +3,20 @@ import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/c
import { Observable } from 'rxjs';
import { timeout } from 'rxjs/operators';
import {isPlatformServer} from "@angular/common";
import {properties} from "../../environments/environment";
import {isArray} from "util";
export const DEFAULT_TIMEOUT = new InjectionToken<number>('defaultTimeout');
@Injectable()
export class TimeoutInterceptor implements HttpInterceptor {
private static TIMEOUT_WHITELIST = [properties.csvAPIURL];
constructor(@Inject(DEFAULT_TIMEOUT) protected defaultTimeout: number, @Inject(PLATFORM_ID) private platformId: 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);
}
@ -20,4 +24,12 @@ export class TimeoutInterceptor implements HttpInterceptor {
const timeoutValueNumeric = Number(timeoutValue);
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;
}
}
}