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

return {
id,
name,
};
}

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

module.exports = DetectorSubsystemAdapter;
10 changes: 7 additions & 3 deletions app/lib/database/adapters/RunAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
* or submit itself to any jurisdiction.
*/

const DetectorSubsystemAdapter = require('./DetectorSubsystemAdapter');

/**
* RunAdapter
*/
class RunAdapter {
constructor() {
this.detectorSubsystemAdapter = new DetectorSubsystemAdapter();
}

/**
* Converts the given database object to an entity object.
*
Expand All @@ -36,6 +38,7 @@ class RunAdapter {
lhcBeamEnergy,
l3CurrentVal,
dipoleCurrentVal,
DetectorSubsystems,
} = databaseObject;

return {
Expand All @@ -51,6 +54,7 @@ class RunAdapter {
lhcBeamEnergy,
l3CurrentVal,
dipoleCurrentVal,
detectorSubsystems: DetectorSubsystems?.map(this.detectorSubsystemAdapter.toEntity.bind(this.detectorSubsystemAdapter)),
}
}

Expand Down
3 changes: 3 additions & 0 deletions app/lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
const PeriodAdapter = require('./PeriodAdapter');
const RunAdapter = require('./RunAdapter');
const DataPassAdapter = require('./DataPassAdapter');
const DetectorSubsystemAdapter = require('./DetectorSubsystemAdapter');

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

module.exports = {
runAdapter,
periodAdapter,
dataPassAdapter,
detectorSubsystemAdapter,
}
33 changes: 33 additions & 0 deletions app/lib/database/models/DetectorSubsystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @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 DetectorSubsystem = sequelize.define('DetectorSubsystem', {
name: {
type: Sequelize.STRING,
unique: true,
},
}, { timestamps: false, tableName: 'detectors_subsystems' });

DetectorSubsystem.associate = (models) => {
DetectorSubsystem.belongsToMany(models.Run, {
through: 'runs_detectors',
foreignKey: 'detector_id',
timestamps: false,
})
};

return DetectorSubsystem;
};
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.DetectorSubsystem, {
through: 'runs_detectors',
foreignKey: 'run_number',
timestamps: false,
});
Run.belongsToMany(models.DataPass, {
through: 'data_passes_runs',
foreignKey: 'run_number',
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 @@ -17,6 +17,7 @@ const BeamType = require('./BeamType.js');
const Period = require('./Period.js');
const Run = require('./Run.js');
const DataPass = require('./DataPass.js');
const DetectorSubsystem = require('./DetectorSubsystem.js');

/**
*
Expand All @@ -29,6 +30,7 @@ const modelsFactory = (sequelize) => {
Period,
Run,
DataPass,
DetectorSubsystem,
};
models = Object.entries(models).map(([modelName, model]) => [modelName, model(sequelize)]); // instantiate models
models.forEach(([_, modelInstance]) => modelInstance.associate?.(sequelize.models)); // associate models
Expand Down
1 change: 1 addition & 0 deletions app/lib/database/models/typdefs/SeqeulizeRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
* @property {number|null} lhcBeamEnergy
* @property {number|null} l3CurrentVal
* @property {number|null} dipoleCurrentVal
* @property {SequelizeDetectorSubsystem[]|null} DetectorSubsystems
*/
19 changes: 19 additions & 0 deletions app/lib/database/models/typdefs/SequelizeDetectorSubsystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @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 SequelizeDetectorSubsystem
*
* @property {number} id
* @property {string} name
*/
41 changes: 41 additions & 0 deletions app/lib/database/repositories/RunRepository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @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 Repository = require("./Repository");
const Sequelize = require('sequelize');
const deepmerge = require('deepmerge');

/**
* Sequelize implementation of the Repository.
*/
class RunRepository extends Repository {
/**
* Returns all Run entities with associated DetectorSubsystem entities.
*
* @param {Object} queryClauses the find query (see sequelize findAll options) or a find query builder
* @returns {Promise<Run[]>} Promise object representing the full mock data
*/
async findAllWithDetectors(queryClauses = {}) {
const baseClause = {
include: [{
model: this.model.sequelize.models.DetectorSubsystem,
raw:true,
required: true,
}],
};
console.log(deepmerge(baseClause, queryClauses))
return this.model.findAll(deepmerge(baseClause, queryClauses));
}
}

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

const Repository = require('./Repository.js');

const RunRepository = require('./RunRepository.js');
/**
* Object for holding repository classes defined in files in this directory.
* If repository is not defined here explicitly then it will be created implicitly via models mapping
* NOTE:
* 1. Instances are created here, so metioned files should export classes not instances.
* 2. The object have to keep each repository under key the same as corresponding model is kept.
*/
const specificallyDefinedRepositories = {};
const specificallyDefinedRepositories = {
Run: RunRepository,
};

/**
* @see specificallyDefinedRepositories
Expand Down
19 changes: 19 additions & 0 deletions app/lib/domain/entities/DetectorSubsystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @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 DetectorSubsystem
*
* @property {number} id
* @property {string} name
*/
1 change: 1 addition & 0 deletions app/lib/domain/entities/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
* @property {number|null} lhcBeamEnergy
* @property {number|null} l3CurrentVal
* @property {number|null} dipoleCurrentVal
* @property {DetectorSubsystem[]|null} detectorSubsystems
*/
6 changes: 3 additions & 3 deletions app/lib/services/runs/RunService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RunService {
* @returns {Promise<Run[]>} Promise object represents the result of this use case.
*/
async getAll({ filter }) {
const runs = await RunRepository.findAll({
const runs = await RunRepository.findAllWithDetectors({
where: filterToSequelizeWhereClause(filter),
});
return runs.map((run) => runAdapter.toEntity(run));
Expand All @@ -44,7 +44,7 @@ class RunService {
* @returns {Promise<Run[]>} Promise object represents the result of this use case.
*/
async getRunsPerPeriod(periodId, { filter }) {
const runs = await RunRepository.findAll({
const runs = await RunRepository.findAllWithDetectors({
where: {
period_id: periodId,
...filterToSequelizeWhereClause(filter),
Expand All @@ -60,7 +60,7 @@ class RunService {
* @returns {Promise<Run[]>} Promise object represents the result of this use case.
*/
async getRunsPerDataPass(dataPassId, { filter }) {
const runs = await RunRepository.findAll({
const runs = await RunRepository.findAllWithDetectors({
include: [
{
model: DataPass,
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"start:dev:local": "(export RCT_DB_HOST=${RCT_DB_HOST:-localhost}; bash -c 'set -o allexport && ls && source ./docker/dev.env && set +o allexport && npm run start:dev')",
"deploy:db:local": "./database/setup-db.sh --env ./docker/dev.env",
"dev": "./rctmake prune,db:export,run,app:attach,stop --target dev",
"idev": "node -e \"app = require('./app/application.js')\" -i",
"idev": "node -e \"app = require('./app/application.js'); const { databaseManager: dbm } = app\" -i",
"node-dev-env": "(export RCT_DB_HOST=$(docker inspect o2rct_database-dev -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'); bash -c 'set -o allexport && ls && source ./docker/dev.env && set +o allexport && node')",
"dev:up": "./rctmake run[up],app:attach",
"dev:up-re": "./rctmake run[up],dump:restore,app:attach -F ",
Expand All @@ -59,6 +59,7 @@
"dependencies": {
"@aliceo2/web-ui": "^2.0.0",
"csvtojson": "^2.0.10",
"deepmerge": "^4.3.1",
"esm": "^3.2.25",
"joi": "^17.9.2",
"less": "^4.1.3",
Expand Down Expand Up @@ -88,6 +89,7 @@
],
"bundleDependencies": [
"@aliceo2/web-ui",
"deepmerge",
"esm",
"joi",
"less",
Expand Down