diff --git a/sample.env b/sample.env index c30f41c5..8fccfdfa 100644 --- a/sample.env +++ b/sample.env @@ -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= PROPOSAL_FOLDERS_CREATION_GROUP_PREFIX="" diff --git a/src/config/validateEnv.ts b/src/config/validateEnv.ts index df7e4bf8..f974cfe0 100644 --- a/src/config/validateEnv.ts +++ b/src/config/validateEnv.ts @@ -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 }), diff --git a/src/queue/consumers/scicat/scicatProposal/mappers/__snapshots__/uoToScicatExperiment.mapper.spec.ts.snap b/src/queue/consumers/scicat/scicatProposal/mappers/__snapshots__/uoToScicatExperiment.mapper.spec.ts.snap index d7008eb9..edb914f7 100644 --- a/src/queue/consumers/scicat/scicatProposal/mappers/__snapshots__/uoToScicatExperiment.mapper.spec.ts.snap +++ b/src/queue/consumers/scicat/scicatProposal/mappers/__snapshots__/uoToScicatExperiment.mapper.spec.ts.snap @@ -14,6 +14,9 @@ Test Abstract", "instrumentIds": [ "scicat-inst-1", ], + "keywords": [ + "WF_01_00", + ], "lastname": "Doe", "metadata": { "instrument_name": { @@ -111,6 +114,9 @@ Test Abstract", "instrumentIds": [ "scicat-inst-1", ], + "keywords": [ + "WF_01_00", + ], "lastname": "Doe", "metadata": { "instrument_name": { diff --git a/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.spec.ts b/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.spec.ts index 90026d14..a8124863 100644 --- a/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.spec.ts +++ b/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.spec.ts @@ -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({ @@ -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(), diff --git a/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.ts b/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.ts index 61c9cc1f..897e87cf 100644 --- a/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.ts +++ b/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.ts @@ -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 ──────────────────────────────────────────────────────────────── // ────────────────────────────────────────────────────────────────────────────── @@ -123,6 +136,7 @@ export const getCreateScicatExperimentDto = ( endTime: new Date(experiment.endsAt), MeasurementPeriodList: [], metadata: buildMetadata(experiment), + keywords: newExperimentKeywords(), }; }; diff --git a/src/queue/consumers/scicat/scicatProposal/type/scicatProposal.type.ts b/src/queue/consumers/scicat/scicatProposal/type/scicatProposal.type.ts index 612e58ec..5f0960c7 100644 --- a/src/queue/consumers/scicat/scicatProposal/type/scicatProposal.type.ts +++ b/src/queue/consumers/scicat/scicatProposal/type/scicatProposal.type.ts @@ -26,6 +26,7 @@ export type CreateScicatProposalDto = { instrumentIds: string[]; MeasurementPeriodList: any[]; metadata?: Record; + keywords?: string[]; }; export type UpdateScicatProposalDto = {