Merge remote-tracking branch 'origin/develop'

This commit is contained in:
Konstantina Galouni 2024-07-23 11:24:11 +03:00
commit a1ec284c63
5 changed files with 90 additions and 35 deletions

View File

@ -75,7 +75,7 @@
</ng-container>
<ng-container *ngIf="!showLoading && funders?.length">
<div class="uk-container uk-container-large">
<div id="target" class="uk-section uk-padding-remove-top uk-margin-top" uk-height-match="target: .alias;">
<div id="target" class="uk-section uk-padding-remove-top uk-margin-top" uk-height-match="target: .shortName;">
<div>
<div *ngIf="funders" class="uk-padding-small uk-padding-remove-vertical uk-margin-medium-bottom uk-flex uk-flex-wrap uk-flex-middle uk-flex-between">
<div class="uk-flex uk-flex-wrap uk-flex-middle uk-flex-between uk-width-auto@m uk-width-1-1 uk-margin-top">
@ -145,10 +145,10 @@
</ng-template>
</div>
<div class="uk-padding-small uk-padding-remove-vertical uk-padding-remove-left uk-margin-medium-left">
<!-- alias -->
<div class="alias uk-text-uppercase uk-text-small uk-margin-top type">
<ng-container *ngIf="funder.alias">
{{funder.alias}}
<!-- shortName -->
<div class="shortName uk-text-uppercase uk-text-small uk-margin-top type">
<ng-container *ngIf="funder.shortName">
{{funder.shortName}}
</ng-container>
</div>
<div class="uk-flex">
@ -243,9 +243,9 @@
<ng-container *ngIf="funder.name">
<span>{{funder.name}}</span>
</ng-container>
<ng-container *ngIf="funder.alias" >
<ng-container *ngIf="funder.shortName" >
<span class="uk-text-uppercase">
({{funder.alias}})
({{funder.shortName}})
</span>
</ng-container>
</div>

View File

@ -54,6 +54,7 @@ export class FundersComponent implements OnInit {
fundersMap = new Map<string, {
"id": string,
"name": string,
"shortName": string,
"alias": string,
"researchProducts": number,
"openAccessResearchProducts": number,
@ -67,19 +68,19 @@ export class FundersComponent implements OnInit {
"registered": boolean
}>();
staticLogos: Map<string, string> = new Map<string, string>([
["arc_________::ARC", "ARC"],
["asap________::ASAP", "ASAP"],
["cihr________::CIHR", "CIHR"],
["euenvagency_::EEA", "EEA"],
["inca________::INCA", "INCa"],
["nhmrc_______::NHMRC", "NHMRC"],
["nih_________::NIH", "NIH"],
["nserc_______::NSERC", "NSERC"],
["nsf_________::NSF", "NSF"],
["sshrc_______::SSHRC", "SSHRC"],
["taraexp_____::tara", "TARA"],
["ukri________::UKRI", "UKRI"],
["wt__________::WT", "WT"]
["arc_________::ARC||Australian Research Council (ARC)||ARC", "ARC"],
["asap________::ASAP||Aligning Science Across Parkinson's||ASAP", "ASAP"],
["cihr________::CIHR||Canadian Institutes of Health Research||CIHR", "CIHR"],
["euenvagency_::EEA||European Environment Agency||EEA", "EEA"],
["inca________::INCA||Institut National du Cancer||INCa", "INCa"],
["nhmrc_______::NHMRC||National Health and Medical Research Council (NHMRC)||NHMRC", "NHMRC"],
["nih_________::NIH||National Institutes of Health||NIH", "NIH"],
["nserc_______::NSERC||Natural Sciences and Engineering Research Council of Canada||NSERC", "NSERC"],
["nsf_________::NSF||National Science Foundation||NSF", "NSF"],
["sshrc_______::SSHRC||Social Sciences and Humanities Research Council||SSHRC", "SSHRC"],
["taraexp_____::tara||Tara Expeditions Foundation||TARA", "TARA"],
["ukri________::UKRI||UK Research and Innovation||UKRI", "UKRI"],
["wt__________::WT||Wellcome Trust||WT", "WT"]
]);
constructor(private router: Router,
@ -160,6 +161,7 @@ export class FundersComponent implements OnInit {
let funder = {
"id": id,
"name": this.removePartAfterCharacters(queriedFunder.name, "||"),
"shortName": queriedFunder.shortName,
"alias": '',
"researchProducts": +queriedFunder.results,
"openAccessResearchProducts": +queriedFunder.openResults,
@ -180,6 +182,9 @@ export class FundersComponent implements OnInit {
if(queriedFunder.stakeholder) {
let stakeholder = queriedFunder.stakeholder;
funder.alias = stakeholder.alias;
if(!funder.shortName) {
funder.shortName = stakeholder.alias;
}
funder.monitorDashboard = stakeholder.alias;
funder.monitorDashboardStatus = stakeholder.visibility;
if(stakeholder.logoUrl) {

View File

@ -11,6 +11,7 @@ const PropertiesReader = require('properties-reader');
const properties = PropertiesReader('./properties.file');
const environment = properties.get("environment");
const preloadRequests = properties.get("preloadRequests").split(',');;
var accesslog = require('access-log');
const cacheMaxSize = 1000;
let cors = require('cors');
@ -84,10 +85,11 @@ let cache = () => {
}
};
accesslogCustomFormat(req, res);
next();
}
} else {
accesslogCustomFormat(req, res);
next();
}
};
@ -105,7 +107,7 @@ app.get('/clear', (req, res) => {
const url = req.query.url;
let message = "";
if (url) {
let key = '__express__' + req.query.url;
let key = req.query.url;
lruCache.delete(key);
message = "Delete entry with key " + url;
entries.set(lruCache.size);
@ -117,15 +119,18 @@ app.get('/clear', (req, res) => {
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
res.header("Content-Type", "application/json");
accesslogCustomFormat(req, res);
res.status(200).send(getResponse(200, message));
});
app.get('/metrics', (req, res) => {
res.set('Content-Type', register.contentType);
accesslogCustomFormat(req, res);
res.end(register.metrics());
});
app.get('/info', (req, res) => {
accesslogCustomFormat(req, res);
res.status(200).send(getResponse(200, {size:lruCache.size, keys: Array.from(lruCache.keys())}));
});
@ -210,3 +215,19 @@ function resetAtMidnight() {
resetAtMidnight(); // Then, reset again next midnight.
}, msToMidnight);
}
function accesslogCustomFormat(req, res){
// default format
accesslog(req, res);
// ::ffff:195.134.66.178 - - [15/Jul/2024:11:24:35 +0300] "GET /clear HTTP/1.1" 200 59 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0"
//custom format
/*
accesslog(req, res,
{
userID: function (req) { return req.user; },
format : 'url=":url" method=":method" statusCode=":statusCode" delta=":delta" ip=":ip"'
});
*/
// url="/clear" method="GET" statusCode="200" delta="2" ip="::ffff:195.134.66.178"
}

View File

@ -1,6 +1,6 @@
{
"name": "memcache-cache",
"version": "1.0.0",
"version": "2.0.0",
"description": "Caching in memory",
"main": "cache.js",
"scripts": {
@ -10,6 +10,7 @@
"prepare-prod": " npm run prepare-dist; cp production-properties.file ./dist/properties.file"
},
"dependencies": {
"access-log": "^0.4.1",
"axios": "^1.6.7",
"compression": "^1.7.4",
"cors": "^2.8.5",

View File

@ -234,51 +234,79 @@ app.get('/explore/funders', async function (req, res) {
let resultsFunders = dataResponses[0].data.refineResults.relfunder;
resultsFunders.forEach(queriedFunder => {
let id = queriedFunder.id.split("||")[0];
let id = queriedFunder.id;
let name = queriedFunder.name.split("||");
if (!fundersMap.has(id)) {
fundersMap.set(id,{name: queriedFunder.name.split("||")[0], id: id, results:queriedFunder.count, openResults: null, projects:null, stakeholder:null});
fundersMap.set(id,{name: name?.length>0 ? name[0] : "", shortName: name?.length>1 ? name[1] : "", id: id, results:queriedFunder.count, openResults: null, projects:null, stakeholder:null});
}
});
let openResultsFunders = dataResponses[1].data.refineResults.relfunder;
openResultsFunders.forEach(queriedFunder => {
let id = queriedFunder.id.split("||")[0];
let id = queriedFunder.id;
let name = queriedFunder.name.split("||");
if (!fundersMap.has(id)) {
fundersMap.set(id,{name: queriedFunder.name.split("||")[0], id: id, results:null, openResults: queriedFunder.count, projects:null, stakeholder:null});
fundersMap.set(id,{name: name?.length>0 ? name[0] : "", shortName: name?.length>1 ? name[1] : "", id: id, results:null, openResults: queriedFunder.count, projects:null, stakeholder:null});
}else{
fundersMap.get(id).openResults = queriedFunder.count;
}
});
let projectFunders = dataResponses[2].data.refineResults.funder;
projectFunders.forEach(queriedFunder => {
let id = queriedFunder.id.split("||")[0];
let id = queriedFunder.id;
let name = queriedFunder.name.split("||");
if (!fundersMap.has(id) ) {
fundersMap.set(id,{name: queriedFunder.name.split("||")[0], id: id, results:null, openResults: null, projects:queriedFunder.count, stakeholder:null});
fundersMap.set(id,{name: name?.length>0 ? name[0] : "", shortName: name?.length>1 ? name[1] : "", id: id, results:null, openResults: null, projects:queriedFunder.count, stakeholder:null});
}else{
fundersMap.get(id).projects = queriedFunder.count;
}
});
let stakeholders = dataResponses[3].data;
stakeholders.forEach(stakeholder => {
let id = stakeholder.index_id;// + "||" + stakeholder.index_name + "||" + stakeholder.index_shortName;
if (fundersMap.has(id)) {
let ministakeholder = {id:id, name:stakeholder.name, alias: stakeholder.alias, visibility: stakeholder.visibility,
let id = stakeholder.index_id + "||" + stakeholder.index_name + "||" + stakeholder.index_shortName;
if (fundersMap.has(id) && (!fundersMap.get(id).stakeholder || (fundersMap.get(id).name === stakeholder.name) || (fundersMap.get(id).shortName === stakeholder.index_shortName))) {
let ministakeholder = {
id:id, name:stakeholder.name,
alias: stakeholder.alias, visibility: stakeholder.visibility,
logoUrl:stakeholder.logoUrl, isUpload: stakeholder.isUpload, websiteUrl: null}
fundersMap.get(id).stakeholder = ministakeholder;
if(!fundersMap.get(id).shortName) {
fundersMap.get(id).shortName = stakeholder.index_shortName;
}
}
});
let funders = dataResponses[4].data;
funders.forEach(funder => {
if (fundersMap.has(funder.id)) {
let storedFunder = fundersMap.get(funder.id);
// let id = funder.id + "||" + (funder.legalName ? (funder.legalName + "||" + (funder.legalShortName ? funder.legalShortName : "")) : "");
// if (fundersMap.has(id)) {
// let storedFunder = fundersMap.get(id);
let storedFunder = null;
fundersMap.forEach((value, key, map) => {
if(key.split("||")[0] === funder.id) {
storedFunder = value;
}
})
if (storedFunder) {
// if(funder.legalName && storedFunder.name && funder.legalName != storedFunder.name) {
// console.log("Diffrent name!!! index: "+storedFunder.name + " vs funders API: "+funder.legalName);
// }
if(funder.legalName) {
storedFunder.name = funder.legalName;
}
storedFunder.country = funder.country;
storedFunder.registered = funder.registered;
if(!storedFunder.shortName) {
storedFunder.shortName = funder.legalShortName;
}
let storedStakeholder = storedFunder.stakeholder;
// if(funder.legalShortName && storedFunder.shortName && funder.legalShortName != storedFunder.shortName) {
// console.log("Diffrent short name!!! index: "+storedFunder.shortName + " vs funders API: "+funder.legalShortName);
// }
let ministakeholder = {
id:funder.id, name:storedStakeholder?.name, alias: storedStakeholder?.alias ? storedStakeholder.alias : funder.legalShortName,
id:storedFunder.id, name:storedStakeholder?.name, alias: storedStakeholder?.alias ? storedStakeholder.alias : funder.legalShortName,
websiteUrl: funder.websiteUrl, logoUrl: storedStakeholder?.logoUrl ? storedStakeholder.logoUrl : funder.logoUrl,
visibility: storedStakeholder?.visibility, isUpload: storedStakeholder?.isUpload
};