[ develop | DONE | ADDED] Utils services: group common requests in a single request
This commit is contained in:
parent
109be1c6f6
commit
a9d06e61fa
|
@ -1,4 +1,5 @@
|
|||
userInfoUrl = https://beta.services.openaire.eu/login-service/userInfo
|
||||
searchServiceAPIUrl = https://beta.services.openaire.eu/search/v2/api/
|
||||
ssl = true
|
||||
localPath = false
|
||||
# photo size in KB
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.6.7",
|
||||
"body-parser": "^1.20.2",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"cors": "^2.8.5",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
userInfoUrl = https://services.openaire.eu/login-service/userInfo
|
||||
searchServiceAPIUrl = https://services.openaire.eu/search/v2/api/
|
||||
ssl = true
|
||||
localPath = false
|
||||
# photo size in KB
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
userInfoUrl = http://mpagasas.di.uoa.gr:19080/login-service/userInfo
|
||||
searchServiceAPIUrl = https://beta.services.openaire.eu/search/v2/api/
|
||||
ssl = false
|
||||
localPath = true
|
||||
# photo size in KB
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const axios = require('axios');
|
||||
var express = require("express");
|
||||
var bodyParser = require("body-parser");
|
||||
var cookieParser = require('cookie-parser');
|
||||
|
@ -12,6 +13,7 @@ if (properties.get('ssl')) {
|
|||
} else {
|
||||
http = require("http");
|
||||
}
|
||||
var searchServiceAPIUrl = properties.get('searchServiceAPIUrl');
|
||||
var auth = properties.get('userInfoUrl');
|
||||
/** @deprecated*/
|
||||
var authDeprecated = auth.includes("accessToken");
|
||||
|
@ -97,6 +99,97 @@ app.delete(['/delete/:filename', '/delete/stakeholder/:filename', '/delete/:type
|
|||
});
|
||||
});
|
||||
|
||||
app.get('/explore/home', async function (req, res) {
|
||||
try {
|
||||
// Make requests to multiple APIs
|
||||
const publicationsRES = await axios.get(searchServiceAPIUrl + 'publications/count?format=json');
|
||||
const datasetsRES = await axios.get(searchServiceAPIUrl + 'datasets/count?format=json');
|
||||
const softwareRES = await axios.get(searchServiceAPIUrl + 'software/count?format=json');
|
||||
const otherRES = await axios.get(searchServiceAPIUrl + 'other/count?format=json');
|
||||
const resultRES = await axios.get(searchServiceAPIUrl +'results/?fields=relfunder&sf=relfunder&format=json&size=0');
|
||||
const datasourcesRES = await axios.get(searchServiceAPIUrl + 'datasources/count?format=json');
|
||||
const organizationsRES = await axios.get(searchServiceAPIUrl + '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=*)');
|
||||
const projectsRES = await axios.get(searchServiceAPIUrl + 'projects/?fields=funder&sf=funder&format=json&size=0');
|
||||
const datasetsInterlinkedRES = await axios.get(searchServiceAPIUrl + 'resources?query=(%20(oaftype%20exact%20result)%20and%20(resulttypeid%20exact%20dataset)%20and%20(relresulttype%3Dpublication)%20%20)&page=0&size=0&format=json');
|
||||
const softwareInterlinkedRES = await axios.get(searchServiceAPIUrl + 'resources?query=(%20(oaftype%20exact%20result)%20and%20(resulttypeid%20exact%20software)%20and%20(relresulttype%3Dpublication)%20%20)&page=0&size=0&format=json');
|
||||
|
||||
// Combine the data
|
||||
const aggregatedData = {
|
||||
publications: publicationsRES.data.total,
|
||||
datasets: datasetsRES.data.total,
|
||||
software: softwareRES.data.total,
|
||||
other: otherRES.data.total,
|
||||
results: resultRES.data.meta.total,
|
||||
/*resultFunders:resultRES.data.refineResults.relfunder.length,*/
|
||||
datasources: datasourcesRES.data.total,
|
||||
organizations: organizationsRES.data.meta.total?organizationsRES.data.meta.total:'--',
|
||||
projects:projectsRES.data.meta.total,
|
||||
/*projectFunders:projectsRES.data.refineResults.funder.length,*/
|
||||
funders: parseNoOfFunders(resultRES, projectsRES),
|
||||
datasetsInterlinked:datasetsInterlinkedRES.data.meta.total,
|
||||
softwareInterlinked:softwareInterlinkedRES.data.meta.total,
|
||||
|
||||
};
|
||||
|
||||
// Send the aggregated data as the response
|
||||
res.json(aggregatedData);
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error.message);
|
||||
res.status(500).send('Internal Server Error');
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/explore/search', async function (req, res) {
|
||||
try {
|
||||
// Make requests to multiple APIs
|
||||
const resultRES = await axios.get(searchServiceAPIUrl +'resources2/?format=json&size=0&type=results&fq=resultbestaccessright%20exact%20%22Open%20Access%22');
|
||||
const datasourcesRES = await axios.get(searchServiceAPIUrl + 'datasources/count?format=json');
|
||||
const organizationsRES = await axios.get(searchServiceAPIUrl + '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=*)');
|
||||
const projectsRES = await axios.get(searchServiceAPIUrl + 'projects/count?format=json');
|
||||
|
||||
// Combine the data
|
||||
const aggregatedData = {
|
||||
results: resultRES.data.meta.total,
|
||||
datasources: datasourcesRES.data.total,
|
||||
organizations: organizationsRES.data.meta.total?organizationsRES.data.meta.total:'--',
|
||||
projects:projectsRES.data.total
|
||||
|
||||
};
|
||||
|
||||
// Send the aggregated data as the response
|
||||
res.json(aggregatedData);
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error.message);
|
||||
res.status(500).send('Internal Server Error');
|
||||
}
|
||||
});
|
||||
app.get('/grouped-requests', async function (req, res) {
|
||||
res.json([
|
||||
"/explore/search",
|
||||
"/explore/home"
|
||||
]);
|
||||
});
|
||||
function parseNoOfFunders(resultRES, projectsRES){
|
||||
// combines the refines qeries on funders field, the funders with results and the funders that have at least one project
|
||||
let mergedFundersSet = new Set();
|
||||
let queriedFunders = resultRES.data.refineResults.relfunder;
|
||||
queriedFunders.forEach(queriedFunder => {
|
||||
if (!mergedFundersSet.has(queriedFunder.id)) {
|
||||
mergedFundersSet.add(queriedFunder.id);
|
||||
}
|
||||
});
|
||||
queriedFunders = projectsRES.data.refineResults.funder;
|
||||
queriedFunders.forEach(queriedFunder => {
|
||||
if(+queriedFunder.count > 1) {
|
||||
if (!mergedFundersSet.has(queriedFunder.id)) {
|
||||
mergedFundersSet.add(queriedFunder.id);
|
||||
}
|
||||
}
|
||||
});
|
||||
return mergedFundersSet.size;
|
||||
}
|
||||
|
||||
|
||||
const server = app.listen(properties.get('port'), function () {
|
||||
console.log("Listening on port %s...", server.address().port);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue