openaire-library/cache-interceptor.service.ts

74 lines
7.1 KiB
TypeScript
Raw Permalink Normal View History

2023-08-04 13:45:41 +02:00
import {Injectable, Inject, PLATFORM_ID, TransferState} from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http';
import { properties } from "../../environments/environment";
@Injectable({
providedIn: 'root'
})
export class CacheInterceptorService implements HttpInterceptor {
cachingRequests = [
// Remove 2 following lines when bug with hidden refine filters is solved.
"/resources2/?format=json&refine=true&fields=instancetypename&fields=foslabel&fields=relfunder&fields=relfundinglevel0_id&fields=relproject&fields=sdg&fields=country&fields=resultlanguagename&fields=resulthostingdatasource&fields=community&&fq=resultbestaccessright exact \"Open Access\"&type=results&page=0&size=0",
"/resources2/?format=json&refine=true&fields=funder&fields=fundinglevel0_id&fields=projectstartyear&fields=projectendyear&fields=projectoamandatepublications&&type=projects&page=0&size=0",
"/resources2/?format=json&refine=true&fields=instancetypename&fields=foslabel&fields=relfunder&fields=sdg&fields=country&fields=resultlanguagename&fields=resulthostingdatasource&fields=community&&type=results&page=0&size=0",
"/resources2/?format=json&refine=true&fields=instancetypename&fields=foslabel&fields=relfunder&fields=relfundinglevel0_id&fields=relproject&fields=sdg&fields=country&fields=resultlanguagename&fields=resulthostingdatasource&fields=community&&fq=resultbestaccessright%20exact%20%22Open%20Access%22&fq=relfunder%20exact%20%22ec__________%3A%3AEC%7C%7CEuropean%20Commission%7C%7CEC%22&type=results&page=0&size=0",
"/resources2/?format=json&refine=true&fields=instancetypename&fields=foslabel&fields=relfunder&fields=sdg&fields=country&fields=resultlanguagename&fields=resulthostingdatasource&fields=community&&type=publications&page=0&size=0",
"/resources2/?format=json&refine=true&fields=instancetypename&fields=foslabel&fields=relfunder&fields=sdg&fields=country&fields=resultlanguagename&fields=resulthostingdatasource&fields=community&&type=datasets&page=0&size=0",
"/resources2/?format=json&refine=true&fields=instancetypename&fields=foslabel&fields=relfunder&fields=sdg&fields=country&fields=resultlanguagename&fields=resulthostingdatasource&fields=community&&type=software&page=0&size=0",
"/resources2/?format=json&refine=true&fields=instancetypename&fields=foslabel&fields=relfunder&fields=sdg&fields=country&fields=resultlanguagename&fields=resulthostingdatasource&fields=community&&type=other&page=0&size=0",
"/resources2/?format=json&refine=true&fields=instancetypename&fields=foslabel&fields=relfunder&fields=sdg&fields=country&fields=resultlanguagename&fields=resulthostingdatasource&fields=community&&fq=resultbestaccessright%20exact%20%22Open%20Access%22&type=results&page=0&size=0",
"/resources2/?format=json&refine=true&fields=instancetypename&fields=foslabel&fields=relfunder&fields=sdg&fields=country&fields=resultlanguagename&fields=resulthostingdatasource&fields=community&&fq=resultbestaccessright exact \"Open Access\"&type=results&page=0&size=0",
"/resources2/?format=json&refine=true&fields=funder&fields=projectoamandatepublications&fields=projectstartyear&fields=projectendyear&&type=projects&page=0&size=0",
[Eosc Explore]: Updated some styles | Replaced "datasourcetypeuiname" field with "eoscdatasourcetype" | Do not add hardcoded compatibility label "Not yet registered" | Bug fix in Access filter 1. styles.less: Renamed from styles.css and added imports of less files and portal-custom.css (to be updated). 2. angular.json: In styles configuration added styles.less. 3. index.html & beta/index.html: In beta badge, used background instead of background-color to css rules. 4. portal-custom.css: Added rule for .search-form to inherit color in background. 5. searchFields.ts: a. Replaced "datasourcetypeuiname" field with "eoscdatasourcetype" for datasources refine filter "Type". b. In method "getResultAdvancedFields()" return always RESULT_ADVANCED_FIELDS without excluding "eoscifguidelines". 6. datasourcesHelper.class.ts: Replaced "datasourcetypeuiname" field with "eoscdatasourcetype" for datasources queries and used updated type names "Research Entity Registry" (old "Registry") and "Journal Archive" (old "Journal archive"). 7. cache-interceptor.service.ts: Updated cachingRequests array, using new "eoscdatasourcetype" and its values. 8. dataProvider.component.html && result-preview.component.html: Do not add hardcoded compatibility label "Not yet registered" and updated checks. 9. resultLanding.service.ts & parsingFunctions.class.ts: Parse resultLandingInfo.eoscSubjects only by "eoscifguidelines" field not "subjects". 10. searchFilter.component.ts: [Bug fix] In Access filter, fixed bug in view all, when clearing the preselected value. * Do not forget to add in package.json in devDependencies, "@types/express-serve-static-core": "4.17.28"
2022-09-30 13:51:00 +02:00
"/resources2/?format=json&refine=true&fields=eoscdatasourcetype&fields=datasourceodlanguages&fields=datasourceodcontenttypes&fields=datasourcecompatibilityname&fields=country&fields=collectedfromname&fields=datasourcethematic&fields=datasourcejurisdiction&&type=datasources&page=0&size=0",
// "/resources2/?format=json&query= ( (reldatasourcecompatibilityid exact driver or reldatasourcecompatibilityid exact driver-openaire2.0 or reldatasourcecompatibilityid exact openaire2.0 or reldatasourcecompatibilityid exact openaire3.0 or reldatasourcecompatibilityid exact openaire4.0 or reldatasourcecompatibilityid exact openaire-cris_1.1 or reldatasourcecompatibilityid exact openaire2.0_data or reldatasourcecompatibilityid exact hostedBy or relproject=*) ) &refine=true&fields=country&&type=organizations&page=0&size=0",
"/resources2/?format=json&refine=true&fields=country&&type=organizations&fq=(reldatasourcecompatibilityid exact driver or reldatasourcecompatibilityid exact driver-openaire2.0 or reldatasourcecompatibilityid exact openaire2.0 or reldatasourcecompatibilityid exact openaire3.0 or reldatasourcecompatibilityid exact openaire4.0 or reldatasourcecompatibilityid exact openaire-cris_1.1 or reldatasourcecompatibilityid exact openaire2.0_data or reldatasourcecompatibilityid exact hostedBy or relproject=*)&page=0&size=0&minRef=true",
"/resources2/?format=json&size=0&type=organizations&fq=(reldatasourcecompatibilityid exact driver or reldatasourcecompatibilityid exact driver-openaire2.0 or reldatasourcecompatibilityid exact openaire2.0 or reldatasourcecompatibilityid exact openaire3.0 or reldatasourcecompatibilityid exact openaire4.0 or reldatasourcecompatibilityid exact openaire-cris_1.1 or reldatasourcecompatibilityid exact openaire2.0_data or reldatasourcecompatibilityid exact hostedBy or relproject=*)",
// "/projects/?format=json&refine=true&page=1&size=0&fields=funder",
"/projects/?fields=funder&sf=funder&format=json&size=0",
"/results/?fields=relfunder&sf=relfunder&format=json&size=0",
[Eosc Explore]: Updated some styles | Replaced "datasourcetypeuiname" field with "eoscdatasourcetype" | Do not add hardcoded compatibility label "Not yet registered" | Bug fix in Access filter 1. styles.less: Renamed from styles.css and added imports of less files and portal-custom.css (to be updated). 2. angular.json: In styles configuration added styles.less. 3. index.html & beta/index.html: In beta badge, used background instead of background-color to css rules. 4. portal-custom.css: Added rule for .search-form to inherit color in background. 5. searchFields.ts: a. Replaced "datasourcetypeuiname" field with "eoscdatasourcetype" for datasources refine filter "Type". b. In method "getResultAdvancedFields()" return always RESULT_ADVANCED_FIELDS without excluding "eoscifguidelines". 6. datasourcesHelper.class.ts: Replaced "datasourcetypeuiname" field with "eoscdatasourcetype" for datasources queries and used updated type names "Research Entity Registry" (old "Registry") and "Journal Archive" (old "Journal archive"). 7. cache-interceptor.service.ts: Updated cachingRequests array, using new "eoscdatasourcetype" and its values. 8. dataProvider.component.html && result-preview.component.html: Do not add hardcoded compatibility label "Not yet registered" and updated checks. 9. resultLanding.service.ts & parsingFunctions.class.ts: Parse resultLandingInfo.eoscSubjects only by "eoscifguidelines" field not "subjects". 10. searchFilter.component.ts: [Bug fix] In Access filter, fixed bug in view all, when clearing the preselected value. * Do not forget to add in package.json in devDependencies, "@types/express-serve-static-core": "4.17.28"
2022-09-30 13:51:00 +02:00
"/resources/?format=json&query=( oaftype exact datasource and (eoscdatasourcetype exact \"Journal Archive\" or eoscdatasourcetype exact \"Repository\"))&refine=true&fields=datasourcetypename&fields=country&fields=datasourceodsubjects&fields=datasourceodcontenttypes&fields=datasourcecompatibilityname&fields=datasourcethematic&fields=datasourcejurisdiction&&type=datasources&page=0&size=0",
"/search/v2/api/datasources/count?format=json", "/search/v2/api/publications/count?format=json", "/search/v2/api/datasets/count?format=json", "/search/v2/api/software/count?format=json", "/search/v2/api/other/count?format=json",
"relresulttype%3Dpublication",
"/resources2/?format=json&size=0&type=projects",
"/resources2/?format=json&size=0&type=datasources",
"/resources2/?format=json&size=0&type=results",
"/resources2/?format=json&size=0&type=results&fq=resultbestaccessright%20exact%20%22Open%20Access%22"
];
constructor(private transferState: TransferState, @Inject(PLATFORM_ID) private platformId: any) {}
public intercept(request: HttpRequest<any>, next: HttpHandler): any {
// console.debug(new Date());
if(this.checkForCachedRequests(request.url)) {
const dupReq = request.clone({url: properties.cacheUrl + encodeURIComponent(request.url)});
return next.handle(dupReq);
} else {
return next.handle(request);
}
}
public checkForCachedRequests(url){
[Library | explore-redesign]: Fixes on FoS and SDGs suggest modal (checked existing subjects, added loading) - In FoS fixed scrolling, search and final response of selected fields. 1. composer.ts & resultLanding.component.ts: Removed "and Technology" from "Fields of Science" typename. 2. resultLanding.component.html: Bind (suggestClicked) to <fos> instead of (feedbackClicked). 3. input.component.ts: [Bug fix] Added check in "filter()" method if option.label. 4. sdg-selection.component.ts: [Bug fix] Set this.loading = false; inside subscribe. 5. fos.component.ts: In title, updated FOS to FoS. 6. sdg-fos-suggest.module.ts: Imported LoadingModule. 7. sdg-fos-suggest.component.ts: Show loading when sending email | Do not initialize <sdg-selection> and <fos-selection> before subjects have value (this way inputs of existing fos/sdgs are checked). 8. fos-selection.component.ts: a. Added @Input() inModal: boolean = false; to set activeSection, when inModal, instead of navigating with fragment. b. [Bug fix] Set this.loading = false; inside subscribe. c. Call this.setObserver(); both in ngOnInit and when keyword changes. d. Updated threshold of observer from 0.25 to 0.1 (large FoS categories were never triggered on scrolling, because less than 25% of their content was visible). e. Updated fosOptions to Map<string, boolean> to track easily checked inputs and updated getSelectedSubjects() accordingly. 9. fos-selection.component.html: In search-input of keyword no options are needed | Updated ngModel of checkbox inputs. 10. cache-interceptor.service.ts: Added check if (!properties.useLongCache) to skip cache.
2023-02-20 19:54:26 +01:00
// Do not call cache when it is not enabled at all.
// This property is not correctly used here. A new property should be introduced. For now it is ok.
if (!properties.useLongCache) {
return false;
}
if(url.indexOf("sf=") !== -1 || url.indexOf("refine=true") !== -1 || url.indexOf("/count?format=json") !== -1 || url.indexOf("relresulttype%3Dpublication") !== -1 ||
(url.indexOf("?format=json&size=0&type=") !== -1 && url.indexOf("query=") == -1)) {
return this.cachingRequests.some(partUrl => (url.indexOf(partUrl) !== -1));
}
return false;
}
}