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
Show all changes
27 commits
Select commit Hold shift + click to select a range
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/FlagTypeAdaper.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 FlagTypeAdapter {

/**
* Converts the given database object to an entity object.
*
* @param {SequelizeFlagType} databaseObject Object to convert.
* @returns {FlagType} Converted entity object.
*/
toEntity(databaseObject) {
const {
id,
name,
method,
bad,
obsolate,
} = databaseObject;

return {
id,
name,
method,
bad,
obsolate,
};
}

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

module.exports = FlagTypeAdapter;
101 changes: 101 additions & 0 deletions app/lib/database/adapters/QualityControlFlagAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @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 FlagTypeAdapter = require('./FlagTypeAdaper');
const QualityControlFlagVerificationAdapter = require('./QualityControlFlagVerificationAdapter');
const DetectorSubsystemAdapter = require('./DetectorSubsystemAdapter');

class QualityControlFlagAdapter {
constructor() {
this.flagTypeAdapter = new FlagTypeAdapter();
this.qualityControlFlagVerificationAdapter = new QualityControlFlagVerificationAdapter();
}

/**
* Converts the given database object to an entity object.
*
* @param {SequelizeQualityControlFlag} databaseObject Object to convert.
* @returns {QualityControlFlag} Converted entity object.
*/
toEntity(databaseObject) {
const {
id,
data_pass_id,
run_number,
detector_id,
timeStart,
timeEnd,
comment,
addedBy,
additionTime,
lastModificationTime,
FlagType: flagType,
QualityControlFlagVerifications: verifications,
} = databaseObject;

return {
id,
data_pass_id,
run_number,
detector_id,
timeStart,
timeEnd,
comment,
addedBy,
additionTime: Number(additionTime),
lastModificationTime: Number(lastModificationTime),
flagType: this.flagTypeAdapter.toEntity(flagType),
verifications: verifications.map((verification) => this.qualityControlFlagVerificationAdapter.toEntity(verification)),
}
}

/**
* Converts the given entity object to database object.
*
* @param {QualityControlFlag} databaseObject Object to convert.
* @returns {SequelizeQualityControlFlag} Converted entity object.
*/
toDatabase(entityObject) {
const {
id,
data_pass_id,
run_number,
detector_id,
timeStart,
timeEnd,
comment,
addedBy,
additionTime,
lastModificationTime,
flagType: FlagType,
verifications,
} = entityObject;

return {
id,
data_pass_id,
run_number,
detector_id,
timeStart,
timeEnd,
comment,
addedBy,
additionTime,
lastModificationTime,
FlagType: this.flagTypeAdapter.toDatabase(FlagType),
QualityControlFlagVerifications: verifications.map((verification) => this.qualityControlFlagVerificationAdapter.toDatabase(verification)),
};
}
}

module.exports = QualityControlFlagAdapter;
57 changes: 57 additions & 0 deletions app/lib/database/adapters/QualityControlFlagVerificationAdapter.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.
*/

class QualityControlFlagVerificationAdapter {

/**
* Converts the given database object to an entity object.
*
* @param {SequelizeQualityControlFlagVerification} databaseObject Object to convert.
* @returns {QualityControlFlagVerification} Converted entity object.
*/
toEntity(databaseObject) {
const {
id,
verifiedBy,
verification_time,
} = databaseObject;

return {
id,
verifiedBy,
verifiedAt: verification_time,
}
}

/**
* Converts the given entity object to database object.
*
* @param {QualityControlFlagVerification} databaseObject Object to convert.
* @returns {SequelizeQualityControlFlagVerification} Converted entity object.
*/
toDatabase(entityObject) {
const {
id,
verifiedBy,
verifiedAt: verification_time,
} = entityObject;

return {
id,
verifiedBy,
verification_time,
};
}
}

module.exports = QualityControlFlagVerificationAdapter;
3 changes: 3 additions & 0 deletions app/lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ const RunAdapter = require('./RunAdapter');
const DataPassAdapter = require('./DataPassAdapter');
const DetectorSubsystemAdapter = require('./DetectorSubsystemAdapter');
const SimulationPassAdapter = require('./SimulationPassAdapter');
const QualityControlFlagAdapter = require('./QualityControlFlagAdapter');

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

module.exports = {
runAdapter,
periodAdapter,
dataPassAdapter,
detectorSubsystemAdapter,
simulationPassAdapter,
qualityControlFlagAdapter,
};
1 change: 1 addition & 0 deletions app/lib/database/models/DataPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = (sequelize) => {
foreignKey: 'data_pass_id',
timestamps: false,
});
DataPass.hasMany(models.QualityControlFlag, {foreignKey: 'data_pass_id'});
};

return DataPass;
Expand Down
1 change: 1 addition & 0 deletions app/lib/database/models/DetectorSubsystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = (sequelize) => {
foreignKey: 'detector_id',
timestamps: false,
})
DetectorSubsystem.hasMany(models.QualityControlFlag, {foreignKey: 'detector_id'});
};

return DetectorSubsystem;
Expand Down
45 changes: 45 additions & 0 deletions app/lib/database/models/FlagType.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.
*/

const Sequelize = require('sequelize');

module.exports = (sequelize) => {
const FlagType = sequelize.define('FlagType', {
name: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
method: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
bad: {
type: Sequelize.BOOLEAN,
unique: true,
allowNull: false,
},
obsolate: {
type: Sequelize.BOOLEAN,
unique: true,
allowNull: false,
},
}, { timestamps: false, tableName: 'flag_types_dictionary'});

FlagType.associate = (models) => {
FlagType.hasMany(models.QualityControlFlag, {foreignKey: 'flag_type_id'});
};

return FlagType;
};
71 changes: 71 additions & 0 deletions app/lib/database/models/QualitControlFlag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @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 QualityControlFlag = sequelize.define('QualityControlFlag', {
timeStart: {
type: Sequelize.DATE,
allowNull: false,
get() {
return Number(this.getDataValue('timeStart'))
}
},
timeEnd: {
type: Sequelize.DATE,
allowNull: false,
get() {
return Number(this.getDataValue('timeEnd'))
}
},
comment: {
type: Sequelize.TEXT,
},
addedBy: {
type: Sequelize.STRING,
allowNull: false,
},
}, {
timestamps: true,
createdAt: 'additionTime',
updatedAt: 'lastModificationTime',
});

const QualityControlFlagVerification = sequelize.define('QualityControlFlagVerification', {
verifiedBy: {
type: Sequelize.STRING,
allowNull: false,
},
}, {
timestamps: true,
createdAt: 'verification_time',
updatedAt: false,
});


QualityControlFlag.associate = (models) => {
QualityControlFlag.belongsTo(models.Run, {foreignKey: 'run_number'});
QualityControlFlag.belongsTo(models.DataPass, {foreignKey: 'data_pass_id'});
QualityControlFlag.belongsTo(models.DetectorSubsystem, {foreignKey: 'detector_id'});
QualityControlFlag.belongsTo(models.FlagType, {foreignKey: 'flag_type_id'});
QualityControlFlag.hasMany(models.QualityControlFlagVerification, {foreignKey: 'qcf_id'});
};


QualityControlFlagVerification.associate = (models) => {
QualityControlFlagVerification.belongsTo(models.QualityControlFlag, {foreignKey: 'qcf_id'});
};

return QualityControlFlag;
};
Loading