From 2b68ead03059ae0c9af719820679ff25ebb2d30a Mon Sep 17 00:00:00 2001 From: Tony Espley Date: Wed, 10 Jun 2020 20:12:57 +0100 Subject: [PATCH] IG-82 - Metadata quality report --- src/config/server.js | 3 +- .../dataset/dataset.detail.router.js | 34 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/config/server.js b/src/config/server.js index 01af3722..110bfb22 100644 --- a/src/config/server.js +++ b/src/config/server.js @@ -18,8 +18,9 @@ require('dotenv').config(); const API_PORT = process.env.PORT || 3001; const session = require("express-session"); var app = express(); + app.use(cors({ - origin: [process.env.homeURL], + origin: [process.env.homeURL.split(',')], credentials: true })); const router = express.Router(); diff --git a/src/resources/dataset/dataset.detail.router.js b/src/resources/dataset/dataset.detail.router.js index 19c212b3..8d09ddee 100644 --- a/src/resources/dataset/dataset.detail.router.js +++ b/src/resources/dataset/dataset.detail.router.js @@ -8,29 +8,39 @@ const router = express.Router(); // search for additional detail on a dataset by using the MDC dataset id router.get('/:id', async (req, res) => { var metadataCatalogue = process.env.metadataURL || 'https://metadata-catalogue.org/hdruk'; - - axios.get(metadataCatalogue + '/api/facets/' + req.params.id + '/profile/uk.ac.hdrukgateway/HdrUkProfilePluginService') - .then(function (response) { - + var metadataQuality = process.env.metadataQualityURL || 'https://europe-west1-hdruk-gateway.cloudfunctions.net/metadataqualityscore'; + var metadataCatalogueError = ''; + + const reqMetadataCatalogue = axios.get(metadataCatalogue + '/api/facets/' + req.params.id + '/profile/uk.ac.hdrukgateway/HdrUkProfilePluginService').catch(err => {metadataCatalogueError = err.message} ); + const reqMetadataQuality = axios.get(metadataQuality + '/api/v1/' + req.params.id, { timeout:5000 }).catch(err => { console.log('Unable to get metadata quality value'+err.message) }); + + try { + const [resMetadataCatalogue, resMetadataQuality] = await axios.all([reqMetadataCatalogue,reqMetadataQuality]); + var result; + + if (resMetadataQuality) { + resMetadataCatalogue.data.quality = resMetadataQuality.data; + } + if (req.query.id && req.query.id !== null && req.query.id !== 'null') { var p = DataRequestModel.find({ $and: [{ userId: req.query.id }, { dataSetId: req.params.id }]}); p.exec((datarequestErr, datarequest) => { if (datarequestErr) return res.json({ success: false, error: datarequestErr }); - result = res.json({ 'success': true, 'data': response.data, 'datarequest': datarequest }); + result = res.json({ 'success': true, 'data': resMetadataCatalogue.data, 'datarequest': datarequest }); }); } else { - result = res.json({ 'success': true, 'data': response.data, 'datarequest': [] }); + result = res.json({ 'success': true, 'data': resMetadataCatalogue.data, 'datarequest': [] }); } - // handle success + return result; - }) - .catch(function (err) { + } + catch (err) { // handle error - return res.json({ success: false, error: err.message + ' (raw message from metadata catalogue)' }); - }) + return res.json({ success: false, error: metadataCatalogueError + ' (raw message from metadata catalogue)' }); + } }); -module.exports = router; +module.exports = router; \ No newline at end of file