Skip to content
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
2 changes: 2 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ SCICAT_USERNAME=
SCICAT_PASSWORD=
SCICAT_PROPOSAL_TRIGGERING_STATUSES="SCHEDULING, ALLOCATED"
SCICAT_EXPERIMENT_TRIGGERING_STATUSES="ACTIVE"
# Keywords set on every new experiment, comma separated. Empty or unset: WF_01_00
SCICAT_NEW_EXPERIMENT_KEYWORDS="WF_01_00"
SCICAT_JWT=<token>

PROPOSAL_FOLDERS_CREATION_GROUP_PREFIX=""
Expand Down
1 change: 1 addition & 0 deletions src/config/validateEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function validateEnv() {
GRAYLOG_SERVER: str({ default: 'it-graylog.esss.lu.se' }),
GRAYLOG_PORT: port({ default: 12201 }),
SCICAT_PROPOSAL_TRIGGERING_STATUSES: str({ default: undefined }),
SCICAT_NEW_EXPERIMENT_KEYWORDS: str({ default: 'WF_01_00' }),
PROPOSAL_FOLDERS_CREATION_GROUP_PREFIX: str({ default: '' }),
PROPOSAL_FOLDERS_CREATION_COMMAND: str({ default: undefined }),
PROPOSAL_FOLDERS_CREATION_TRIGGERING_STATUSES: str({ default: undefined }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Test Abstract",
"instrumentIds": [
"scicat-inst-1",
],
"keywords": [
"WF_01_00",
],
"lastname": "Doe",
"metadata": {
"instrument_name": {
Expand Down Expand Up @@ -111,6 +114,9 @@ Test Abstract",
"instrumentIds": [
"scicat-inst-1",
],
"keywords": [
"WF_01_00",
],
"lastname": "Doe",
"metadata": {
"instrument_name": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,54 @@ describe('getCreateScicatExperimentDto', () => {
});
});

describe('keywords from SCICAT_NEW_EXPERIMENT_KEYWORDS', () => {
afterEach(() => {
delete process.env.SCICAT_NEW_EXPERIMENT_KEYWORDS;
});

it('sets the configured keyword on the new experiment', () => {
process.env.SCICAT_NEW_EXPERIMENT_KEYWORDS = 'WF_01_00';

const dto = getCreateScicatExperimentDto(
createBaseUoExperiment(),
instrumentIds
);

expect(dto.keywords).toEqual(['WF_01_00']);
});

it('accepts a comma separated list and trims spaces', () => {
process.env.SCICAT_NEW_EXPERIMENT_KEYWORDS = 'WF_01_00, WF_02_00 ,';

const dto = getCreateScicatExperimentDto(
createBaseUoExperiment(),
instrumentIds
);

expect(dto.keywords).toEqual(['WF_01_00', 'WF_02_00']);
});

it('falls back to WF_01_00 when the setting is not set', () => {
const dto = getCreateScicatExperimentDto(
createBaseUoExperiment(),
instrumentIds
);

expect(dto.keywords).toEqual(['WF_01_00']);
});

it('falls back to WF_01_00 when the setting is empty', () => {
process.env.SCICAT_NEW_EXPERIMENT_KEYWORDS = ' ';

const dto = getCreateScicatExperimentDto(
createBaseUoExperiment(),
instrumentIds
);

expect(dto.keywords).toEqual(['WF_01_00']);
});
});

it('skips visitor entries when user is null', () => {
const dto = getCreateScicatExperimentDto(
createBaseUoExperiment({
Expand Down Expand Up @@ -173,6 +221,18 @@ describe('getUpdateScicatExperimentDto', () => {
});
});

it('does not send keywords, so the workflow keywords are kept', () => {
process.env.SCICAT_NEW_EXPERIMENT_KEYWORDS = 'WF_01_00';

const dto = getUpdateScicatExperimentDto(
createBaseUoExperiment(),
instrumentIds
);

expect((dto as any).keywords).toBeUndefined();
delete process.env.SCICAT_NEW_EXPERIMENT_KEYWORDS;
});

it('should not include proposalId', () => {
const dto = getUpdateScicatExperimentDto(
createBaseUoExperiment(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ import {
import { metadataEntry } from '../utils/common';
import { scicatApi } from '../utils/scicatApi';

// Keywords set on every new experiment, from SCICAT_NEW_EXPERIMENT_KEYWORDS (comma separated),
// WF_01_00 when none are given. Create only: SciCat replaces the whole keyword list on update.
const DEFAULT_NEW_EXPERIMENT_KEYWORDS = ['WF_01_00'];

const newExperimentKeywords = (): string[] => {
const keywords = (process.env.SCICAT_NEW_EXPERIMENT_KEYWORDS ?? '')
.split(',')
.map((keyword) => keyword.trim())
.filter(Boolean);

return keywords.length > 0 ? keywords : DEFAULT_NEW_EXPERIMENT_KEYWORDS;
};

// ──────────────────────────────────────────────────────────────────────────────
// ── Experiment ────────────────────────────────────────────────────────────────
// ──────────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -123,6 +136,7 @@ export const getCreateScicatExperimentDto = (
endTime: new Date(experiment.endsAt),
MeasurementPeriodList: [],
metadata: buildMetadata(experiment),
keywords: newExperimentKeywords(),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type CreateScicatProposalDto = {
instrumentIds: string[];
MeasurementPeriodList: any[];
metadata?: Record<string, unknown>;
keywords?: string[];
};

export type UpdateScicatProposalDto = {
Expand Down
Loading