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
55 changes: 55 additions & 0 deletions app/lib/database/adapters/SimulationPassAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @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 SimulationPassAdapter {
/**
* Converts the given database object to an entity object.
*
* @param {SequelizeSimulationPass} databaseObject Object to convert.
* @returns {SimulationPass} Converted entity object.
*/
toEntity(databaseObject) {
const {
id,
name,
description,
jiraId,
PWG,
requestedEvents,
outputSize,
} = databaseObject;

return {
id,
name,
description,
jiraId,
PWG,
requestedEvents,
outputSize,
};
}

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

module.exports = SimulationPassAdapter;
5 changes: 4 additions & 1 deletion app/lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ const PeriodAdapter = require('./PeriodAdapter');
const RunAdapter = require('./RunAdapter');
const DataPassAdapter = require('./DataPassAdapter');
const DetectorSubsystemAdapter = require('./DetectorSubsystemAdapter');
const SimulationPassAdapter = require('./SimulationPassAdapter');

const runAdapter = new RunAdapter();
const periodAdapter = new PeriodAdapter();
const dataPassAdapter = new DataPassAdapter();
const detectorSubsystemAdapter = new DetectorSubsystemAdapter();
const simulationPassAdapter = new SimulationPassAdapter();

module.exports = {
runAdapter,
periodAdapter,
dataPassAdapter,
detectorSubsystemAdapter,
}
simulationPassAdapter,
};
5 changes: 5 additions & 0 deletions app/lib/database/models/DataPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ module.exports = (sequelize) => {
foreignKey: 'data_pass_id',
timestamps: false,
});
DataPass.belongsToMany(models.SimulationPass, {
through: 'anchored_passes',
foreignKey: 'data_pass_id',
timestamps: false,
});
};

return DataPass;
Expand Down
5 changes: 5 additions & 0 deletions app/lib/database/models/Period.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ module.exports = (sequelize) => {
Period.associate = (models) => {
Period.hasMany(models.Run);
Period.belongsTo(models.BeamType, {foreginKey: 'beam_type_id'})
Period.belongsToMany(models.SimulationPass, {
through: 'anchored_periods',
foreignKey: 'period_id',
timestamps: false,
});
};

return Period;
Expand Down
5 changes: 5 additions & 0 deletions app/lib/database/models/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ module.exports = (sequelize) => {
foreignKey: 'run_number',
timestamps: false,
});
Run.belongsToMany(models.SimulationPass, {
through: 'simulation_passes_runs',
foreignKey: 'run_number',
timestamps: false,
});
};

return Run;
Expand Down
62 changes: 62 additions & 0 deletions app/lib/database/models/SimulationPass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @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 SimulationPass = sequelize.define('SimulationPass', {
name: {
type: Sequelize.STRING,
unique: true,
},
description: {
type: Sequelize.TEXT,
},
jiraId: {
type: Sequelize.STRING,
field: 'jira'
},
PWG: {
type: Sequelize.TEXT,
field: 'pwg',
},
requestedEvents: {
type: Sequelize.INTEGER,
field: 'number_of_events',
},
outputSize: {
type: Sequelize.REAL,
field: 'size',
},
}, { timestamps: false });

SimulationPass.associate = (models) => {
SimulationPass.belongsToMany(models.Period, {
through: 'anchored_periods',
foreignKey: 'sim_pass_id',
timestamps: false,
});
SimulationPass.belongsToMany(models.DataPass, {
through: 'anchored_passes',
foreignKey: 'sim_pass_id',
timestamps: false,
});
SimulationPass.belongsToMany(models.Run, {
through: 'simulation_passes_runs',
foreignKey: 'simulation_pass_id',
timestamps: false,
});
};

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

/**
*
Expand All @@ -31,6 +32,7 @@ const modelsFactory = (sequelize) => {
Run,
DataPass,
DetectorSubsystem,
SimulationPass,
};
models = Object.entries(models).map(([modelName, model]) => [modelName, model(sequelize)]); // instantiate models
models.forEach(([_, modelInstance]) => modelInstance.associate?.(sequelize.models)); // associate models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@
*/

/**
* Execute an async function and return an eventually thrown error
* @typedef SequelizeSimulationPass
*
* @param {function} callable an async function to call
*
* @return {Promise<null|Error>} the eventually caught error
* @property {Number} id
* @property {string} name
* @property {string|null} description
* @property {string|null} jiraId
* @property {string|null} PWG
* @property {Number|null} requestedEvents
* @property {Number|null} outputSize
*/

module.exports.catchAsyncError = async (callable) => {
try {
await callable();
} catch (e) {
return e;
}
return null;
};
1 change: 0 additions & 1 deletion app/lib/database/repositories/RunRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class RunRepository extends Repository {
required: true,
}],
};
console.log(deepmerge(baseClause, queryClauses))
return this.model.findAll(deepmerge(baseClause, queryClauses));
}
}
Expand Down
24 changes: 24 additions & 0 deletions app/lib/domain/entities/SimulationPass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @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 SimulationPass
*
* @property {Number} id
* @property {string} name
* @property {string|null} description
* @property {string|null} jiraId
* @property {string|null} PWG
* @property {Number|null} requestedEvents
* @property {Number|null} outputSize
*/
19 changes: 19 additions & 0 deletions app/lib/server/controllers/dataPass.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,26 @@ const listDataPassesPerPeriodHandler = async (req, res, next) => {
}
};

/**
* List data passes anchored to simulation pass 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 listAnchoredToSimulationPass = 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.getAnchoredToSimulationPass(validatedDTO.params.id, validatedDTO.query);
res.json({
data: runs,
});
}
};

module.exports = {
listDataPassesHandler,
listDataPassesPerPeriodHandler,
listAnchoredToSimulationPass,
};
1 change: 1 addition & 0 deletions app/lib/server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ module.exports = {
PeriodController: require('./period.controller.js'),
apiDocumentationCotroller: require('./ApiDocumentation.controller.js'),
DataPassController: require('./dataPass.controller.js'),
SimulationPassController: require('./simulationPass.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 @@ -69,8 +69,27 @@ const listRunsPerDataPass = 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 listRunsPerSimulationPassHandler = 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.getRunsPerSimulationPass(validatedDTO.params.id, validatedDTO.query);
res.json({
data: runs,
});
}
};

module.exports = {
listRunsHandler,
listRunsPerPeriodHandler,
listRunsPerDataPass,
listRunsPerSimulationPassHandler,
};
76 changes: 76 additions & 0 deletions app/lib/server/controllers/simulationPass.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @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 { simulationPassService } = require('../../services/simulationPasses/SimulationPassService');
const { stdDataRequestDTO } = require('../../domain/dtos');
const { validateDtoOrRepondOnFailure } = require('../utilities');
const Joi = require('joi');

/**
* List All simulation 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 listSimulationPassesHandler = async (req, res, next) => {
const validatedDTO = await validateDtoOrRepondOnFailure(stdDataRequestDTO, req, res);
if (validatedDTO) {
const runs = await simulationPassService.getAll(validatedDTO.query);
res.json({
data: runs,
});
}
};

/**
* List simulation 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 listSimulationPassesPerPeriodHandler = async (req, res, next) => {
const customDTO = stdDataRequestDTO.keys({ params: { id: Joi.number() } });
const validatedDTO = await validateDtoOrRepondOnFailure(customDTO, req, res);
if (validatedDTO) {
const runs = await simulationPassService.getSimulationPassesPerPeriod(validatedDTO.params.id, validatedDTO.query);
res.json({
data: runs,
});
}
};

/**
* List simulation passes which are anchored to data pass wich 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 listAnchorageForDataPassHandler = async (req, res, next) => {
const customDTO = stdDataRequestDTO.keys({ params: { id: Joi.number() } });
const validatedDTO = await validateDtoOrRepondOnFailure(customDTO, req, res);
if (validatedDTO) {
const runs = await simulationPassService.getAnchorageForDataPass(validatedDTO.params.id, validatedDTO.query);
res.json({
data: runs,
});
}
};

module.exports = {
listSimulationPassesHandler,
listSimulationPassesPerPeriodHandler,
listAnchorageForDataPassHandler,
};
Loading