[ develop | DONE | ADDED] Utils servise: add a method to get counts for results, use the same method in /explore/home
This commit is contained in:
parent
178846353c
commit
c81c6196c0
|
@ -104,10 +104,7 @@ app.get('/explore/home', async function (req, res) {
|
|||
try {
|
||||
// Make requests to multiple APIs
|
||||
let requests= [
|
||||
searchServiceAPIUrl + 'publications/count?format=json',
|
||||
searchServiceAPIUrl + 'datasets/count?format=json',
|
||||
searchServiceAPIUrl + 'software/count?format=json',
|
||||
searchServiceAPIUrl + 'other/count?format=json',
|
||||
"http://localhost:" + properties.get('port') + "/portals/countResults",
|
||||
searchServiceAPIUrl +'results/?fields=relfunder&sf=relfunder&format=json&size=0',
|
||||
searchServiceAPIUrl + 'datasources/count?format=json',
|
||||
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=*)',
|
||||
|
@ -121,26 +118,24 @@ app.get('/explore/home', async function (req, res) {
|
|||
const allRequestsSuccessful = dataResponses.every((response) => response.status === 200);
|
||||
// Combine the data
|
||||
const aggregatedData = {
|
||||
publications: dataResponses[0].data.total,
|
||||
datasets: dataResponses[1].data.total,
|
||||
software: dataResponses[2].data.total,
|
||||
other: dataResponses[3].data.total,
|
||||
results: dataResponses[4].data.meta.total,
|
||||
/*resultFunders:resultRES.data.refineResults.relfunder.length,*/
|
||||
datasources: dataResponses[5].data.total,
|
||||
organizations: dataResponses[6].data.meta.total,
|
||||
projects:dataResponses[7].data.meta.total,
|
||||
/*projectFunders:projectsRES.data.refineResults.funder.length,*/
|
||||
funders: parseNoOfFunders(dataResponses[4].data, dataResponses[7].data),
|
||||
datasetsInterlinked:dataResponses[8].data.meta.total,
|
||||
softwareInterlinked:dataResponses[9].data.meta.total,
|
||||
publications: dataResponses[0].data.publications,
|
||||
datasets: dataResponses[0].data.datasets,
|
||||
software: dataResponses[0].data.software,
|
||||
other: dataResponses[0].data.other,
|
||||
results: dataResponses[1].data.meta.total,
|
||||
datasources: dataResponses[2].data.total,
|
||||
organizations: dataResponses[3].data.meta.total,
|
||||
projects:dataResponses[4].data.meta.total,
|
||||
funders: parseNoOfFunders(dataResponses[1].data, dataResponses[4].data),
|
||||
datasetsInterlinked:dataResponses[5].data.meta.total,
|
||||
softwareInterlinked:dataResponses[6].data.meta.total,
|
||||
success:allRequestsSuccessful
|
||||
|
||||
};
|
||||
// Send the aggregated data as the response
|
||||
res.status(allRequestsSuccessful?200:207).json(aggregatedData);
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error.message);
|
||||
console.error('Error fetching data:', error);
|
||||
res.status(500).send('Internal Server Error');
|
||||
}
|
||||
});
|
||||
|
@ -178,6 +173,47 @@ app.get('/explore/search', async function (req, res) {
|
|||
}
|
||||
});
|
||||
|
||||
app.get('/portals/countResults', async function (req, res) {
|
||||
const field = req.query.field;
|
||||
let allowedFields = ["communityid"];
|
||||
if(field && allowedFields.indexOf(field) ==-1){
|
||||
res.status(405).send('Not allowed request');
|
||||
return;
|
||||
}
|
||||
const value = req.query.value;
|
||||
const params = field && value?(encodeURI("&fq=" + field + "=" + value)):"";
|
||||
let aggregatedData = {};
|
||||
|
||||
try {
|
||||
// Make requests to multiple APIs
|
||||
let requests= [
|
||||
searchServiceAPIUrl +'publications/count?format=json' + params,
|
||||
searchServiceAPIUrl +'datasets/count?format=json' + params,
|
||||
searchServiceAPIUrl +'software/count?format=json' + params,
|
||||
searchServiceAPIUrl +'other/count?format=json' + params
|
||||
]
|
||||
const dataPromises = requests.map((url) => axios.get( url));
|
||||
const dataResponses = await Promise.all(dataPromises);
|
||||
// Determine if all additional requests were successful
|
||||
const allRequestsSuccessful = dataResponses.every((response) => response.status === 200);
|
||||
// Combine the data
|
||||
aggregatedData = {
|
||||
publications: dataResponses[0].data.total,
|
||||
datasets: dataResponses[1].data.total,
|
||||
software: dataResponses[2].data.total,
|
||||
other:dataResponses[3].data.total,
|
||||
success:allRequestsSuccessful
|
||||
|
||||
};
|
||||
|
||||
// Send the aggregated data as the response
|
||||
res.status(allRequestsSuccessful?200:207).json(aggregatedData);
|
||||
} catch (error) {
|
||||
console.log(aggregatedData)
|
||||
console.error('Error fetching data:', error);
|
||||
res.status(500).send('Internal Server Error');
|
||||
}
|
||||
});
|
||||
app.get('/explore/funders', async function (req, res) {
|
||||
let aggregatedData = {};
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue