Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const dataPassesActiveColumns = {

nonPhysicsProductions: {
name: 'Include nonphysics productions',
filter: (filteringModel) => checkboxes(filteringModel.get('include[byName]').selectionModel),
filter: (filteringModel) => checkboxes(filteringModel.get('permittedNonPhysicsNames').selectionModel),
visible: false,
},
};
2 changes: 1 addition & 1 deletion lib/public/views/DataPasses/DataPassesOverviewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class DataPassesOverviewModel extends OverviewPageModel {
super();
this._filteringModel = new FilteringModel({
names: new TextTokensFilterModel(),
'include[byName]': new SelectionFilterModel({
permittedNonPhysicsNames: new SelectionFilterModel({
availableOptions: NON_PHYSICS_PRODUCTIONS_NAMES_WORDS.map((word) => ({ label: word.toUpperCase(), value: word })),
}),
});
Expand Down
12 changes: 5 additions & 7 deletions lib/server/controllers/dataPasses.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ const listDataPassesHandler = async (req, res) => {
lhcPeriodIds: Joi.array().items(Joi.number()),
ids: Joi.array().items(Joi.number()),
names: Joi.array().items(Joi.string()),
include: Joi.object({ byName: Joi.string().custom((value, helper) => {
if (value.length > 10) {
return helper.error('byName cannot have more than 10 characters');
}
const nameTokens = value?.split(',');
// 'debug,test' or the reverse have a length of 10
permittedNonPhysicsNames: Joi.string().max(10).custom((value, helper) => {
const nameTokens = value.split(',');
const allTokensCorrect = nameTokens.every((token) => NON_PHYSICS_PRODUCTIONS_NAMES_WORDS.includes(token));
if (!allTokensCorrect) {
return helper.error(`All byName must comma delimited list of ${NON_PHYSICS_PRODUCTIONS_NAMES_WORDS}`);
return helper.error(`All permittedNonPhysicsNames must comma delimited list of ${NON_PHYSICS_PRODUCTIONS_NAMES_WORDS}`);
}
return nameTokens;
}) }),
}),
},
page: PaginationDto,
sort: DtoFactory.order(['id', 'name']),
Expand Down
55 changes: 27 additions & 28 deletions lib/server/services/dataPasses/DataPassService.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,25 @@ class DataPassService {
* @returns {Promise<CountedItems<DataPass>>} result
*/
async getAll({
filter,
filter = {},
limit,
offset,
sort,
} = {}) {
const queryBuilder = this.prepareQueryBuilder();

/**
* @typedef
* @property {object} filter
* @property {number[]} [filter.lhcPeriodIds] lhcPeriod identifier to filter with
* @property {number[]} [filter.simulationPassIds] simulationPass identifier to filter with
* @property {number[]} [filter.ids] data passes identifier to filter with
* @property {string[]} [filter.names] data passes names to filter with
* @property {boolean} [filter.includeByName] list of tokens in data passes names which indicate
* a given data pass should not be excluded, possible tokens are 'test', 'debug'.
*/
const { ids, names, permittedNonPhysicsNames = [], lhcPeriodIds, simulationPassIds } = filter;

if (sort) {
for (const property in sort) {
queryBuilder.orderBy(property, sort[property]);
Expand All @@ -108,37 +120,24 @@ class DataPassService {
queryBuilder.offset(offset);
}

if (filter) {
/**
* @typedef
* @property {object} filter
* @property {number[]} [filter.lhcPeriodIds] lhcPeriod identifier to filter with
* @property {number[]} [filter.simulationPassIds] simulationPass identifier to filter with
* @property {number[]} [filter.ids] data passes identifier to filter with
* @property {string[]} [filter.names] data passes names to filter with
* @property {boolean} [filter.include.byName] list of tokens in data passes names which indicate
* a given data pass should not be excluded, possible tokens are 'test', 'debug'.
*/
const { ids, names, lhcPeriodIds, simulationPassIds } = filter;
if (lhcPeriodIds) {
queryBuilder.where('lhcPeriodId').oneOf(...lhcPeriodIds);
}
if (simulationPassIds) {
queryBuilder.whereAssociation('anchoredSimulationPasses', 'id').oneOf(...simulationPassIds);
}
if (ids) {
queryBuilder.where('id').oneOf(...ids);
}
if (names) {
queryBuilder.where('name').oneOf(...names);
}
if (lhcPeriodIds) {
queryBuilder.where('lhcPeriodId').oneOf(...lhcPeriodIds);
}
if (simulationPassIds) {
queryBuilder.whereAssociation('anchoredSimulationPasses', 'id').oneOf(...simulationPassIds);
}
if (ids) {
queryBuilder.where('id').oneOf(...ids);
}
if (names) {
queryBuilder.where('name').oneOf(...names);
}

const byName = filter?.include?.byName ?? [];
if (!byName.includes(NonPhysicsProductionsNamesWords.TEST)) {
if (!permittedNonPhysicsNames.includes(NonPhysicsProductionsNamesWords.TEST)) {
queryBuilder.where('name').not().substring(`\\_${NonPhysicsProductionsNamesWords.TEST}`);
}
if (!byName.includes(NonPhysicsProductionsNamesWords.DEBUG)) {

if (!permittedNonPhysicsNames.includes(NonPhysicsProductionsNamesWords.DEBUG)) {
queryBuilder.where('name').not().substring(`\\_${NonPhysicsProductionsNamesWords.DEBUG}`);
}

Expand Down
4 changes: 2 additions & 2 deletions test/api/dataPasses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ module.exports = () => {
});
});
it('should successfully include TEST productions', async () => {
const response = await request(server).get('/api/dataPasses?filter[lhcPeriodIds][]=2&filter[include][byName]=test');
const response = await request(server).get('/api/dataPasses?filter[lhcPeriodIds][]=2&filter[permittedNonPhysicsNames]=test');
expect(response.status).to.be.equal(200);
const { data } = await response.body;
expect(data.map(({ name }) => name)).to.have.all.members(['LHC22b_apass1', 'LHC22b_skimming','LHC22b_apass2_skimmed', 'LHC22b_test']);
});
it('should successfully include DEBUG productions', async () => {
const response = await request(server).get('/api/dataPasses?filter[lhcPeriodIds][]=2&filter[include][byName]=debug');
const response = await request(server).get('/api/dataPasses?filter[lhcPeriodIds][]=2&filter[permittedNonPhysicsNames]=debug');
expect(response.status).to.be.equal(200);
const { data } = await response.body;
expect(data.map(({ name }) => name)).to.have.all.members(['LHC22b_apass1', 'LHC22b_skimming','LHC22b_apass2_skimmed', 'LHC22b_debug']);
Expand Down
Loading