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
7 changes: 6 additions & 1 deletion app/config/databasePersistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* eslint-disable max-len */

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

const flags = require('./flagsDefinitions.json')
const particle_phys_data = {
p: {
full_name: 'proton',
Expand Down Expand Up @@ -52,6 +52,11 @@ module.exports = {
query: Object.entries(particle_phys_data).map(([name, d]) => `INSERT INTO particle_phys_data("id", "name", "full_name", "A", "Z")
VALUES (DEFAULT, '${name}', '${d.full_name}', ${d.A}, ${d.Z});`),
},
flags: {
description: 'flags types dict insert',
query: flags.map((f) => `INSERT INTO flags_types_dictionary("id", "name", "method", "bad", "obsolate")
VALUES (${f.id}, '${f.name}', '${f.method}', ${f.bad}::bool, ${f.obsolete}::bool);`),
},
},

beam_type_mappings: {
Expand Down
100 changes: 100 additions & 0 deletions app/config/flagsDefinitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
[
{
"id": "1",
"method": "Unknown",
"name": "Unknown",
"bad": "1",
"obsolete": "0"
},
{
"id": "2",
"method": "UnknownQuality",
"name": "Unknown Quality",
"bad": "1",
"obsolete": "0"
},
{
"id": "3",
"method": "CertifiedByExpert",
"name": "Certified by Expert",
"bad": "0",
"obsolete": "0"
},
{
"id": "10",
"method": "NoDetectorData",
"name": "No Detector Data",
"bad": "1",
"obsolete": "0"
},
{
"id": "11",
"method": "LimitedAcceptance",
"name": "Limited acceptance",
"bad": "1",
"obsolete": "0"
},
{
"id": "12",
"method": "BadPID",
"name": "Bad PID",
"bad": "1",
"obsolete": "0"
},
{
"id": "13",
"method": "BadTracking",
"name": "Bad Tracking",
"bad": "1",
"obsolete": "0"
},
{
"id": "14",
"method": "BadHadronPID",
"name": "Bad Hadron PID",
"bad": "1",
"obsolete": "0"
},
{
"id": "15",
"method": "BadElectronPID",
"name": "Bad Electron PID",
"bad": "1",
"obsolete": "0"
},
{
"id": "16",
"method": "BadEMCalorimetry",
"name": "Bad EM Calorimetry",
"bad": "1",
"obsolete": "0"
},
{
"id": "17",
"method": "BadPhotonCalorimetry",
"name": "Bad Photon Calorimetry",
"bad": "1",
"obsolete": "0"
},
{
"id": "65500",
"method": "ObsoleteFlagExample",
"name": "Obsolete flag example",
"bad": "1",
"obsolete": "1"
},
{
"id": "65501",
"method": "NotBadFlagExample",
"name": "Not bad flag example",
"bad": "0",
"obsolete": "0"
},
{
"id": "65535",
"method": "Invalid",
"name": "Invalid",
"bad": "1",
"obsolete": "0"
}
]
8 changes: 8 additions & 0 deletions app/config/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const mcViews = {

module.exports = { // Properties that will be provided to frontend in the public folder
roles: require('./roles.js'),
flagsTypes: require('./flagsDefinitions.json'),
endpoints: {
login: '/login/',
logout: '/logout/',
Expand Down Expand Up @@ -97,6 +98,13 @@ module.exports = { // Properties that will be provided to frontend in the public
flags: 'flags',
},

operationsNames: {
flag_insert: 'flags_insert',
flag_delete: 'flag_delete',
flag_update: 'flag_update',
verification_insert: 'verification_insert'
},

filteringParams: {
types: {
matchExcludeType: matchExcludeType,
Expand Down
29 changes: 28 additions & 1 deletion app/lib/database/DatabaseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,41 @@ class DatabaseService {
}

try {
const query = QueryBuilder.build(params);
const query = QueryBuilder.buildSelect(params);
await this.pgExec(query, connectErrorHandler, dbResponseHandler, dbResErrorHandler);
} catch (e) {
this.logger.error(e.stack)
this.responseWithStatus(res, 400, e)
}
}


async pgExecDataInsert(req, res) {
this.checkToken(req, res);
const dbResponseHandler = (dbRes) => {
return res.json({data: dbRes})
}
const dbResErrorHandler = (e) => {
this.logger.error(e.message + ' :: ' + e.stack)
this.responseWithStatus(res, 500, e.code);
}
const connectErrorHandler = (connectErr) => {
this.logger.error('Error acquiring client:: ' + connectErr.stack)
this.responseWithStatus(res, 500, connectErr.message);
}

try {
await this.pgExec(
QueryBuilder.buildInsert(params),
connectErrorHandler,
dbResponseHandler,
dbResErrorHandler);
} catch (e) {
this.logger.error(e.stack)
this.responseWithStatus(res, 400, e)
}
}

async pgExecDataInsert(req, res) {
this.responseWithStatus(res, 400, 'NOT IMPLEMENTED');
}
Expand Down
11 changes: 8 additions & 3 deletions app/lib/database/QueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
*/

const config = require('../config/configProvider.js');
const views = require("./views")
const { pagesNames: PN } = config.public;
const views = require('./views');
const procedures = require('./procedures')

const { pagesNames: PN, procedures: PC } = config.public;
const DRP = config.public.dataReqParams;

const pageToViewName = {};
Expand Down Expand Up @@ -82,7 +84,7 @@ class QueryBuilder {
return sqlWhereClause?.length > 0 ? `WHERE ${sqlWhereClause}` : '';
}

static build(params) {
static buildSelect(params) {

const dataSubsetQueryPart = (params) => params[DRP.countRecords] === 'true' ? '' :
`LIMIT ${params[DRP.rowsOnSite]} OFFSET ${params[DRP.rowsOnSite] * (params[DRP.site] - 1)}`;
Expand Down Expand Up @@ -113,6 +115,9 @@ class QueryBuilder {
${dataSubsetQueryPart(params)};`;
}

static buildInsertOrUpdate(params) {
return procedures[params.procedure](params)
}
}

module.exports = QueryBuilder;
72 changes: 72 additions & 0 deletions app/lib/database/procedures/flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* 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 flag_insert = (query) => `
DO
$do$
DECLARE pass_id integer;
DECLARE det_id integer;
DECLARE flag_id integer;
BEGIN
select id into pass_id from data_passes where name = '${query.data_pass_name}';
select id into det_id from detectors_subsystems where name = '${query.detector}';
select id into flag_id from flags_types_dictionary where name = '${query.flag_type}';

INSERT INTO quality_control_flags (data_pass_id, run_number, detector_id, flag_type_id,
time_start, time_end, comment, added_by, addition_time, last_modified_by, last_modification_time)
VALUES(pass_id, ${query.run_number}, det_id, flag_id,
${query.time_start}, ${query.time_end}, '${query.comment}', '${query.added_by}', now(), null, null);
END
$do$;
`;

const flag_update = (query) => {
return 'NOT IMPLEMENTED PLEASE REMOVE OLD FLAG INSTANCE';
`
DO
$do$
BEGIN
INSERT INTO quality_control_flags (data_pass_id, run_number, detector_id, flag_type_id,
time_start, time_end, comment, added_by, addition_time, last_modified_by, last_modification_time)
VALUES(pass_id, ${query.run_number}, det_id, flag_id,
${query.time_start}, ${query.time_end}, '${query.comment}', '${query.added_by}', now(), null, null);
END
$do$;
`;
}
const flag_delete = (query) => `
DO
$do$
BEGIN
DELETE FROM quality_control_flags where id = ${query.qcf_id};
END
$do$;
`;

const verification_insert = (query) => `
DO
$do$
BEGIN
INSERT INTO verifications (qcf_id, verification_time, verified_by)
VALUES(${query.qcf_id}, now(), '${query.by}');
END
$do$;
`;

module.exports = {
flag_insert,
flag_delete,
flag_update,
verification_insert
};
20 changes: 20 additions & 0 deletions app/lib/database/procedures/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* 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 flags = require('./flags.js');

module.exports = {
...flags
}
24 changes: 19 additions & 5 deletions app/lib/database/views/flags_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@
* or submit itself to any jurisdiction.
*/

const flags_view = (query) => `
const flags_view = (query) => {

rn = query.run_numbers;
let rn_sql = null;
if (typeof(rn) === 'object') {
rn_sql = rn.join(",");
} else if (typeof(rn) === 'string') {
rn_sql = rn
} else {
throw `run_number seems to be incorrect ${rn}`
}

return `
SELECT
qcf.id,
qcf.time_start,
qcf.time_end,
ftd.flag,
ftd.name,
qcf.comment,
r.run_number,
ds.name,
Expand All @@ -36,10 +49,11 @@ const flags_view = (query) => `
LEFT OUTER JOIN verifications as v
ON qcf.id = v.qcf_id

WHERE r.run_number in (${query.run_numbers.join(",")}) AND
dp.name = ${query.data_pass_id}
GROUP BY qcf.id, qcf.time_start, qcf.time_end, ftd.flag, qcf.comment, r.run_number, ds.name
WHERE r.run_number in (${rn_sql}) AND
dp.name = ${query.data_pass_name}
GROUP BY qcf.id, qcf.time_start, qcf.time_end, ftd.name, qcf.comment, r.run_number, ds.name

`;
}

module.exports = flags_view;
Loading