Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate dataset principalInvestigator to principalInvestigators #1536

Merged
merged 4 commits into from
Dec 11, 2024
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
31 changes: 31 additions & 0 deletions migrations/20241202105905-multiple-principal-investigators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
async up(db, client) {
await db.collection("Dataset").updateMany({}, [
{
$set: {
principalInvestigators: ["$principalInvestigator"],
},
},
]);

await db
.collection("Dataset")
.updateMany({}, { $unset: { principalInvestigator: "" } });
},

async down(db, client) {
await db.collection("Dataset").updateMany({}, [
{
$set: {
principalInvestigator: {
$arrayElemAt: ["$principalInvestigators", 0],
},
},
},
]);

await db
.collection("Dataset")
.updateMany({}, { $unset: { principalInvestigators: "" } });
},
};
65 changes: 53 additions & 12 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,28 @@ export class DatasetsController {
whereFilter.instrumentIds = whereFilter.instrumentId;
delete whereFilter.instrumentId;
}
if ("investigator" in whereFilter) {
if (typeof whereFilter.investigator === "string") {
whereFilter.principalInvestigators = {
$in: [whereFilter.investigator],
};
} else {
whereFilter.principalInvestigators = whereFilter.investigator;
}

delete whereFilter.investigator;
}
if ("principalInvestigator" in whereFilter) {
whereFilter.investigator = whereFilter.principalInvestigator;
if (typeof whereFilter.investigator === "string") {
whereFilter.principalInvestigators = {
$in: [whereFilter.principalInvestigator],
};
} else {
whereFilter.principalInvestigators = whereFilter.principalInvestigator;
}
delete whereFilter.principalInvestigator;
}

return whereFilter;
}
convertObsoleteToCurrentSchema(
Expand Down Expand Up @@ -463,15 +481,22 @@ export class DatasetsController {
(inputObsoleteDataset as CreateRawDatasetObsoleteDto).instrumentId,
];
}
if ("principalInvestigator" in inputObsoleteDataset) {
propertiesModifier.principalInvestigators = [
(inputObsoleteDataset as CreateRawDatasetObsoleteDto)
.principalInvestigator,
];
}
} else if (
inputObsoleteDataset instanceof CreateDerivedDatasetObsoleteDto ||
inputObsoleteDataset instanceof UpdateDerivedDatasetObsoleteDto ||
inputObsoleteDataset instanceof PartialUpdateDerivedDatasetObsoleteDto
) {
if ("investigator" in inputObsoleteDataset) {
propertiesModifier.principalInvestigator = (
inputObsoleteDataset as CreateDerivedDatasetObsoleteDto
).investigator;
propertiesModifier.principalInvestigators = [
(inputObsoleteDataset as CreateDerivedDatasetObsoleteDto)
.investigator,
];
}
}

Expand Down Expand Up @@ -516,18 +541,34 @@ export class DatasetsController {
): OutputDatasetObsoleteDto {
const propertiesModifier: Record<string, unknown> = {};
if (inputDataset) {
if ("proposalIds" in inputDataset) {
propertiesModifier.proposalId = inputDataset.proposalIds![0];
if ("proposalIds" in inputDataset && inputDataset.proposalIds?.length) {
propertiesModifier.proposalId = inputDataset.proposalIds[0];
}
if ("sampleIds" in inputDataset && inputDataset.sampleIds?.length) {
propertiesModifier.sampleId = inputDataset.sampleIds[0];
}
if ("sampleIds" in inputDataset) {
propertiesModifier.sampleId = inputDataset.sampleIds![0];
if (
"instrumentIds" in inputDataset &&
inputDataset.instrumentIds?.length
) {
propertiesModifier.instrumentId = inputDataset.instrumentIds[0];
}
if ("instrumentIds" in inputDataset) {
propertiesModifier.instrumentId = inputDataset.instrumentIds![0];

if (
"principalInvestigators" in inputDataset &&
inputDataset.principalInvestigators?.length
) {
propertiesModifier.principalInvestigator =
inputDataset.principalInvestigators[0];
}

if (inputDataset.type == "derived") {
if ("investigator" in inputDataset) {
propertiesModifier.investigator = inputDataset.principalInvestigator;
if (
"investigator" in inputDataset &&
inputDataset.principalInvestigators?.length
) {
propertiesModifier.investigator =
inputDataset.principalInvestigators[0];
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/datasets/datasets.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const mockDataset: DatasetClass = {
pid: "testPid",
owner: "testOwner",
ownerEmail: "[email protected]",
instrumentId: "testInstrumentId",
instrumentIds: ["testInstrumentId"],
orcidOfOwner: "https://0000.0000.0000.0001",
contactEmail: "[email protected]",
sourceFolder: "/nfs/groups/beamlines/test/123456",
Expand Down Expand Up @@ -59,24 +59,20 @@ const mockDataset: DatasetClass = {
createdAt: new Date("2021-11-11T12:29:02.083Z"),
updatedAt: new Date("2021-11-11T12:29:02.083Z"),
techniques: [],
principalInvestigator: "testInvestigator",
principalInvestigators: ["testInvestigator"],
endTime: new Date("2021-12-11T12:29:02.083Z"),
creationLocation: "test",
dataFormat: "Test Format",
scientificMetadata: {},
proposalId: "ABCDEF",
sampleId: "testSampleId",
attachments: [],
proposalIds: ["ABCDEF"],
sampleIds: ["testSampleId"],
accessGroups: [],
createdBy: "test user",
datablocks: [],
origdatablocks: [],
ownerGroup: "test",
relationships: [],
sharedWith: [],
updatedBy: "test",
instrumentGroup: "test",
investigator: "test",
inputDatasets: [],
usedSoftware: [],
jobParameters: {},
Expand Down
10 changes: 6 additions & 4 deletions src/datasets/dto/update-dataset.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,14 @@ export class UpdateDatasetDto extends OwnableDto {

@ApiProperty({
type: String,
required: true,
required: false,
isArray: true,
description:
"First name and last name of principal investigator(s). If multiple PIs are present, use a semicolon separated list. This field is required if the dataset is a Raw dataset.",
"First and last name of principal investigator(s). Multiple PIs can be provided as separate strings in the array. This field is required if the dataset is a Raw dataset.",
})
@IsString()
readonly principalInvestigator: string;
@IsOptional()
@IsString({ each: true })
readonly principalInvestigators?: string[];

@ApiProperty({
type: Date,
Expand Down
7 changes: 4 additions & 3 deletions src/datasets/schemas/dataset.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Document } from "mongoose";
import { OwnableClass } from "src/common/schemas/ownable.schema";
import { v4 as uuidv4 } from "uuid";
import { DatasetType } from "../dataset-type.enum";

Check warning on line 6 in src/datasets/schemas/dataset.schema.ts

View workflow job for this annotation

GitHub Actions / eslint

'DatasetType' is defined but never used
import { HistoryClass, HistorySchema } from "./history.schema";
import { LifecycleClass, LifecycleSchema } from "./lifecycle.schema";
import { RelationshipClass, RelationshipSchema } from "./relationship.schema";
Expand Down Expand Up @@ -357,11 +357,12 @@
@ApiProperty({
type: String,
required: false,
isArray: true,
description:
"First name and last name of principal investigator(s). If multiple PIs are present, use a semicolon separated list. This field is required if the dataset is a Raw dataset.",
"First and last name of principal investigator(s). Multiple PIs can be provided as separate strings in the array. This field is required if the dataset is a Raw dataset.",
})
@Prop({ type: String, required: false })
principalInvestigator?: string;
@Prop({ type: [String], required: false })
principalInvestigators?: string[];
martin-trajanovski marked this conversation as resolved.
Show resolved Hide resolved

@ApiProperty({
type: Date,
Expand Down
2 changes: 1 addition & 1 deletion test/DatasetCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("2400: CustomDataset: Custom Type Datasets", () => {
before(() => {
db.collection("Dataset").deleteMany({});
});
beforeEach(async() => {
beforeEach(async () => {
accessTokenAdminIngestor = await utils.getToken(appUrl, {
username: "adminIngestor",
password: TestData.Accounts["adminIngestor"]["password"],
Expand Down
10 changes: 5 additions & 5 deletions test/TestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ const TestData = {
},

CustomDatasetCorrectMin: {
principalInvestigator: faker.internet.email(),
principalInvestigators: [faker.internet.email()],
owner: faker.internet.username(),
contactEmail: faker.internet.email(),
sourceFolder: faker.system.directoryPath(),
Expand All @@ -492,7 +492,7 @@ const TestData = {
},

CustomDatasetCorrect: {
principalInvestigator: "[email protected]",
principalInvestigators: ["[email protected]"],
inputDatasets: ["/data/input/file1.dat"],
usedSoftware: [
"https://gitlab.psi.ch/ANALYSIS/csaxs/commit/7d5888bfffc440bb613bc7fa50adc0097853446c",
Expand Down Expand Up @@ -522,7 +522,7 @@ const TestData = {
},

CustomDatasetWrongType: {
principalInvestigator: "[email protected]",
principalInvestigators: ["[email protected]"],
jobParameters: {
nscans: 10,
},
Expand All @@ -540,7 +540,7 @@ const TestData = {
},

CustomDatasetWrongData: {
principalInvestigator: "[email protected]",
principalInvestigators: ["[email protected]"],
jobParameters: {
nscans: 10,
},
Expand All @@ -559,7 +559,7 @@ const TestData = {
},

CustomDatasetIncompleteData: {
principalInvestigator: "[email protected]",
principalInvestigators: ["[email protected]"],
jobParameters: {
nscans: 10,
},
Expand Down
Loading