diff --git a/landingPages/htmlProjectReport/htmlProjectReport.service.ts b/landingPages/htmlProjectReport/htmlProjectReport.service.ts
index 8a4db598..6aed001d 100644
--- a/landingPages/htmlProjectReport/htmlProjectReport.service.ts
+++ b/landingPages/htmlProjectReport/htmlProjectReport.service.ts
@@ -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));
}
}
diff --git a/landingPages/organization/organization.component.ts b/landingPages/organization/organization.component.ts
index 2cd53ece..41f5be78 100644
--- a/landingPages/organization/organization.component.ts
+++ b/landingPages/organization/organization.component.ts
@@ -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());
}));
}
},
diff --git a/services/reports.service.ts b/services/reports.service.ts
index 56abf310..4fbf20da 100644
--- a/services/reports.service.ts
+++ b/services/reports.service.ts
@@ -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));
}
diff --git a/timeout-interceptor.service.ts b/timeout-interceptor.service.ts
index 87e67ef4..77d6264e 100644
--- a/timeout-interceptor.service.ts
+++ b/timeout-interceptor.service.ts
@@ -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('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, next: HttpHandler): Observable> {
- 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, service: string | string[]):boolean {
+ if(isArray(service)) {
+ return !!service.find(element => req.url.indexOf(element) !== -1);
+ } else {
+ return req.url.indexOf(service) !== -1;
+ }
+ }
}