Skip to content

Commit e3037a9

Browse files
author
NarrowsProjects
committed
feat: create summary view for data pass and data pass versions
1 parent 2636bf3 commit e3037a9

7 files changed

Lines changed: 108 additions & 53 deletions

File tree

lib/database/adapters/DataPassAdapter.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DataPassAdapter {
2020
*/
2121
constructor() {
2222
this.toEntity = this.toEntity.bind(this);
23+
this.toSummary = this.toSummary.bind(this);
2324
this.dataPassVersionAdapter = null;
2425
}
2526

@@ -30,13 +31,22 @@ class DataPassAdapter {
3031
* @returns {DataPass} Converted entity object.
3132
*/
3233
toEntity(databaseObject) {
33-
const {
34-
id,
35-
name,
36-
versions,
37-
skimmingStage,
38-
isFrozen,
39-
} = databaseObject;
34+
const { versions = [] } = databaseObject;
35+
36+
const entity = this.toSummary(databaseObject);
37+
entity.versions = versions.map(this.dataPassVersionAdapter.toEntity);
38+
39+
return entity;
40+
}
41+
42+
/**
43+
* Converts the given database object to an entity object.
44+
*
45+
* @param {SequelizeDataPass} databaseObject Object to convert.
46+
* @returns {DataPass} Converted entity object.
47+
*/
48+
toSummary(databaseObject) {
49+
const { id, name, skimmingStage, versions = [], isFrozen } = databaseObject;
4050

4151
const runsCount = databaseObject.get('runsCount');
4252
const simulationPassesCount = databaseObject.get('simulationPassesCount');
@@ -45,9 +55,9 @@ class DataPassAdapter {
4555
return {
4656
id,
4757
name,
48-
skimmingStage,
49-
versions: (versions ?? []).map(this.dataPassVersionAdapter.toEntity),
58+
versions: versions.map(this.dataPassVersionAdapter.toSummary),
5059
pdpBeamTypes,
60+
skimmingStage,
5161
runsCount,
5262
simulationPassesCount,
5363
isFrozen,

lib/database/adapters/DataPassVersionAdapter.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DataPassVersionAdapter {
2020
*/
2121
constructor() {
2222
this.toEntity = this.toEntity.bind(this);
23+
this.toSummary = this.toSummary.bind(this);
2324
this.dataPassVersionStatusAdapter = null;
2425
}
2526

@@ -30,32 +31,38 @@ class DataPassVersionAdapter {
3031
* @returns {DataPass} Converted entity object.
3132
*/
3233
toEntity(databaseObject) {
34+
const entity = this.toSummary(databaseObject);
35+
const { id, dataPassId, lastSeen, statusHistory = [], createdAt, updatedAt } = databaseObject;
36+
37+
entity.statusHistory = statusHistory.map(this.dataPassVersionStatusAdapter.toEntity);
38+
entity.id = id;
39+
entity.dataPassId = dataPassId;
40+
entity.lastSeen = lastSeen;
41+
entity.createdAt = createdAt ? new Date(createdAt).getTime() : null;
42+
entity.updatedAt = updatedAt ? new Date(updatedAt).getTime() : null;
43+
44+
return entity;
45+
}
46+
47+
/**
48+
* Converts the given database object to an summary object.
49+
*
50+
* @param {SequelizeDataPass} databaseObject Object to convert.
51+
* @returns {DataPass} Converted summary object.
52+
*/
53+
toSummary(databaseObject) {
3354
const {
34-
id,
35-
dataPassId,
3655
description,
3756
reconstructedEventsCount,
3857
outputSize,
39-
lastSeen,
40-
4158
statusHistory = [],
42-
43-
createdAt,
44-
updatedAt,
4559
} = databaseObject;
4660

4761
return {
48-
id,
49-
dataPassId,
5062
description,
5163
reconstructedEventsCount,
5264
outputSize,
53-
lastSeen,
54-
55-
statusHistory: (statusHistory ?? []).map(this.dataPassVersionStatusAdapter.toEntity),
56-
57-
createdAt: createdAt ? new Date(createdAt).getTime() : null,
58-
updatedAt: updatedAt ? new Date(updatedAt).getTime() : null,
65+
statusHistory: statusHistory.map(this.dataPassVersionStatusAdapter.toSummary),
5966
};
6067
}
6168
}

lib/database/adapters/DataPassVersionStatusAdapter.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ class DataPassVersionStatusAdapter {
4343
createdAt: createdAt ? new Date(createdAt).getTime() : null,
4444
};
4545
}
46+
47+
/**
48+
* Converts the given database object to an summary object.
49+
*
50+
* @param {SequelizeDataPassVersionStatus} databaseObject Object to convert.
51+
* @returns {DataPassVersionStatus} Converted summary object.
52+
*/
53+
toSummary(databaseObject) {
54+
const { status } = databaseObject;
55+
return { status };
56+
}
4657
}
4758

4859
module.exports = { DataPassVersionStatusAdapter };

lib/server/services/dataPasses/DataPassService.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14-
const { Op } = require('sequelize');
1514
const { repositories: { DataPassRepository, LhcPeriodRepository } } = require('../../../database');
1615
const { dataSource } = require('../../../database/DataSource.js');
1716
const { dataPassAdapter } = require('../../../database/adapters');
@@ -23,6 +22,7 @@ const { BadParameterError } = require('../../errors/BadParameterError');
2322
const { SkimmingStage } = require('../../../domain/enums/SkimmingStage');
2423
const { LogManager } = require('@aliceo2/web-ui');
2524
const { NonPhysicsProductionsNamesWords } = require('../../../domain/enums/NonPhysicsProductionsNamesWords.js');
25+
const { dataPassSumary, dataPassVersionSummary } = require('../../views/dataPasses/summary.js');
2626

2727
/**
2828
* @typedef DataPassIdentifier
@@ -141,12 +141,17 @@ class DataPassService {
141141
queryBuilder.where('name').not().substring(`\\_${NonPhysicsProductionsNamesWords.DEBUG}`);
142142
}
143143

144+
queryBuilder.selectAttributes([...dataPassSumary.attributes]);
145+
144146
const { count, rows } = await DataPassRepository.findAndCountAll(queryBuilder);
145-
const dataPassesVersions = await DataPassVersionRepository.findAll({
146-
include: 'statusHistory',
147-
where: { dataPassId: { [Op.in]: rows.map(({ id }) => id) } },
148-
order: [['statusHistory', 'createdAt', 'ASC']],
149-
});
147+
const dataPassVersionsQueryBuilder = dataSource.createQueryBuilder();
148+
149+
dataPassVersionsQueryBuilder.selectAttributes([...dataPassVersionSummary.attributes]);
150+
dataPassVersionsQueryBuilder.includeAll([...dataPassVersionSummary.include]);
151+
dataPassVersionsQueryBuilder.where('dataPassId').oneOf(...rows.map(({ id }) => id));
152+
dataPassVersionsQueryBuilder.pushOrders([...dataPassVersionSummary.order]);
153+
const dataPassesVersions = await DataPassVersionRepository.findAll(dataPassVersionsQueryBuilder);
154+
150155
const dataPassIdToVersions = dataPassesVersions.reduce((acc, version) => {
151156
const { dataPassId } = version;
152157
acc[dataPassId] = [...acc[dataPassId] ?? [], version];
@@ -159,7 +164,7 @@ class DataPassService {
159164

160165
return {
161166
count: count.length, // When using grouping sequelize returns from finAndCountAll counts per each group
162-
rows: rows.map(dataPassAdapter.toEntity),
167+
rows: rows.map(dataPassAdapter.toSummary),
163168
};
164169
}
165170

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
export const dataPassSumary = {
15+
attributes: ['id', 'name', 'skimmingStage', 'isFrozen'],
16+
};
17+
18+
export const dataPassVersionSummary = {
19+
attributes: ['outputSize', 'reconstructedEventsCount', 'description', 'dataPassId'],
20+
include: [{ association: 'statusHistory', attributes: ['status'] }],
21+
order: [['statusHistory', 'createdAt', 'ASC']],
22+
};

test/api/dataPasses.test.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,18 @@ const { Op } = require('sequelize');
2222
const { buildUrl } = require('@aliceo2/web-ui');
2323
const { BkpRoles } = require('../../lib/domain/enums/BkpRoles.js');
2424

25-
const LHC22b_apass1 = {
25+
const LHC22b_apass1_summary = {
2626
id: 1,
2727
name: 'LHC22b_apass1',
2828
pdpBeamTypes: ['pp'],
2929
skimmingStage: SkimmingStage.SKIMMABLE,
3030
isFrozen: false,
3131
versions: [
3232
{
33-
id: 1,
34-
dataPassId: 1,
3533
description: 'Some random desc',
3634
reconstructedEventsCount: 50948694,
3735
outputSize: 56875682112600,
38-
lastSeen: 108,
39-
statusHistory: [
40-
{
41-
createdAt: 1704884400000,
42-
dataPassVersionId: 1,
43-
id: 1,
44-
status: 'Running',
45-
},
46-
{
47-
createdAt: 1704885060000,
48-
dataPassVersionId: 1,
49-
id: 2,
50-
status: 'Deleted',
51-
},
52-
],
53-
createdAt: 1704884400000,
54-
updatedAt: 1704884400000,
36+
statusHistory: [{ status: 'Running' }, { status: 'Deleted' }],
5537
},
5638
],
5739
runsCount: 3,
@@ -94,7 +76,7 @@ module.exports = () => {
9476
expect(meta).to.be.eql({ page: { totalCount: 1, pageCount: 1 } });
9577
expect(data).to.be.an('array');
9678
expect(data).to.be.lengthOf(1);
97-
expect(data[0]).to.be.eql(LHC22b_apass1);
79+
expect(data[0]).to.be.eql(LHC22b_apass1_summary);
9880

9981
done();
10082
});

test/lib/server/services/dataPasses/DataPassService.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ const LHC22b_apass1 = {
5959
simulationPassesCount: 1,
6060
};
6161

62+
const LHC22b_apass1_summary = {
63+
id: 1,
64+
name: 'LHC22b_apass1',
65+
pdpBeamTypes: ['pp'],
66+
skimmingStage: SkimmingStage.SKIMMABLE,
67+
isFrozen: false,
68+
versions: [
69+
{
70+
description: 'Some random desc',
71+
reconstructedEventsCount: 50948694,
72+
outputSize: 56875682112600,
73+
statusHistory: [{ status: 'Running' }, { status: 'Deleted' }],
74+
},
75+
],
76+
runsCount: 3,
77+
simulationPassesCount: 1,
78+
};
79+
6280
module.exports = () => {
6381
before(resetDatabaseContent);
6482

@@ -95,7 +113,7 @@ module.exports = () => {
95113
};
96114
const { rows: dataPasses } = await dataPassService.getAll(dto.query);
97115
expect(dataPasses).to.be.lengthOf(1);
98-
expect(dataPasses[0]).to.be.eql(LHC22b_apass1);
116+
expect(dataPasses[0]).to.be.eql(LHC22b_apass1_summary);
99117
});
100118

101119
it('should successfully filter data passes on ids', async () => {

0 commit comments

Comments
 (0)