Skip to content

Commit 76bdd1f

Browse files
committed
new endpoint: project/<id>/versions
1 parent 95aaffd commit 76bdd1f

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

‎src/docs/description.yml‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,62 @@ paths:
13461346
example: >
13471347
No example is provided since each analysis is different. Look at the schemas
13481348
1349+
/projects/{projectAccessionOrID}/versions:
1350+
get:
1351+
summary: Get the versions of all data in a project.
1352+
description: >
1353+
Get the versions of the project metadata, every MD metadata and every analysis in a specific $DATABASE project.
1354+
Versions of all MDs are returned, even if a specific MD is requested.
1355+
References are not included. Missing versions are returned as null.
1356+
parameters:
1357+
- $ref: '#/definitions/arguments/projectAccessionOrID'
1358+
tags:
1359+
- projects
1360+
responses:
1361+
200:
1362+
description: an object containing data versions
1363+
content:
1364+
application/json:
1365+
schema:
1366+
type: object
1367+
properties:
1368+
metadata:
1369+
type: string
1370+
nullable: true
1371+
description: Project metadata version
1372+
analyses:
1373+
type: object
1374+
description: Versions of project-wide analyses, by analysis name
1375+
additionalProperties:
1376+
type: string
1377+
nullable: true
1378+
mds:
1379+
type: array
1380+
items:
1381+
type: object
1382+
properties:
1383+
name:
1384+
type: string
1385+
metadata:
1386+
type: string
1387+
nullable: true
1388+
description: MD metadata version
1389+
analyses:
1390+
type: object
1391+
description: Versions of MD analyses, by analysis name
1392+
additionalProperties:
1393+
type: string
1394+
nullable: true
1395+
example:
1396+
metadata: '0.0.7'
1397+
analyses: {}
1398+
mds:
1399+
- name: replica 1
1400+
metadata: null
1401+
analyses:
1402+
rmsds: '1.0.0'
1403+
fluctuation: '0.1.0'
1404+
13491405
/nodes:
13501406
get:
13511407
summary: Get a list of available nodes.

‎src/routes/projects/index.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ localRouter.use('/:project/references', require('./references'));
260260
localRouter.use('/:project/inputs', require('./inputs'));
261261
// Topology
262262
localRouter.use('/:project/topology', require('./topology'));
263+
// Versions
264+
localRouter.use('/:project/versions', require('./versions'));
263265

264266
// If we are using the global API then any further query is mapped to the corresponding database
265267
// Set a handler to be used for both GET and POST methods
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const Router = require('express').Router;
2+
// A standard request and response handler used widely in most endpoints
3+
const handler = require('../../../utils/generic-handler');
4+
// Get the database handler
5+
const getDatabase = require('../../../database');
6+
7+
const router = Router({ mergeParams: true });
8+
9+
// Get the versions of all data related to the requested project (references excluded)
10+
// This includes the project metadata, every MD metadata and every analysis
11+
router.route('/').get(
12+
handler({
13+
async retriever(request) {
14+
// Stablish database connection and retrieve our custom handler
15+
const database = await getDatabase(request);
16+
// Get raw project data, which includes all MDs
17+
// Note that the MD number in the request (if any) is ignored since we return versions for all MDs
18+
const projectData = await database.getRawProjectData(
19+
{ 'metadata.ver': true, 'mds.name': true, 'mds.ver': true });
20+
// If something went wrong then return the error
21+
if (projectData.error) return projectData;
22+
// Get the version of every analysis, but not the analysis data itself
23+
const cursor = await database.analyses.find(
24+
{ project: projectData._id },
25+
{ projection: { _id: false, name: true, md: true, 'value.version': true } },
26+
);
27+
const analyses = await cursor.toArray();
28+
// Set the versions of project-wide analyses (i.e. those with no MD)
29+
const projectAnalyses = {};
30+
// Set the versions of every MD, including its analyses
31+
const mds = (projectData.mds || []).map(md => ({
32+
name: md.name,
33+
metadata: md.ver || null,
34+
analyses: {},
35+
}));
36+
analyses.forEach(analysis => {
37+
const version = (analysis.value && analysis.value.version) || null;
38+
if (analysis.md === undefined || analysis.md === null)
39+
projectAnalyses[analysis.name] = version;
40+
// MDs may have been removed while their analyses remain, so make sure the MD exists
41+
else if (mds[analysis.md]) mds[analysis.md].analyses[analysis.name] = version;
42+
});
43+
return {
44+
metadata: (projectData.metadata && projectData.metadata.ver) || null,
45+
analyses: projectAnalyses,
46+
mds,
47+
};
48+
}
49+
}),
50+
);
51+
52+
module.exports = router;

0 commit comments

Comments
 (0)