Skip to content

Commit

Permalink
[O2B-1157] Improve QC flags get all API (#1515)
Browse files Browse the repository at this point in the history
* [O2B-1157] Improve QC flags get all API

* Fix tests

* Fix tests

* Fix linter

* Fix more tests

* Fixed linter again

* Fix default ordering

* Remove overview workaround

* Delegate from/to to data/simulation pass qc flags

* Fix more tests

* Fix more tests

* Fix linter

* Remove spurious data pass id

* Throw in adapter if qc flag is not eagerly fetched
  • Loading branch information
martinboulais authored Apr 17, 2024
1 parent 7e4fdcc commit 9e97ec3
Show file tree
Hide file tree
Showing 30 changed files with 851 additions and 707 deletions.
72 changes: 72 additions & 0 deletions lib/database/adapters/DataPassQcFlagAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @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 { AdapterError } = require('../../server/errors/AdapterError.js');

/**
* Adapter for data pass QC flag
*/
class DataPassQcFlagAdapter {
/**
* Constructor
*/
constructor() {
this.toEntity = this.toEntity.bind(this);

this.dataPassAdapter = null;
this.qcFlagTypeAdapter = null;
this.qcFlagVerificationAdapter = null;
this.userAdapter = null;
}

/**
* Converts the given database object to an entity object.
*
* @param {SequelizeDataPassQcFlag} databaseObject Object to convert.
* @returns {DataPassQcFlag} Converted entity object.
*/
toEntity(databaseObject) {
const {
dataPassId,
qualityControlFlagId,
qcFlag,
createdAt,
updatedAt,
dataPass,
} = databaseObject;

if (qcFlag === null) {
throw new AdapterError('Related QC flag missing in DataPassQcFlag.');
}

return {
dataPassId,
qcFlagId: qualityControlFlagId,
from: qcFlag.from,
to: qcFlag.to,
comment: qcFlag.comment,
createdById: qcFlag.createdById,
flagTypeId: qcFlag.flagTypeId,
runNumber: qcFlag.runNumber,
dplDetectorId: qcFlag.dplDetectorId,
createdAt,
updatedAt,
dataPass: dataPass ? this.dataPassAdapter.toEntity(dataPass) : null,
createdBy: qcFlag.createdBy ? this.userAdapter.toEntity(qcFlag.createdBy) : null,
flagType: qcFlag.flagType ? this.qcFlagTypeAdapter.toEntity(qcFlag.flagType) : null,
verifications: qcFlag.verifications ? this.qcFlagVerificationAdapter.toEntity(qcFlag.verifications) : null,
};
}
}

exports.DataPassQcFlagAdapter = DataPassQcFlagAdapter;
72 changes: 72 additions & 0 deletions lib/database/adapters/SimulationPassQcFlagAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @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 { AdapterError } = require('../../server/errors/AdapterError.js');

/**
* Adapter for simulation pass QC flag
*/
class SimulationPassQcFlagAdapter {
/**
* Constructor
*/
constructor() {
this.toEntity = this.toEntity.bind(this);

this.simulationPassAdapter = null;
this.qcFlagTypeAdapter = null;
this.qcFlagVerificationAdapter = null;
this.userAdapter = null;
}

/**
* Converts the given database object to an entity object.
*
* @param {SequelizeSimulationPassQcFlag} databaseObject Object to convert.
* @returns {SimulationPassQcFlag} Converted entity object.
*/
toEntity(databaseObject) {
const {
simulationPassId,
qualityControlFlagId,
qcFlag,
createdAt,
updatedAt,
simulationPass,
} = databaseObject;

if (qcFlag === null) {
throw new AdapterError('Related QC flag missing in SimulationPassQcFlag.');
}

return {
simulationPassId,
qcFlagId: qualityControlFlagId,
from: qcFlag.from,
to: qcFlag.to,
comment: qcFlag.comment,
createdById: qcFlag.createdById,
flagTypeId: qcFlag.flagTypeId,
runNumber: qcFlag.runNumber,
dplDetectorId: qcFlag.dplDetectorId,
createdAt,
updatedAt,
simulationPass: simulationPass ? this.simulationPassAdapter.toEntity(simulationPass) : null,
createdBy: qcFlag.createdBy ? this.userAdapter.toEntity(qcFlag.createdBy) : null,
flagType: qcFlag.flagType ? this.qcFlagTypeAdapter.toEntity(qcFlag.flagType) : null,
verifications: qcFlag.verifications ? this.qcFlagVerificationAdapter.toEntity(qcFlag.verifications) : null,
};
}
}

exports.SimulationPassQcFlagAdapter = SimulationPassQcFlagAdapter;
16 changes: 16 additions & 0 deletions lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

const AttachmentAdapter = require('./AttachmentAdapter');
const { DataPassQcFlagAdapter } = require('./DataPassQcFlagAdapter.js');
const DetectorAdapter = require('./DetectorAdapter');
const { DplDetectorAdapter } = require('./dpl/DplDetectorAdapter.js');
const { DplProcessExecutionAdapter } = require('./dpl/DplProcessExecutionAdapter.js');
Expand Down Expand Up @@ -41,8 +42,10 @@ const LhcPeriodAdapter = require('./LhcPeriodAdapter');
const LhcPeriodStatisticsAdapter = require('./LhcPeriodStatisticsAdapter');
const DataPassAdapter = require('./DataPassAdapter');
const SimulationPassAdapter = require('./SimulationPassAdapter.js');
const { SimulationPassQcFlagAdapter } = require('./SimulationPassQcFlagAdapter');

const attachmentAdapter = new AttachmentAdapter();
const dataPassQcFlagAdapter = new DataPassQcFlagAdapter();
const dataPassAdapter = new DataPassAdapter();
const detectorAdapter = new DetectorAdapter();
const dplDetectorAdapter = new DplDetectorAdapter();
Expand All @@ -69,11 +72,17 @@ const runAdapter = new RunAdapter();
const runDetectorsAdapter = new RunDetectorsAdapter();
const runTypeAdapter = new RunTypeAdapter();
const simulationPassAdapter = new SimulationPassAdapter();
const simulationPassQcFlagAdapter = new SimulationPassQcFlagAdapter();
const subsystemAdapter = new SubsystemAdapter();
const tagAdapter = new TagAdapter();
const userAdapter = new UserAdapter();

// Fill dependencies
dataPassQcFlagAdapter.dataPassAdapter = dataPassAdapter;
dataPassQcFlagAdapter.qcFlagTypeAdapter = qcFlagTypeAdapter;
dataPassQcFlagAdapter.userAdapter = userAdapter;
dataPassQcFlagAdapter.qcFlagVerificationAdapter = qcFlagVerificationAdapter;

dplDetectorAdapter.dplProcessExecutionAdapter = dplProcessExecutionAdapter;

dplProcessAdapter.dplProcessExecutionAdapter = dplProcessExecutionAdapter;
Expand Down Expand Up @@ -122,9 +131,15 @@ runAdapter.logAdapter = logAdapter;
runAdapter.runTypeAdapter = runTypeAdapter;
runAdapter.tagAdapter = tagAdapter;

simulationPassQcFlagAdapter.simulationPassAdapter = simulationPassAdapter;
simulationPassQcFlagAdapter.userAdapter = userAdapter;
simulationPassQcFlagAdapter.qcFlagTypeAdapter = qcFlagTypeAdapter;
simulationPassQcFlagAdapter.qcFlagVerificationAdapter = qcFlagVerificationAdapter;

module.exports = {
attachmentAdapter,
dataPassAdapter,
dataPassQcFlagAdapter,
detectorAdapter,
dplDetectorAdapter,
dplProcessAdapter,
Expand All @@ -150,6 +165,7 @@ module.exports = {
runDetectorsAdapter,
runTypeAdapter,
simulationPassAdapter,
simulationPassQcFlagAdapter,
subsystemAdapter,
tagAdapter,
userAdapter,
Expand Down
38 changes: 38 additions & 0 deletions lib/database/models/dataPassQcFlag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @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 QcFlag = sequelize.define(
'DataPassQcFlag',
{
dataPassId: {
type: Sequelize.INTEGER,
primaryKey: true,
},
qualityControlFlagId: {
type: Sequelize.INTEGER,
primaryKey: true,
},
},
{ tableName: 'data_pass_quality_control_flag' },
);

QcFlag.associate = (models) => {
QcFlag.belongsTo(models.QcFlag, { as: 'qcFlag', foreignKey: 'qualityControlFlagId', targetKey: 'id' });
QcFlag.belongsTo(models.DataPass, { as: 'dataPass' });
};

return QcFlag;
};
32 changes: 18 additions & 14 deletions lib/database/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/

const Attachment = require('./attachment');
const DataPass = require('./dataPass.js');
const DataPassQcFlag = require('./dataPassQcFlag.js');
const Detector = require('./detector');
const DplDetector = require('./dpl/dpldetector.js');
const DplProcess = require('./dpl/dplprocess.js');
Expand All @@ -25,26 +27,28 @@ const FlpRole = require('./flprole');
const Host = require('./host.js');
const LhcFill = require('./lhcFill');
const LhcFillStatistics = require('./lhcFillStatistics.js');
const LhcPeriod = require('./lhcPeriod');
const LhcPeriodStatistics = require('./lhcPeriodsStatistics');
const Log = require('./log');
const QcFlag = require('./qcFlag.js');
const QcFlagType = require('./qcFlagType.js');
const QcFlagVerification = require('./qcFlagVerification.js');
const ReasonType = require('./reasontype');
const Run = require('./run');
const RunDetectors = require('./rundetectors.js');
const RunType = require('./runType');
const SimulationPass = require('./simulationPass.js');
const SimulationPassQcFlag = require('./simulationPassQcFlag.js');
const StableBeamRun = require('./stableBeamsRun.js');
const Subsystem = require('./subsystem');
const Tag = require('./tag');
const User = require('./user');
const LhcPeriod = require('./lhcPeriod');
const LhcPeriodStatistics = require('./lhcPeriodsStatistics');
const DataPass = require('./dataPass.js');
const QcFlagType = require('./qcFlagType.js');
const QcFlag = require('./qcFlag.js');
const QcFlagVerification = require('./qcFlagVerification.js');
const SimulationPass = require('./simulationPass.js');

module.exports = (sequelize) => {
const models = {
Attachment: Attachment(sequelize),
DataPass: DataPass(sequelize),
DataPassQcFlag: DataPassQcFlag(sequelize),
Detector: Detector(sequelize),
DplDetector: DplDetector(sequelize),
DplProcess: DplProcess(sequelize),
Expand All @@ -58,22 +62,22 @@ module.exports = (sequelize) => {
Host: Host(sequelize),
LhcFill: LhcFill(sequelize),
LhcFillStatistics: LhcFillStatistics(sequelize),
LhcPeriod: LhcPeriod(sequelize),
LhcPeriodStatistics: LhcPeriodStatistics(sequelize),
Log: Log(sequelize),
QcFlag: QcFlag(sequelize),
QcFlagType: QcFlagType(sequelize),
QcFlagVerification: QcFlagVerification(sequelize),
ReasonType: ReasonType(sequelize),
Run: Run(sequelize),
RunDetectors: RunDetectors(sequelize),
RunType: RunType(sequelize),
SimulationPass: SimulationPass(sequelize),
SimulationPassQcFlag: SimulationPassQcFlag(sequelize),
StableBeamRun: StableBeamRun(sequelize),
Subsystem: Subsystem(sequelize),
Tag: Tag(sequelize),
User: User(sequelize),
LhcPeriod: LhcPeriod(sequelize),
LhcPeriodStatistics: LhcPeriodStatistics(sequelize),
DataPass: DataPass(sequelize),
QcFlagType: QcFlagType(sequelize),
QcFlag: QcFlag(sequelize),
QcFlagVerification: QcFlagVerification(sequelize),
SimulationPass: SimulationPass(sequelize),
};

Object.entries(models).forEach(([_key, model]) => {
Expand Down
38 changes: 38 additions & 0 deletions lib/database/models/simulationPassQcFlag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @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 QcFlag = sequelize.define(
'SimulationPassQcFlag',
{
simulationPassId: {
type: Sequelize.INTEGER,
primaryKey: true,
},
qualityControlFlagId: {
type: Sequelize.INTEGER,
primaryKey: true,
},
},
{ tableName: 'simulation_pass_quality_control_flag' },
);

QcFlag.associate = (models) => {
QcFlag.belongsTo(models.QcFlag, { as: 'qcFlag', foreignKey: 'qualityControlFlagId', targetKey: 'id' });
QcFlag.belongsTo(models.SimulationPass, { as: 'simulationPass' });
};

return QcFlag;
};
22 changes: 22 additions & 0 deletions lib/database/models/typedefs/SequelizeDataPassQcFlag.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 SequelizeDataPassQcFlag
* @property {number} dataPassId
* @property {number} qualityControlFlagId
* @property {number} createdAt
* @property {number} updatedAt
* @property {SequelizeQcFlag|null} qcFlag
* @property {SequelizeDataPass|null} dataPass
*/
Loading

0 comments on commit 9e97ec3

Please sign in to comment.