Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions app/lib/database/adapters/DataPassAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/


class DataPassAdapter {
/**
* Converts the given database object to an entity object.
*
* @param {SequelizeDataPass} databaseObject Object to convert.
* @returns {DataPass} Converted entity object.
*/
toEntity(databaseObject) {
const {
id,
name,
description,
reconstructedEvents,
outputSize,
} = databaseObject;

return {
id,
name,
description,
reconstructedEvents,
outputSize,
};
}

/**
* Converts the given entity object to database object.
*
* @param {DataPass} databaseObject Object to convert.
* @returns {SequelizeDataPass} Converted entity object.
*/
toDatabase(entityObject) {
return entityObject;
}
}

module.exports = DataPassAdapter;
5 changes: 4 additions & 1 deletion app/lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

const PeriodAdapter = require('./PeriodAdapter');
const RunAdapter = require('./RunAdapter');
const DataPassAdapter = require('./DataPassAdapter');

const runAdapter = new RunAdapter();
const periodAdapter = new PeriodAdapter;
const periodAdapter = new PeriodAdapter();
const dataPassAdapter = new DataPassAdapter();

module.exports = {
runAdapter,
periodAdapter,
dataPassAdapter,
}
47 changes: 47 additions & 0 deletions app/lib/database/models/DataPass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const Sequelize = require('sequelize');

module.exports = (sequelize) => {
const DataPass = sequelize.define('DataPass', {
name: {
type: Sequelize.STRING,
unique: true,
},
description: {
type: Sequelize.TEXT,
},
reconstructedEvents: {
type: Sequelize.INTEGER,
field: 'number_of_events',
},
outputSize: {
type: Sequelize.REAL,
field: 'size',
},
lastRun: {
type: Sequelize.INTEGER,
},
}, { timestamps: false });
DataPass.associate = (models) => {
DataPass.belongsTo(models.Period);
DataPass.belongsToMany(models.Run, {
through: 'data_passes_runs',
foreignKey: 'data_pass_id',
timestamps: false,
});
};

return DataPass;
};
5 changes: 5 additions & 0 deletions app/lib/database/models/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ module.exports = (sequelize) => {

Run.associate = (models) => {
Run.belongsTo(models.Period);
Run.belongsToMany(models.DataPass, {
through: 'data_passes_runs',
foreignKey: 'run_number',
timestamps: false,
});
};

return Run;
Expand Down
2 changes: 2 additions & 0 deletions app/lib/database/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Sequelize = require('sequelize');
const BeamType = require('./BeamType.js');
const Period = require('./Period.js');
const Run = require('./Run.js');
const DataPass = require('./DataPass.js');

/**
*
Expand All @@ -27,6 +28,7 @@ const modelsFactory = (sequelize) => {
BeamType,
Period,
Run,
DataPass,
};
models = Object.entries(models).map(([modelName, model]) => [modelName, model(sequelize)]); // instantiate models
models.forEach(([_, modelInstance]) => modelInstance.associate?.(sequelize.models)); // associate models
Expand Down
22 changes: 22 additions & 0 deletions app/lib/database/models/typdefs/SequelizeDataPass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/**
* @typedef SequelizeDataPass
*
* @property {Number} id
* @property {string} name
* @property {string|null} description
* @property {Number|null} reconstructedEvents
* @property {Number|null} outputSize
*/
22 changes: 22 additions & 0 deletions app/lib/domain/entities/DataPass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/**
* @typedef DataPass
*
* @property {Number} id
* @property {string} name
* @property {string|null} description
* @property {Number|null} reconstructedEvents
* @property {Number|null} outputSize
*/
57 changes: 57 additions & 0 deletions app/lib/server/controllers/dataPass.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const { dataPassService } = require('../../services/dataPasses/DataPassService');
const { stdDataRequestDTO } = require('../../domain/dtos');
const { validateDtoOrRepondOnFailure } = require('../utilities');
const Joi = require('joi');

/**
* List All data passes in db
* @param {Object} req express HTTP request object
* @param {Object} res express HTTP response object
* @param {Object} next express next handler
* @returns {undefined}
*/
const listDataPassesHandler = async (req, res, next) => {
const validatedDTO = await validateDtoOrRepondOnFailure(stdDataRequestDTO, req, res);
if (validatedDTO) {
const runs = await dataPassService.getAll(validatedDTO.query);
res.json({
data: runs,
});
}
};

/**
* List data passes belonging to period which id is provided
* @param {Object} req express HTTP request object
* @param {Object} res express HTTP response object
* @param {Object} next express next handler
* @returns {undefined}
*/
const listDataPassesPerPeriodHandler = async (req, res, next) => {
const customDTO = stdDataRequestDTO.keys({ params: { id: Joi.number() } });
const validatedDTO = await validateDtoOrRepondOnFailure(customDTO, req, res);
if (validatedDTO) {
const runs = await dataPassService.getDataPassesPerPeriod(validatedDTO.params.id, validatedDTO.query);
res.json({
data: runs,
});
}
};

module.exports = {
listDataPassesHandler,
listDataPassesPerPeriodHandler,
};
1 change: 1 addition & 0 deletions app/lib/server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ module.exports = {
RunController: require('./run.controller.js'),
PeriodController: require('./period.controller.js'),
apiDocumentationCotroller: require('./ApiDocumentation.controller.js'),
DataPassController: require('./dataPass.controller.js'),
};
19 changes: 19 additions & 0 deletions app/lib/server/controllers/run.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,26 @@ const listRunsPerPeriodHandler = async (req, res, next) => {
}
};

/**
* List runs belonging to period which id is provided
* @param {Object} req express HTTP request object
* @param {Object} res express HTTP response object
* @param {Object} next express next handler
* @returns {undefined}
*/
const listRunsPerDataPass = async (req, res, next) => {
const customDTO = stdDataRequestDTO.keys({ params: { id: Joi.number() } });
const validatedDTO = await validateDtoOrRepondOnFailure(customDTO, req, res);
if (validatedDTO) {
const runs = await runService.getRunsPerDataPass(validatedDTO.params.id, validatedDTO.query);
res.json({
data: runs,
});
}
};

module.exports = {
listRunsHandler,
listRunsPerPeriodHandler,
listRunsPerDataPass,
};
32 changes: 32 additions & 0 deletions app/lib/server/routers/dataPass.router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const { DataPassController, RunController } = require('../controllers');

module.exports = {
path: '/data-passes',
args: { public: false },
children: [
{
method: 'get',
controller: DataPassController.listDataPassesHandler,
description: 'List all data passes which are present in DB',
},
{
path: '/:id/runs',
method: 'get',
controller: RunController.listRunsPerDataPass,
description: 'List runs belonging to data pass which id is provided',
},
],
};
4 changes: 3 additions & 1 deletion app/lib/server/routers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
const { controllerHandlerWrapper } = require('../utilities');
const periodRouter = require('./period.router.js');
const runRouter = require('./run.router.js');
const dataPassRouter = require('./dataPass.router.js');
const docsRouter = require('./docs.router.js');
const apiDocumentationCotroller = require('../controllers/ApiDocumentation.controller.js');

const routeTrees = [
docsRouter,
runRouter,
periodRouter,
runRouter,
dataPassRouter,
];

const checkPath = (path) => {
Expand Down
8 changes: 7 additions & 1 deletion app/lib/server/routers/period.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* or submit itself to any jurisdiction.
*/

const { PeriodController, RunController } = require('../controllers');
const { PeriodController, RunController, DataPassController } = require('../controllers');

module.exports = {
path: '/periods',
Expand All @@ -28,5 +28,11 @@ module.exports = {
controller: RunController.listRunsPerPeriodHandler,
description: 'List all runs associated with period which id is provided',
},
{
method: 'get',
path: '/:id/data-passes',
controller: DataPassController.listDataPassesPerPeriodHandler,
description: 'List all data passes associated with period which id is provided',
},
],
};
Loading