Skip to content
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
21 changes: 21 additions & 0 deletions lib/database/models/typedefs/SequalizeBeamMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @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 SequelizeBeamMode
*
* BeamMode is currently a string column in the runs table, but we define this typedef as if it were a full model for future use.
* BeamMode should become independent entity in the future. [O2B-1499]
*
* @property {string} name
Comment thread
Houwie7000 marked this conversation as resolved.
*/
29 changes: 27 additions & 2 deletions lib/server/controllers/runs.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const { dtoValidator } = require('../utilities');
const { ApiConfig } = require('../../config/index.js');
const { DtoFactory } = require('../../domain/dtos/DtoFactory.js');
const { runService } = require('../services/run/RunService.js');
const { getAllBeamModes } = require('../services/beam/getAllBeamModes.js');
const { updateExpressResponseFromNativeError } = require('../express/updateExpressResponseFromNativeError.js');
const { runToHttpView } = require('./runsToHttpView.js');

Expand Down Expand Up @@ -278,8 +279,7 @@ const updateRunByRunNumber = async (request, response) => {
* @param {Object} _request The *request* object represents the HTTP request and has properties for the request query
* string, parameters, body, HTTP headers, and so on.
* @param {Object} response The *response* object represents the HTTP response that an Express app sends when it gets
* an
* HTTP request.
* an HTTP request.
* @param {Function} _next The *next* object represents the next middleware function which is used to pass control to
* the next middleware function.
* @returns {undefined}
Expand All @@ -297,6 +297,30 @@ const listReasonTypes = async (_request, response, _next) => {
}
};

/**
Comment thread
isaachilly marked this conversation as resolved.
* Retrieve a list of unique beam modes
*
* @param {Object} _request The *request* object represents the HTTP request and has properties for the request query
* string, parameters, body, HTTP headers, and so on.
* @param {Object} response The *response* object represents the HTTP response that an Express app sends when it gets
* an HTTP request.
* @param {NextFunction} _next The *next* object represents the next middleware function which is used to pass control to
* the next middleware function.
* @returns {undefined}
*/
const listBeamModes = async (_request, response, _next) => {
try {
const beamModes = await getAllBeamModes();
if (beamModes && beamModes.length > 0) {
response.status(200).json({ data: beamModes });
} else {
response.status(204).json({ data: [] });
Comment thread
isaachilly marked this conversation as resolved.
}
} catch {
response.status(502).json({ errors: ['Unable to retrieve list of beam modes'] });
}
};

// eslint-disable-next-line jsdoc/require-param
/**
* Retrieve distinct combination of levels of alice L3 and dipole current rounded to kilo amperes
Expand All @@ -323,6 +347,7 @@ module.exports = {
getLogsByRunNumberHandler,
getFlpsByRunNumberHandler,
listReasonTypes,
listBeamModes,
listRuns,
startRun,
updateRunByRunNumber,
Expand Down
5 changes: 5 additions & 0 deletions lib/server/routers/runs.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ module.exports = {
path: 'reasonTypes',
controller: RunsController.listReasonTypes,
},
{
method: 'get',
path: 'beamModes',
controller: RunsController.listBeamModes,
},
{
method: 'get',
controller: RunsController.listRuns,
Expand Down
32 changes: 32 additions & 0 deletions lib/server/services/beam/getAllBeamModes.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 { repositories: { RunRepository }, sequelize } = require('../../../database');
const { Op } = require('sequelize');

/**
* Return the a list of unique beam modes which is built from the runs data
*
* @returns {Promise<SequelizeBeamMode[]>} Promise resolving with the list of unique beam modes
*/
exports.getAllBeamModes = async () => {
const beamModes = await RunRepository.findAll({
where: {
lhc_beam_mode: {
[Op.ne]: null,
},
},
attributes: [[sequelize.fn('DISTINCT', sequelize.col('lhc_beam_mode')), 'name']],
});
return beamModes;
};
13 changes: 13 additions & 0 deletions test/api/runs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,19 @@ module.exports = () => {
});
});


describe('GET /api/runs/beamModes', () => {
it('should successfully return status 200 and list of beam modes', async () => {
const { body } = await request(server)
.get('/api/runs/beamModes')
.expect(200);

expect(body.data).to.be.an('array');
expect(body.data).to.have.lengthOf(4);

expect(body.data[0].name).to.equal('STABLE BEAMS');
});
});
describe('GET /api/runs/reasonTypes', () => {
it('should successfully return status 200 and list of reason types', async () => {
const { body } = await request(server)
Expand Down
27 changes: 27 additions & 0 deletions test/lib/server/services/beamMode/getAllBeamModes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @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 { expect } = require('chai');
const { getAllBeamModes } = require('../../../../../lib/server/services/beam/getAllBeamModes.js');

module.exports = () => {
it('should successfully return the full list of not null beam modes from runs table', async () => {
const beamModes = await getAllBeamModes();
expect(beamModes.map(({ dataValues: { name } }) => ({ name }))).to.deep.eq([
{ name: 'STABLE BEAMS' },
{ name: 'STABLE' },
{ name: 'NO BEAM' },
{ name: 'UNSTABLE BEAMS' },
]);
});
};
18 changes: 18 additions & 0 deletions test/lib/server/services/beamMode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @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 getAllBeamModes = require('./getAllBeamModes.test.js');

module.exports = () => {
describe('getAllBeamModes', getAllBeamModes);
};
2 changes: 2 additions & 0 deletions test/lib/server/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

const { resetDatabaseContent } = require('../../../utilities/resetDatabaseContent.js');

const BeamModeSuite = require('./beamMode/index.js');
const DetectorSuite = require('./detector/index.js');
const DplSuite = require('./dpl/index.js');
const Environment = require('./environment/index.js');
Expand All @@ -38,6 +39,7 @@ module.exports = () => {

after(resetDatabaseContent);

describe('BeamMode', BeamModeSuite);
describe('Detector', DetectorSuite);
describe('DPL', DplSuite);
describe('Environment', Environment);
Expand Down
Loading