Skip to content

Commit

Permalink
IG-82 - Metadata quality report
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyespley-pa committed Jun 10, 2020
1 parent 0b2787f commit 2b68ead
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
34 changes: 22 additions & 12 deletions src/resources/dataset/dataset.detail.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 2b68ead

Please sign in to comment.