From 1798c0cc13386955f5d0245951a30b98d06cb5bc Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 4 Sep 2024 17:28:26 +0200 Subject: [PATCH 01/38] refactor naming of current dataset schema and dto. Added new unified dataset schema and dto --- src/datasets/datasets.controller.ts | 19 +- src/datasets/datasets.service.ts | 36 ++- .../dto/create-dataset-obsolete.dto.ts | 34 ++ src/datasets/dto/create-dataset.dto.ts | 9 - .../dto/output-dataset-obsolete.dto.ts | 237 ++++++++++++++ src/datasets/dto/output-dataset.dto.ts | 41 +++ .../dto/update-dataset-obsolete.dto.ts | 298 ++++++++++++++++++ src/datasets/dto/update-dataset.dto.ts | 141 ++++++++- .../dto/update-derived-dataset.dto.ts | 4 +- src/datasets/dto/update-raw-dataset.dto.ts | 4 +- src/datasets/schemas/dataset.schema.ts | 149 ++++----- 11 files changed, 852 insertions(+), 120 deletions(-) create mode 100644 src/datasets/dto/create-dataset-obsolete.dto.ts create mode 100644 src/datasets/dto/output-dataset-obsolete.dto.ts create mode 100644 src/datasets/dto/output-dataset.dto.ts create mode 100644 src/datasets/dto/update-dataset-obsolete.dto.ts diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 0d7706ee1..42233e22a 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -36,7 +36,7 @@ import { } from "@nestjs/swagger"; import { Request } from "express"; import { DatasetsService } from "./datasets.service"; -import { PartialUpdateDatasetDto } from "./dto/update-dataset.dto"; +import { PartialUpdateDatasetObsoleteDto } from "./dto/update-dataset-obsolete.dto"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; import { CreateRawDatasetDto } from "./dto/create-raw-dataset.dto"; import { CreateDerivedDatasetDto } from "./dto/create-derived-dataset.dto"; @@ -98,6 +98,7 @@ import { JWTUser } from "src/auth/interfaces/jwt-user.interface"; import { LogbooksService } from "src/logbooks/logbooks.service"; import configuration from "src/config/configuration"; import { DatasetType } from "./dataset-type.enum"; +import { OutputDatasetObsoleteDto } from "./dto/output-dataset-obsolete.dto"; @ApiBearerAuth() @ApiExtraModels( @@ -597,7 +598,7 @@ export class DatasetsController { @Req() request: Request, @Headers() headers: Record, @Query(new FilterPipe()) queryFilter: { filter?: string }, - ): Promise { + ): Promise { const mergedFilters = replaceLikeOperator( this.updateMergedFiltersForList( request, @@ -606,7 +607,9 @@ export class DatasetsController { ) as IFilters; // this should be implemented at database level - const datasets = await this.datasetsService.findAll(mergedFilters); + const datasets = (await this.datasetsService.findAll( + mergedFilters, + )) as OutputDatasetObsoleteDto[]; if (datasets && datasets.length > 0) { const includeFilters = mergedFilters.include ?? []; await Promise.all( @@ -917,7 +920,7 @@ export class DatasetsController { @Req() request: Request, @Headers() headers: Record, @Query(new FilterPipe()) queryFilter: { filter?: string }, - ): Promise { + ): Promise { const mergedFilters = replaceLikeOperator( this.updateMergedFiltersForList( request, @@ -927,7 +930,7 @@ export class DatasetsController { const dataset = (await this.datasetsService.findOne( mergedFilters, - )) as DatasetClass; + )) as OutputDatasetObsoleteDto; if (dataset) { const includeFilters = mergedFilters.include ?? []; @@ -1585,7 +1588,7 @@ export class DatasetsController { const datablock = await this.origDatablocksService.create(createOrigDatablock); - const updateDatasetDto: PartialUpdateDatasetDto = { + const updateDatasetDto: PartialUpdateDatasetObsoleteDto = { size: dataset.size + datablock.size, numberOfFiles: dataset.numberOfFiles + datablock.dataFileList.length, }; @@ -1804,7 +1807,7 @@ export class DatasetsController { where: { datasetId: pid }, }); // update dataset size and files number - const updateDatasetDto: PartialUpdateDatasetDto = { + const updateDatasetDto: PartialUpdateDatasetObsoleteDto = { size: odb.reduce((a, b) => a + b.size, 0), numberOfFiles: odb.reduce((a, b) => a + b.dataFileList.length, 0), }; @@ -2034,7 +2037,7 @@ export class DatasetsController { datasetId: pid, }); // update dataset size and files number - const updateDatasetDto: PartialUpdateDatasetDto = { + const updateDatasetDto: PartialUpdateDatasetObsoleteDto = { packedSize: remainingDatablocks.reduce((a, b) => a + b.packedSize, 0), numberOfFilesArchived: remainingDatablocks.reduce( (a, b) => a + b.dataFileList.length, diff --git a/src/datasets/datasets.service.ts b/src/datasets/datasets.service.ts index c78974c1e..680222e8e 100644 --- a/src/datasets/datasets.service.ts +++ b/src/datasets/datasets.service.ts @@ -24,11 +24,11 @@ import { ElasticSearchService } from "src/elastic-search/elastic-search.service" import { InitialDatasetsService } from "src/initial-datasets/initial-datasets.service"; import { LogbooksService } from "src/logbooks/logbooks.service"; import { DatasetType } from "./dataset-type.enum"; -import { CreateDatasetDto } from "./dto/create-dataset.dto"; +import { CreateDatasetObsoleteDto } from "./dto/create-dataset-obsolete.dto"; import { - PartialUpdateDatasetDto, - UpdateDatasetDto, -} from "./dto/update-dataset.dto"; + PartialUpdateDatasetObsoleteDto, + UpdateDatasetObsoleteDto, +} from "./dto/update-dataset-obsolete.dto"; import { PartialUpdateDerivedDatasetDto, UpdateDerivedDatasetDto, @@ -58,7 +58,9 @@ export class DatasetsService { } } - async create(createDatasetDto: CreateDatasetDto): Promise { + async create( + createDatasetDto: CreateDatasetObsoleteDto, + ): Promise { const username = (this.request.user as JWTUser).username; const createdDataset = new this.datasetModel( // insert created and updated fields @@ -206,7 +208,7 @@ export class DatasetsService { async findByIdAndReplace( id: string, updateDatasetDto: - | UpdateDatasetDto + | UpdateDatasetObsoleteDto | UpdateRawDatasetDto | UpdateDerivedDatasetDto, ): Promise { @@ -252,7 +254,7 @@ export class DatasetsService { async findByIdAndUpdate( id: string, updateDatasetDto: - | PartialUpdateDatasetDto + | PartialUpdateDatasetObsoleteDto | PartialUpdateRawDatasetDto | PartialUpdateDerivedDatasetDto | UpdateQuery, @@ -434,20 +436,28 @@ export class DatasetsService { async updateHistory( req: Request, dataset: DatasetClass, - data: UpdateDatasetDto, + data: UpdateDatasetObsoleteDto, ) { if (req.body.history) { delete req.body.history; } if (!req.body.size && !req.body.packedSize) { - const updatedFields: Omit = - data; + const updatedFields: Omit< + UpdateDatasetObsoleteDto, + "updatedAt" | "updatedBy" + > = data; const historyItem: Record = {}; Object.keys(updatedFields).forEach((updatedField) => { - historyItem[updatedField as keyof UpdateDatasetDto] = { - currentValue: data[updatedField as keyof UpdateDatasetDto], - previousValue: dataset[updatedField as keyof UpdateDatasetDto], + historyItem[updatedField as keyof UpdateDatasetObsoleteDto] = { + currentValue: data[updatedField as keyof UpdateDatasetObsoleteDto], + previousValue: + dataset[ + updatedField as keyof Omit< + UpdateDatasetObsoleteDto, + "attachments" | "origdatablocks" | "datablocks" + > + ], }; }); dataset.history = dataset.history ?? []; diff --git a/src/datasets/dto/create-dataset-obsolete.dto.ts b/src/datasets/dto/create-dataset-obsolete.dto.ts new file mode 100644 index 000000000..a75fe5dfe --- /dev/null +++ b/src/datasets/dto/create-dataset-obsolete.dto.ts @@ -0,0 +1,34 @@ +import { IsEnum, IsOptional, IsString } from "class-validator"; +import { ApiProperty } from "@nestjs/swagger"; +import { DatasetType } from "../dataset-type.enum"; +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; + +export class CreateDatasetObsoleteDto extends UpdateDatasetObsoleteDto { + @ApiProperty({ + type: String, + required: false, + description: "Persistent identifier of the dataset.", + }) + @IsOptional() + @IsString() + pid?: string; + + @ApiProperty({ + type: String, + required: true, + enum: [DatasetType.Raw, DatasetType.Derived], + description: + "Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models.", + }) + @IsEnum(DatasetType) + readonly type: string; + + @ApiProperty({ + type: String, + required: false, + description: "Version of the API used in creation of the dataset.", + }) + @IsOptional() + @IsString() + readonly version?: string; +} diff --git a/src/datasets/dto/create-dataset.dto.ts b/src/datasets/dto/create-dataset.dto.ts index c9b5b7ad5..8ee18d733 100644 --- a/src/datasets/dto/create-dataset.dto.ts +++ b/src/datasets/dto/create-dataset.dto.ts @@ -22,13 +22,4 @@ export class CreateDatasetDto extends UpdateDatasetDto { }) @IsEnum(DatasetType) readonly type: string; - - @ApiProperty({ - type: String, - required: false, - description: "Version of the API used in creation of the dataset.", - }) - @IsOptional() - @IsString() - readonly version?: string; } diff --git a/src/datasets/dto/output-dataset-obsolete.dto.ts b/src/datasets/dto/output-dataset-obsolete.dto.ts new file mode 100644 index 000000000..dced6bc31 --- /dev/null +++ b/src/datasets/dto/output-dataset-obsolete.dto.ts @@ -0,0 +1,237 @@ +import { + IsArray, + IsDateString, + IsEnum, + IsObject, + IsOptional, + IsString, +} from "class-validator"; +import { ApiProperty, getSchemaPath } from "@nestjs/swagger"; +import { DatasetType } from "../dataset-type.enum"; +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; +import { Attachment } from "src/attachments/schemas/attachment.schema"; +import { Type } from "class-transformer"; +import { OrigDatablock } from "src/origdatablocks/schemas/origdatablock.schema"; +import { Datablock } from "src/datablocks/schemas/datablock.schema"; + +export class OutputDatasetObsoleteDto extends UpdateDatasetObsoleteDto { + @ApiProperty({ + type: String, + required: false, + description: "Persistent identifier of the dataset.", + }) + @IsString() + readonly pid: string; + + @ApiProperty({ + type: String, + required: true, + enum: [DatasetType.Raw, DatasetType.Derived], + description: + "Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models.", + }) + @IsEnum(DatasetType) + readonly type: string; + + @ApiProperty({ + type: String, + required: false, + description: "Version of the API used in creation of the dataset.", + }) + @IsOptional() + @IsString() + readonly version?: string; + + @ApiProperty({ + type: String, + required: 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.", + }) + @IsString() + @IsOptional() + readonly principalInvestigator?: string; + + @ApiProperty({ + type: Date, + required: false, + description: + "Start time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) + @IsOptional() + @IsDateString() + readonly startTime?: Date; + + @ApiProperty({ + type: Date, + required: false, + description: + "End time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) + @IsOptional() + @IsDateString() + readonly endTime?: Date; + + @ApiProperty({ + type: String, + required: true, + description: + "Unique location identifier where data was taken, usually in the form /Site-name/facility-name/instrumentOrBeamline-name. This field is required if the dataset is a Raw dataset.", + }) + @IsString() + @IsOptional() + readonly creationLocation?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "Defines the format of the data files in this dataset, e.g Nexus Version x.y.", + }) + @IsOptional() + @IsString() + readonly dataFormat?: string; + + @ApiProperty({ + type: String, + required: false, + description: "The ID of the proposal to which the dataset belongs.", + }) + @IsOptional() + @IsString() + readonly proposalId?: string; + + @ApiProperty({ + type: String, + required: false, + description: "ID of the sample used when collecting the data.", + }) + @IsOptional() + @IsString() + readonly sampleId?: string; + + @ApiProperty({ + type: String, + required: false, + description: "ID of the instrument where the data was created.", + }) + @IsOptional() + @IsString() + readonly instrumentId?: string; + + @ApiProperty({ + type: String, + required: true, + description: + "First name and last name of the person or people pursuing the data analysis. The string may contain a list of names, which should then be separated by semicolons.", + }) + @IsString() + @IsOptional() + readonly investigator?: string; + + @ApiProperty({ + type: [String], + required: true, + description: + "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs.", + }) + @IsString({ + each: true, + }) + @IsOptional() + readonly inputDatasets?: string[]; + + @ApiProperty({ + type: [String], + required: true, + description: + "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data.", + }) + @IsString({ + each: true, + }) + @IsOptional() + readonly usedSoftware?: string[]; + + @ApiProperty({ + type: Object, + required: false, + description: + "The creation process of the derived data will usually depend on input job parameters. The full structure of these input parameters are stored here.", + }) + @IsOptional() + @IsObject() + readonly jobParameters?: Record; + + @ApiProperty({ + type: String, + required: false, + description: + "The output job logfile. Keep the size of this log data well below 15 MB.", + }) + @IsOptional() + @IsString() + readonly jobLogData?: string; + + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(Attachment) }, + required: false, + description: + "Small, less than 16 MB attachments, envisaged for png/jpeg previews.", + }) + @IsOptional() + @IsArray() + @Type(() => Attachment) + attachments?: Attachment[]; + + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(OrigDatablock) }, + required: false, + description: + "Containers that list all files and their attributes which make up a dataset. Usually filled at the time the dataset's metadata is created in the data catalog. Can be used by subsequent archiving processes to create the archived datasets.", + }) + origdatablocks?: OrigDatablock[]; + + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(Datablock) }, + required: false, + description: + "When archiving a dataset, all files contained in the dataset are listed here together with their checksum information. Several datablocks can be created if the file listing is too long for a single datablock. This partitioning decision is done by the archiving system to allow for chunks of datablocks with manageable sizes. E.g a datasets consisting of 10 TB of data could be split into 10 datablocks of about 1 TB each. The upper limit set by the data catalog system itself is given by the fact that documents must be smaller than 16 MB, which typically allows for datasets of about 100000 files.", + }) + datablocks?: Datablock[]; + + @ApiProperty({ + type: String, + required: true, + description: + "Indicate the user who created this record. This property is added and maintained by the system.", + }) + createdBy: string; + + @ApiProperty({ + type: String, + required: true, + description: + "Indicate the user who updated this record last. This property is added and maintained by the system.", + }) + updatedBy: string; + + @ApiProperty({ + type: Date, + required: true, + description: + "Date and time when this record was created. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", + }) + createdAt: Date; + + @ApiProperty({ + type: Date, + required: true, + description: + "Date and time when this record was updated last. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", + }) + updatedAt: Date; +} diff --git a/src/datasets/dto/output-dataset.dto.ts b/src/datasets/dto/output-dataset.dto.ts new file mode 100644 index 000000000..8809e3756 --- /dev/null +++ b/src/datasets/dto/output-dataset.dto.ts @@ -0,0 +1,41 @@ +import { ApiProperty } from "@nestjs/swagger"; +import { CreateDatasetDto } from "./create-dataset.dto"; +import { IsString } from "class-validator"; + +export class OutputDatasetDto extends CreateDatasetDto { + @ApiProperty({ + type: String, + required: true, + description: + "Indicate the user who created this record. This property is added and maintained by the system.", + }) + @IsString() + createdBy: string; + + @ApiProperty({ + type: String, + required: true, + description: + "Indicate the user who updated this record last. This property is added and maintained by the system.", + }) + @IsString() + updatedBy: string; + + @ApiProperty({ + type: Date, + required: true, + description: + "Date and time when this record was created. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", + }) + @IsString() + createdAt: Date; + + @ApiProperty({ + type: Date, + required: true, + description: + "Date and time when this record was updated last. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", + }) + @IsString() + updatedAt: Date; +} diff --git a/src/datasets/dto/update-dataset-obsolete.dto.ts b/src/datasets/dto/update-dataset-obsolete.dto.ts new file mode 100644 index 000000000..f2be1c2d2 --- /dev/null +++ b/src/datasets/dto/update-dataset-obsolete.dto.ts @@ -0,0 +1,298 @@ +import { + ApiProperty, + ApiTags, + getSchemaPath, + PartialType, +} from "@nestjs/swagger"; +import { OwnableDto } from "../../common/dto/ownable.dto"; +import { + IsArray, + IsBoolean, + IsDateString, + IsEmail, + IsFQDN, + IsInt, + IsNumber, + IsObject, + IsOptional, + IsString, + ValidateNested, +} from "class-validator"; +import { TechniqueClass } from "../schemas/technique.schema"; +import { Type } from "class-transformer"; +import { CreateTechniqueDto } from "./create-technique.dto"; +import { RelationshipClass } from "../schemas/relationship.schema"; +import { CreateRelationshipDto } from "./create-relationship.dto"; +import { LifecycleClass } from "../schemas/lifecycle.schema"; +import { Attachment } from "../../attachments/schemas/attachment.schema"; +import { OrigDatablock } from "../../origdatablocks/schemas/origdatablock.schema"; +import { Datablock } from "../../datablocks/schemas/datablock.schema"; + +@ApiTags("datasets") +export class UpdateDatasetObsoleteDto extends OwnableDto { + @ApiProperty({ + type: String, + required: true, + description: + "Owner or custodian of the dataset, usually first name + last name. The string may contain a list of persons, which should then be separated by semicolons.", + }) + @IsString() + readonly owner: string; + + @ApiProperty({ + type: String, + required: false, + description: + "Email of the owner or custodian of the dataset. The string may contain a list of emails, which should then be separated by semicolons.", + }) + @IsOptional() + @IsEmail() + readonly ownerEmail?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "ORCID of the owner or custodian. The string may contain a list of ORCIDs, which should then be separated by semicolons.", + }) + @IsOptional() + @IsString() + readonly orcidOfOwner?: string; + + @ApiProperty({ + type: String, + required: true, + description: + "Email of the contact person for this dataset. The string may contain a list of emails, which should then be separated by semicolons.", + }) + @IsEmail() + readonly contactEmail: string; + + @ApiProperty({ + type: String, + required: true, + description: + "Absolute file path on file server containing the files of this dataset, e.g. /some/path/to/sourcefolder. In case of a single file dataset, e.g. HDF5 data, it contains the path up to, but excluding the filename. Trailing slashes are removed.", + }) + @IsString() + readonly sourceFolder: string; + + @ApiProperty({ + type: String, + required: false, + description: + "DNS host name of file server hosting sourceFolder, optionally including a protocol e.g. [protocol://]fileserver1.example.com", + }) + @IsOptional() + @IsFQDN() + readonly sourceFolderHost?: string; + + /* + * size and number of files fields should be managed by the system + */ + @ApiProperty({ + type: Number, + default: 0, + required: false, + description: + "Total size of all source files contained in source folder on disk when unpacked.", + }) + @IsOptional() + @IsInt() + readonly size?: number = 0; + + @ApiProperty({ + type: Number, + default: 0, + required: false, + description: + "Total size of all datablock package files created for this dataset.", + }) + @IsOptional() + @IsInt() + readonly packedSize?: number = 0; + + @ApiProperty({ + type: Number, + default: 0, + required: false, + description: + "Total number of files in all OrigDatablocks for this dataset.", + }) + @IsOptional() + @IsInt() + readonly numberOfFiles?: number = 0; + + @ApiProperty({ + type: Number, + default: 0, + required: true, + description: "Total number of files in all Datablocks for this dataset.", + }) + @IsOptional() + @IsInt() + readonly numberOfFilesArchived?: number; + + @ApiProperty({ + type: Date, + required: true, + description: + "Time when dataset became fully available on disk, i.e. all containing files have been written, or the dataset was created in SciCat.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) + @IsDateString() + readonly creationTime: Date; + + @ApiProperty({ + type: String, + required: false, + description: + "Defines a level of trust, e.g. a measure of how much data was verified or used by other persons.", + }) + @IsOptional() + @IsString() + readonly validationStatus?: string; + + @ApiProperty({ + type: [String], + required: false, + description: + "Array of tags associated with the meaning or contents of this dataset. Values should ideally come from defined vocabularies, taxonomies, ontologies or knowledge graphs.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly keywords?: string[]; + + @ApiProperty({ + type: String, + required: false, + description: "Free text explanation of contents of dataset.", + }) + @IsOptional() + @IsString() + readonly description?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid. Will be autofilled if missing using info from sourceFolder.", + }) + @IsOptional() + @IsString() + readonly datasetName?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "ACIA information about AUthenticity,COnfidentiality,INtegrity and AVailability requirements of dataset. E.g. AV(ailabilty)=medium could trigger the creation of a two tape copies. Format 'AV=medium,CO=low'", + }) + @IsOptional() + @IsString() + readonly classification?: string; + + @ApiProperty({ + type: String, + required: false, + description: "Name of the license under which the data can be used.", + }) + @IsOptional() + @IsString() + readonly license?: string; + + // it needs to be discussed if this fields is managed by the user or by the system + @ApiProperty({ + type: Boolean, + required: false, + default: false, + description: "Flag is true when data are made publicly available.", + }) + @IsOptional() + @IsBoolean() + readonly isPublished?: boolean; + + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(TechniqueClass) }, + required: false, + default: [], + description: "Stores the metadata information for techniques.", + }) + @IsOptional() + @IsArray() + @ValidateNested({ each: true }) + @Type(() => CreateTechniqueDto) + readonly techniques?: TechniqueClass[]; + + // it needs to be discussed if this fields is managed by the user or by the system + @ApiProperty({ + type: [String], + required: false, + default: [], + description: "List of users that the dataset has been shared with.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly sharedWith?: string[]; + + // it needs to be discussed if this fields is managed by the user or by the system + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(RelationshipClass) }, + required: false, + default: [], + description: "Stores the relationships with other datasets.", + }) + @IsArray() + @IsOptional() + @ValidateNested({ each: true }) + @Type(() => CreateRelationshipDto) + readonly relationships?: RelationshipClass[]; + + @ApiProperty({ + type: LifecycleClass, + required: false, + default: {}, + description: + "Describes the current status of the dataset during its lifetime with respect to the storage handling systems.", + }) + @IsOptional() + readonly datasetlifecycle: LifecycleClass; + + @ApiProperty({ + type: Object, + required: false, + default: {}, + description: "JSON object containing the scientific metadata.", + }) + @IsOptional() + @IsObject() + readonly scientificMetadata?: Record; + + @ApiProperty({ + type: String, + required: false, + description: "Comment the user has about a given dataset.", + }) + @IsOptional() + @IsString() + readonly comment?: string; + + @ApiProperty({ + type: Number, + required: false, + description: + "Data Quality Metrics is a number given by the user to rate the dataset.", + }) + @IsOptional() + @IsNumber() + readonly dataQualityMetrics?: number; +} + +export class PartialUpdateDatasetObsoleteDto extends PartialType( + UpdateDatasetObsoleteDto, +) {} diff --git a/src/datasets/dto/update-dataset.dto.ts b/src/datasets/dto/update-dataset.dto.ts index aab14a7e5..c4ea63c4b 100644 --- a/src/datasets/dto/update-dataset.dto.ts +++ b/src/datasets/dto/update-dataset.dto.ts @@ -24,9 +24,6 @@ import { CreateTechniqueDto } from "./create-technique.dto"; import { RelationshipClass } from "../schemas/relationship.schema"; import { CreateRelationshipDto } from "./create-relationship.dto"; import { LifecycleClass } from "../schemas/lifecycle.schema"; -import { Attachment } from "../../attachments/schemas/attachment.schema"; -import { OrigDatablock } from "../../origdatablocks/schemas/origdatablock.schema"; -import { Datablock } from "../../datablocks/schemas/datablock.schema"; @ApiTags("datasets") export class UpdateDatasetDto extends OwnableDto { @@ -37,7 +34,8 @@ export class UpdateDatasetDto extends OwnableDto { "Owner or custodian of the dataset, usually first name + last name. The string may contain a list of persons, which should then be separated by semicolons.", }) @IsString() - readonly owner: string; + @IsOptional() + readonly owner?: string; @ApiProperty({ type: String, @@ -175,13 +173,12 @@ export class UpdateDatasetDto extends OwnableDto { @ApiProperty({ type: String, - required: false, + required: true, description: "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid. Will be autofilled if missing using info from sourceFolder.", }) - @IsOptional() @IsString() - readonly datasetName?: string; + readonly datasetName: string; @ApiProperty({ type: String, @@ -211,7 +208,7 @@ export class UpdateDatasetDto extends OwnableDto { }) @IsOptional() @IsBoolean() - readonly isPublished?: boolean; + readonly isPublished?: boolean = false; @ApiProperty({ type: "array", @@ -261,7 +258,7 @@ export class UpdateDatasetDto extends OwnableDto { "Describes the current status of the dataset during its lifetime with respect to the storage handling systems.", }) @IsOptional() - readonly datasetlifecycle: LifecycleClass; + readonly datasetlifecycle?: LifecycleClass; @ApiProperty({ type: Object, @@ -292,14 +289,134 @@ export class UpdateDatasetDto extends OwnableDto { @IsNumber() readonly dataQualityMetrics?: number; + @ApiProperty({ + type: String, + required: 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.", + }) + @IsString() + readonly principalInvestigator: string; + + @ApiProperty({ + type: Date, + required: false, + description: + "Start time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) @IsOptional() - attachments?: Attachment[]; + @IsDateString() + readonly startTime?: Date; + @ApiProperty({ + type: Date, + required: false, + description: + "End time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) @IsOptional() - origdatablocks?: OrigDatablock[]; + @IsDateString() + readonly endTime?: Date; + @ApiProperty({ + type: String, + required: false, + description: + "Unique location identifier where data was taken, usually in the form /Site-name/facility-name/instrumentOrBeamline-name. This field is required if the dataset is a Raw dataset.", + }) @IsOptional() - datablocks?: Datablock[]; + @IsString() + readonly creationLocation?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "Defines the format of the data files in this dataset, e.g Nexus Version x.y.", + }) + @IsOptional() + @IsString() + readonly dataFormat?: string; + + @ApiProperty({ + type: [String], + required: false, + description: + "ID of the proposal or proposals which the dataset belongs to.
This dataset might have been acquired under the listed proposals or is derived from datasets acquired from datasets belonging to the listed datasets.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly proposalId?: string[]; + + @ApiProperty({ + type: [String], + required: false, + description: + "ID of the sample or samples used when collecting the data included or used in this dataset.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly sampleId?: string[]; + + @ApiProperty({ + type: String, + required: false, + description: + "ID of the instrument or instruments where the data included or used in this datasets was collected on.", + }) + @IsOptional() + @IsString({ + each: false, + }) + readonly instrumentId?: string[]; + + @ApiProperty({ + type: [String], + required: true, + description: + "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs.", + }) + @IsOptional() + @IsString({ + each: false, + }) + readonly inputDatasets?: string[]; + + @ApiProperty({ + type: [String], + required: false, + description: + "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly usedSoftware?: string[]; + + @ApiProperty({ + type: Object, + required: false, + description: + "The creation process of the derived data will usually depend on input job parameters. The full structure of these input parameters are stored here.", + }) + @IsOptional() + @IsObject() + readonly jobParameters?: Record; + + @ApiProperty({ + type: String, + required: false, + description: + "The output job logfile. Keep the size of this log data well below 15 MB.", + }) + @IsOptional() + @IsString() + readonly jobLogData?: string; } export class PartialUpdateDatasetDto extends PartialType(UpdateDatasetDto) {} diff --git a/src/datasets/dto/update-derived-dataset.dto.ts b/src/datasets/dto/update-derived-dataset.dto.ts index 5f4d83a1d..a654c5bca 100644 --- a/src/datasets/dto/update-derived-dataset.dto.ts +++ b/src/datasets/dto/update-derived-dataset.dto.ts @@ -1,8 +1,8 @@ -import { UpdateDatasetDto } from "./update-dataset.dto"; +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; import { ApiProperty, PartialType } from "@nestjs/swagger"; import { IsObject, IsOptional, IsString } from "class-validator"; -export class UpdateDerivedDatasetDto extends UpdateDatasetDto { +export class UpdateDerivedDatasetDto extends UpdateDatasetObsoleteDto { @ApiProperty({ type: String, required: true, diff --git a/src/datasets/dto/update-raw-dataset.dto.ts b/src/datasets/dto/update-raw-dataset.dto.ts index a03fa14ad..5926b854f 100644 --- a/src/datasets/dto/update-raw-dataset.dto.ts +++ b/src/datasets/dto/update-raw-dataset.dto.ts @@ -1,8 +1,8 @@ import { IsDateString, IsOptional, IsString } from "class-validator"; -import { UpdateDatasetDto } from "./update-dataset.dto"; +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; import { ApiProperty, PartialType } from "@nestjs/swagger"; -export class UpdateRawDatasetDto extends UpdateDatasetDto { +export class UpdateRawDatasetDto extends UpdateDatasetObsoleteDto { /* we need to discuss if the naming is adequate. */ @ApiProperty({ type: String, diff --git a/src/datasets/schemas/dataset.schema.ts b/src/datasets/schemas/dataset.schema.ts index 74c29aaa7..a50055b98 100644 --- a/src/datasets/schemas/dataset.schema.ts +++ b/src/datasets/schemas/dataset.schema.ts @@ -244,28 +244,21 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: String, - required: false, + required: true, description: - "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid. Will be autofilled if missing using info from sourceFolder.", + "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid.", }) @Prop({ type: String, - required: false, - default: function datasetName() { - const sourceFolder = (this as DatasetDocument).sourceFolder; - if (!sourceFolder) return ""; - const arr = sourceFolder.split("/"); - if (arr.length == 1) return arr[0]; - else return arr[arr.length - 2] + "/" + arr[arr.length - 1]; - }, + required: true, }) - datasetName?: string; + datasetName: string; @ApiProperty({ type: String, required: false, description: - "ACIA information about AUthenticity,COnfidentiality,INtegrity and AVailability requirements of dataset. E.g. AV(ailabilty)=medium could trigger the creation of a two tape copies. Format 'AV=medium,CO=low'", + "ACIA information about AUthenticity,COnfidentiality,INtegrity and AVailability requirements of dataset. E.g. AV(ailabilty)=medium could trigger the creation of a two tape copies. Format 'AV=medium,CO=low'. Please check the following post for more info: https://en.wikipedia.org/wiki/Parkerian_Hexad", }) @Prop({ type: String, required: false }) classification?: string; @@ -280,11 +273,12 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: String, - required: false, - description: "Version of the API used in creation of the dataset.", + required: true, + description: + "Version of the API used when the dataset was created or last updated. API version is defined in code for each release. Managed by the system.", }) - @Prop({ type: String, required: false }) - version?: string; + @Prop({ type: String, required: true }) + version: string; @ApiProperty({ type: "array", @@ -298,12 +292,12 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: LifecycleClass, - required: false, + required: true, default: {}, description: "Describes the current status of the dataset during its lifetime with respect to the storage handling systems.", }) - @Prop({ type: LifecycleSchema, default: {}, required: false }) + @Prop({ type: LifecycleSchema, default: {}, required: true }) datasetlifecycle?: LifecycleClass; @ApiProperty({ @@ -311,7 +305,8 @@ export class DatasetClass extends OwnableClass { items: { $ref: getSchemaPath(TechniqueClass) }, required: false, default: [], - description: "Stores the metadata information for techniques.", + description: + "Array of techniques information, with technique name and pid.", }) @Prop({ type: [TechniqueSchema], required: false, default: [] }) techniques?: TechniqueClass[]; @@ -321,7 +316,8 @@ export class DatasetClass extends OwnableClass { items: { $ref: getSchemaPath(RelationshipClass) }, required: false, default: [], - description: "Stores the relationships with other datasets.", + description: + "Array of relationships with other datasets. It contains relationship type and destination dataset", }) @Prop({ type: [RelationshipSchema], required: false, default: [] }) relationships?: RelationshipClass[]; @@ -330,7 +326,8 @@ export class DatasetClass extends OwnableClass { type: [String], required: false, default: [], - description: "List of users that the dataset has been shared with.", + description: + "List of additional users that the dataset has been shared with.", }) @Prop({ type: [String], @@ -339,37 +336,37 @@ export class DatasetClass extends OwnableClass { }) sharedWith?: string[]; - @ApiProperty({ - type: "array", - items: { $ref: getSchemaPath(Attachment) }, - required: false, - description: - "Small, less than 16 MB attachments, envisaged for png/jpeg previews.", - }) - @Prop({ type: [AttachmentSchema], default: [] }) - attachments?: Attachment[]; - - @ApiProperty({ - isArray: true, - type: OrigDatablock, - items: { $ref: getSchemaPath(OrigDatablock) }, - required: false, - description: - "Containers that list all files and their attributes which make up a dataset. Usually filled at the time the dataset's metadata is created in the data catalog. Can be used by subsequent archiving processes to create the archived datasets.", - }) - @Prop({ type: [OrigDatablockSchema], default: [] }) - origdatablocks: OrigDatablock[]; - - @ApiProperty({ - isArray: true, - type: Datablock, - items: { $ref: getSchemaPath(Datablock) }, - required: false, - description: - "When archiving a dataset, all files contained in the dataset are listed here together with their checksum information. Several datablocks can be created if the file listing is too long for a single datablock. This partitioning decision is done by the archiving system to allow for chunks of datablocks with manageable sizes. E.g a datasets consisting of 10 TB of data could be split into 10 datablocks of about 1 TB each. The upper limit set by the data catalog system itself is given by the fact that documents must be smaller than 16 MB, which typically allows for datasets of about 100000 files.", - }) - @Prop({ type: [DatablockSchema], default: [] }) - datablocks: Datablock[]; + // @ApiProperty({ + // type: "array", + // items: { $ref: getSchemaPath(Attachment) }, + // required: false, + // description: + // "Small, less than 16 MB attachments, envisaged for png/jpeg previews.", + // }) + // @Prop({ type: [AttachmentSchema], default: [] }) + // attachments?: Attachment[]; + + // @ApiProperty({ + // isArray: true, + // type: OrigDatablock, + // items: { $ref: getSchemaPath(OrigDatablock) }, + // required: false, + // description: + // "Containers that list all files and their attributes which make up a dataset. Usually filled at the time the dataset's metadata is created in the data catalog. Can be used by subsequent archiving processes to create the archived datasets.", + // }) + // @Prop({ type: [OrigDatablockSchema], default: [] }) + // origdatablocks: OrigDatablock[]; + + // @ApiProperty({ + // isArray: true, + // type: Datablock, + // items: { $ref: getSchemaPath(Datablock) }, + // required: false, + // description: + // "When archiving a dataset, all files contained in the dataset are listed here together with their checksum information. Several datablocks can be created if the file listing is too long for a single datablock. This partitioning decision is done by the archiving system to allow for chunks of datablocks with manageable sizes. E.g a datasets consisting of 10 TB of data could be split into 10 datablocks of about 1 TB each. The upper limit set by the data catalog system itself is given by the fact that documents must be smaller than 16 MB, which typically allows for datasets of about 100000 files.", + // }) + // @Prop({ type: [DatablockSchema], default: [] }) + // datablocks: Datablock[]; @ApiProperty({ type: Object, @@ -383,7 +380,8 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: String, required: false, - description: "Comment the user has about a given dataset.", + description: + "Short comment provided by the user about a given dataset. This is additional to the description field.", }) @Prop({ type: String, @@ -400,7 +398,7 @@ export class DatasetClass extends OwnableClass { type: Number, required: false, }) - dataQualityMetrics: number; + dataQualityMetrics?: number; /* * fields related to Raw Datasets @@ -436,7 +434,7 @@ export class DatasetClass extends OwnableClass { type: String, required: true, description: - "Unique location identifier where data was taken, usually in the form /Site-name/facility-name/instrumentOrBeamline-name. This field is required if the dataset is a Raw dataset.", + "Unique location identifier where data was acquired. Usually in the form /Site-name/facility-name/instrumentOrBeamline-name.", }) @Prop({ type: String, required: false, index: true }) creationLocation?: string; @@ -453,44 +451,47 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: String, required: false, - description: "The ID of the proposal to which the dataset belongs.", + description: + "The ID of the proposal to which the dataset belongs to and it has been acquired under.", }) @Prop({ type: String, ref: "Proposal", required: false }) proposalId?: string; @ApiProperty({ - type: String, + type: [String], required: false, - description: "ID of the sample used when collecting the data.", + description: + "Single ID or array of IDS of the samples used when collecting the data.", }) - @Prop({ type: String, ref: "Sample", required: false }) - sampleId?: string; + @Prop({ type: [String], ref: "Sample", required: false }) + sampleId?: string[]; @ApiProperty({ - type: String, + type: [String], required: false, - description: "ID of the instrument where the data was created.", + description: + "Id of the instrument or array of IDS of the instruments where the data contained in this dataset was created/acquired.", }) - @Prop({ type: String, ref: "Instrument", required: false }) - instrumentId?: string; + @Prop({ type: [String], ref: "Instrument", required: false }) + instrumentId?: string[]; /* * Derived Dataset */ - @ApiProperty({ - type: String, - required: false, - description: - "First name and last name of the person or people pursuing the data analysis. The string may contain a list of names, which should then be separated by semicolons.", - }) - @Prop({ type: String, required: false, index: true }) - investigator?: string; + // @ApiProperty({ + // type: String, + // required: false, + // description: + // "First name and last name of the person or people pursuing the data analysis. The string may contain a list of names, which should then be separated by semicolons.", + // }) + // @Prop({ type: String, required: false, index: true }) + // investigator?: string; @ApiProperty({ type: [String], required: false, description: - "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs. This field is required if the dataset is a Derived dataset.", + "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs.", }) @Prop({ type: [String], required: false }) inputDatasets?: string[]; @@ -499,7 +500,7 @@ export class DatasetClass extends OwnableClass { type: [String], required: false, description: - "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data. This field is required if the dataset is a Derived dataset.", + "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data.", }) @Prop({ type: [String], required: false }) usedSoftware?: string[]; From 6ff6c6a7db7a8ee9abc4162c860eca38322bd773 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Thu, 5 Sep 2024 13:58:25 +0200 Subject: [PATCH 02/38] solved weird dependency in jobs --- src/jobs/jobs.controller.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/jobs/jobs.controller.ts b/src/jobs/jobs.controller.ts index 588f202f9..838fc724c 100644 --- a/src/jobs/jobs.controller.ts +++ b/src/jobs/jobs.controller.ts @@ -179,25 +179,26 @@ export class JobsController { // Indexing originDataBlock with pid and create set of files for each dataset const datasets = await this.datasetsService.findAll(filter); // Include origdatablocks - await Promise.all( + const aggregatedData = await Promise.all( datasets.map(async (dataset) => { - dataset.origdatablocks = await this.origDatablocksService.findAll( - { + return { + dataset: dataset, + origdatablocks: await this.origDatablocksService.findAll({ datasetId: dataset.pid, - }, - ); + }), + }; }), ); - const result: Record> = datasets.reduce( - (acc: Record>, dataset) => { + const result: Record> = aggregatedData.reduce( + (acc: Record>, data) => { // Using Set make searching more efficient - const files = dataset.origdatablocks.reduce((acc, block) => { + const files = data.origdatablocks.reduce((acc, block) => { block.dataFileList.forEach((file) => { acc.add(file.path); }); return acc; }, new Set()); - acc[dataset.pid] = files; + acc[data.dataset.pid] = files; return acc; }, {}, From 74b6edd5360a6dd7b2afdc8d0062859c37478f5c Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 6 Sep 2024 16:57:59 +0200 Subject: [PATCH 03/38] still refactoring names, started working on tests --- src/datasets/datasets.controller.ts | 180 +- src/datasets/datasets.service.ts | 10 +- .../dto/create-derived-dataset.dto.ts | 27 - src/datasets/dto/create-raw-dataset.dto.ts | 27 - src/datasets/dto/update-dataset.dto.ts | 6 +- .../dto/update-derived-dataset.dto.ts | 60 - src/datasets/dto/update-raw-dataset.dto.ts | 100 - src/datasets/schemas/dataset.schema.ts | 6 +- .../origdatablocks.controller.ts | 4 +- test/DatasetAuthorization.js | 2879 +++++++++-------- 10 files changed, 1584 insertions(+), 1715 deletions(-) delete mode 100644 src/datasets/dto/create-derived-dataset.dto.ts delete mode 100644 src/datasets/dto/create-raw-dataset.dto.ts delete mode 100644 src/datasets/dto/update-derived-dataset.dto.ts delete mode 100644 src/datasets/dto/update-raw-dataset.dto.ts diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 42233e22a..89e6f7536 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -38,8 +38,8 @@ import { Request } from "express"; import { DatasetsService } from "./datasets.service"; import { PartialUpdateDatasetObsoleteDto } from "./dto/update-dataset-obsolete.dto"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; -import { CreateRawDatasetDto } from "./dto/create-raw-dataset.dto"; -import { CreateDerivedDatasetDto } from "./dto/create-derived-dataset.dto"; +import { CreateRawDatasetObsoleteDto } from "./dto/create-raw-dataset-obsolete.dto"; +import { CreateDerivedDatasetObsoleteDto } from "./dto/create-derived-dataset-obsolete.dto"; import { PoliciesGuard } from "src/casl/guards/policies.guard"; import { CheckPolicies } from "src/casl/decorators/check-policies.decorator"; import { AppAbility, CaslAbilityFactory } from "src/casl/casl-ability.factory"; @@ -74,13 +74,13 @@ import { validate, ValidationError, ValidatorOptions } from "class-validator"; import { HistoryInterceptor } from "src/common/interceptors/history.interceptor"; import { CreateDatasetOrigDatablockDto } from "src/origdatablocks/dto/create-dataset-origdatablock"; import { - PartialUpdateRawDatasetDto, - UpdateRawDatasetDto, -} from "./dto/update-raw-dataset.dto"; + PartialUpdateRawDatasetObsoleteDto, + UpdateRawDatasetObsoleteDto, +} from "./dto/update-raw-dataset-obsolete.dto"; import { - PartialUpdateDerivedDatasetDto, - UpdateDerivedDatasetDto, -} from "./dto/update-derived-dataset.dto"; + PartialUpdateDerivedDatasetObsoleteDto, + UpdateDerivedDatasetObsoleteDto, +} from "./dto/update-derived-dataset-obsolete.dto"; import { CreateDatasetDatablockDto } from "src/datablocks/dto/create-dataset-datablock"; import { filterDescription, @@ -99,12 +99,13 @@ import { LogbooksService } from "src/logbooks/logbooks.service"; import configuration from "src/config/configuration"; import { DatasetType } from "./dataset-type.enum"; import { OutputDatasetObsoleteDto } from "./dto/output-dataset-obsolete.dto"; +import { CreateDatasetDto } from "./dto/create-dataset.dto"; @ApiBearerAuth() @ApiExtraModels( CreateAttachmentDto, - CreateDerivedDatasetDto, - CreateRawDatasetDto, + CreateDerivedDatasetObsoleteDto, + CreateRawDatasetObsoleteDto, HistoryClass, TechniqueClass, RelationshipClass, @@ -283,7 +284,7 @@ export class DatasetsController { return dataset; } - async checkPermissionsForDataset(request: Request, id: string) { + async checkPermissionsForDatasetObsolete(request: Request, id: string) { const dataset = await this.datasetsService.findOne({ where: { pid: id } }); const user: JWTUser = request.user as JWTUser; @@ -332,7 +333,10 @@ export class DatasetsController { } async generateDatasetInstanceForPermissions( - dataset: CreateRawDatasetDto | CreateDerivedDatasetDto | DatasetClass, + dataset: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | DatasetClass, ): Promise { const datasetInstance = new DatasetClass(); datasetInstance._id = ""; @@ -345,9 +349,9 @@ export class DatasetsController { return datasetInstance; } - async checkPermissionsForDatasetCreate( + async checkPermissionsForObsoleteDatasetCreate( request: Request, - dataset: CreateRawDatasetDto | CreateDerivedDatasetDto, + dataset: CreateRawDatasetObsoleteDto | CreateDerivedDatasetObsoleteDto, ) { const user: JWTUser = request.user as JWTUser; @@ -388,6 +392,69 @@ export class DatasetsController { return dataset; } + convertObsoleteToCurrentSchema( + inputDataset: CreateRawDatasetObsoleteDto | CreateDerivedDatasetObsoleteDto, + ): CreateDatasetDto { + const propertiesModifier: Record = {}; + if (inputDataset.type == "raw") { + if ("proposalId" in inputDataset) { + propertiesModifier.proposalIds = [ + (inputDataset as CreateRawDatasetObsoleteDto).proposalId, + ]; + } + if ("sampleId" in inputDataset) { + propertiesModifier.sampleIds = [ + (inputDataset as CreateRawDatasetObsoleteDto).sampleId, + ]; + } + if ("instrumentIds" in inputDataset) { + propertiesModifier.instrumentIds = [ + (inputDataset as CreateRawDatasetObsoleteDto).instrumentId, + ]; + } + } else { + if ("investigator" in inputDataset) { + propertiesModifier.principalInvestigator = [ + (inputDataset as CreateDerivedDatasetObsoleteDto).investigator, + ]; + } + } + + const outputDataset: CreateDatasetDto = { + ...(inputDataset as CreateDatasetDto), + ...propertiesModifier, + }; + + return outputDataset; + } + + convertCurrentToObsoleteSchema( + inputDataset: DatasetClass, + ): OutputDatasetObsoleteDto { + const propertiesModifier: Record = {}; + if ("proposalIds" in inputDataset) { + propertiesModifier.proposalIds = inputDataset.proposalIds![0]; + } + if ("sampleIds" in inputDataset) { + propertiesModifier.sampleIds = inputDataset.sampleIds![0]; + } + if ("instrumentIds" in inputDataset) { + propertiesModifier.instrumentIds = inputDataset.instrumentIds![0]; + } + if (inputDataset.type == "raw") { + if ("investigator" in inputDataset) { + propertiesModifier.investigator = inputDataset.principalInvestigator; + } + } + + const outputDataset: OutputDatasetObsoleteDto = { + ...(inputDataset as OutputDatasetObsoleteDto), + ...propertiesModifier, + }; + + return outputDataset; + } + // POST /datasets @UseGuards(PoliciesGuard) @CheckPolicies("datasets", (ability: AppAbility) => @@ -404,14 +471,14 @@ export class DatasetsController { description: "It creates a new dataset and returns it completed with systems fields.", }) - @ApiExtraModels(CreateRawDatasetDto, CreateDerivedDatasetDto) + @ApiExtraModels(CreateRawDatasetObsoleteDto, CreateDerivedDatasetObsoleteDto) @ApiBody({ description: "Input fields for the dataset to be created", required: true, schema: { oneOf: [ - { $ref: getSchemaPath(CreateRawDatasetDto) }, - { $ref: getSchemaPath(CreateDerivedDatasetDto) }, + { $ref: getSchemaPath(CreateRawDatasetObsoleteDto) }, + { $ref: getSchemaPath(CreateDerivedDatasetObsoleteDto) }, ], }, }) @@ -422,25 +489,34 @@ export class DatasetsController { }) async create( @Req() request: Request, - @Body() createDatasetDto: CreateRawDatasetDto | CreateDerivedDatasetDto, - ): Promise { + @Body() + createDatasetObsoleteDto: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto, + ): Promise { // validate dataset - await this.validateDataset( - createDatasetDto, - createDatasetDto.type === "raw" - ? CreateRawDatasetDto - : CreateDerivedDatasetDto, + await this.validateDatasetObsolete( + createDatasetObsoleteDto, + createDatasetObsoleteDto.type === "raw" + ? CreateRawDatasetObsoleteDto + : CreateDerivedDatasetObsoleteDto, ); - const datasetDTO = await this.checkPermissionsForDatasetCreate( - request, - createDatasetDto, - ); + const obsoleteDatasetDto = + await this.checkPermissionsForObsoleteDatasetCreate( + request, + createDatasetObsoleteDto, + ); try { - const createdDataset = await this.datasetsService.create(datasetDTO); + const datasetDto = + this.convertObsoleteToCurrentSchema(obsoleteDatasetDto); + const createdDataset = await this.datasetsService.create(datasetDto); + + const outputObsoleteDatasetDto = + this.convertCurrentToObsoleteSchema(createdDataset); - return createdDataset; + return outputObsoleteDatasetDto; } catch (error) { if ((error as MongoError).code === 11000) { throw new ConflictException( @@ -452,21 +528,21 @@ export class DatasetsController { } } - async validateDataset( + async validateDatasetObsolete( inputDatasetDto: - | CreateRawDatasetDto - | CreateDerivedDatasetDto - | PartialUpdateRawDatasetDto - | PartialUpdateDerivedDatasetDto - | UpdateRawDatasetDto - | UpdateDerivedDatasetDto, + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | PartialUpdateRawDatasetObsoleteDto + | PartialUpdateDerivedDatasetObsoleteDto + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto, dto: ClassConstructor< - | CreateRawDatasetDto - | CreateDerivedDatasetDto - | PartialUpdateRawDatasetDto - | PartialUpdateDerivedDatasetDto - | UpdateRawDatasetDto - | UpdateDerivedDatasetDto + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | PartialUpdateRawDatasetObsoleteDto + | PartialUpdateDerivedDatasetObsoleteDto + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto >, ) { const validateOptions: ValidatorOptions = { @@ -481,7 +557,7 @@ export class DatasetsController { if ( inputDatasetDto instanceof - (CreateRawDatasetDto || CreateDerivedDatasetDto) + (CreateRawDatasetObsoleteDto || CreateDerivedDatasetObsoleteDto) ) { if (!(inputDatasetDto.type in DatasetType)) { throw new HttpException( @@ -526,14 +602,14 @@ export class DatasetsController { description: "It validates the dataset provided as input, and returns true if the information is a valid dataset", }) - @ApiExtraModels(CreateRawDatasetDto, CreateDerivedDatasetDto) + @ApiExtraModels(CreateRawDatasetObsoleteDto, CreateDerivedDatasetObsoleteDto) @ApiBody({ description: "Input fields for the dataset that needs to be validated", required: true, schema: { oneOf: [ - { $ref: getSchemaPath(CreateRawDatasetDto) }, - { $ref: getSchemaPath(CreateDerivedDatasetDto) }, + { $ref: getSchemaPath(CreateRawDatasetObsoleteDto) }, + { $ref: getSchemaPath(CreateDerivedDatasetObsoleteDto) }, ], }, }) @@ -545,9 +621,15 @@ export class DatasetsController { }) async isValid( @Req() request: Request, - @Body() createDatasetDto: CreateRawDatasetDto | CreateDerivedDatasetDto, + @Body() + createDatasetObsoleteDto: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto, ): Promise<{ valid: boolean }> { - await this.checkPermissionsForDatasetCreate(request, createDatasetDto); + await this.checkPermissionsForObsoleteDatasetCreate( + request, + createDatasetObsoleteDto, + ); const dtoTestRawCorrect = plainToInstance( CreateRawDatasetDto, diff --git a/src/datasets/datasets.service.ts b/src/datasets/datasets.service.ts index 680222e8e..60793750d 100644 --- a/src/datasets/datasets.service.ts +++ b/src/datasets/datasets.service.ts @@ -24,7 +24,7 @@ import { ElasticSearchService } from "src/elastic-search/elastic-search.service" import { InitialDatasetsService } from "src/initial-datasets/initial-datasets.service"; import { LogbooksService } from "src/logbooks/logbooks.service"; import { DatasetType } from "./dataset-type.enum"; -import { CreateDatasetObsoleteDto } from "./dto/create-dataset-obsolete.dto"; +import { CreateDatasetDto } from "./dto/create-dataset.dto"; import { PartialUpdateDatasetObsoleteDto, UpdateDatasetObsoleteDto, @@ -32,11 +32,11 @@ import { import { PartialUpdateDerivedDatasetDto, UpdateDerivedDatasetDto, -} from "./dto/update-derived-dataset.dto"; +} from "./dto/update-derived-dataset-obsolete.dto"; import { PartialUpdateRawDatasetDto, UpdateRawDatasetDto, -} from "./dto/update-raw-dataset.dto"; +} from "./dto/update-raw-dataset-obsolete.dto"; import { IDatasetFields } from "./interfaces/dataset-filters.interface"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; @@ -58,9 +58,7 @@ export class DatasetsService { } } - async create( - createDatasetDto: CreateDatasetObsoleteDto, - ): Promise { + async create(createDatasetDto: CreateDatasetDto): Promise { const username = (this.request.user as JWTUser).username; const createdDataset = new this.datasetModel( // insert created and updated fields diff --git a/src/datasets/dto/create-derived-dataset.dto.ts b/src/datasets/dto/create-derived-dataset.dto.ts deleted file mode 100644 index f95240c82..000000000 --- a/src/datasets/dto/create-derived-dataset.dto.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { UpdateDerivedDatasetDto } from "./update-derived-dataset.dto"; -import { ApiProperty } from "@nestjs/swagger"; -import { IsEnum, IsOptional, IsString } from "class-validator"; -import { DatasetType } from "../dataset-type.enum"; - -export class CreateDerivedDatasetDto extends UpdateDerivedDatasetDto { - @ApiProperty({ - type: String, - required: false, - description: "Persistent identifier of the dataset.", - }) - @IsOptional() - @IsString() - pid?: string; - - @IsEnum(DatasetType) - readonly type: string = DatasetType.Derived; - - @ApiProperty({ - type: String, - required: false, - description: "Version of the API used in creation of the dataset.", - }) - @IsOptional() - @IsString() - readonly version?: string; -} diff --git a/src/datasets/dto/create-raw-dataset.dto.ts b/src/datasets/dto/create-raw-dataset.dto.ts deleted file mode 100644 index fafa70b78..000000000 --- a/src/datasets/dto/create-raw-dataset.dto.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { UpdateRawDatasetDto } from "./update-raw-dataset.dto"; -import { ApiProperty } from "@nestjs/swagger"; -import { IsEnum, IsOptional, IsString } from "class-validator"; -import { DatasetType } from "../dataset-type.enum"; - -export class CreateRawDatasetDto extends UpdateRawDatasetDto { - @ApiProperty({ - type: String, - required: false, - description: "Persistent identifier of the dataset.", - }) - @IsOptional() - @IsString() - pid?: string; - - @IsEnum(DatasetType) - readonly type: string = DatasetType.Raw; - - @ApiProperty({ - type: String, - required: false, - description: "Version of the API used in creation of the dataset.", - }) - @IsOptional() - @IsString() - readonly version?: string; -} diff --git a/src/datasets/dto/update-dataset.dto.ts b/src/datasets/dto/update-dataset.dto.ts index c4ea63c4b..ad928772f 100644 --- a/src/datasets/dto/update-dataset.dto.ts +++ b/src/datasets/dto/update-dataset.dto.ts @@ -348,7 +348,7 @@ export class UpdateDatasetDto extends OwnableDto { @IsString({ each: true, }) - readonly proposalId?: string[]; + readonly proposalIds?: string[]; @ApiProperty({ type: [String], @@ -360,7 +360,7 @@ export class UpdateDatasetDto extends OwnableDto { @IsString({ each: true, }) - readonly sampleId?: string[]; + readonly sampleIds?: string[]; @ApiProperty({ type: String, @@ -372,7 +372,7 @@ export class UpdateDatasetDto extends OwnableDto { @IsString({ each: false, }) - readonly instrumentId?: string[]; + readonly instrumentIds?: string[]; @ApiProperty({ type: [String], diff --git a/src/datasets/dto/update-derived-dataset.dto.ts b/src/datasets/dto/update-derived-dataset.dto.ts deleted file mode 100644 index a654c5bca..000000000 --- a/src/datasets/dto/update-derived-dataset.dto.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; -import { ApiProperty, PartialType } from "@nestjs/swagger"; -import { IsObject, IsOptional, IsString } from "class-validator"; - -export class UpdateDerivedDatasetDto extends UpdateDatasetObsoleteDto { - @ApiProperty({ - type: String, - required: true, - description: - "First name and last name of the person or people pursuing the data analysis. The string may contain a list of names, which should then be separated by semicolons.", - }) - @IsString() - readonly investigator: string; - - @ApiProperty({ - type: [String], - required: true, - description: - "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs.", - }) - @IsString({ - each: true, - }) - readonly inputDatasets: string[]; - - @ApiProperty({ - type: [String], - required: true, - description: - "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data.", - }) - @IsString({ - each: true, - }) - readonly usedSoftware: string[]; - - @ApiProperty({ - type: Object, - required: false, - description: - "The creation process of the derived data will usually depend on input job parameters. The full structure of these input parameters are stored here.", - }) - @IsOptional() - @IsObject() - readonly jobParameters?: Record; - - @ApiProperty({ - type: String, - required: false, - description: - "The output job logfile. Keep the size of this log data well below 15 MB.", - }) - @IsOptional() - @IsString() - readonly jobLogData?: string; -} - -export class PartialUpdateDerivedDatasetDto extends PartialType( - UpdateDerivedDatasetDto, -) {} diff --git a/src/datasets/dto/update-raw-dataset.dto.ts b/src/datasets/dto/update-raw-dataset.dto.ts deleted file mode 100644 index 5926b854f..000000000 --- a/src/datasets/dto/update-raw-dataset.dto.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { IsDateString, IsOptional, IsString } from "class-validator"; -import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; -import { ApiProperty, PartialType } from "@nestjs/swagger"; - -export class UpdateRawDatasetDto extends UpdateDatasetObsoleteDto { - /* we need to discuss if the naming is adequate. */ - @ApiProperty({ - type: String, - required: 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.", - }) - @IsString() - readonly principalInvestigator: string; - - @ApiProperty({ - type: Date, - required: false, - description: - "Start time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", - }) - @IsOptional() - @IsDateString() - readonly startTime?: Date; - - @ApiProperty({ - type: Date, - required: false, - description: - "End time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", - }) - @IsOptional() - @IsDateString() - readonly endTime?: Date; - - @ApiProperty({ - type: String, - required: true, - description: - "Unique location identifier where data was taken, usually in the form /Site-name/facility-name/instrumentOrBeamline-name. This field is required if the dataset is a Raw dataset.", - }) - @IsString() - readonly creationLocation: string; - - @ApiProperty({ - type: String, - required: false, - description: - "Defines the format of the data files in this dataset, e.g Nexus Version x.y.", - }) - @IsOptional() - @IsString() - readonly dataFormat?: string; - - @ApiProperty({ - type: String, - required: false, - description: "The ID of the proposal to which the dataset belongs.", - }) - @IsOptional() - @IsString() - readonly proposalId?: string; - - @ApiProperty({ - type: String, - required: false, - description: "ID of the sample used when collecting the data.", - }) - @IsOptional() - @IsString() - readonly sampleId?: string; - - @ApiProperty({ - type: String, - required: false, - description: "ID of the instrument where the data was created.", - }) - @IsOptional() - @IsString() - readonly instrumentId: string; - - @IsOptional() - investigator?: string; - - @IsOptional() - inputDatasets?: string[]; - - @IsOptional() - usedSoftware?: string[]; - - @IsOptional() - jobParameters?: Record; - - @IsOptional() - jobLogData?: string; -} - -export class PartialUpdateRawDatasetDto extends PartialType( - UpdateRawDatasetDto, -) {} diff --git a/src/datasets/schemas/dataset.schema.ts b/src/datasets/schemas/dataset.schema.ts index a50055b98..58fdcd1e4 100644 --- a/src/datasets/schemas/dataset.schema.ts +++ b/src/datasets/schemas/dataset.schema.ts @@ -455,7 +455,7 @@ export class DatasetClass extends OwnableClass { "The ID of the proposal to which the dataset belongs to and it has been acquired under.", }) @Prop({ type: String, ref: "Proposal", required: false }) - proposalId?: string; + proposalIds?: string; @ApiProperty({ type: [String], @@ -464,7 +464,7 @@ export class DatasetClass extends OwnableClass { "Single ID or array of IDS of the samples used when collecting the data.", }) @Prop({ type: [String], ref: "Sample", required: false }) - sampleId?: string[]; + sampleIds?: string[]; @ApiProperty({ type: [String], @@ -473,7 +473,7 @@ export class DatasetClass extends OwnableClass { "Id of the instrument or array of IDS of the instruments where the data contained in this dataset was created/acquired.", }) @Prop({ type: [String], ref: "Instrument", required: false }) - instrumentId?: string[]; + instrumentIds?: string[]; /* * Derived Dataset diff --git a/src/origdatablocks/origdatablocks.controller.ts b/src/origdatablocks/origdatablocks.controller.ts index f1a0f13be..308eb32e9 100644 --- a/src/origdatablocks/origdatablocks.controller.ts +++ b/src/origdatablocks/origdatablocks.controller.ts @@ -45,8 +45,8 @@ import { PartialUpdateDatasetDto } from "src/datasets/dto/update-dataset.dto"; import { filterDescription, filterExample } from "src/common/utils"; import { JWTUser } from "src/auth/interfaces/jwt-user.interface"; import { DatasetClass } from "src/datasets/schemas/dataset.schema"; -import { CreateRawDatasetDto } from "src/datasets/dto/create-raw-dataset.dto"; -import { CreateDerivedDatasetDto } from "src/datasets/dto/create-derived-dataset.dto"; +import { CreateRawDatasetDto } from "src/datasets/dto/create-raw-dataset-obsolete.dto"; +import { CreateDerivedDatasetDto } from "src/datasets/dto/create-derived-dataset-obsolete.dto"; import { logger } from "@user-office-software/duo-logger"; @ApiBearerAuth() diff --git a/test/DatasetAuthorization.js b/test/DatasetAuthorization.js index ab707200d..56a8b7717 100644 --- a/test/DatasetAuthorization.js +++ b/test/DatasetAuthorization.js @@ -45,7 +45,7 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { before(() => { db.collection("Dataset").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], @@ -76,13 +76,14 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { password: TestData.Accounts["archiveManager"]["password"], }); }); - + afterEach((done) => { sandbox.restore(); done(); }); it("0010: adds dataset 1 as Admin Ingestor", async () => { + console.log(JSON.stringify(dataset1)); return request(appUrl) .post("/api/v3/Datasets") .send(dataset1) @@ -91,6 +92,8 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { .expect(TestData.EntryCreatedStatusCode) .expect("Content-Type", /json/) .then((res) => { + console.log("Results"); + console.log(res.body); res.body.should.have.property("ownerGroup").and.equal("group4"); res.body.should.have.property("type").and.equal("raw"); res.body.should.have.property("isPublished").and.equal(true); @@ -100,1440 +103,1440 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { }); }); - it("0020: adds dataset 2 as Admin Ingestor", async () => { - return request(appUrl) - .post("/api/v3/Datasets") - .send(dataset2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("ownerGroup").and.equal("group1"); - res.body.should.have.property("type").and.equal("raw"); - res.body.should.have.property("isPublished").and.equal(false); - res.body.should.have.property("pid").and.be.string; - datasetPid2 = res.body["pid"]; - encodedDatasetPid2 = encodeURIComponent(datasetPid2); - }); - }); - - it("0030: adds dataset 3 as Admin Ingestor", async () => { - return request(appUrl) - .post("/api/v3/Datasets") - .send(dataset3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("ownerGroup").and.equal("group2"); - res.body.should.have.property("type").and.equal("raw"); - res.body.should.have.property("isPublished").and.equal(false); - res.body.should.have.property("pid").and.be.string; - datasetPid3 = res.body["pid"]; - encodedDatasetPid3 = encodeURIComponent(datasetPid3); - }); - }); - - it("0040: adds a new origDatablock on the published dataset as Admin Ingestor", async () => { - return request(appUrl) - .post(`/api/v3/datasets/${encodedDatasetPid1}/origdatablocks`) - .send(TestData.OrigDataBlockCorrect1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have - .property("size") - .and.equal(TestData.OrigDataBlockCorrect1.size); - res.body.should.have.property("id").and.be.string; - }); - }); - - it("0050: adds a new datablock on the published dataset as Admin Ingestor", async () => { - const randomArchiveId = Math.random().toString(36).slice(2); - - return request(appUrl) - .post(`/api/v3/datasets/${encodedDatasetPid1}/datablocks`) - .send({ ...TestData.DataBlockCorrect, archiveId: randomArchiveId }) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have - .property("size") - .and.equal(TestData.DataBlockCorrect.size); - res.body.should.have.property("id").and.be.string; - }); - }); - - it("0060: adds a new attachment on the published dataset as Admin Ingestor", async () => { - return request(appUrl) - .post(`/api/v3/datasets/${encodedDatasetPid1}/attachments`) - .send(TestData.AttachmentCorrect) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/); - }); - - it("0070: list of public datasets, aka as unauthenticated user", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - res.body[0]["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0080: access public dataset as unauthenticated user", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0090: access private dataset as unauthenticated user", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .expect("Content-Type", /json/) - .expect(TestData.AccessForbiddenStatusCode); - }); - - it("0100: list of datasets for Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(3); - }); - }); - - it("0110: datasets counts for Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/count") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body["count"].should.be.equal(3); - }); - }); - - it("0120: access dataset 1 as Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0130: full query for datasets for Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/fullquery") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(3); - }); - }); - - it("0140: access dataset 2 as Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0150: access dataset 3 as Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0160: list of datasets for User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(2); - res.body[1]["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0170: datasets count for User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets/count") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body["count"].should.be.equal(2); - }); - }); - - it("0180: access dataset 1 as User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0190: access dataset 2 as User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0200: access dataset 3 as User 1, which should fail as forbidden", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect("Content-Type", /json/) - .expect(TestData.AccessForbiddenStatusCode); - }); - - it("0210: full query for datasets for User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets/fullquery") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - res.body[0]["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0220: list of datasets for User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(2); - res.body[1]["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0230: datasets count for User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets/count") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body["count"].should.be.equal(2); - }); - }); - - it("0240: access dataset 1 as User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0250: access dataset 2 as User 2, which should fail as forbidden", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect("Content-Type", /json/) - .expect(TestData.AccessForbiddenStatusCode); - }); - - it("0260: access dataset 3 as User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0270: full query for datasets for User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets/fullquery") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - res.body[0]["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0280: list of datasets for User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(3); - }); - }); - - it("0290: datasets count for User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/count") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body["count"].should.be.equal(3); - }); - }); - - it("0300: access dataset 1 as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0310: access dataset 2 as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0320: access dataset 3 as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0330: full query for datasets for User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/fullquery") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(2); - }); - }); - - it("0340: update dataset 2 to be published as Admin Ingestor", async () => { - return request(appUrl) - .patch(`/api/v3/Datasets/${encodedDatasetPid2}`) - .send({ isPublished: true }) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.SuccessfulPatchStatusCode) - .expect("Content-Type", /json/); - }); - - it("0350: full query for datasets for User 2", async () => { - const fields = { - isPublished: true, - }; - - return request(appUrl) - .get( - `/api/v3/Datasets/fullquery?fields=${encodeURIComponent( - JSON.stringify(fields), - )}`, - ) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(2); - }); - }); - - it("0360: full facet for datasets for User 2", async () => { - const fields = { - isPublished: true, - }; - return request(appUrl) - .get( - `/api/v3/Datasets/fullfacet?fields=${encodeURIComponent( - JSON.stringify(fields), - )}`, - ) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body[0].all[0].totalSets.should.be.equal(2); - }); - }); - - it("0370: access dataset 1 origdatablocks as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/origdatablocks") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - }); - }); - - it("0380: access dataset 1 datablocks as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/datablocks") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - }); - }); - - it("0390: access dataset 1 attachments as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/attachments") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - }); - }); - - it("0400: access dataset 1 thumbnail as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/thumbnail") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode); - }); - - it("0410: should delete dataset 1 as Archive Manager", async () => { - return request(appUrl) - .delete("/api/v3/datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - .expect(TestData.SuccessfulDeleteStatusCode) - .expect("Content-Type", /json/); - }); - - it("0420: should delete dataset 2 as Archive Manager", async () => { - return request(appUrl) - .delete("/api/v3/datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - .expect(TestData.SuccessfulDeleteStatusCode) - .expect("Content-Type", /json/); - }); - - it("0430: should delete dataset 3 as Archive Manager", async () => { - return request(appUrl) - .delete("/api/v3/datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - .expect(TestData.SuccessfulDeleteStatusCode) - .expect("Content-Type", /json/); - }); - - it("0500: add a new raw dataset as Admin", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0501: add a new incomplete raw dataset as Admin, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0502: add a new raw dataset with specified pid as Admin", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "admin", - }; - console.log("0502: pid : " + datasetWithPid["pid"]); - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0503: add a new raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0504: add a new invalid raw dataset with specified pid as Admin, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: uuidv4(), - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0505: add a new invalid raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0510: add a new raw dataset with different owner group as Admin", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0520: add a new incomplete raw dataset with different owner group as Admin, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0530: add a new raw dataset with specified pid and different owner group as Admin", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0540: add a new raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0550: add a new invalid raw dataset with specified pid and different owner group as Admin, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0560: add a new invalid raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0600: add a new raw dataset as User 1 which belongs to a create dataset group", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0601: add a new incomplete raw dataset as User 1 which belongs to a create dataset group", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0602: add a new raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0603: add a new raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0604: add a new invalid raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0605: add a new invalid raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0610: add a new raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0620: add a new incomplete raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0630: add a new raw dataset with specified pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0640: add a new raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0650: add a new invalid raw dataset with specified pid and different owner group as User 1 which belongs to a ", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0660: add a new invalid raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0700: add a new raw dataset as User 2 which belongs to a create dataset with pid group", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0701: add a new incomplete raw dataset as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0702: add a new raw dataset with specified pid as User 2 which belongs to a create dataset with pid group", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0703: add a new raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0704: add a new invalid raw dataset with specified pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0705: add a new invalid raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0710: add a new raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0720: add a new incomplete raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0730: add a new raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0740: add a new raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0750: add a new invalid raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0760: add a new invalid raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0800: add a new raw dataset as User 3 which belongs to a create dataset privileged group", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0801: add a new incomplete raw dataset as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0802: add a new raw dataset with specified pid as User 3 which belongs to a create dataset privileged group", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0803: add a new raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0804: add a new invalid raw dataset with specified pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0805: add a new invalid raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0810: add a new raw dataset with different owner group as User 3 which belongs to a create dataset privileged group", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0820: add a new incomplete raw dataset with different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0830: add a new raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0840: add a new raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0850: add a new invalid raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0860: add a new invalid raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); + // it("0020: adds dataset 2 as Admin Ingestor", async () => { + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(dataset2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("ownerGroup").and.equal("group1"); + // res.body.should.have.property("type").and.equal("raw"); + // res.body.should.have.property("isPublished").and.equal(false); + // res.body.should.have.property("pid").and.be.string; + // datasetPid2 = res.body["pid"]; + // encodedDatasetPid2 = encodeURIComponent(datasetPid2); + // }); + // }); + + // it("0030: adds dataset 3 as Admin Ingestor", async () => { + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(dataset3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("ownerGroup").and.equal("group2"); + // res.body.should.have.property("type").and.equal("raw"); + // res.body.should.have.property("isPublished").and.equal(false); + // res.body.should.have.property("pid").and.be.string; + // datasetPid3 = res.body["pid"]; + // encodedDatasetPid3 = encodeURIComponent(datasetPid3); + // }); + // }); + + // it("0040: adds a new origDatablock on the published dataset as Admin Ingestor", async () => { + // return request(appUrl) + // .post(`/api/v3/datasets/${encodedDatasetPid1}/origdatablocks`) + // .send(TestData.OrigDataBlockCorrect1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have + // .property("size") + // .and.equal(TestData.OrigDataBlockCorrect1.size); + // res.body.should.have.property("id").and.be.string; + // }); + // }); + + // it("0050: adds a new datablock on the published dataset as Admin Ingestor", async () => { + // const randomArchiveId = Math.random().toString(36).slice(2); + + // return request(appUrl) + // .post(`/api/v3/datasets/${encodedDatasetPid1}/datablocks`) + // .send({ ...TestData.DataBlockCorrect, archiveId: randomArchiveId }) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have + // .property("size") + // .and.equal(TestData.DataBlockCorrect.size); + // res.body.should.have.property("id").and.be.string; + // }); + // }); + + // it("0060: adds a new attachment on the published dataset as Admin Ingestor", async () => { + // return request(appUrl) + // .post(`/api/v3/datasets/${encodedDatasetPid1}/attachments`) + // .send(TestData.AttachmentCorrect) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0070: list of public datasets, aka as unauthenticated user", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // res.body[0]["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0080: access public dataset as unauthenticated user", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0090: access private dataset as unauthenticated user", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .expect("Content-Type", /json/) + // .expect(TestData.AccessForbiddenStatusCode); + // }); + + // it("0100: list of datasets for Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(3); + // }); + // }); + + // it("0110: datasets counts for Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/count") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body["count"].should.be.equal(3); + // }); + // }); + + // it("0120: access dataset 1 as Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0130: full query for datasets for Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/fullquery") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(3); + // }); + // }); + + // it("0140: access dataset 2 as Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0150: access dataset 3 as Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0160: list of datasets for User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(2); + // res.body[1]["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0170: datasets count for User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/count") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body["count"].should.be.equal(2); + // }); + // }); + + // it("0180: access dataset 1 as User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0190: access dataset 2 as User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0200: access dataset 3 as User 1, which should fail as forbidden", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.AccessForbiddenStatusCode); + // }); + + // it("0210: full query for datasets for User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/fullquery") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // res.body[0]["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0220: list of datasets for User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(2); + // res.body[1]["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0230: datasets count for User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/count") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body["count"].should.be.equal(2); + // }); + // }); + + // it("0240: access dataset 1 as User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0250: access dataset 2 as User 2, which should fail as forbidden", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.AccessForbiddenStatusCode); + // }); + + // it("0260: access dataset 3 as User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0270: full query for datasets for User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/fullquery") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // res.body[0]["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0280: list of datasets for User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(3); + // }); + // }); + + // it("0290: datasets count for User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/count") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body["count"].should.be.equal(3); + // }); + // }); + + // it("0300: access dataset 1 as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0310: access dataset 2 as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0320: access dataset 3 as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0330: full query for datasets for User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/fullquery") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(2); + // }); + // }); + + // it("0340: update dataset 2 to be published as Admin Ingestor", async () => { + // return request(appUrl) + // .patch(`/api/v3/Datasets/${encodedDatasetPid2}`) + // .send({ isPublished: true }) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.SuccessfulPatchStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0350: full query for datasets for User 2", async () => { + // const fields = { + // isPublished: true, + // }; + + // return request(appUrl) + // .get( + // `/api/v3/Datasets/fullquery?fields=${encodeURIComponent( + // JSON.stringify(fields), + // )}`, + // ) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(2); + // }); + // }); + + // it("0360: full facet for datasets for User 2", async () => { + // const fields = { + // isPublished: true, + // }; + // return request(appUrl) + // .get( + // `/api/v3/Datasets/fullfacet?fields=${encodeURIComponent( + // JSON.stringify(fields), + // )}`, + // ) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body[0].all[0].totalSets.should.be.equal(2); + // }); + // }); + + // it("0370: access dataset 1 origdatablocks as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/origdatablocks") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // }); + // }); + + // it("0380: access dataset 1 datablocks as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/datablocks") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // }); + // }); + + // it("0390: access dataset 1 attachments as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/attachments") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // }); + // }); + + // it("0400: access dataset 1 thumbnail as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/thumbnail") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode); + // }); + + // it("0410: should delete dataset 1 as Archive Manager", async () => { + // return request(appUrl) + // .delete("/api/v3/datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + // .expect(TestData.SuccessfulDeleteStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0420: should delete dataset 2 as Archive Manager", async () => { + // return request(appUrl) + // .delete("/api/v3/datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + // .expect(TestData.SuccessfulDeleteStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0430: should delete dataset 3 as Archive Manager", async () => { + // return request(appUrl) + // .delete("/api/v3/datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + // .expect(TestData.SuccessfulDeleteStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0500: add a new raw dataset as Admin", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0501: add a new incomplete raw dataset as Admin, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0502: add a new raw dataset with specified pid as Admin", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "admin", + // }; + // console.log("0502: pid : " + datasetWithPid["pid"]); + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0503: add a new raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0504: add a new invalid raw dataset with specified pid as Admin, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: uuidv4(), + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0505: add a new invalid raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0510: add a new raw dataset with different owner group as Admin", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0520: add a new incomplete raw dataset with different owner group as Admin, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0530: add a new raw dataset with specified pid and different owner group as Admin", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0540: add a new raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0550: add a new invalid raw dataset with specified pid and different owner group as Admin, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0560: add a new invalid raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0600: add a new raw dataset as User 1 which belongs to a create dataset group", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0601: add a new incomplete raw dataset as User 1 which belongs to a create dataset group", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0602: add a new raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0603: add a new raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0604: add a new invalid raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0605: add a new invalid raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0610: add a new raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0620: add a new incomplete raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0630: add a new raw dataset with specified pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0640: add a new raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0650: add a new invalid raw dataset with specified pid and different owner group as User 1 which belongs to a ", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0660: add a new invalid raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0700: add a new raw dataset as User 2 which belongs to a create dataset with pid group", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0701: add a new incomplete raw dataset as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0702: add a new raw dataset with specified pid as User 2 which belongs to a create dataset with pid group", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0703: add a new raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0704: add a new invalid raw dataset with specified pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0705: add a new invalid raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0710: add a new raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0720: add a new incomplete raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0730: add a new raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0740: add a new raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0750: add a new invalid raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0760: add a new invalid raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0800: add a new raw dataset as User 3 which belongs to a create dataset privileged group", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0801: add a new incomplete raw dataset as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0802: add a new raw dataset with specified pid as User 3 which belongs to a create dataset privileged group", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0803: add a new raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0804: add a new invalid raw dataset with specified pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0805: add a new invalid raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0810: add a new raw dataset with different owner group as User 3 which belongs to a create dataset privileged group", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0820: add a new incomplete raw dataset with different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0830: add a new raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0840: add a new raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0850: add a new invalid raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0860: add a new invalid raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); }); From cffb06064b5a2df33a817df08de94fee6455a5d3 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 11 Sep 2024 15:01:03 +0200 Subject: [PATCH 04/38] fix types on obsolete schemas --- src/datasets/datasets.controller.ts | 54 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 89e6f7536..19c480a9d 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -632,14 +632,14 @@ export class DatasetsController { ); const dtoTestRawCorrect = plainToInstance( - CreateRawDatasetDto, - createDatasetDto, + CreateRawDatasetObsoleteDto, + createDatasetObsoleteDto, ); const errorsTestRawCorrect = await validate(dtoTestRawCorrect); const dtoTestDerivedCorrect = plainToInstance( - CreateDerivedDatasetDto, - createDatasetDto, + CreateDerivedDatasetObsoleteDto, + createDatasetObsoleteDto, ); const errorsTestDerivedCorrect = await validate(dtoTestDerivedCorrect); @@ -1109,7 +1109,7 @@ export class DatasetsController { @Req() request: Request, @Param("pid") id: string, ): Promise { - const dataset = await this.checkPermissionsForDataset(request, id); + const dataset = await this.checkPermissionsForDatasetObsolete(request, id); return dataset; } @@ -1137,15 +1137,18 @@ export class DatasetsController { description: "Id of the dataset to modify", type: String, }) - @ApiExtraModels(PartialUpdateRawDatasetDto, PartialUpdateDerivedDatasetDto) + @ApiExtraModels( + PartialUpdateRawDatasetObsoleteDto, + PartialUpdateDerivedDatasetObsoleteDto, + ) @ApiBody({ description: "Fields that needs to be updated in the dataset. Only the fields that needs to be updated have to be passed in.", required: true, schema: { oneOf: [ - { $ref: getSchemaPath(PartialUpdateRawDatasetDto) }, - { $ref: getSchemaPath(PartialUpdateDerivedDatasetDto) }, + { $ref: getSchemaPath(PartialUpdateRawDatasetObsoleteDto) }, + { $ref: getSchemaPath(PartialUpdateDerivedDatasetObsoleteDto) }, ], }, }) @@ -1160,8 +1163,8 @@ export class DatasetsController { @Param("pid") pid: string, @Body() updateDatasetDto: - | PartialUpdateRawDatasetDto - | PartialUpdateDerivedDatasetDto, + | PartialUpdateRawDatasetObsoleteDto + | PartialUpdateDerivedDatasetObsoleteDto, ): Promise { const foundDataset = await this.datasetsService.findOne({ where: { pid } }); @@ -1170,11 +1173,11 @@ export class DatasetsController { } // NOTE: Default validation pipe does not validate union types. So we need custom validation. - await this.validateDataset( + await this.validateDatasetObsolete( updateDatasetDto, foundDataset.type === "raw" - ? PartialUpdateRawDatasetDto - : PartialUpdateDerivedDatasetDto, + ? PartialUpdateRawDatasetObsoleteDto + : PartialUpdateDerivedDatasetObsoleteDto, ); // NOTE: We need DatasetClass instance because casl module can not recognize the type from dataset mongo database model. If other fields are needed can be added later. @@ -1220,15 +1223,15 @@ export class DatasetsController { description: "Id of the dataset to modify", type: String, }) - @ApiExtraModels(UpdateRawDatasetDto, UpdateDerivedDatasetDto) + @ApiExtraModels(UpdateRawDatasetObsoleteDto, UpdateDerivedDatasetObsoleteDto) @ApiBody({ description: "Dataset object that needs to be updated. The whole dataset object with updated fields have to be passed in.", required: true, schema: { oneOf: [ - { $ref: getSchemaPath(UpdateRawDatasetDto) }, - { $ref: getSchemaPath(UpdateDerivedDatasetDto) }, + { $ref: getSchemaPath(UpdateRawDatasetObsoleteDto) }, + { $ref: getSchemaPath(UpdateDerivedDatasetObsoleteDto) }, ], }, }) @@ -1241,7 +1244,10 @@ export class DatasetsController { async findByIdAndReplace( @Req() request: Request, @Param("pid") pid: string, - @Body() updateDatasetDto: UpdateRawDatasetDto | UpdateDerivedDatasetDto, + @Body() + updateDatasetObsoleteDto: + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto, ): Promise { const foundDataset = await this.datasetsService.findOne({ where: { pid } }); @@ -1250,11 +1256,11 @@ export class DatasetsController { } // NOTE: Default validation pipe does not validate union types. So we need custom validation. - const outputDto = await this.validateDataset( - updateDatasetDto, + const outputDto = await this.validateDatasetObsolete( + updateDatasetObsoleteDto, foundDataset.type === "raw" - ? UpdateRawDatasetDto - : UpdateDerivedDatasetDto, + ? UpdateRawDatasetObsoleteDto + : UpdateDerivedDatasetObsoleteDto, ); const datasetInstance = @@ -1274,7 +1280,9 @@ export class DatasetsController { return this.datasetsService.findByIdAndReplace( pid, - outputDto as UpdateRawDatasetDto | UpdateDerivedDatasetDto, + outputDto as + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto, ); } @@ -2172,7 +2180,7 @@ export class DatasetsController { Action.DatasetLogbookRead, ); - const proposalId = dataset?.proposalId; + const proposalId = (dataset?.proposalIds || [])[0]; if (!proposalId) return null; From fc8127231ab1d99ac3aca6691980cd565378ad46 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 13 Sep 2024 15:56:54 +0200 Subject: [PATCH 05/38] updated to use latest dataset schema in service --- src/datasets/datasets.controller.ts | 125 +++++++++++++++++-------- src/datasets/datasets.service.ts | 47 ++++------ src/datasets/dto/update-dataset.dto.ts | 20 ++++ 3 files changed, 123 insertions(+), 69 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 19c480a9d..9071f6e53 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -100,6 +100,10 @@ import configuration from "src/config/configuration"; import { DatasetType } from "./dataset-type.enum"; import { OutputDatasetObsoleteDto } from "./dto/output-dataset-obsolete.dto"; import { CreateDatasetDto } from "./dto/create-dataset.dto"; +import { + PartialUpdateDatasetDto, + UpdateDatasetDto, +} from "./dto/update-dataset.dto"; @ApiBearerAuth() @ApiExtraModels( @@ -393,60 +397,98 @@ export class DatasetsController { } convertObsoleteToCurrentSchema( - inputDataset: CreateRawDatasetObsoleteDto | CreateDerivedDatasetObsoleteDto, - ): CreateDatasetDto { + inputObsoleteDataset: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto + | PartialUpdateRawDatasetObsoleteDto + | PartialUpdateDerivedDatasetObsoleteDto, + ): CreateDatasetDto | UpdateDatasetDto | PartialUpdateDatasetDto { const propertiesModifier: Record = {}; - if (inputDataset.type == "raw") { - if ("proposalId" in inputDataset) { + + if ( + inputObsoleteDataset instanceof CreateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof UpdateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof PartialUpdateRawDatasetObsoleteDto + ) { + if ("proposalId" in inputObsoleteDataset) { propertiesModifier.proposalIds = [ - (inputDataset as CreateRawDatasetObsoleteDto).proposalId, + (inputObsoleteDataset as CreateRawDatasetObsoleteDto).proposalId, ]; } - if ("sampleId" in inputDataset) { + if ("sampleId" in inputObsoleteDataset) { propertiesModifier.sampleIds = [ - (inputDataset as CreateRawDatasetObsoleteDto).sampleId, + (inputObsoleteDataset as CreateRawDatasetObsoleteDto).sampleId, ]; } - if ("instrumentIds" in inputDataset) { + if ("instrumentIds" in inputObsoleteDataset) { propertiesModifier.instrumentIds = [ - (inputDataset as CreateRawDatasetObsoleteDto).instrumentId, + (inputObsoleteDataset as CreateRawDatasetObsoleteDto).instrumentId, ]; } } else { - if ("investigator" in inputDataset) { + if ("investigator" in inputObsoleteDataset) { propertiesModifier.principalInvestigator = [ - (inputDataset as CreateDerivedDatasetObsoleteDto).investigator, + (inputObsoleteDataset as CreateDerivedDatasetObsoleteDto) + .investigator, ]; } } - const outputDataset: CreateDatasetDto = { - ...(inputDataset as CreateDatasetDto), - ...propertiesModifier, - }; + let outputDataset: + | CreateDatasetDto + | UpdateDatasetDto + | PartialUpdateDatasetDto = {}; + if ( + inputObsoleteDataset instanceof CreateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof CreateDerivedDatasetObsoleteDto + ) { + outputDataset = { + ...(inputObsoleteDataset as CreateDatasetDto), + ...propertiesModifier, + } as CreateDatasetDto; + } else if ( + inputObsoleteDataset instanceof UpdateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof UpdateDerivedDatasetObsoleteDto + ) { + outputDataset = { + ...(inputObsoleteDataset as UpdateDatasetDto), + ...propertiesModifier, + } as UpdateDatasetDto; + } else if ( + inputObsoleteDataset instanceof PartialUpdateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof PartialUpdateDerivedDatasetObsoleteDto + ) { + outputDataset = { + ...(inputObsoleteDataset as PartialUpdateDatasetDto), + ...propertiesModifier, + } as PartialUpdateDatasetDto; + } return outputDataset; } convertCurrentToObsoleteSchema( - inputDataset: DatasetClass, + inputDataset: DatasetClass | null, ): OutputDatasetObsoleteDto { const propertiesModifier: Record = {}; - if ("proposalIds" in inputDataset) { - propertiesModifier.proposalIds = inputDataset.proposalIds![0]; - } - if ("sampleIds" in inputDataset) { - propertiesModifier.sampleIds = inputDataset.sampleIds![0]; - } - if ("instrumentIds" in inputDataset) { - propertiesModifier.instrumentIds = inputDataset.instrumentIds![0]; - } - if (inputDataset.type == "raw") { - if ("investigator" in inputDataset) { - propertiesModifier.investigator = inputDataset.principalInvestigator; + if (inputDataset) { + if ("proposalIds" in inputDataset) { + propertiesModifier.proposalIds = inputDataset.proposalIds![0]; + } + if ("sampleIds" in inputDataset) { + propertiesModifier.sampleIds = inputDataset.sampleIds![0]; + } + if ("instrumentIds" in inputDataset) { + propertiesModifier.instrumentIds = inputDataset.instrumentIds![0]; + } + if (inputDataset.type == "raw") { + if ("investigator" in inputDataset) { + propertiesModifier.investigator = inputDataset.principalInvestigator; + } } } - const outputDataset: OutputDatasetObsoleteDto = { ...(inputDataset as OutputDatasetObsoleteDto), ...propertiesModifier, @@ -509,8 +551,9 @@ export class DatasetsController { ); try { - const datasetDto = - this.convertObsoleteToCurrentSchema(obsoleteDatasetDto); + const datasetDto = this.convertObsoleteToCurrentSchema( + obsoleteDatasetDto, + ) as CreateDatasetDto; const createdDataset = await this.datasetsService.create(datasetDto); const outputObsoleteDatasetDto = @@ -772,7 +815,7 @@ export class DatasetsController { async fullquery( @Req() request: Request, @Query() filters: { fields?: string; limits?: string }, - ): Promise { + ): Promise { const user: JWTUser = request.user as JWTUser; const fields: IDatasetFields = JSON.parse(filters.fields ?? "{}"); @@ -809,7 +852,9 @@ export class DatasetsController { limits: JSON.parse(filters.limits ?? "{}"), }; - return this.datasetsService.fullquery(parsedFilters); + const results = await this.datasetsService.fullquery(parsedFilters); + + return results as OutputDatasetObsoleteDto[]; } // GET /fullfacets @@ -1108,10 +1153,12 @@ export class DatasetsController { async findById( @Req() request: Request, @Param("pid") id: string, - ): Promise { - const dataset = await this.checkPermissionsForDatasetObsolete(request, id); + ): Promise { + const dataset = this.convertCurrentToObsoleteSchema( + await this.checkPermissionsForDatasetObsolete(request, id), + ); - return dataset; + return dataset as OutputDatasetObsoleteDto; } // PATCH /datasets/:id @@ -1165,7 +1212,7 @@ export class DatasetsController { updateDatasetDto: | PartialUpdateRawDatasetObsoleteDto | PartialUpdateDerivedDatasetObsoleteDto, - ): Promise { + ): Promise { const foundDataset = await this.datasetsService.findOne({ where: { pid } }); if (!foundDataset) { @@ -1196,7 +1243,9 @@ export class DatasetsController { throw new ForbiddenException("Unauthorized to update this dataset"); } - return this.datasetsService.findByIdAndUpdate(pid, updateDatasetDto); + return this.convertCurrentToObsoleteSchema( + await this.datasetsService.findByIdAndUpdate(pid, updateDatasetDto), + ); } // PUT /datasets/:id diff --git a/src/datasets/datasets.service.ts b/src/datasets/datasets.service.ts index 60793750d..723552172 100644 --- a/src/datasets/datasets.service.ts +++ b/src/datasets/datasets.service.ts @@ -25,20 +25,13 @@ import { InitialDatasetsService } from "src/initial-datasets/initial-datasets.se import { LogbooksService } from "src/logbooks/logbooks.service"; import { DatasetType } from "./dataset-type.enum"; import { CreateDatasetDto } from "./dto/create-dataset.dto"; -import { - PartialUpdateDatasetObsoleteDto, - UpdateDatasetObsoleteDto, -} from "./dto/update-dataset-obsolete.dto"; -import { - PartialUpdateDerivedDatasetDto, - UpdateDerivedDatasetDto, -} from "./dto/update-derived-dataset-obsolete.dto"; -import { - PartialUpdateRawDatasetDto, - UpdateRawDatasetDto, -} from "./dto/update-raw-dataset-obsolete.dto"; import { IDatasetFields } from "./interfaces/dataset-filters.interface"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; +import { + PartialUpdateDatasetDto, + PartialUpdateDatasetWithHistoryDto, + UpdateDatasetDto, +} from "./dto/update-dataset.dto"; @Injectable({ scope: Scope.REQUEST }) export class DatasetsService { @@ -205,10 +198,7 @@ export class DatasetsService { // we update the full dataset if exist or create a new one if it does not async findByIdAndReplace( id: string, - updateDatasetDto: - | UpdateDatasetObsoleteDto - | UpdateRawDatasetDto - | UpdateDerivedDatasetDto, + updateDatasetDto: UpdateDatasetDto, ): Promise { const username = (this.request.user as JWTUser).username; const existingDataset = await this.datasetModel.findOne({ pid: id }).exec(); @@ -252,10 +242,8 @@ export class DatasetsService { async findByIdAndUpdate( id: string, updateDatasetDto: - | PartialUpdateDatasetObsoleteDto - | PartialUpdateRawDatasetDto - | PartialUpdateDerivedDatasetDto - | UpdateQuery, + | PartialUpdateDatasetDto + | PartialUpdateDatasetWithHistoryDto, ): Promise { const existingDataset = await this.datasetModel.findOne({ pid: id }).exec(); // check if we were able to find the dataset @@ -434,7 +422,7 @@ export class DatasetsService { async updateHistory( req: Request, dataset: DatasetClass, - data: UpdateDatasetObsoleteDto, + data: PartialUpdateDatasetDto, ) { if (req.body.history) { delete req.body.history; @@ -442,17 +430,17 @@ export class DatasetsService { if (!req.body.size && !req.body.packedSize) { const updatedFields: Omit< - UpdateDatasetObsoleteDto, + PartialUpdateDatasetDto, "updatedAt" | "updatedBy" > = data; const historyItem: Record = {}; Object.keys(updatedFields).forEach((updatedField) => { - historyItem[updatedField as keyof UpdateDatasetObsoleteDto] = { - currentValue: data[updatedField as keyof UpdateDatasetObsoleteDto], + historyItem[updatedField as keyof UpdateDatasetDto] = { + currentValue: data[updatedField as keyof UpdateDatasetDto], previousValue: dataset[ updatedField as keyof Omit< - UpdateDatasetObsoleteDto, + UpdateDatasetDto, "attachments" | "origdatablocks" | "datablocks" > ], @@ -468,18 +456,15 @@ export class DatasetsService { if (logbookEnabled) { const user = (req.user as JWTUser).username.replace("ldap.", ""); const datasetPid = dataset.pid; - const proposalId = - dataset.type === DatasetType.Raw - ? (dataset as unknown as DatasetClass).proposalId - : undefined; - if (proposalId) { + const proposalIds = dataset.proposalIds || []; + (proposalIds as Array).forEach(async (proposalId) => { await Promise.all( Object.keys(updatedFields).map(async (updatedField) => { const message = `${user} updated "${updatedField}" of dataset with PID ${datasetPid}`; await this.logbooksService.sendMessage(proposalId, { message }); }), ); - } + }); } } } diff --git a/src/datasets/dto/update-dataset.dto.ts b/src/datasets/dto/update-dataset.dto.ts index ad928772f..26866705d 100644 --- a/src/datasets/dto/update-dataset.dto.ts +++ b/src/datasets/dto/update-dataset.dto.ts @@ -24,6 +24,7 @@ import { CreateTechniqueDto } from "./create-technique.dto"; import { RelationshipClass } from "../schemas/relationship.schema"; import { CreateRelationshipDto } from "./create-relationship.dto"; import { LifecycleClass } from "../schemas/lifecycle.schema"; +import { HistoryClass } from "../schemas/history.schema"; @ApiTags("datasets") export class UpdateDatasetDto extends OwnableDto { @@ -420,3 +421,22 @@ export class UpdateDatasetDto extends OwnableDto { } export class PartialUpdateDatasetDto extends PartialType(UpdateDatasetDto) {} + +export class UpdateDatasetWithHistoryDto extends UpdateDatasetDto { + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(HistoryClass) }, + required: false, + default: [], + description: "List of history objects containing old and new values.", + }) + @IsArray() + @IsOptional() + @ValidateNested({ each: true }) + @Type(() => HistoryClass) + readonly history?: HistoryClass[]; +} + +export class PartialUpdateDatasetWithHistoryDto extends PartialType( + UpdateDatasetWithHistoryDto, +) {} From 41d304cb331ded691f2bcc977d3fa9a4b54a39fa Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 13 Sep 2024 16:04:08 +0200 Subject: [PATCH 06/38] refactoring data types --- src/datasets/datasets.controller.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 9071f6e53..575adc98b 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -1297,7 +1297,7 @@ export class DatasetsController { updateDatasetObsoleteDto: | UpdateRawDatasetObsoleteDto | UpdateDerivedDatasetObsoleteDto, - ): Promise { + ): Promise { const foundDataset = await this.datasetsService.findOne({ where: { pid } }); if (!foundDataset) { @@ -1305,7 +1305,7 @@ export class DatasetsController { } // NOTE: Default validation pipe does not validate union types. So we need custom validation. - const outputDto = await this.validateDatasetObsolete( + const updateValidatedDto = await this.validateDatasetObsolete( updateDatasetObsoleteDto, foundDataset.type === "raw" ? UpdateRawDatasetObsoleteDto @@ -1327,12 +1327,15 @@ export class DatasetsController { throw new ForbiddenException("Unauthorized to update this dataset"); } - return this.datasetsService.findByIdAndReplace( + const updateDatasetDto = + await this.convertObsoleteToCurrentSchema(updateValidatedDto); + + const outputDatasetDto = await this.datasetsService.findByIdAndReplace( pid, - outputDto as - | UpdateRawDatasetObsoleteDto - | UpdateDerivedDatasetObsoleteDto, + updateDatasetDto as UpdateDatasetDto, ); + + return await this.convertCurrentToObsoleteSchema(outputDatasetDto); } // DELETE /datasets/:id From 0c3b316dcf153c18ac05f6cfc9b4a0c4695ac5c0 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Mon, 16 Sep 2024 14:31:38 +0200 Subject: [PATCH 07/38] First two dataset test passing --- src/datasets/datasets.controller.ts | 27 +++++++++----- src/datasets/schemas/dataset.schema.ts | 6 +-- .../origdatablocks.controller.ts | 9 +++-- .../published-data.controller.ts | 8 +++- test/DatasetAuthorization.js | 37 +++++++++---------- 5 files changed, 50 insertions(+), 37 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 575adc98b..9e1430701 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -61,7 +61,7 @@ import { DatablocksService } from "src/datablocks/datablocks.service"; import { Datablock } from "src/datablocks/schemas/datablock.schema"; import { CreateDatablockDto } from "src/datablocks/dto/create-datablock.dto"; import { PartialUpdateDatablockDto } from "src/datablocks/dto/update-datablock.dto"; -import { UpdateQuery } from "mongoose"; +import { Document, UpdateQuery } from "mongoose"; import { FilterPipe } from "src/common/pipes/filter.pipe"; import { UTCTimeInterceptor } from "src/common/interceptors/utc-time.interceptor"; import { DataFile } from "src/common/schemas/datafile.schema"; @@ -405,7 +405,9 @@ export class DatasetsController { | PartialUpdateRawDatasetObsoleteDto | PartialUpdateDerivedDatasetObsoleteDto, ): CreateDatasetDto | UpdateDatasetDto | PartialUpdateDatasetDto { - const propertiesModifier: Record = {}; + const propertiesModifier: Record = { + version: "v3", + }; if ( inputObsoleteDataset instanceof CreateRawDatasetObsoleteDto || @@ -489,8 +491,9 @@ export class DatasetsController { } } } + const outputDataset: OutputDatasetObsoleteDto = { - ...(inputDataset as OutputDatasetObsoleteDto), + ...(inputDataset as DatasetDocument).toObject(), ...propertiesModifier, }; @@ -537,17 +540,17 @@ export class DatasetsController { | CreateDerivedDatasetObsoleteDto, ): Promise { // validate dataset - await this.validateDatasetObsolete( + const validatedDatasetObsoleteDto = (await this.validateDatasetObsolete( createDatasetObsoleteDto, createDatasetObsoleteDto.type === "raw" ? CreateRawDatasetObsoleteDto : CreateDerivedDatasetObsoleteDto, - ); + )) as CreateRawDatasetObsoleteDto | CreateDerivedDatasetObsoleteDto; const obsoleteDatasetDto = await this.checkPermissionsForObsoleteDatasetCreate( request, - createDatasetObsoleteDto, + validatedDatasetObsoleteDto, ); try { @@ -598,11 +601,18 @@ export class DatasetsController { }, }; + // first we convert input object to the correct class + const outputDatasetDto = plainToInstance(dto, inputDatasetDto); + if ( - inputDatasetDto instanceof + outputDatasetDto instanceof (CreateRawDatasetObsoleteDto || CreateDerivedDatasetObsoleteDto) ) { - if (!(inputDatasetDto.type in DatasetType)) { + if ( + !(Object.values(DatasetType) as string[]).includes( + outputDatasetDto.type, + ) + ) { throw new HttpException( { status: HttpStatus.BAD_REQUEST, @@ -613,7 +623,6 @@ export class DatasetsController { } } - const outputDatasetDto = plainToInstance(dto, inputDatasetDto); const errors = await validate(outputDatasetDto, validateOptions); if (errors.length > 0) { diff --git a/src/datasets/schemas/dataset.schema.ts b/src/datasets/schemas/dataset.schema.ts index 58fdcd1e4..9b3d7f7e2 100644 --- a/src/datasets/schemas/dataset.schema.ts +++ b/src/datasets/schemas/dataset.schema.ts @@ -449,13 +449,13 @@ export class DatasetClass extends OwnableClass { dataFormat?: string; @ApiProperty({ - type: String, + type: [String], required: false, description: "The ID of the proposal to which the dataset belongs to and it has been acquired under.", }) - @Prop({ type: String, ref: "Proposal", required: false }) - proposalIds?: string; + @Prop({ type: [String], ref: "Proposal", required: false }) + proposalIds?: string[]; @ApiProperty({ type: [String], diff --git a/src/origdatablocks/origdatablocks.controller.ts b/src/origdatablocks/origdatablocks.controller.ts index 308eb32e9..97e21d50b 100644 --- a/src/origdatablocks/origdatablocks.controller.ts +++ b/src/origdatablocks/origdatablocks.controller.ts @@ -45,8 +45,8 @@ import { PartialUpdateDatasetDto } from "src/datasets/dto/update-dataset.dto"; import { filterDescription, filterExample } from "src/common/utils"; import { JWTUser } from "src/auth/interfaces/jwt-user.interface"; import { DatasetClass } from "src/datasets/schemas/dataset.schema"; -import { CreateRawDatasetDto } from "src/datasets/dto/create-raw-dataset-obsolete.dto"; -import { CreateDerivedDatasetDto } from "src/datasets/dto/create-derived-dataset-obsolete.dto"; +import { CreateRawDatasetObsoleteDto } from "src/datasets/dto/create-raw-dataset-obsolete.dto"; +import { CreateDerivedDatasetObsoleteDto } from "src/datasets/dto/create-derived-dataset-obsolete.dto"; import { logger } from "@user-office-software/duo-logger"; @ApiBearerAuth() @@ -103,7 +103,10 @@ export class OrigDatablocksController { // } async generateOrigDatablockInstanceInstanceForPermissions( - dataset: CreateRawDatasetDto | CreateDerivedDatasetDto | DatasetClass, + dataset: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | DatasetClass, ): Promise { const origDatablockInstance = new OrigDatablock(); origDatablockInstance.datasetId = dataset.pid || ""; diff --git a/src/published-data/published-data.controller.ts b/src/published-data/published-data.controller.ts index 3d8199c7d..0786e9a53 100644 --- a/src/published-data/published-data.controller.ts +++ b/src/published-data/published-data.controller.ts @@ -166,13 +166,17 @@ export class PublishedDataController { }) async formPopulate(@Query("pid") pid: string) { const formData: IFormPopulateData = {}; - const dataset = await this.datasetsService.findOne({ where: { pid } }); + const dataset = (await this.datasetsService.findOne({ + where: { pid }, + })) as unknown as DatasetClass; let proposalId; if (dataset) { formData.resourceType = dataset.type; formData.description = dataset.description; - proposalId = (dataset as unknown as DatasetClass).proposalId; + if ("proposalIds" in dataset) { + proposalId = dataset.proposalIds![0]; + } } let proposal; diff --git a/test/DatasetAuthorization.js b/test/DatasetAuthorization.js index 56a8b7717..63e4b21c5 100644 --- a/test/DatasetAuthorization.js +++ b/test/DatasetAuthorization.js @@ -83,7 +83,6 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { }); it("0010: adds dataset 1 as Admin Ingestor", async () => { - console.log(JSON.stringify(dataset1)); return request(appUrl) .post("/api/v3/Datasets") .send(dataset1) @@ -92,8 +91,6 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { .expect(TestData.EntryCreatedStatusCode) .expect("Content-Type", /json/) .then((res) => { - console.log("Results"); - console.log(res.body); res.body.should.have.property("ownerGroup").and.equal("group4"); res.body.should.have.property("type").and.equal("raw"); res.body.should.have.property("isPublished").and.equal(true); @@ -103,23 +100,23 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { }); }); - // it("0020: adds dataset 2 as Admin Ingestor", async () => { - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(dataset2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("ownerGroup").and.equal("group1"); - // res.body.should.have.property("type").and.equal("raw"); - // res.body.should.have.property("isPublished").and.equal(false); - // res.body.should.have.property("pid").and.be.string; - // datasetPid2 = res.body["pid"]; - // encodedDatasetPid2 = encodeURIComponent(datasetPid2); - // }); - // }); + it("0020: adds dataset 2 as Admin Ingestor", async () => { + return request(appUrl) + .post("/api/v3/Datasets") + .send(dataset2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("ownerGroup").and.equal("group1"); + res.body.should.have.property("type").and.equal("raw"); + res.body.should.have.property("isPublished").and.equal(false); + res.body.should.have.property("pid").and.be.string; + datasetPid2 = res.body["pid"]; + encodedDatasetPid2 = encodeURIComponent(datasetPid2); + }); + }); // it("0030: adds dataset 3 as Admin Ingestor", async () => { // return request(appUrl) From bc4532ca162b64347a64e33244560761761e8371 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 17 Sep 2024 14:47:28 +0200 Subject: [PATCH 08/38] fixed tests in Datasets Simple --- src/datasets/datasets.controller.ts | 7 +- test/DatasetAuthorization.js | 2835 +++++++++++++-------------- 2 files changed, 1420 insertions(+), 1422 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 9e1430701..2b4b3aec1 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -431,10 +431,9 @@ export class DatasetsController { } } else { if ("investigator" in inputObsoleteDataset) { - propertiesModifier.principalInvestigator = [ - (inputObsoleteDataset as CreateDerivedDatasetObsoleteDto) - .investigator, - ]; + propertiesModifier.principalInvestigator = ( + inputObsoleteDataset as CreateDerivedDatasetObsoleteDto + ).investigator; } } diff --git a/test/DatasetAuthorization.js b/test/DatasetAuthorization.js index 63e4b21c5..3aeb7f749 100644 --- a/test/DatasetAuthorization.js +++ b/test/DatasetAuthorization.js @@ -118,1422 +118,1421 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { }); }); - // it("0030: adds dataset 3 as Admin Ingestor", async () => { - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(dataset3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("ownerGroup").and.equal("group2"); - // res.body.should.have.property("type").and.equal("raw"); - // res.body.should.have.property("isPublished").and.equal(false); - // res.body.should.have.property("pid").and.be.string; - // datasetPid3 = res.body["pid"]; - // encodedDatasetPid3 = encodeURIComponent(datasetPid3); - // }); - // }); - - // it("0040: adds a new origDatablock on the published dataset as Admin Ingestor", async () => { - // return request(appUrl) - // .post(`/api/v3/datasets/${encodedDatasetPid1}/origdatablocks`) - // .send(TestData.OrigDataBlockCorrect1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have - // .property("size") - // .and.equal(TestData.OrigDataBlockCorrect1.size); - // res.body.should.have.property("id").and.be.string; - // }); - // }); - - // it("0050: adds a new datablock on the published dataset as Admin Ingestor", async () => { - // const randomArchiveId = Math.random().toString(36).slice(2); - - // return request(appUrl) - // .post(`/api/v3/datasets/${encodedDatasetPid1}/datablocks`) - // .send({ ...TestData.DataBlockCorrect, archiveId: randomArchiveId }) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have - // .property("size") - // .and.equal(TestData.DataBlockCorrect.size); - // res.body.should.have.property("id").and.be.string; - // }); - // }); - - // it("0060: adds a new attachment on the published dataset as Admin Ingestor", async () => { - // return request(appUrl) - // .post(`/api/v3/datasets/${encodedDatasetPid1}/attachments`) - // .send(TestData.AttachmentCorrect) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0070: list of public datasets, aka as unauthenticated user", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // res.body[0]["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0080: access public dataset as unauthenticated user", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0090: access private dataset as unauthenticated user", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .expect("Content-Type", /json/) - // .expect(TestData.AccessForbiddenStatusCode); - // }); - - // it("0100: list of datasets for Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(3); - // }); - // }); - - // it("0110: datasets counts for Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/count") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body["count"].should.be.equal(3); - // }); - // }); - - // it("0120: access dataset 1 as Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0130: full query for datasets for Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/fullquery") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(3); - // }); - // }); - - // it("0140: access dataset 2 as Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0150: access dataset 3 as Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0160: list of datasets for User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(2); - // res.body[1]["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0170: datasets count for User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/count") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body["count"].should.be.equal(2); - // }); - // }); - - // it("0180: access dataset 1 as User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0190: access dataset 2 as User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0200: access dataset 3 as User 1, which should fail as forbidden", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.AccessForbiddenStatusCode); - // }); - - // it("0210: full query for datasets for User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/fullquery") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // res.body[0]["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0220: list of datasets for User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(2); - // res.body[1]["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0230: datasets count for User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/count") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body["count"].should.be.equal(2); - // }); - // }); - - // it("0240: access dataset 1 as User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0250: access dataset 2 as User 2, which should fail as forbidden", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.AccessForbiddenStatusCode); - // }); - - // it("0260: access dataset 3 as User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0270: full query for datasets for User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/fullquery") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // res.body[0]["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0280: list of datasets for User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(3); - // }); - // }); - - // it("0290: datasets count for User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/count") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body["count"].should.be.equal(3); - // }); - // }); - - // it("0300: access dataset 1 as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0310: access dataset 2 as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0320: access dataset 3 as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0330: full query for datasets for User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/fullquery") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(2); - // }); - // }); - - // it("0340: update dataset 2 to be published as Admin Ingestor", async () => { - // return request(appUrl) - // .patch(`/api/v3/Datasets/${encodedDatasetPid2}`) - // .send({ isPublished: true }) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.SuccessfulPatchStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0350: full query for datasets for User 2", async () => { - // const fields = { - // isPublished: true, - // }; - - // return request(appUrl) - // .get( - // `/api/v3/Datasets/fullquery?fields=${encodeURIComponent( - // JSON.stringify(fields), - // )}`, - // ) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(2); - // }); - // }); - - // it("0360: full facet for datasets for User 2", async () => { - // const fields = { - // isPublished: true, - // }; - // return request(appUrl) - // .get( - // `/api/v3/Datasets/fullfacet?fields=${encodeURIComponent( - // JSON.stringify(fields), - // )}`, - // ) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body[0].all[0].totalSets.should.be.equal(2); - // }); - // }); - - // it("0370: access dataset 1 origdatablocks as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/origdatablocks") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // }); - // }); - - // it("0380: access dataset 1 datablocks as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/datablocks") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // }); - // }); - - // it("0390: access dataset 1 attachments as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/attachments") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // }); - // }); - - // it("0400: access dataset 1 thumbnail as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/thumbnail") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode); - // }); - - // it("0410: should delete dataset 1 as Archive Manager", async () => { - // return request(appUrl) - // .delete("/api/v3/datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - // .expect(TestData.SuccessfulDeleteStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0420: should delete dataset 2 as Archive Manager", async () => { - // return request(appUrl) - // .delete("/api/v3/datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - // .expect(TestData.SuccessfulDeleteStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0430: should delete dataset 3 as Archive Manager", async () => { - // return request(appUrl) - // .delete("/api/v3/datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - // .expect(TestData.SuccessfulDeleteStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0500: add a new raw dataset as Admin", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0501: add a new incomplete raw dataset as Admin, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0502: add a new raw dataset with specified pid as Admin", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "admin", - // }; - // console.log("0502: pid : " + datasetWithPid["pid"]); - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0503: add a new raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0504: add a new invalid raw dataset with specified pid as Admin, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: uuidv4(), - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0505: add a new invalid raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0510: add a new raw dataset with different owner group as Admin", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0520: add a new incomplete raw dataset with different owner group as Admin, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0530: add a new raw dataset with specified pid and different owner group as Admin", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0540: add a new raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0550: add a new invalid raw dataset with specified pid and different owner group as Admin, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0560: add a new invalid raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0600: add a new raw dataset as User 1 which belongs to a create dataset group", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0601: add a new incomplete raw dataset as User 1 which belongs to a create dataset group", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0602: add a new raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0603: add a new raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0604: add a new invalid raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0605: add a new invalid raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0610: add a new raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0620: add a new incomplete raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0630: add a new raw dataset with specified pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0640: add a new raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0650: add a new invalid raw dataset with specified pid and different owner group as User 1 which belongs to a ", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0660: add a new invalid raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0700: add a new raw dataset as User 2 which belongs to a create dataset with pid group", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0701: add a new incomplete raw dataset as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0702: add a new raw dataset with specified pid as User 2 which belongs to a create dataset with pid group", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0703: add a new raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0704: add a new invalid raw dataset with specified pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0705: add a new invalid raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0710: add a new raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0720: add a new incomplete raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0730: add a new raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0740: add a new raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0750: add a new invalid raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0760: add a new invalid raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0800: add a new raw dataset as User 3 which belongs to a create dataset privileged group", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0801: add a new incomplete raw dataset as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0802: add a new raw dataset with specified pid as User 3 which belongs to a create dataset privileged group", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0803: add a new raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0804: add a new invalid raw dataset with specified pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0805: add a new invalid raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0810: add a new raw dataset with different owner group as User 3 which belongs to a create dataset privileged group", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0820: add a new incomplete raw dataset with different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0830: add a new raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0840: add a new raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0850: add a new invalid raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0860: add a new invalid raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); + it("0030: adds dataset 3 as Admin Ingestor", async () => { + return request(appUrl) + .post("/api/v3/Datasets") + .send(dataset3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("ownerGroup").and.equal("group2"); + res.body.should.have.property("type").and.equal("raw"); + res.body.should.have.property("isPublished").and.equal(false); + res.body.should.have.property("pid").and.be.string; + datasetPid3 = res.body["pid"]; + encodedDatasetPid3 = encodeURIComponent(datasetPid3); + }); + }); + + it("0040: adds a new origDatablock on the published dataset as Admin Ingestor", async () => { + return request(appUrl) + .post(`/api/v3/datasets/${encodedDatasetPid1}/origdatablocks`) + .send(TestData.OrigDataBlockCorrect1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have + .property("size") + .and.equal(TestData.OrigDataBlockCorrect1.size); + res.body.should.have.property("id").and.be.string; + }); + }); + + it("0050: adds a new datablock on the published dataset as Admin Ingestor", async () => { + const randomArchiveId = Math.random().toString(36).slice(2); + + return request(appUrl) + .post(`/api/v3/datasets/${encodedDatasetPid1}/datablocks`) + .send({ ...TestData.DataBlockCorrect, archiveId: randomArchiveId }) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have + .property("size") + .and.equal(TestData.DataBlockCorrect.size); + res.body.should.have.property("id").and.be.string; + }); + }); + + it("0060: adds a new attachment on the published dataset as Admin Ingestor", async () => { + return request(appUrl) + .post(`/api/v3/datasets/${encodedDatasetPid1}/attachments`) + .send(TestData.AttachmentCorrect) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/); + }); + + it("0070: list of public datasets, aka as unauthenticated user", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + res.body[0]["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0080: access public dataset as unauthenticated user", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0090: access private dataset as unauthenticated user", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(TestData.AccessForbiddenStatusCode); + }); + + it("0100: list of datasets for Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(3); + }); + }); + + it("0110: datasets counts for Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/count") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body["count"].should.be.equal(3); + }); + }); + + it("0120: access dataset 1 as Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0130: full query for datasets for Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/fullquery") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(3); + }); + }); + + it("0140: access dataset 2 as Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0150: access dataset 3 as Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0160: list of datasets for User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(2); + res.body[1]["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0170: datasets count for User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets/count") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body["count"].should.be.equal(2); + }); + }); + + it("0180: access dataset 1 as User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0190: access dataset 2 as User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0200: access dataset 3 as User 1, which should fail as forbidden", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect("Content-Type", /json/) + .expect(TestData.AccessForbiddenStatusCode); + }); + + it("0210: full query for datasets for User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets/fullquery") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + res.body[0]["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0220: list of datasets for User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(2); + res.body[1]["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0230: datasets count for User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets/count") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body["count"].should.be.equal(2); + }); + }); + + it("0240: access dataset 1 as User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0250: access dataset 2 as User 2, which should fail as forbidden", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect("Content-Type", /json/) + .expect(TestData.AccessForbiddenStatusCode); + }); + + it("0260: access dataset 3 as User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0270: full query for datasets for User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets/fullquery") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + res.body[0]["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0280: list of datasets for User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(3); + }); + }); + + it("0290: datasets count for User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/count") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body["count"].should.be.equal(3); + }); + }); + + it("0300: access dataset 1 as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0310: access dataset 2 as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0320: access dataset 3 as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0330: full query for datasets for User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/fullquery") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(2); + }); + }); + + it("0340: update dataset 2 to be published as Admin Ingestor", async () => { + return request(appUrl) + .patch(`/api/v3/Datasets/${encodedDatasetPid2}`) + .send({ isPublished: true }) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulPatchStatusCode) + .expect("Content-Type", /json/); + }); + + it("0350: full query for datasets for User 2", async () => { + const fields = { + isPublished: true, + }; + + return request(appUrl) + .get( + `/api/v3/Datasets/fullquery?fields=${encodeURIComponent( + JSON.stringify(fields), + )}`, + ) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(2); + }); + }); + + it("0360: full facet for datasets for User 2", async () => { + const fields = { + isPublished: true, + }; + return request(appUrl) + .get( + `/api/v3/Datasets/fullfacet?fields=${encodeURIComponent( + JSON.stringify(fields), + )}`, + ) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body[0].all[0].totalSets.should.be.equal(2); + }); + }); + + it("0370: access dataset 1 origdatablocks as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/origdatablocks") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + }); + }); + + it("0380: access dataset 1 datablocks as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/datablocks") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + }); + }); + + it("0390: access dataset 1 attachments as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/attachments") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + }); + }); + + it("0400: access dataset 1 thumbnail as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/thumbnail") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode); + }); + + it("0410: should delete dataset 1 as Archive Manager", async () => { + return request(appUrl) + .delete("/api/v3/datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + .expect(TestData.SuccessfulDeleteStatusCode) + .expect("Content-Type", /json/); + }); + + it("0420: should delete dataset 2 as Archive Manager", async () => { + return request(appUrl) + .delete("/api/v3/datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + .expect(TestData.SuccessfulDeleteStatusCode) + .expect("Content-Type", /json/); + }); + + it("0430: should delete dataset 3 as Archive Manager", async () => { + return request(appUrl) + .delete("/api/v3/datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + .expect(TestData.SuccessfulDeleteStatusCode) + .expect("Content-Type", /json/); + }); + + it("0500: add a new raw dataset as Admin", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0501: add a new incomplete raw dataset as Admin, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0502: add a new raw dataset with specified pid as Admin", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0503: add a new raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0504: add a new invalid raw dataset with specified pid as Admin, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: uuidv4(), + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0505: add a new invalid raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0510: add a new raw dataset with different owner group as Admin", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0520: add a new incomplete raw dataset with different owner group as Admin, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0530: add a new raw dataset with specified pid and different owner group as Admin", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0540: add a new raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0550: add a new invalid raw dataset with specified pid and different owner group as Admin, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0560: add a new invalid raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0600: add a new raw dataset as User 1 which belongs to a create dataset group", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0601: add a new incomplete raw dataset as User 1 which belongs to a create dataset group", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0602: add a new raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0603: add a new raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0604: add a new invalid raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0605: add a new invalid raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0610: add a new raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0620: add a new incomplete raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0630: add a new raw dataset with specified pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0640: add a new raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0650: add a new invalid raw dataset with specified pid and different owner group as User 1 which belongs to a ", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0660: add a new invalid raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0700: add a new raw dataset as User 2 which belongs to a create dataset with pid group", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0701: add a new incomplete raw dataset as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0702: add a new raw dataset with specified pid as User 2 which belongs to a create dataset with pid group", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0703: add a new raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0704: add a new invalid raw dataset with specified pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0705: add a new invalid raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0710: add a new raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0720: add a new incomplete raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0730: add a new raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0740: add a new raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0750: add a new invalid raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0760: add a new invalid raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0800: add a new raw dataset as User 3 which belongs to a create dataset privileged group", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0801: add a new incomplete raw dataset as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0802: add a new raw dataset with specified pid as User 3 which belongs to a create dataset privileged group", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0803: add a new raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0804: add a new invalid raw dataset with specified pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0805: add a new invalid raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0810: add a new raw dataset with different owner group as User 3 which belongs to a create dataset privileged group", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0820: add a new incomplete raw dataset with different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0830: add a new raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0840: add a new raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0850: add a new invalid raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0860: add a new invalid raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); }); From 5f84530aedff67270a60ae71232448d06c05ea8b Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 17 Sep 2024 17:35:20 +0200 Subject: [PATCH 09/38] making progress with tests --- src/datasets/datasets.controller.ts | 31 +++++++++++++++++------------ test/DerivedDatasetDatablock.js | 2 +- test/OrigDatablockForRawDataset.js | 3 ++- test/TestData.js | 4 +++- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 2b4b3aec1..741c41e79 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -556,6 +556,7 @@ export class DatasetsController { const datasetDto = this.convertObsoleteToCurrentSchema( obsoleteDatasetDto, ) as CreateDatasetDto; + console.log(datasetDto); const createdDataset = await this.datasetsService.create(datasetDto); const outputObsoleteDatasetDto = @@ -1063,30 +1064,34 @@ export class DatasetsController { ) as Record, ) as IFilters; - const dataset = (await this.datasetsService.findOne( - mergedFilters, - )) as OutputDatasetObsoleteDto; + const databaseDataset = await this.datasetsService.findOne(mergedFilters); - if (dataset) { + const outputDataset = + await this.convertCurrentToObsoleteSchema(databaseDataset); + + if (outputDataset) { const includeFilters = mergedFilters.include ?? []; await Promise.all( includeFilters.map(async ({ relation }) => { switch (relation) { case "attachments": { - dataset.attachments = await this.attachmentsService.findAll({ - datasetId: dataset.pid, - }); + outputDataset.attachments = await this.attachmentsService.findAll( + { + datasetId: outputDataset.pid, + }, + ); break; } case "origdatablocks": { - dataset.origdatablocks = await this.origDatablocksService.findAll( - { where: { datasetId: dataset.pid } }, - ); + outputDataset.origdatablocks = + await this.origDatablocksService.findAll({ + where: { datasetId: outputDataset.pid }, + }); break; } case "datablocks": { - dataset.datablocks = await this.datablocksService.findAll({ - datasetId: dataset.pid, + outputDataset.datablocks = await this.datablocksService.findAll({ + datasetId: outputDataset.pid, }); break; } @@ -1094,7 +1099,7 @@ export class DatasetsController { }), ); } - return dataset; + return outputDataset; } // GET /datasets/count diff --git a/test/DerivedDatasetDatablock.js b/test/DerivedDatasetDatablock.js index 8ef6ff8c7..6c223246c 100644 --- a/test/DerivedDatasetDatablock.js +++ b/test/DerivedDatasetDatablock.js @@ -13,7 +13,7 @@ describe("0750: DerivedDatasetDatablock: Test Datablocks and their relation to d before(() => { db.collection("Dataset").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], diff --git a/test/OrigDatablockForRawDataset.js b/test/OrigDatablockForRawDataset.js index 057134d35..859b49333 100644 --- a/test/OrigDatablockForRawDataset.js +++ b/test/OrigDatablockForRawDataset.js @@ -23,7 +23,7 @@ describe("1200: OrigDatablockForRawDataset: Test OrigDatablocks and their relati db.collection("Dataset").deleteMany({}); db.collection("OrigDatablock").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], @@ -304,6 +304,7 @@ describe("1200: OrigDatablockForRawDataset: Test OrigDatablocks and their relati .expect(TestData.SuccessfulGetStatusCode) .expect("Content-Type", /json/) .then((res) => { + console.log(res.body); res.body["pid"].should.be.equal(decodeURIComponent(datasetPid1)); res.body.origdatablocks.should.be .instanceof(Array) diff --git a/test/TestData.js b/test/TestData.js index 538f657bf..bee14fe4c 100644 --- a/test/TestData.js +++ b/test/TestData.js @@ -119,6 +119,7 @@ const TestData = { sourceFolder: faker.system.directoryPath(), owner: faker.internet.userName(), contactEmail: faker.internet.email(), + datasetName: faker.string.sample(), }, RawCorrect: { @@ -384,13 +385,14 @@ const TestData = { DerivedCorrectMin: { investigator: faker.internet.email(), - inputDatasets: [faker.system.filePath()], + inputDatasets: [faker.string.uuid()], usedSoftware: [faker.internet.url()], owner: faker.internet.userName(), contactEmail: faker.internet.email(), sourceFolder: faker.system.directoryPath(), creationTime: faker.date.past(), ownerGroup: faker.string.alphanumeric(6), + datasetName: faker.string.sample(), type: "derived", }, From 6bdbb4311759187086249afdd9c2402dec602336 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 4 Sep 2024 17:28:26 +0200 Subject: [PATCH 10/38] refactor naming of current dataset schema and dto. Added new unified dataset schema and dto --- src/datasets/datasets.controller.ts | 19 +- src/datasets/datasets.service.ts | 36 ++- .../dto/create-dataset-obsolete.dto.ts | 34 ++ src/datasets/dto/create-dataset.dto.ts | 9 - .../dto/output-dataset-obsolete.dto.ts | 237 ++++++++++++++ src/datasets/dto/output-dataset.dto.ts | 41 +++ .../dto/update-dataset-obsolete.dto.ts | 298 ++++++++++++++++++ src/datasets/dto/update-dataset.dto.ts | 141 ++++++++- .../dto/update-derived-dataset.dto.ts | 4 +- src/datasets/dto/update-raw-dataset.dto.ts | 4 +- src/datasets/schemas/dataset.schema.ts | 149 ++++----- 11 files changed, 852 insertions(+), 120 deletions(-) create mode 100644 src/datasets/dto/create-dataset-obsolete.dto.ts create mode 100644 src/datasets/dto/output-dataset-obsolete.dto.ts create mode 100644 src/datasets/dto/output-dataset.dto.ts create mode 100644 src/datasets/dto/update-dataset-obsolete.dto.ts diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 0d7706ee1..42233e22a 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -36,7 +36,7 @@ import { } from "@nestjs/swagger"; import { Request } from "express"; import { DatasetsService } from "./datasets.service"; -import { PartialUpdateDatasetDto } from "./dto/update-dataset.dto"; +import { PartialUpdateDatasetObsoleteDto } from "./dto/update-dataset-obsolete.dto"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; import { CreateRawDatasetDto } from "./dto/create-raw-dataset.dto"; import { CreateDerivedDatasetDto } from "./dto/create-derived-dataset.dto"; @@ -98,6 +98,7 @@ import { JWTUser } from "src/auth/interfaces/jwt-user.interface"; import { LogbooksService } from "src/logbooks/logbooks.service"; import configuration from "src/config/configuration"; import { DatasetType } from "./dataset-type.enum"; +import { OutputDatasetObsoleteDto } from "./dto/output-dataset-obsolete.dto"; @ApiBearerAuth() @ApiExtraModels( @@ -597,7 +598,7 @@ export class DatasetsController { @Req() request: Request, @Headers() headers: Record, @Query(new FilterPipe()) queryFilter: { filter?: string }, - ): Promise { + ): Promise { const mergedFilters = replaceLikeOperator( this.updateMergedFiltersForList( request, @@ -606,7 +607,9 @@ export class DatasetsController { ) as IFilters; // this should be implemented at database level - const datasets = await this.datasetsService.findAll(mergedFilters); + const datasets = (await this.datasetsService.findAll( + mergedFilters, + )) as OutputDatasetObsoleteDto[]; if (datasets && datasets.length > 0) { const includeFilters = mergedFilters.include ?? []; await Promise.all( @@ -917,7 +920,7 @@ export class DatasetsController { @Req() request: Request, @Headers() headers: Record, @Query(new FilterPipe()) queryFilter: { filter?: string }, - ): Promise { + ): Promise { const mergedFilters = replaceLikeOperator( this.updateMergedFiltersForList( request, @@ -927,7 +930,7 @@ export class DatasetsController { const dataset = (await this.datasetsService.findOne( mergedFilters, - )) as DatasetClass; + )) as OutputDatasetObsoleteDto; if (dataset) { const includeFilters = mergedFilters.include ?? []; @@ -1585,7 +1588,7 @@ export class DatasetsController { const datablock = await this.origDatablocksService.create(createOrigDatablock); - const updateDatasetDto: PartialUpdateDatasetDto = { + const updateDatasetDto: PartialUpdateDatasetObsoleteDto = { size: dataset.size + datablock.size, numberOfFiles: dataset.numberOfFiles + datablock.dataFileList.length, }; @@ -1804,7 +1807,7 @@ export class DatasetsController { where: { datasetId: pid }, }); // update dataset size and files number - const updateDatasetDto: PartialUpdateDatasetDto = { + const updateDatasetDto: PartialUpdateDatasetObsoleteDto = { size: odb.reduce((a, b) => a + b.size, 0), numberOfFiles: odb.reduce((a, b) => a + b.dataFileList.length, 0), }; @@ -2034,7 +2037,7 @@ export class DatasetsController { datasetId: pid, }); // update dataset size and files number - const updateDatasetDto: PartialUpdateDatasetDto = { + const updateDatasetDto: PartialUpdateDatasetObsoleteDto = { packedSize: remainingDatablocks.reduce((a, b) => a + b.packedSize, 0), numberOfFilesArchived: remainingDatablocks.reduce( (a, b) => a + b.dataFileList.length, diff --git a/src/datasets/datasets.service.ts b/src/datasets/datasets.service.ts index c78974c1e..680222e8e 100644 --- a/src/datasets/datasets.service.ts +++ b/src/datasets/datasets.service.ts @@ -24,11 +24,11 @@ import { ElasticSearchService } from "src/elastic-search/elastic-search.service" import { InitialDatasetsService } from "src/initial-datasets/initial-datasets.service"; import { LogbooksService } from "src/logbooks/logbooks.service"; import { DatasetType } from "./dataset-type.enum"; -import { CreateDatasetDto } from "./dto/create-dataset.dto"; +import { CreateDatasetObsoleteDto } from "./dto/create-dataset-obsolete.dto"; import { - PartialUpdateDatasetDto, - UpdateDatasetDto, -} from "./dto/update-dataset.dto"; + PartialUpdateDatasetObsoleteDto, + UpdateDatasetObsoleteDto, +} from "./dto/update-dataset-obsolete.dto"; import { PartialUpdateDerivedDatasetDto, UpdateDerivedDatasetDto, @@ -58,7 +58,9 @@ export class DatasetsService { } } - async create(createDatasetDto: CreateDatasetDto): Promise { + async create( + createDatasetDto: CreateDatasetObsoleteDto, + ): Promise { const username = (this.request.user as JWTUser).username; const createdDataset = new this.datasetModel( // insert created and updated fields @@ -206,7 +208,7 @@ export class DatasetsService { async findByIdAndReplace( id: string, updateDatasetDto: - | UpdateDatasetDto + | UpdateDatasetObsoleteDto | UpdateRawDatasetDto | UpdateDerivedDatasetDto, ): Promise { @@ -252,7 +254,7 @@ export class DatasetsService { async findByIdAndUpdate( id: string, updateDatasetDto: - | PartialUpdateDatasetDto + | PartialUpdateDatasetObsoleteDto | PartialUpdateRawDatasetDto | PartialUpdateDerivedDatasetDto | UpdateQuery, @@ -434,20 +436,28 @@ export class DatasetsService { async updateHistory( req: Request, dataset: DatasetClass, - data: UpdateDatasetDto, + data: UpdateDatasetObsoleteDto, ) { if (req.body.history) { delete req.body.history; } if (!req.body.size && !req.body.packedSize) { - const updatedFields: Omit = - data; + const updatedFields: Omit< + UpdateDatasetObsoleteDto, + "updatedAt" | "updatedBy" + > = data; const historyItem: Record = {}; Object.keys(updatedFields).forEach((updatedField) => { - historyItem[updatedField as keyof UpdateDatasetDto] = { - currentValue: data[updatedField as keyof UpdateDatasetDto], - previousValue: dataset[updatedField as keyof UpdateDatasetDto], + historyItem[updatedField as keyof UpdateDatasetObsoleteDto] = { + currentValue: data[updatedField as keyof UpdateDatasetObsoleteDto], + previousValue: + dataset[ + updatedField as keyof Omit< + UpdateDatasetObsoleteDto, + "attachments" | "origdatablocks" | "datablocks" + > + ], }; }); dataset.history = dataset.history ?? []; diff --git a/src/datasets/dto/create-dataset-obsolete.dto.ts b/src/datasets/dto/create-dataset-obsolete.dto.ts new file mode 100644 index 000000000..a75fe5dfe --- /dev/null +++ b/src/datasets/dto/create-dataset-obsolete.dto.ts @@ -0,0 +1,34 @@ +import { IsEnum, IsOptional, IsString } from "class-validator"; +import { ApiProperty } from "@nestjs/swagger"; +import { DatasetType } from "../dataset-type.enum"; +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; + +export class CreateDatasetObsoleteDto extends UpdateDatasetObsoleteDto { + @ApiProperty({ + type: String, + required: false, + description: "Persistent identifier of the dataset.", + }) + @IsOptional() + @IsString() + pid?: string; + + @ApiProperty({ + type: String, + required: true, + enum: [DatasetType.Raw, DatasetType.Derived], + description: + "Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models.", + }) + @IsEnum(DatasetType) + readonly type: string; + + @ApiProperty({ + type: String, + required: false, + description: "Version of the API used in creation of the dataset.", + }) + @IsOptional() + @IsString() + readonly version?: string; +} diff --git a/src/datasets/dto/create-dataset.dto.ts b/src/datasets/dto/create-dataset.dto.ts index c9b5b7ad5..8ee18d733 100644 --- a/src/datasets/dto/create-dataset.dto.ts +++ b/src/datasets/dto/create-dataset.dto.ts @@ -22,13 +22,4 @@ export class CreateDatasetDto extends UpdateDatasetDto { }) @IsEnum(DatasetType) readonly type: string; - - @ApiProperty({ - type: String, - required: false, - description: "Version of the API used in creation of the dataset.", - }) - @IsOptional() - @IsString() - readonly version?: string; } diff --git a/src/datasets/dto/output-dataset-obsolete.dto.ts b/src/datasets/dto/output-dataset-obsolete.dto.ts new file mode 100644 index 000000000..dced6bc31 --- /dev/null +++ b/src/datasets/dto/output-dataset-obsolete.dto.ts @@ -0,0 +1,237 @@ +import { + IsArray, + IsDateString, + IsEnum, + IsObject, + IsOptional, + IsString, +} from "class-validator"; +import { ApiProperty, getSchemaPath } from "@nestjs/swagger"; +import { DatasetType } from "../dataset-type.enum"; +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; +import { Attachment } from "src/attachments/schemas/attachment.schema"; +import { Type } from "class-transformer"; +import { OrigDatablock } from "src/origdatablocks/schemas/origdatablock.schema"; +import { Datablock } from "src/datablocks/schemas/datablock.schema"; + +export class OutputDatasetObsoleteDto extends UpdateDatasetObsoleteDto { + @ApiProperty({ + type: String, + required: false, + description: "Persistent identifier of the dataset.", + }) + @IsString() + readonly pid: string; + + @ApiProperty({ + type: String, + required: true, + enum: [DatasetType.Raw, DatasetType.Derived], + description: + "Characterize type of dataset, either 'raw' or 'derived'. Autofilled when choosing the proper inherited models.", + }) + @IsEnum(DatasetType) + readonly type: string; + + @ApiProperty({ + type: String, + required: false, + description: "Version of the API used in creation of the dataset.", + }) + @IsOptional() + @IsString() + readonly version?: string; + + @ApiProperty({ + type: String, + required: 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.", + }) + @IsString() + @IsOptional() + readonly principalInvestigator?: string; + + @ApiProperty({ + type: Date, + required: false, + description: + "Start time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) + @IsOptional() + @IsDateString() + readonly startTime?: Date; + + @ApiProperty({ + type: Date, + required: false, + description: + "End time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) + @IsOptional() + @IsDateString() + readonly endTime?: Date; + + @ApiProperty({ + type: String, + required: true, + description: + "Unique location identifier where data was taken, usually in the form /Site-name/facility-name/instrumentOrBeamline-name. This field is required if the dataset is a Raw dataset.", + }) + @IsString() + @IsOptional() + readonly creationLocation?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "Defines the format of the data files in this dataset, e.g Nexus Version x.y.", + }) + @IsOptional() + @IsString() + readonly dataFormat?: string; + + @ApiProperty({ + type: String, + required: false, + description: "The ID of the proposal to which the dataset belongs.", + }) + @IsOptional() + @IsString() + readonly proposalId?: string; + + @ApiProperty({ + type: String, + required: false, + description: "ID of the sample used when collecting the data.", + }) + @IsOptional() + @IsString() + readonly sampleId?: string; + + @ApiProperty({ + type: String, + required: false, + description: "ID of the instrument where the data was created.", + }) + @IsOptional() + @IsString() + readonly instrumentId?: string; + + @ApiProperty({ + type: String, + required: true, + description: + "First name and last name of the person or people pursuing the data analysis. The string may contain a list of names, which should then be separated by semicolons.", + }) + @IsString() + @IsOptional() + readonly investigator?: string; + + @ApiProperty({ + type: [String], + required: true, + description: + "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs.", + }) + @IsString({ + each: true, + }) + @IsOptional() + readonly inputDatasets?: string[]; + + @ApiProperty({ + type: [String], + required: true, + description: + "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data.", + }) + @IsString({ + each: true, + }) + @IsOptional() + readonly usedSoftware?: string[]; + + @ApiProperty({ + type: Object, + required: false, + description: + "The creation process of the derived data will usually depend on input job parameters. The full structure of these input parameters are stored here.", + }) + @IsOptional() + @IsObject() + readonly jobParameters?: Record; + + @ApiProperty({ + type: String, + required: false, + description: + "The output job logfile. Keep the size of this log data well below 15 MB.", + }) + @IsOptional() + @IsString() + readonly jobLogData?: string; + + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(Attachment) }, + required: false, + description: + "Small, less than 16 MB attachments, envisaged for png/jpeg previews.", + }) + @IsOptional() + @IsArray() + @Type(() => Attachment) + attachments?: Attachment[]; + + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(OrigDatablock) }, + required: false, + description: + "Containers that list all files and their attributes which make up a dataset. Usually filled at the time the dataset's metadata is created in the data catalog. Can be used by subsequent archiving processes to create the archived datasets.", + }) + origdatablocks?: OrigDatablock[]; + + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(Datablock) }, + required: false, + description: + "When archiving a dataset, all files contained in the dataset are listed here together with their checksum information. Several datablocks can be created if the file listing is too long for a single datablock. This partitioning decision is done by the archiving system to allow for chunks of datablocks with manageable sizes. E.g a datasets consisting of 10 TB of data could be split into 10 datablocks of about 1 TB each. The upper limit set by the data catalog system itself is given by the fact that documents must be smaller than 16 MB, which typically allows for datasets of about 100000 files.", + }) + datablocks?: Datablock[]; + + @ApiProperty({ + type: String, + required: true, + description: + "Indicate the user who created this record. This property is added and maintained by the system.", + }) + createdBy: string; + + @ApiProperty({ + type: String, + required: true, + description: + "Indicate the user who updated this record last. This property is added and maintained by the system.", + }) + updatedBy: string; + + @ApiProperty({ + type: Date, + required: true, + description: + "Date and time when this record was created. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", + }) + createdAt: Date; + + @ApiProperty({ + type: Date, + required: true, + description: + "Date and time when this record was updated last. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", + }) + updatedAt: Date; +} diff --git a/src/datasets/dto/output-dataset.dto.ts b/src/datasets/dto/output-dataset.dto.ts new file mode 100644 index 000000000..8809e3756 --- /dev/null +++ b/src/datasets/dto/output-dataset.dto.ts @@ -0,0 +1,41 @@ +import { ApiProperty } from "@nestjs/swagger"; +import { CreateDatasetDto } from "./create-dataset.dto"; +import { IsString } from "class-validator"; + +export class OutputDatasetDto extends CreateDatasetDto { + @ApiProperty({ + type: String, + required: true, + description: + "Indicate the user who created this record. This property is added and maintained by the system.", + }) + @IsString() + createdBy: string; + + @ApiProperty({ + type: String, + required: true, + description: + "Indicate the user who updated this record last. This property is added and maintained by the system.", + }) + @IsString() + updatedBy: string; + + @ApiProperty({ + type: Date, + required: true, + description: + "Date and time when this record was created. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", + }) + @IsString() + createdAt: Date; + + @ApiProperty({ + type: Date, + required: true, + description: + "Date and time when this record was updated last. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", + }) + @IsString() + updatedAt: Date; +} diff --git a/src/datasets/dto/update-dataset-obsolete.dto.ts b/src/datasets/dto/update-dataset-obsolete.dto.ts new file mode 100644 index 000000000..f2be1c2d2 --- /dev/null +++ b/src/datasets/dto/update-dataset-obsolete.dto.ts @@ -0,0 +1,298 @@ +import { + ApiProperty, + ApiTags, + getSchemaPath, + PartialType, +} from "@nestjs/swagger"; +import { OwnableDto } from "../../common/dto/ownable.dto"; +import { + IsArray, + IsBoolean, + IsDateString, + IsEmail, + IsFQDN, + IsInt, + IsNumber, + IsObject, + IsOptional, + IsString, + ValidateNested, +} from "class-validator"; +import { TechniqueClass } from "../schemas/technique.schema"; +import { Type } from "class-transformer"; +import { CreateTechniqueDto } from "./create-technique.dto"; +import { RelationshipClass } from "../schemas/relationship.schema"; +import { CreateRelationshipDto } from "./create-relationship.dto"; +import { LifecycleClass } from "../schemas/lifecycle.schema"; +import { Attachment } from "../../attachments/schemas/attachment.schema"; +import { OrigDatablock } from "../../origdatablocks/schemas/origdatablock.schema"; +import { Datablock } from "../../datablocks/schemas/datablock.schema"; + +@ApiTags("datasets") +export class UpdateDatasetObsoleteDto extends OwnableDto { + @ApiProperty({ + type: String, + required: true, + description: + "Owner or custodian of the dataset, usually first name + last name. The string may contain a list of persons, which should then be separated by semicolons.", + }) + @IsString() + readonly owner: string; + + @ApiProperty({ + type: String, + required: false, + description: + "Email of the owner or custodian of the dataset. The string may contain a list of emails, which should then be separated by semicolons.", + }) + @IsOptional() + @IsEmail() + readonly ownerEmail?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "ORCID of the owner or custodian. The string may contain a list of ORCIDs, which should then be separated by semicolons.", + }) + @IsOptional() + @IsString() + readonly orcidOfOwner?: string; + + @ApiProperty({ + type: String, + required: true, + description: + "Email of the contact person for this dataset. The string may contain a list of emails, which should then be separated by semicolons.", + }) + @IsEmail() + readonly contactEmail: string; + + @ApiProperty({ + type: String, + required: true, + description: + "Absolute file path on file server containing the files of this dataset, e.g. /some/path/to/sourcefolder. In case of a single file dataset, e.g. HDF5 data, it contains the path up to, but excluding the filename. Trailing slashes are removed.", + }) + @IsString() + readonly sourceFolder: string; + + @ApiProperty({ + type: String, + required: false, + description: + "DNS host name of file server hosting sourceFolder, optionally including a protocol e.g. [protocol://]fileserver1.example.com", + }) + @IsOptional() + @IsFQDN() + readonly sourceFolderHost?: string; + + /* + * size and number of files fields should be managed by the system + */ + @ApiProperty({ + type: Number, + default: 0, + required: false, + description: + "Total size of all source files contained in source folder on disk when unpacked.", + }) + @IsOptional() + @IsInt() + readonly size?: number = 0; + + @ApiProperty({ + type: Number, + default: 0, + required: false, + description: + "Total size of all datablock package files created for this dataset.", + }) + @IsOptional() + @IsInt() + readonly packedSize?: number = 0; + + @ApiProperty({ + type: Number, + default: 0, + required: false, + description: + "Total number of files in all OrigDatablocks for this dataset.", + }) + @IsOptional() + @IsInt() + readonly numberOfFiles?: number = 0; + + @ApiProperty({ + type: Number, + default: 0, + required: true, + description: "Total number of files in all Datablocks for this dataset.", + }) + @IsOptional() + @IsInt() + readonly numberOfFilesArchived?: number; + + @ApiProperty({ + type: Date, + required: true, + description: + "Time when dataset became fully available on disk, i.e. all containing files have been written, or the dataset was created in SciCat.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) + @IsDateString() + readonly creationTime: Date; + + @ApiProperty({ + type: String, + required: false, + description: + "Defines a level of trust, e.g. a measure of how much data was verified or used by other persons.", + }) + @IsOptional() + @IsString() + readonly validationStatus?: string; + + @ApiProperty({ + type: [String], + required: false, + description: + "Array of tags associated with the meaning or contents of this dataset. Values should ideally come from defined vocabularies, taxonomies, ontologies or knowledge graphs.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly keywords?: string[]; + + @ApiProperty({ + type: String, + required: false, + description: "Free text explanation of contents of dataset.", + }) + @IsOptional() + @IsString() + readonly description?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid. Will be autofilled if missing using info from sourceFolder.", + }) + @IsOptional() + @IsString() + readonly datasetName?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "ACIA information about AUthenticity,COnfidentiality,INtegrity and AVailability requirements of dataset. E.g. AV(ailabilty)=medium could trigger the creation of a two tape copies. Format 'AV=medium,CO=low'", + }) + @IsOptional() + @IsString() + readonly classification?: string; + + @ApiProperty({ + type: String, + required: false, + description: "Name of the license under which the data can be used.", + }) + @IsOptional() + @IsString() + readonly license?: string; + + // it needs to be discussed if this fields is managed by the user or by the system + @ApiProperty({ + type: Boolean, + required: false, + default: false, + description: "Flag is true when data are made publicly available.", + }) + @IsOptional() + @IsBoolean() + readonly isPublished?: boolean; + + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(TechniqueClass) }, + required: false, + default: [], + description: "Stores the metadata information for techniques.", + }) + @IsOptional() + @IsArray() + @ValidateNested({ each: true }) + @Type(() => CreateTechniqueDto) + readonly techniques?: TechniqueClass[]; + + // it needs to be discussed if this fields is managed by the user or by the system + @ApiProperty({ + type: [String], + required: false, + default: [], + description: "List of users that the dataset has been shared with.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly sharedWith?: string[]; + + // it needs to be discussed if this fields is managed by the user or by the system + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(RelationshipClass) }, + required: false, + default: [], + description: "Stores the relationships with other datasets.", + }) + @IsArray() + @IsOptional() + @ValidateNested({ each: true }) + @Type(() => CreateRelationshipDto) + readonly relationships?: RelationshipClass[]; + + @ApiProperty({ + type: LifecycleClass, + required: false, + default: {}, + description: + "Describes the current status of the dataset during its lifetime with respect to the storage handling systems.", + }) + @IsOptional() + readonly datasetlifecycle: LifecycleClass; + + @ApiProperty({ + type: Object, + required: false, + default: {}, + description: "JSON object containing the scientific metadata.", + }) + @IsOptional() + @IsObject() + readonly scientificMetadata?: Record; + + @ApiProperty({ + type: String, + required: false, + description: "Comment the user has about a given dataset.", + }) + @IsOptional() + @IsString() + readonly comment?: string; + + @ApiProperty({ + type: Number, + required: false, + description: + "Data Quality Metrics is a number given by the user to rate the dataset.", + }) + @IsOptional() + @IsNumber() + readonly dataQualityMetrics?: number; +} + +export class PartialUpdateDatasetObsoleteDto extends PartialType( + UpdateDatasetObsoleteDto, +) {} diff --git a/src/datasets/dto/update-dataset.dto.ts b/src/datasets/dto/update-dataset.dto.ts index aab14a7e5..c4ea63c4b 100644 --- a/src/datasets/dto/update-dataset.dto.ts +++ b/src/datasets/dto/update-dataset.dto.ts @@ -24,9 +24,6 @@ import { CreateTechniqueDto } from "./create-technique.dto"; import { RelationshipClass } from "../schemas/relationship.schema"; import { CreateRelationshipDto } from "./create-relationship.dto"; import { LifecycleClass } from "../schemas/lifecycle.schema"; -import { Attachment } from "../../attachments/schemas/attachment.schema"; -import { OrigDatablock } from "../../origdatablocks/schemas/origdatablock.schema"; -import { Datablock } from "../../datablocks/schemas/datablock.schema"; @ApiTags("datasets") export class UpdateDatasetDto extends OwnableDto { @@ -37,7 +34,8 @@ export class UpdateDatasetDto extends OwnableDto { "Owner or custodian of the dataset, usually first name + last name. The string may contain a list of persons, which should then be separated by semicolons.", }) @IsString() - readonly owner: string; + @IsOptional() + readonly owner?: string; @ApiProperty({ type: String, @@ -175,13 +173,12 @@ export class UpdateDatasetDto extends OwnableDto { @ApiProperty({ type: String, - required: false, + required: true, description: "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid. Will be autofilled if missing using info from sourceFolder.", }) - @IsOptional() @IsString() - readonly datasetName?: string; + readonly datasetName: string; @ApiProperty({ type: String, @@ -211,7 +208,7 @@ export class UpdateDatasetDto extends OwnableDto { }) @IsOptional() @IsBoolean() - readonly isPublished?: boolean; + readonly isPublished?: boolean = false; @ApiProperty({ type: "array", @@ -261,7 +258,7 @@ export class UpdateDatasetDto extends OwnableDto { "Describes the current status of the dataset during its lifetime with respect to the storage handling systems.", }) @IsOptional() - readonly datasetlifecycle: LifecycleClass; + readonly datasetlifecycle?: LifecycleClass; @ApiProperty({ type: Object, @@ -292,14 +289,134 @@ export class UpdateDatasetDto extends OwnableDto { @IsNumber() readonly dataQualityMetrics?: number; + @ApiProperty({ + type: String, + required: 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.", + }) + @IsString() + readonly principalInvestigator: string; + + @ApiProperty({ + type: Date, + required: false, + description: + "Start time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) @IsOptional() - attachments?: Attachment[]; + @IsDateString() + readonly startTime?: Date; + @ApiProperty({ + type: Date, + required: false, + description: + "End time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) @IsOptional() - origdatablocks?: OrigDatablock[]; + @IsDateString() + readonly endTime?: Date; + @ApiProperty({ + type: String, + required: false, + description: + "Unique location identifier where data was taken, usually in the form /Site-name/facility-name/instrumentOrBeamline-name. This field is required if the dataset is a Raw dataset.", + }) @IsOptional() - datablocks?: Datablock[]; + @IsString() + readonly creationLocation?: string; + + @ApiProperty({ + type: String, + required: false, + description: + "Defines the format of the data files in this dataset, e.g Nexus Version x.y.", + }) + @IsOptional() + @IsString() + readonly dataFormat?: string; + + @ApiProperty({ + type: [String], + required: false, + description: + "ID of the proposal or proposals which the dataset belongs to.
This dataset might have been acquired under the listed proposals or is derived from datasets acquired from datasets belonging to the listed datasets.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly proposalId?: string[]; + + @ApiProperty({ + type: [String], + required: false, + description: + "ID of the sample or samples used when collecting the data included or used in this dataset.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly sampleId?: string[]; + + @ApiProperty({ + type: String, + required: false, + description: + "ID of the instrument or instruments where the data included or used in this datasets was collected on.", + }) + @IsOptional() + @IsString({ + each: false, + }) + readonly instrumentId?: string[]; + + @ApiProperty({ + type: [String], + required: true, + description: + "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs.", + }) + @IsOptional() + @IsString({ + each: false, + }) + readonly inputDatasets?: string[]; + + @ApiProperty({ + type: [String], + required: false, + description: + "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data.", + }) + @IsOptional() + @IsString({ + each: true, + }) + readonly usedSoftware?: string[]; + + @ApiProperty({ + type: Object, + required: false, + description: + "The creation process of the derived data will usually depend on input job parameters. The full structure of these input parameters are stored here.", + }) + @IsOptional() + @IsObject() + readonly jobParameters?: Record; + + @ApiProperty({ + type: String, + required: false, + description: + "The output job logfile. Keep the size of this log data well below 15 MB.", + }) + @IsOptional() + @IsString() + readonly jobLogData?: string; } export class PartialUpdateDatasetDto extends PartialType(UpdateDatasetDto) {} diff --git a/src/datasets/dto/update-derived-dataset.dto.ts b/src/datasets/dto/update-derived-dataset.dto.ts index 5f4d83a1d..a654c5bca 100644 --- a/src/datasets/dto/update-derived-dataset.dto.ts +++ b/src/datasets/dto/update-derived-dataset.dto.ts @@ -1,8 +1,8 @@ -import { UpdateDatasetDto } from "./update-dataset.dto"; +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; import { ApiProperty, PartialType } from "@nestjs/swagger"; import { IsObject, IsOptional, IsString } from "class-validator"; -export class UpdateDerivedDatasetDto extends UpdateDatasetDto { +export class UpdateDerivedDatasetDto extends UpdateDatasetObsoleteDto { @ApiProperty({ type: String, required: true, diff --git a/src/datasets/dto/update-raw-dataset.dto.ts b/src/datasets/dto/update-raw-dataset.dto.ts index a03fa14ad..5926b854f 100644 --- a/src/datasets/dto/update-raw-dataset.dto.ts +++ b/src/datasets/dto/update-raw-dataset.dto.ts @@ -1,8 +1,8 @@ import { IsDateString, IsOptional, IsString } from "class-validator"; -import { UpdateDatasetDto } from "./update-dataset.dto"; +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; import { ApiProperty, PartialType } from "@nestjs/swagger"; -export class UpdateRawDatasetDto extends UpdateDatasetDto { +export class UpdateRawDatasetDto extends UpdateDatasetObsoleteDto { /* we need to discuss if the naming is adequate. */ @ApiProperty({ type: String, diff --git a/src/datasets/schemas/dataset.schema.ts b/src/datasets/schemas/dataset.schema.ts index 74c29aaa7..a50055b98 100644 --- a/src/datasets/schemas/dataset.schema.ts +++ b/src/datasets/schemas/dataset.schema.ts @@ -244,28 +244,21 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: String, - required: false, + required: true, description: - "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid. Will be autofilled if missing using info from sourceFolder.", + "A name for the dataset, given by the creator to carry some semantic meaning. Useful for display purposes e.g. instead of displaying the pid.", }) @Prop({ type: String, - required: false, - default: function datasetName() { - const sourceFolder = (this as DatasetDocument).sourceFolder; - if (!sourceFolder) return ""; - const arr = sourceFolder.split("/"); - if (arr.length == 1) return arr[0]; - else return arr[arr.length - 2] + "/" + arr[arr.length - 1]; - }, + required: true, }) - datasetName?: string; + datasetName: string; @ApiProperty({ type: String, required: false, description: - "ACIA information about AUthenticity,COnfidentiality,INtegrity and AVailability requirements of dataset. E.g. AV(ailabilty)=medium could trigger the creation of a two tape copies. Format 'AV=medium,CO=low'", + "ACIA information about AUthenticity,COnfidentiality,INtegrity and AVailability requirements of dataset. E.g. AV(ailabilty)=medium could trigger the creation of a two tape copies. Format 'AV=medium,CO=low'. Please check the following post for more info: https://en.wikipedia.org/wiki/Parkerian_Hexad", }) @Prop({ type: String, required: false }) classification?: string; @@ -280,11 +273,12 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: String, - required: false, - description: "Version of the API used in creation of the dataset.", + required: true, + description: + "Version of the API used when the dataset was created or last updated. API version is defined in code for each release. Managed by the system.", }) - @Prop({ type: String, required: false }) - version?: string; + @Prop({ type: String, required: true }) + version: string; @ApiProperty({ type: "array", @@ -298,12 +292,12 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: LifecycleClass, - required: false, + required: true, default: {}, description: "Describes the current status of the dataset during its lifetime with respect to the storage handling systems.", }) - @Prop({ type: LifecycleSchema, default: {}, required: false }) + @Prop({ type: LifecycleSchema, default: {}, required: true }) datasetlifecycle?: LifecycleClass; @ApiProperty({ @@ -311,7 +305,8 @@ export class DatasetClass extends OwnableClass { items: { $ref: getSchemaPath(TechniqueClass) }, required: false, default: [], - description: "Stores the metadata information for techniques.", + description: + "Array of techniques information, with technique name and pid.", }) @Prop({ type: [TechniqueSchema], required: false, default: [] }) techniques?: TechniqueClass[]; @@ -321,7 +316,8 @@ export class DatasetClass extends OwnableClass { items: { $ref: getSchemaPath(RelationshipClass) }, required: false, default: [], - description: "Stores the relationships with other datasets.", + description: + "Array of relationships with other datasets. It contains relationship type and destination dataset", }) @Prop({ type: [RelationshipSchema], required: false, default: [] }) relationships?: RelationshipClass[]; @@ -330,7 +326,8 @@ export class DatasetClass extends OwnableClass { type: [String], required: false, default: [], - description: "List of users that the dataset has been shared with.", + description: + "List of additional users that the dataset has been shared with.", }) @Prop({ type: [String], @@ -339,37 +336,37 @@ export class DatasetClass extends OwnableClass { }) sharedWith?: string[]; - @ApiProperty({ - type: "array", - items: { $ref: getSchemaPath(Attachment) }, - required: false, - description: - "Small, less than 16 MB attachments, envisaged for png/jpeg previews.", - }) - @Prop({ type: [AttachmentSchema], default: [] }) - attachments?: Attachment[]; - - @ApiProperty({ - isArray: true, - type: OrigDatablock, - items: { $ref: getSchemaPath(OrigDatablock) }, - required: false, - description: - "Containers that list all files and their attributes which make up a dataset. Usually filled at the time the dataset's metadata is created in the data catalog. Can be used by subsequent archiving processes to create the archived datasets.", - }) - @Prop({ type: [OrigDatablockSchema], default: [] }) - origdatablocks: OrigDatablock[]; - - @ApiProperty({ - isArray: true, - type: Datablock, - items: { $ref: getSchemaPath(Datablock) }, - required: false, - description: - "When archiving a dataset, all files contained in the dataset are listed here together with their checksum information. Several datablocks can be created if the file listing is too long for a single datablock. This partitioning decision is done by the archiving system to allow for chunks of datablocks with manageable sizes. E.g a datasets consisting of 10 TB of data could be split into 10 datablocks of about 1 TB each. The upper limit set by the data catalog system itself is given by the fact that documents must be smaller than 16 MB, which typically allows for datasets of about 100000 files.", - }) - @Prop({ type: [DatablockSchema], default: [] }) - datablocks: Datablock[]; + // @ApiProperty({ + // type: "array", + // items: { $ref: getSchemaPath(Attachment) }, + // required: false, + // description: + // "Small, less than 16 MB attachments, envisaged for png/jpeg previews.", + // }) + // @Prop({ type: [AttachmentSchema], default: [] }) + // attachments?: Attachment[]; + + // @ApiProperty({ + // isArray: true, + // type: OrigDatablock, + // items: { $ref: getSchemaPath(OrigDatablock) }, + // required: false, + // description: + // "Containers that list all files and their attributes which make up a dataset. Usually filled at the time the dataset's metadata is created in the data catalog. Can be used by subsequent archiving processes to create the archived datasets.", + // }) + // @Prop({ type: [OrigDatablockSchema], default: [] }) + // origdatablocks: OrigDatablock[]; + + // @ApiProperty({ + // isArray: true, + // type: Datablock, + // items: { $ref: getSchemaPath(Datablock) }, + // required: false, + // description: + // "When archiving a dataset, all files contained in the dataset are listed here together with their checksum information. Several datablocks can be created if the file listing is too long for a single datablock. This partitioning decision is done by the archiving system to allow for chunks of datablocks with manageable sizes. E.g a datasets consisting of 10 TB of data could be split into 10 datablocks of about 1 TB each. The upper limit set by the data catalog system itself is given by the fact that documents must be smaller than 16 MB, which typically allows for datasets of about 100000 files.", + // }) + // @Prop({ type: [DatablockSchema], default: [] }) + // datablocks: Datablock[]; @ApiProperty({ type: Object, @@ -383,7 +380,8 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: String, required: false, - description: "Comment the user has about a given dataset.", + description: + "Short comment provided by the user about a given dataset. This is additional to the description field.", }) @Prop({ type: String, @@ -400,7 +398,7 @@ export class DatasetClass extends OwnableClass { type: Number, required: false, }) - dataQualityMetrics: number; + dataQualityMetrics?: number; /* * fields related to Raw Datasets @@ -436,7 +434,7 @@ export class DatasetClass extends OwnableClass { type: String, required: true, description: - "Unique location identifier where data was taken, usually in the form /Site-name/facility-name/instrumentOrBeamline-name. This field is required if the dataset is a Raw dataset.", + "Unique location identifier where data was acquired. Usually in the form /Site-name/facility-name/instrumentOrBeamline-name.", }) @Prop({ type: String, required: false, index: true }) creationLocation?: string; @@ -453,44 +451,47 @@ export class DatasetClass extends OwnableClass { @ApiProperty({ type: String, required: false, - description: "The ID of the proposal to which the dataset belongs.", + description: + "The ID of the proposal to which the dataset belongs to and it has been acquired under.", }) @Prop({ type: String, ref: "Proposal", required: false }) proposalId?: string; @ApiProperty({ - type: String, + type: [String], required: false, - description: "ID of the sample used when collecting the data.", + description: + "Single ID or array of IDS of the samples used when collecting the data.", }) - @Prop({ type: String, ref: "Sample", required: false }) - sampleId?: string; + @Prop({ type: [String], ref: "Sample", required: false }) + sampleId?: string[]; @ApiProperty({ - type: String, + type: [String], required: false, - description: "ID of the instrument where the data was created.", + description: + "Id of the instrument or array of IDS of the instruments where the data contained in this dataset was created/acquired.", }) - @Prop({ type: String, ref: "Instrument", required: false }) - instrumentId?: string; + @Prop({ type: [String], ref: "Instrument", required: false }) + instrumentId?: string[]; /* * Derived Dataset */ - @ApiProperty({ - type: String, - required: false, - description: - "First name and last name of the person or people pursuing the data analysis. The string may contain a list of names, which should then be separated by semicolons.", - }) - @Prop({ type: String, required: false, index: true }) - investigator?: string; + // @ApiProperty({ + // type: String, + // required: false, + // description: + // "First name and last name of the person or people pursuing the data analysis. The string may contain a list of names, which should then be separated by semicolons.", + // }) + // @Prop({ type: String, required: false, index: true }) + // investigator?: string; @ApiProperty({ type: [String], required: false, description: - "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs. This field is required if the dataset is a Derived dataset.", + "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs.", }) @Prop({ type: [String], required: false }) inputDatasets?: string[]; @@ -499,7 +500,7 @@ export class DatasetClass extends OwnableClass { type: [String], required: false, description: - "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data. This field is required if the dataset is a Derived dataset.", + "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data.", }) @Prop({ type: [String], required: false }) usedSoftware?: string[]; From 2fdc8bf1d89927dc4b8f7c7f42a24fc649e18311 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Thu, 5 Sep 2024 13:58:25 +0200 Subject: [PATCH 11/38] solved weird dependency in jobs --- src/jobs/jobs.controller.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/jobs/jobs.controller.ts b/src/jobs/jobs.controller.ts index 588f202f9..838fc724c 100644 --- a/src/jobs/jobs.controller.ts +++ b/src/jobs/jobs.controller.ts @@ -179,25 +179,26 @@ export class JobsController { // Indexing originDataBlock with pid and create set of files for each dataset const datasets = await this.datasetsService.findAll(filter); // Include origdatablocks - await Promise.all( + const aggregatedData = await Promise.all( datasets.map(async (dataset) => { - dataset.origdatablocks = await this.origDatablocksService.findAll( - { + return { + dataset: dataset, + origdatablocks: await this.origDatablocksService.findAll({ datasetId: dataset.pid, - }, - ); + }), + }; }), ); - const result: Record> = datasets.reduce( - (acc: Record>, dataset) => { + const result: Record> = aggregatedData.reduce( + (acc: Record>, data) => { // Using Set make searching more efficient - const files = dataset.origdatablocks.reduce((acc, block) => { + const files = data.origdatablocks.reduce((acc, block) => { block.dataFileList.forEach((file) => { acc.add(file.path); }); return acc; }, new Set()); - acc[dataset.pid] = files; + acc[data.dataset.pid] = files; return acc; }, {}, From ac468a1fd0e3f6e20d94e481c1b442aca2f88239 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 6 Sep 2024 16:57:59 +0200 Subject: [PATCH 12/38] still refactoring names, started working on tests --- src/datasets/datasets.controller.ts | 180 +- src/datasets/datasets.service.ts | 10 +- .../dto/create-derived-dataset.dto.ts | 27 - src/datasets/dto/create-raw-dataset.dto.ts | 27 - src/datasets/dto/update-dataset.dto.ts | 6 +- .../dto/update-derived-dataset.dto.ts | 60 - src/datasets/dto/update-raw-dataset.dto.ts | 100 - src/datasets/schemas/dataset.schema.ts | 6 +- .../origdatablocks.controller.ts | 4 +- test/DatasetAuthorization.js | 2879 +++++++++-------- 10 files changed, 1584 insertions(+), 1715 deletions(-) delete mode 100644 src/datasets/dto/create-derived-dataset.dto.ts delete mode 100644 src/datasets/dto/create-raw-dataset.dto.ts delete mode 100644 src/datasets/dto/update-derived-dataset.dto.ts delete mode 100644 src/datasets/dto/update-raw-dataset.dto.ts diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 42233e22a..89e6f7536 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -38,8 +38,8 @@ import { Request } from "express"; import { DatasetsService } from "./datasets.service"; import { PartialUpdateDatasetObsoleteDto } from "./dto/update-dataset-obsolete.dto"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; -import { CreateRawDatasetDto } from "./dto/create-raw-dataset.dto"; -import { CreateDerivedDatasetDto } from "./dto/create-derived-dataset.dto"; +import { CreateRawDatasetObsoleteDto } from "./dto/create-raw-dataset-obsolete.dto"; +import { CreateDerivedDatasetObsoleteDto } from "./dto/create-derived-dataset-obsolete.dto"; import { PoliciesGuard } from "src/casl/guards/policies.guard"; import { CheckPolicies } from "src/casl/decorators/check-policies.decorator"; import { AppAbility, CaslAbilityFactory } from "src/casl/casl-ability.factory"; @@ -74,13 +74,13 @@ import { validate, ValidationError, ValidatorOptions } from "class-validator"; import { HistoryInterceptor } from "src/common/interceptors/history.interceptor"; import { CreateDatasetOrigDatablockDto } from "src/origdatablocks/dto/create-dataset-origdatablock"; import { - PartialUpdateRawDatasetDto, - UpdateRawDatasetDto, -} from "./dto/update-raw-dataset.dto"; + PartialUpdateRawDatasetObsoleteDto, + UpdateRawDatasetObsoleteDto, +} from "./dto/update-raw-dataset-obsolete.dto"; import { - PartialUpdateDerivedDatasetDto, - UpdateDerivedDatasetDto, -} from "./dto/update-derived-dataset.dto"; + PartialUpdateDerivedDatasetObsoleteDto, + UpdateDerivedDatasetObsoleteDto, +} from "./dto/update-derived-dataset-obsolete.dto"; import { CreateDatasetDatablockDto } from "src/datablocks/dto/create-dataset-datablock"; import { filterDescription, @@ -99,12 +99,13 @@ import { LogbooksService } from "src/logbooks/logbooks.service"; import configuration from "src/config/configuration"; import { DatasetType } from "./dataset-type.enum"; import { OutputDatasetObsoleteDto } from "./dto/output-dataset-obsolete.dto"; +import { CreateDatasetDto } from "./dto/create-dataset.dto"; @ApiBearerAuth() @ApiExtraModels( CreateAttachmentDto, - CreateDerivedDatasetDto, - CreateRawDatasetDto, + CreateDerivedDatasetObsoleteDto, + CreateRawDatasetObsoleteDto, HistoryClass, TechniqueClass, RelationshipClass, @@ -283,7 +284,7 @@ export class DatasetsController { return dataset; } - async checkPermissionsForDataset(request: Request, id: string) { + async checkPermissionsForDatasetObsolete(request: Request, id: string) { const dataset = await this.datasetsService.findOne({ where: { pid: id } }); const user: JWTUser = request.user as JWTUser; @@ -332,7 +333,10 @@ export class DatasetsController { } async generateDatasetInstanceForPermissions( - dataset: CreateRawDatasetDto | CreateDerivedDatasetDto | DatasetClass, + dataset: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | DatasetClass, ): Promise { const datasetInstance = new DatasetClass(); datasetInstance._id = ""; @@ -345,9 +349,9 @@ export class DatasetsController { return datasetInstance; } - async checkPermissionsForDatasetCreate( + async checkPermissionsForObsoleteDatasetCreate( request: Request, - dataset: CreateRawDatasetDto | CreateDerivedDatasetDto, + dataset: CreateRawDatasetObsoleteDto | CreateDerivedDatasetObsoleteDto, ) { const user: JWTUser = request.user as JWTUser; @@ -388,6 +392,69 @@ export class DatasetsController { return dataset; } + convertObsoleteToCurrentSchema( + inputDataset: CreateRawDatasetObsoleteDto | CreateDerivedDatasetObsoleteDto, + ): CreateDatasetDto { + const propertiesModifier: Record = {}; + if (inputDataset.type == "raw") { + if ("proposalId" in inputDataset) { + propertiesModifier.proposalIds = [ + (inputDataset as CreateRawDatasetObsoleteDto).proposalId, + ]; + } + if ("sampleId" in inputDataset) { + propertiesModifier.sampleIds = [ + (inputDataset as CreateRawDatasetObsoleteDto).sampleId, + ]; + } + if ("instrumentIds" in inputDataset) { + propertiesModifier.instrumentIds = [ + (inputDataset as CreateRawDatasetObsoleteDto).instrumentId, + ]; + } + } else { + if ("investigator" in inputDataset) { + propertiesModifier.principalInvestigator = [ + (inputDataset as CreateDerivedDatasetObsoleteDto).investigator, + ]; + } + } + + const outputDataset: CreateDatasetDto = { + ...(inputDataset as CreateDatasetDto), + ...propertiesModifier, + }; + + return outputDataset; + } + + convertCurrentToObsoleteSchema( + inputDataset: DatasetClass, + ): OutputDatasetObsoleteDto { + const propertiesModifier: Record = {}; + if ("proposalIds" in inputDataset) { + propertiesModifier.proposalIds = inputDataset.proposalIds![0]; + } + if ("sampleIds" in inputDataset) { + propertiesModifier.sampleIds = inputDataset.sampleIds![0]; + } + if ("instrumentIds" in inputDataset) { + propertiesModifier.instrumentIds = inputDataset.instrumentIds![0]; + } + if (inputDataset.type == "raw") { + if ("investigator" in inputDataset) { + propertiesModifier.investigator = inputDataset.principalInvestigator; + } + } + + const outputDataset: OutputDatasetObsoleteDto = { + ...(inputDataset as OutputDatasetObsoleteDto), + ...propertiesModifier, + }; + + return outputDataset; + } + // POST /datasets @UseGuards(PoliciesGuard) @CheckPolicies("datasets", (ability: AppAbility) => @@ -404,14 +471,14 @@ export class DatasetsController { description: "It creates a new dataset and returns it completed with systems fields.", }) - @ApiExtraModels(CreateRawDatasetDto, CreateDerivedDatasetDto) + @ApiExtraModels(CreateRawDatasetObsoleteDto, CreateDerivedDatasetObsoleteDto) @ApiBody({ description: "Input fields for the dataset to be created", required: true, schema: { oneOf: [ - { $ref: getSchemaPath(CreateRawDatasetDto) }, - { $ref: getSchemaPath(CreateDerivedDatasetDto) }, + { $ref: getSchemaPath(CreateRawDatasetObsoleteDto) }, + { $ref: getSchemaPath(CreateDerivedDatasetObsoleteDto) }, ], }, }) @@ -422,25 +489,34 @@ export class DatasetsController { }) async create( @Req() request: Request, - @Body() createDatasetDto: CreateRawDatasetDto | CreateDerivedDatasetDto, - ): Promise { + @Body() + createDatasetObsoleteDto: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto, + ): Promise { // validate dataset - await this.validateDataset( - createDatasetDto, - createDatasetDto.type === "raw" - ? CreateRawDatasetDto - : CreateDerivedDatasetDto, + await this.validateDatasetObsolete( + createDatasetObsoleteDto, + createDatasetObsoleteDto.type === "raw" + ? CreateRawDatasetObsoleteDto + : CreateDerivedDatasetObsoleteDto, ); - const datasetDTO = await this.checkPermissionsForDatasetCreate( - request, - createDatasetDto, - ); + const obsoleteDatasetDto = + await this.checkPermissionsForObsoleteDatasetCreate( + request, + createDatasetObsoleteDto, + ); try { - const createdDataset = await this.datasetsService.create(datasetDTO); + const datasetDto = + this.convertObsoleteToCurrentSchema(obsoleteDatasetDto); + const createdDataset = await this.datasetsService.create(datasetDto); + + const outputObsoleteDatasetDto = + this.convertCurrentToObsoleteSchema(createdDataset); - return createdDataset; + return outputObsoleteDatasetDto; } catch (error) { if ((error as MongoError).code === 11000) { throw new ConflictException( @@ -452,21 +528,21 @@ export class DatasetsController { } } - async validateDataset( + async validateDatasetObsolete( inputDatasetDto: - | CreateRawDatasetDto - | CreateDerivedDatasetDto - | PartialUpdateRawDatasetDto - | PartialUpdateDerivedDatasetDto - | UpdateRawDatasetDto - | UpdateDerivedDatasetDto, + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | PartialUpdateRawDatasetObsoleteDto + | PartialUpdateDerivedDatasetObsoleteDto + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto, dto: ClassConstructor< - | CreateRawDatasetDto - | CreateDerivedDatasetDto - | PartialUpdateRawDatasetDto - | PartialUpdateDerivedDatasetDto - | UpdateRawDatasetDto - | UpdateDerivedDatasetDto + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | PartialUpdateRawDatasetObsoleteDto + | PartialUpdateDerivedDatasetObsoleteDto + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto >, ) { const validateOptions: ValidatorOptions = { @@ -481,7 +557,7 @@ export class DatasetsController { if ( inputDatasetDto instanceof - (CreateRawDatasetDto || CreateDerivedDatasetDto) + (CreateRawDatasetObsoleteDto || CreateDerivedDatasetObsoleteDto) ) { if (!(inputDatasetDto.type in DatasetType)) { throw new HttpException( @@ -526,14 +602,14 @@ export class DatasetsController { description: "It validates the dataset provided as input, and returns true if the information is a valid dataset", }) - @ApiExtraModels(CreateRawDatasetDto, CreateDerivedDatasetDto) + @ApiExtraModels(CreateRawDatasetObsoleteDto, CreateDerivedDatasetObsoleteDto) @ApiBody({ description: "Input fields for the dataset that needs to be validated", required: true, schema: { oneOf: [ - { $ref: getSchemaPath(CreateRawDatasetDto) }, - { $ref: getSchemaPath(CreateDerivedDatasetDto) }, + { $ref: getSchemaPath(CreateRawDatasetObsoleteDto) }, + { $ref: getSchemaPath(CreateDerivedDatasetObsoleteDto) }, ], }, }) @@ -545,9 +621,15 @@ export class DatasetsController { }) async isValid( @Req() request: Request, - @Body() createDatasetDto: CreateRawDatasetDto | CreateDerivedDatasetDto, + @Body() + createDatasetObsoleteDto: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto, ): Promise<{ valid: boolean }> { - await this.checkPermissionsForDatasetCreate(request, createDatasetDto); + await this.checkPermissionsForObsoleteDatasetCreate( + request, + createDatasetObsoleteDto, + ); const dtoTestRawCorrect = plainToInstance( CreateRawDatasetDto, diff --git a/src/datasets/datasets.service.ts b/src/datasets/datasets.service.ts index 680222e8e..60793750d 100644 --- a/src/datasets/datasets.service.ts +++ b/src/datasets/datasets.service.ts @@ -24,7 +24,7 @@ import { ElasticSearchService } from "src/elastic-search/elastic-search.service" import { InitialDatasetsService } from "src/initial-datasets/initial-datasets.service"; import { LogbooksService } from "src/logbooks/logbooks.service"; import { DatasetType } from "./dataset-type.enum"; -import { CreateDatasetObsoleteDto } from "./dto/create-dataset-obsolete.dto"; +import { CreateDatasetDto } from "./dto/create-dataset.dto"; import { PartialUpdateDatasetObsoleteDto, UpdateDatasetObsoleteDto, @@ -32,11 +32,11 @@ import { import { PartialUpdateDerivedDatasetDto, UpdateDerivedDatasetDto, -} from "./dto/update-derived-dataset.dto"; +} from "./dto/update-derived-dataset-obsolete.dto"; import { PartialUpdateRawDatasetDto, UpdateRawDatasetDto, -} from "./dto/update-raw-dataset.dto"; +} from "./dto/update-raw-dataset-obsolete.dto"; import { IDatasetFields } from "./interfaces/dataset-filters.interface"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; @@ -58,9 +58,7 @@ export class DatasetsService { } } - async create( - createDatasetDto: CreateDatasetObsoleteDto, - ): Promise { + async create(createDatasetDto: CreateDatasetDto): Promise { const username = (this.request.user as JWTUser).username; const createdDataset = new this.datasetModel( // insert created and updated fields diff --git a/src/datasets/dto/create-derived-dataset.dto.ts b/src/datasets/dto/create-derived-dataset.dto.ts deleted file mode 100644 index f95240c82..000000000 --- a/src/datasets/dto/create-derived-dataset.dto.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { UpdateDerivedDatasetDto } from "./update-derived-dataset.dto"; -import { ApiProperty } from "@nestjs/swagger"; -import { IsEnum, IsOptional, IsString } from "class-validator"; -import { DatasetType } from "../dataset-type.enum"; - -export class CreateDerivedDatasetDto extends UpdateDerivedDatasetDto { - @ApiProperty({ - type: String, - required: false, - description: "Persistent identifier of the dataset.", - }) - @IsOptional() - @IsString() - pid?: string; - - @IsEnum(DatasetType) - readonly type: string = DatasetType.Derived; - - @ApiProperty({ - type: String, - required: false, - description: "Version of the API used in creation of the dataset.", - }) - @IsOptional() - @IsString() - readonly version?: string; -} diff --git a/src/datasets/dto/create-raw-dataset.dto.ts b/src/datasets/dto/create-raw-dataset.dto.ts deleted file mode 100644 index fafa70b78..000000000 --- a/src/datasets/dto/create-raw-dataset.dto.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { UpdateRawDatasetDto } from "./update-raw-dataset.dto"; -import { ApiProperty } from "@nestjs/swagger"; -import { IsEnum, IsOptional, IsString } from "class-validator"; -import { DatasetType } from "../dataset-type.enum"; - -export class CreateRawDatasetDto extends UpdateRawDatasetDto { - @ApiProperty({ - type: String, - required: false, - description: "Persistent identifier of the dataset.", - }) - @IsOptional() - @IsString() - pid?: string; - - @IsEnum(DatasetType) - readonly type: string = DatasetType.Raw; - - @ApiProperty({ - type: String, - required: false, - description: "Version of the API used in creation of the dataset.", - }) - @IsOptional() - @IsString() - readonly version?: string; -} diff --git a/src/datasets/dto/update-dataset.dto.ts b/src/datasets/dto/update-dataset.dto.ts index c4ea63c4b..ad928772f 100644 --- a/src/datasets/dto/update-dataset.dto.ts +++ b/src/datasets/dto/update-dataset.dto.ts @@ -348,7 +348,7 @@ export class UpdateDatasetDto extends OwnableDto { @IsString({ each: true, }) - readonly proposalId?: string[]; + readonly proposalIds?: string[]; @ApiProperty({ type: [String], @@ -360,7 +360,7 @@ export class UpdateDatasetDto extends OwnableDto { @IsString({ each: true, }) - readonly sampleId?: string[]; + readonly sampleIds?: string[]; @ApiProperty({ type: String, @@ -372,7 +372,7 @@ export class UpdateDatasetDto extends OwnableDto { @IsString({ each: false, }) - readonly instrumentId?: string[]; + readonly instrumentIds?: string[]; @ApiProperty({ type: [String], diff --git a/src/datasets/dto/update-derived-dataset.dto.ts b/src/datasets/dto/update-derived-dataset.dto.ts deleted file mode 100644 index a654c5bca..000000000 --- a/src/datasets/dto/update-derived-dataset.dto.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; -import { ApiProperty, PartialType } from "@nestjs/swagger"; -import { IsObject, IsOptional, IsString } from "class-validator"; - -export class UpdateDerivedDatasetDto extends UpdateDatasetObsoleteDto { - @ApiProperty({ - type: String, - required: true, - description: - "First name and last name of the person or people pursuing the data analysis. The string may contain a list of names, which should then be separated by semicolons.", - }) - @IsString() - readonly investigator: string; - - @ApiProperty({ - type: [String], - required: true, - description: - "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs.", - }) - @IsString({ - each: true, - }) - readonly inputDatasets: string[]; - - @ApiProperty({ - type: [String], - required: true, - description: - "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data.", - }) - @IsString({ - each: true, - }) - readonly usedSoftware: string[]; - - @ApiProperty({ - type: Object, - required: false, - description: - "The creation process of the derived data will usually depend on input job parameters. The full structure of these input parameters are stored here.", - }) - @IsOptional() - @IsObject() - readonly jobParameters?: Record; - - @ApiProperty({ - type: String, - required: false, - description: - "The output job logfile. Keep the size of this log data well below 15 MB.", - }) - @IsOptional() - @IsString() - readonly jobLogData?: string; -} - -export class PartialUpdateDerivedDatasetDto extends PartialType( - UpdateDerivedDatasetDto, -) {} diff --git a/src/datasets/dto/update-raw-dataset.dto.ts b/src/datasets/dto/update-raw-dataset.dto.ts deleted file mode 100644 index 5926b854f..000000000 --- a/src/datasets/dto/update-raw-dataset.dto.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { IsDateString, IsOptional, IsString } from "class-validator"; -import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; -import { ApiProperty, PartialType } from "@nestjs/swagger"; - -export class UpdateRawDatasetDto extends UpdateDatasetObsoleteDto { - /* we need to discuss if the naming is adequate. */ - @ApiProperty({ - type: String, - required: 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.", - }) - @IsString() - readonly principalInvestigator: string; - - @ApiProperty({ - type: Date, - required: false, - description: - "Start time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", - }) - @IsOptional() - @IsDateString() - readonly startTime?: Date; - - @ApiProperty({ - type: Date, - required: false, - description: - "End time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", - }) - @IsOptional() - @IsDateString() - readonly endTime?: Date; - - @ApiProperty({ - type: String, - required: true, - description: - "Unique location identifier where data was taken, usually in the form /Site-name/facility-name/instrumentOrBeamline-name. This field is required if the dataset is a Raw dataset.", - }) - @IsString() - readonly creationLocation: string; - - @ApiProperty({ - type: String, - required: false, - description: - "Defines the format of the data files in this dataset, e.g Nexus Version x.y.", - }) - @IsOptional() - @IsString() - readonly dataFormat?: string; - - @ApiProperty({ - type: String, - required: false, - description: "The ID of the proposal to which the dataset belongs.", - }) - @IsOptional() - @IsString() - readonly proposalId?: string; - - @ApiProperty({ - type: String, - required: false, - description: "ID of the sample used when collecting the data.", - }) - @IsOptional() - @IsString() - readonly sampleId?: string; - - @ApiProperty({ - type: String, - required: false, - description: "ID of the instrument where the data was created.", - }) - @IsOptional() - @IsString() - readonly instrumentId: string; - - @IsOptional() - investigator?: string; - - @IsOptional() - inputDatasets?: string[]; - - @IsOptional() - usedSoftware?: string[]; - - @IsOptional() - jobParameters?: Record; - - @IsOptional() - jobLogData?: string; -} - -export class PartialUpdateRawDatasetDto extends PartialType( - UpdateRawDatasetDto, -) {} diff --git a/src/datasets/schemas/dataset.schema.ts b/src/datasets/schemas/dataset.schema.ts index a50055b98..58fdcd1e4 100644 --- a/src/datasets/schemas/dataset.schema.ts +++ b/src/datasets/schemas/dataset.schema.ts @@ -455,7 +455,7 @@ export class DatasetClass extends OwnableClass { "The ID of the proposal to which the dataset belongs to and it has been acquired under.", }) @Prop({ type: String, ref: "Proposal", required: false }) - proposalId?: string; + proposalIds?: string; @ApiProperty({ type: [String], @@ -464,7 +464,7 @@ export class DatasetClass extends OwnableClass { "Single ID or array of IDS of the samples used when collecting the data.", }) @Prop({ type: [String], ref: "Sample", required: false }) - sampleId?: string[]; + sampleIds?: string[]; @ApiProperty({ type: [String], @@ -473,7 +473,7 @@ export class DatasetClass extends OwnableClass { "Id of the instrument or array of IDS of the instruments where the data contained in this dataset was created/acquired.", }) @Prop({ type: [String], ref: "Instrument", required: false }) - instrumentId?: string[]; + instrumentIds?: string[]; /* * Derived Dataset diff --git a/src/origdatablocks/origdatablocks.controller.ts b/src/origdatablocks/origdatablocks.controller.ts index f1a0f13be..308eb32e9 100644 --- a/src/origdatablocks/origdatablocks.controller.ts +++ b/src/origdatablocks/origdatablocks.controller.ts @@ -45,8 +45,8 @@ import { PartialUpdateDatasetDto } from "src/datasets/dto/update-dataset.dto"; import { filterDescription, filterExample } from "src/common/utils"; import { JWTUser } from "src/auth/interfaces/jwt-user.interface"; import { DatasetClass } from "src/datasets/schemas/dataset.schema"; -import { CreateRawDatasetDto } from "src/datasets/dto/create-raw-dataset.dto"; -import { CreateDerivedDatasetDto } from "src/datasets/dto/create-derived-dataset.dto"; +import { CreateRawDatasetDto } from "src/datasets/dto/create-raw-dataset-obsolete.dto"; +import { CreateDerivedDatasetDto } from "src/datasets/dto/create-derived-dataset-obsolete.dto"; import { logger } from "@user-office-software/duo-logger"; @ApiBearerAuth() diff --git a/test/DatasetAuthorization.js b/test/DatasetAuthorization.js index ab707200d..56a8b7717 100644 --- a/test/DatasetAuthorization.js +++ b/test/DatasetAuthorization.js @@ -45,7 +45,7 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { before(() => { db.collection("Dataset").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], @@ -76,13 +76,14 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { password: TestData.Accounts["archiveManager"]["password"], }); }); - + afterEach((done) => { sandbox.restore(); done(); }); it("0010: adds dataset 1 as Admin Ingestor", async () => { + console.log(JSON.stringify(dataset1)); return request(appUrl) .post("/api/v3/Datasets") .send(dataset1) @@ -91,6 +92,8 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { .expect(TestData.EntryCreatedStatusCode) .expect("Content-Type", /json/) .then((res) => { + console.log("Results"); + console.log(res.body); res.body.should.have.property("ownerGroup").and.equal("group4"); res.body.should.have.property("type").and.equal("raw"); res.body.should.have.property("isPublished").and.equal(true); @@ -100,1440 +103,1440 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { }); }); - it("0020: adds dataset 2 as Admin Ingestor", async () => { - return request(appUrl) - .post("/api/v3/Datasets") - .send(dataset2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("ownerGroup").and.equal("group1"); - res.body.should.have.property("type").and.equal("raw"); - res.body.should.have.property("isPublished").and.equal(false); - res.body.should.have.property("pid").and.be.string; - datasetPid2 = res.body["pid"]; - encodedDatasetPid2 = encodeURIComponent(datasetPid2); - }); - }); - - it("0030: adds dataset 3 as Admin Ingestor", async () => { - return request(appUrl) - .post("/api/v3/Datasets") - .send(dataset3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("ownerGroup").and.equal("group2"); - res.body.should.have.property("type").and.equal("raw"); - res.body.should.have.property("isPublished").and.equal(false); - res.body.should.have.property("pid").and.be.string; - datasetPid3 = res.body["pid"]; - encodedDatasetPid3 = encodeURIComponent(datasetPid3); - }); - }); - - it("0040: adds a new origDatablock on the published dataset as Admin Ingestor", async () => { - return request(appUrl) - .post(`/api/v3/datasets/${encodedDatasetPid1}/origdatablocks`) - .send(TestData.OrigDataBlockCorrect1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have - .property("size") - .and.equal(TestData.OrigDataBlockCorrect1.size); - res.body.should.have.property("id").and.be.string; - }); - }); - - it("0050: adds a new datablock on the published dataset as Admin Ingestor", async () => { - const randomArchiveId = Math.random().toString(36).slice(2); - - return request(appUrl) - .post(`/api/v3/datasets/${encodedDatasetPid1}/datablocks`) - .send({ ...TestData.DataBlockCorrect, archiveId: randomArchiveId }) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have - .property("size") - .and.equal(TestData.DataBlockCorrect.size); - res.body.should.have.property("id").and.be.string; - }); - }); - - it("0060: adds a new attachment on the published dataset as Admin Ingestor", async () => { - return request(appUrl) - .post(`/api/v3/datasets/${encodedDatasetPid1}/attachments`) - .send(TestData.AttachmentCorrect) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/); - }); - - it("0070: list of public datasets, aka as unauthenticated user", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - res.body[0]["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0080: access public dataset as unauthenticated user", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0090: access private dataset as unauthenticated user", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .expect("Content-Type", /json/) - .expect(TestData.AccessForbiddenStatusCode); - }); - - it("0100: list of datasets for Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(3); - }); - }); - - it("0110: datasets counts for Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/count") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body["count"].should.be.equal(3); - }); - }); - - it("0120: access dataset 1 as Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0130: full query for datasets for Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/fullquery") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(3); - }); - }); - - it("0140: access dataset 2 as Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0150: access dataset 3 as Admin Ingestor", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0160: list of datasets for User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(2); - res.body[1]["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0170: datasets count for User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets/count") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body["count"].should.be.equal(2); - }); - }); - - it("0180: access dataset 1 as User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0190: access dataset 2 as User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0200: access dataset 3 as User 1, which should fail as forbidden", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect("Content-Type", /json/) - .expect(TestData.AccessForbiddenStatusCode); - }); - - it("0210: full query for datasets for User 1", async () => { - return request(appUrl) - .get("/api/v3/Datasets/fullquery") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - res.body[0]["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0220: list of datasets for User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(2); - res.body[1]["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0230: datasets count for User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets/count") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body["count"].should.be.equal(2); - }); - }); - - it("0240: access dataset 1 as User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0250: access dataset 2 as User 2, which should fail as forbidden", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect("Content-Type", /json/) - .expect(TestData.AccessForbiddenStatusCode); - }); - - it("0260: access dataset 3 as User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0270: full query for datasets for User 2", async () => { - return request(appUrl) - .get("/api/v3/Datasets/fullquery") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - res.body[0]["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0280: list of datasets for User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(3); - }); - }); - - it("0290: datasets count for User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/count") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body["count"].should.be.equal(3); - }); - }); - - it("0300: access dataset 1 as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid1); - }); - }); - - it("0310: access dataset 2 as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid2); - }); - }); - - it("0320: access dataset 3 as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body["pid"].should.be.equal(datasetPid3); - }); - }); - - it("0330: full query for datasets for User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/fullquery") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(2); - }); - }); - - it("0340: update dataset 2 to be published as Admin Ingestor", async () => { - return request(appUrl) - .patch(`/api/v3/Datasets/${encodedDatasetPid2}`) - .send({ isPublished: true }) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.SuccessfulPatchStatusCode) - .expect("Content-Type", /json/); - }); - - it("0350: full query for datasets for User 2", async () => { - const fields = { - isPublished: true, - }; - - return request(appUrl) - .get( - `/api/v3/Datasets/fullquery?fields=${encodeURIComponent( - JSON.stringify(fields), - )}`, - ) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(2); - }); - }); - - it("0360: full facet for datasets for User 2", async () => { - const fields = { - isPublished: true, - }; - return request(appUrl) - .get( - `/api/v3/Datasets/fullfacet?fields=${encodeURIComponent( - JSON.stringify(fields), - )}`, - ) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.SuccessfulGetStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body[0].all[0].totalSets.should.be.equal(2); - }); - }); - - it("0370: access dataset 1 origdatablocks as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/origdatablocks") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - }); - }); - - it("0380: access dataset 1 datablocks as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/datablocks") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - }); - }); - - it("0390: access dataset 1 attachments as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/attachments") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode) - .then((res) => { - res.body.should.be.an("array").to.have.lengthOf(1); - }); - }); - - it("0400: access dataset 1 thumbnail as User 3", async () => { - return request(appUrl) - .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/thumbnail") - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect("Content-Type", /json/) - .expect(TestData.SuccessfulGetStatusCode); - }); - - it("0410: should delete dataset 1 as Archive Manager", async () => { - return request(appUrl) - .delete("/api/v3/datasets/" + encodedDatasetPid1) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - .expect(TestData.SuccessfulDeleteStatusCode) - .expect("Content-Type", /json/); - }); - - it("0420: should delete dataset 2 as Archive Manager", async () => { - return request(appUrl) - .delete("/api/v3/datasets/" + encodedDatasetPid2) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - .expect(TestData.SuccessfulDeleteStatusCode) - .expect("Content-Type", /json/); - }); - - it("0430: should delete dataset 3 as Archive Manager", async () => { - return request(appUrl) - .delete("/api/v3/datasets/" + encodedDatasetPid3) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - .expect(TestData.SuccessfulDeleteStatusCode) - .expect("Content-Type", /json/); - }); - - it("0500: add a new raw dataset as Admin", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0501: add a new incomplete raw dataset as Admin, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0502: add a new raw dataset with specified pid as Admin", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "admin", - }; - console.log("0502: pid : " + datasetWithPid["pid"]); - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0503: add a new raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0504: add a new invalid raw dataset with specified pid as Admin, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: uuidv4(), - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0505: add a new invalid raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "admin", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0510: add a new raw dataset with different owner group as Admin", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0520: add a new incomplete raw dataset with different owner group as Admin, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0530: add a new raw dataset with specified pid and different owner group as Admin", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0540: add a new raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0550: add a new invalid raw dataset with specified pid and different owner group as Admin, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0560: add a new invalid raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0600: add a new raw dataset as User 1 which belongs to a create dataset group", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0601: add a new incomplete raw dataset as User 1 which belongs to a create dataset group", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0602: add a new raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0603: add a new raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0604: add a new invalid raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0605: add a new invalid raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0610: add a new raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0620: add a new incomplete raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0630: add a new raw dataset with specified pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0640: add a new raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0650: add a new invalid raw dataset with specified pid and different owner group as User 1 which belongs to a ", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0660: add a new invalid raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser1}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0700: add a new raw dataset as User 2 which belongs to a create dataset with pid group", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0701: add a new incomplete raw dataset as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0702: add a new raw dataset with specified pid as User 2 which belongs to a create dataset with pid group", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0703: add a new raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0704: add a new invalid raw dataset with specified pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0705: add a new invalid raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group2", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0710: add a new raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0720: add a new incomplete raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0730: add a new raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0740: add a new raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.CreationForbiddenStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0750: add a new invalid raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0760: add a new invalid raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser2}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0800: add a new raw dataset as User 3 which belongs to a create dataset privileged group", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0801: add a new incomplete raw dataset as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0802: add a new raw dataset with specified pid as User 3 which belongs to a create dataset privileged group", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0803: add a new raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0804: add a new invalid raw dataset with specified pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0805: add a new invalid raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group3", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0810: add a new raw dataset with different owner group as User 3 which belongs to a create dataset privileged group", async () => { - const newDataset = { - ...TestData.RawCorrect, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.be.string; - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0820: add a new incomplete raw dataset with different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const newDataset = { - ...TestData.RawWrong_1, - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(newDataset) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0830: add a new raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.EntryCreatedStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - res.body.should.have.property("owner").and.be.string; - res.body.should.have.property("type").and.equal("raw"); - }); - }); - - it("0840: add a new raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const datasetWithPid = { - ...TestData.RawCorrect, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(datasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0850: add a new invalid raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const invalidDatasetWithPid = { - ...TestData.RawWrong_1, - pid: TestData.PidPrefix + "/" + uuidv4(), - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); - - it("0860: add a new invalid raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - const invalidDatasetWithInvalidPid = { - ...TestData.RawWrong_1, - pid: "this-is-invalid-pid-1", - ownerGroup: "group1", - }; - - return request(appUrl) - .post("/api/v3/Datasets") - .send(invalidDatasetWithInvalidPid) - .set("Accept", "application/json") - .set({ Authorization: `Bearer ${accessTokenUser3}` }) - .expect(TestData.BadRequestStatusCode) - .expect("Content-Type", /json/) - .then((res) => { - res.body.should.not.have.property("pid"); - }); - }); + // it("0020: adds dataset 2 as Admin Ingestor", async () => { + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(dataset2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("ownerGroup").and.equal("group1"); + // res.body.should.have.property("type").and.equal("raw"); + // res.body.should.have.property("isPublished").and.equal(false); + // res.body.should.have.property("pid").and.be.string; + // datasetPid2 = res.body["pid"]; + // encodedDatasetPid2 = encodeURIComponent(datasetPid2); + // }); + // }); + + // it("0030: adds dataset 3 as Admin Ingestor", async () => { + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(dataset3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("ownerGroup").and.equal("group2"); + // res.body.should.have.property("type").and.equal("raw"); + // res.body.should.have.property("isPublished").and.equal(false); + // res.body.should.have.property("pid").and.be.string; + // datasetPid3 = res.body["pid"]; + // encodedDatasetPid3 = encodeURIComponent(datasetPid3); + // }); + // }); + + // it("0040: adds a new origDatablock on the published dataset as Admin Ingestor", async () => { + // return request(appUrl) + // .post(`/api/v3/datasets/${encodedDatasetPid1}/origdatablocks`) + // .send(TestData.OrigDataBlockCorrect1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have + // .property("size") + // .and.equal(TestData.OrigDataBlockCorrect1.size); + // res.body.should.have.property("id").and.be.string; + // }); + // }); + + // it("0050: adds a new datablock on the published dataset as Admin Ingestor", async () => { + // const randomArchiveId = Math.random().toString(36).slice(2); + + // return request(appUrl) + // .post(`/api/v3/datasets/${encodedDatasetPid1}/datablocks`) + // .send({ ...TestData.DataBlockCorrect, archiveId: randomArchiveId }) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have + // .property("size") + // .and.equal(TestData.DataBlockCorrect.size); + // res.body.should.have.property("id").and.be.string; + // }); + // }); + + // it("0060: adds a new attachment on the published dataset as Admin Ingestor", async () => { + // return request(appUrl) + // .post(`/api/v3/datasets/${encodedDatasetPid1}/attachments`) + // .send(TestData.AttachmentCorrect) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0070: list of public datasets, aka as unauthenticated user", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // res.body[0]["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0080: access public dataset as unauthenticated user", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0090: access private dataset as unauthenticated user", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .expect("Content-Type", /json/) + // .expect(TestData.AccessForbiddenStatusCode); + // }); + + // it("0100: list of datasets for Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(3); + // }); + // }); + + // it("0110: datasets counts for Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/count") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body["count"].should.be.equal(3); + // }); + // }); + + // it("0120: access dataset 1 as Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0130: full query for datasets for Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/fullquery") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(3); + // }); + // }); + + // it("0140: access dataset 2 as Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0150: access dataset 3 as Admin Ingestor", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0160: list of datasets for User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(2); + // res.body[1]["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0170: datasets count for User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/count") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body["count"].should.be.equal(2); + // }); + // }); + + // it("0180: access dataset 1 as User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0190: access dataset 2 as User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0200: access dataset 3 as User 1, which should fail as forbidden", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.AccessForbiddenStatusCode); + // }); + + // it("0210: full query for datasets for User 1", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/fullquery") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // res.body[0]["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0220: list of datasets for User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(2); + // res.body[1]["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0230: datasets count for User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/count") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body["count"].should.be.equal(2); + // }); + // }); + + // it("0240: access dataset 1 as User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0250: access dataset 2 as User 2, which should fail as forbidden", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.AccessForbiddenStatusCode); + // }); + + // it("0260: access dataset 3 as User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0270: full query for datasets for User 2", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/fullquery") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // res.body[0]["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0280: list of datasets for User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(3); + // }); + // }); + + // it("0290: datasets count for User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/count") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body["count"].should.be.equal(3); + // }); + // }); + + // it("0300: access dataset 1 as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid1); + // }); + // }); + + // it("0310: access dataset 2 as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid2); + // }); + // }); + + // it("0320: access dataset 3 as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body["pid"].should.be.equal(datasetPid3); + // }); + // }); + + // it("0330: full query for datasets for User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/fullquery") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(2); + // }); + // }); + + // it("0340: update dataset 2 to be published as Admin Ingestor", async () => { + // return request(appUrl) + // .patch(`/api/v3/Datasets/${encodedDatasetPid2}`) + // .send({ isPublished: true }) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + // .expect(TestData.SuccessfulPatchStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0350: full query for datasets for User 2", async () => { + // const fields = { + // isPublished: true, + // }; + + // return request(appUrl) + // .get( + // `/api/v3/Datasets/fullquery?fields=${encodeURIComponent( + // JSON.stringify(fields), + // )}`, + // ) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(2); + // }); + // }); + + // it("0360: full facet for datasets for User 2", async () => { + // const fields = { + // isPublished: true, + // }; + // return request(appUrl) + // .get( + // `/api/v3/Datasets/fullfacet?fields=${encodeURIComponent( + // JSON.stringify(fields), + // )}`, + // ) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.SuccessfulGetStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body[0].all[0].totalSets.should.be.equal(2); + // }); + // }); + + // it("0370: access dataset 1 origdatablocks as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/origdatablocks") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // }); + // }); + + // it("0380: access dataset 1 datablocks as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/datablocks") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // }); + // }); + + // it("0390: access dataset 1 attachments as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/attachments") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode) + // .then((res) => { + // res.body.should.be.an("array").to.have.lengthOf(1); + // }); + // }); + + // it("0400: access dataset 1 thumbnail as User 3", async () => { + // return request(appUrl) + // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/thumbnail") + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect("Content-Type", /json/) + // .expect(TestData.SuccessfulGetStatusCode); + // }); + + // it("0410: should delete dataset 1 as Archive Manager", async () => { + // return request(appUrl) + // .delete("/api/v3/datasets/" + encodedDatasetPid1) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + // .expect(TestData.SuccessfulDeleteStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0420: should delete dataset 2 as Archive Manager", async () => { + // return request(appUrl) + // .delete("/api/v3/datasets/" + encodedDatasetPid2) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + // .expect(TestData.SuccessfulDeleteStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0430: should delete dataset 3 as Archive Manager", async () => { + // return request(appUrl) + // .delete("/api/v3/datasets/" + encodedDatasetPid3) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + // .expect(TestData.SuccessfulDeleteStatusCode) + // .expect("Content-Type", /json/); + // }); + + // it("0500: add a new raw dataset as Admin", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0501: add a new incomplete raw dataset as Admin, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0502: add a new raw dataset with specified pid as Admin", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "admin", + // }; + // console.log("0502: pid : " + datasetWithPid["pid"]); + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0503: add a new raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0504: add a new invalid raw dataset with specified pid as Admin, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: uuidv4(), + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0505: add a new invalid raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "admin", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0510: add a new raw dataset with different owner group as Admin", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0520: add a new incomplete raw dataset with different owner group as Admin, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0530: add a new raw dataset with specified pid and different owner group as Admin", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0540: add a new raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0550: add a new invalid raw dataset with specified pid and different owner group as Admin, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0560: add a new invalid raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0600: add a new raw dataset as User 1 which belongs to a create dataset group", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0601: add a new incomplete raw dataset as User 1 which belongs to a create dataset group", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0602: add a new raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0603: add a new raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0604: add a new invalid raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0605: add a new invalid raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0610: add a new raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0620: add a new incomplete raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0630: add a new raw dataset with specified pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0640: add a new raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0650: add a new invalid raw dataset with specified pid and different owner group as User 1 which belongs to a ", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0660: add a new invalid raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser1}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0700: add a new raw dataset as User 2 which belongs to a create dataset with pid group", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0701: add a new incomplete raw dataset as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0702: add a new raw dataset with specified pid as User 2 which belongs to a create dataset with pid group", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0703: add a new raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0704: add a new invalid raw dataset with specified pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0705: add a new invalid raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group2", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0710: add a new raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0720: add a new incomplete raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0730: add a new raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0740: add a new raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.CreationForbiddenStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0750: add a new invalid raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0760: add a new invalid raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser2}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0800: add a new raw dataset as User 3 which belongs to a create dataset privileged group", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0801: add a new incomplete raw dataset as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0802: add a new raw dataset with specified pid as User 3 which belongs to a create dataset privileged group", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0803: add a new raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0804: add a new invalid raw dataset with specified pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0805: add a new invalid raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group3", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0810: add a new raw dataset with different owner group as User 3 which belongs to a create dataset privileged group", async () => { + // const newDataset = { + // ...TestData.RawCorrect, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.be.string; + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0820: add a new incomplete raw dataset with different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const newDataset = { + // ...TestData.RawWrong_1, + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(newDataset) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0830: add a new raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.EntryCreatedStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + // res.body.should.have.property("owner").and.be.string; + // res.body.should.have.property("type").and.equal("raw"); + // }); + // }); + + // it("0840: add a new raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const datasetWithPid = { + // ...TestData.RawCorrect, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(datasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0850: add a new invalid raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const invalidDatasetWithPid = { + // ...TestData.RawWrong_1, + // pid: TestData.PidPrefix + "/" + uuidv4(), + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); + + // it("0860: add a new invalid raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + // const invalidDatasetWithInvalidPid = { + // ...TestData.RawWrong_1, + // pid: "this-is-invalid-pid-1", + // ownerGroup: "group1", + // }; + + // return request(appUrl) + // .post("/api/v3/Datasets") + // .send(invalidDatasetWithInvalidPid) + // .set("Accept", "application/json") + // .set({ Authorization: `Bearer ${accessTokenUser3}` }) + // .expect(TestData.BadRequestStatusCode) + // .expect("Content-Type", /json/) + // .then((res) => { + // res.body.should.not.have.property("pid"); + // }); + // }); }); From c6d59fb04ed0fc05066b90a53f93c51fdb49c333 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 11 Sep 2024 15:01:03 +0200 Subject: [PATCH 13/38] fix types on obsolete schemas --- src/datasets/datasets.controller.ts | 54 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 89e6f7536..19c480a9d 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -632,14 +632,14 @@ export class DatasetsController { ); const dtoTestRawCorrect = plainToInstance( - CreateRawDatasetDto, - createDatasetDto, + CreateRawDatasetObsoleteDto, + createDatasetObsoleteDto, ); const errorsTestRawCorrect = await validate(dtoTestRawCorrect); const dtoTestDerivedCorrect = plainToInstance( - CreateDerivedDatasetDto, - createDatasetDto, + CreateDerivedDatasetObsoleteDto, + createDatasetObsoleteDto, ); const errorsTestDerivedCorrect = await validate(dtoTestDerivedCorrect); @@ -1109,7 +1109,7 @@ export class DatasetsController { @Req() request: Request, @Param("pid") id: string, ): Promise { - const dataset = await this.checkPermissionsForDataset(request, id); + const dataset = await this.checkPermissionsForDatasetObsolete(request, id); return dataset; } @@ -1137,15 +1137,18 @@ export class DatasetsController { description: "Id of the dataset to modify", type: String, }) - @ApiExtraModels(PartialUpdateRawDatasetDto, PartialUpdateDerivedDatasetDto) + @ApiExtraModels( + PartialUpdateRawDatasetObsoleteDto, + PartialUpdateDerivedDatasetObsoleteDto, + ) @ApiBody({ description: "Fields that needs to be updated in the dataset. Only the fields that needs to be updated have to be passed in.", required: true, schema: { oneOf: [ - { $ref: getSchemaPath(PartialUpdateRawDatasetDto) }, - { $ref: getSchemaPath(PartialUpdateDerivedDatasetDto) }, + { $ref: getSchemaPath(PartialUpdateRawDatasetObsoleteDto) }, + { $ref: getSchemaPath(PartialUpdateDerivedDatasetObsoleteDto) }, ], }, }) @@ -1160,8 +1163,8 @@ export class DatasetsController { @Param("pid") pid: string, @Body() updateDatasetDto: - | PartialUpdateRawDatasetDto - | PartialUpdateDerivedDatasetDto, + | PartialUpdateRawDatasetObsoleteDto + | PartialUpdateDerivedDatasetObsoleteDto, ): Promise { const foundDataset = await this.datasetsService.findOne({ where: { pid } }); @@ -1170,11 +1173,11 @@ export class DatasetsController { } // NOTE: Default validation pipe does not validate union types. So we need custom validation. - await this.validateDataset( + await this.validateDatasetObsolete( updateDatasetDto, foundDataset.type === "raw" - ? PartialUpdateRawDatasetDto - : PartialUpdateDerivedDatasetDto, + ? PartialUpdateRawDatasetObsoleteDto + : PartialUpdateDerivedDatasetObsoleteDto, ); // NOTE: We need DatasetClass instance because casl module can not recognize the type from dataset mongo database model. If other fields are needed can be added later. @@ -1220,15 +1223,15 @@ export class DatasetsController { description: "Id of the dataset to modify", type: String, }) - @ApiExtraModels(UpdateRawDatasetDto, UpdateDerivedDatasetDto) + @ApiExtraModels(UpdateRawDatasetObsoleteDto, UpdateDerivedDatasetObsoleteDto) @ApiBody({ description: "Dataset object that needs to be updated. The whole dataset object with updated fields have to be passed in.", required: true, schema: { oneOf: [ - { $ref: getSchemaPath(UpdateRawDatasetDto) }, - { $ref: getSchemaPath(UpdateDerivedDatasetDto) }, + { $ref: getSchemaPath(UpdateRawDatasetObsoleteDto) }, + { $ref: getSchemaPath(UpdateDerivedDatasetObsoleteDto) }, ], }, }) @@ -1241,7 +1244,10 @@ export class DatasetsController { async findByIdAndReplace( @Req() request: Request, @Param("pid") pid: string, - @Body() updateDatasetDto: UpdateRawDatasetDto | UpdateDerivedDatasetDto, + @Body() + updateDatasetObsoleteDto: + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto, ): Promise { const foundDataset = await this.datasetsService.findOne({ where: { pid } }); @@ -1250,11 +1256,11 @@ export class DatasetsController { } // NOTE: Default validation pipe does not validate union types. So we need custom validation. - const outputDto = await this.validateDataset( - updateDatasetDto, + const outputDto = await this.validateDatasetObsolete( + updateDatasetObsoleteDto, foundDataset.type === "raw" - ? UpdateRawDatasetDto - : UpdateDerivedDatasetDto, + ? UpdateRawDatasetObsoleteDto + : UpdateDerivedDatasetObsoleteDto, ); const datasetInstance = @@ -1274,7 +1280,9 @@ export class DatasetsController { return this.datasetsService.findByIdAndReplace( pid, - outputDto as UpdateRawDatasetDto | UpdateDerivedDatasetDto, + outputDto as + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto, ); } @@ -2172,7 +2180,7 @@ export class DatasetsController { Action.DatasetLogbookRead, ); - const proposalId = dataset?.proposalId; + const proposalId = (dataset?.proposalIds || [])[0]; if (!proposalId) return null; From 74a6c266cbde1c61eaa4c651059c496e6f01f20b Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 13 Sep 2024 15:56:54 +0200 Subject: [PATCH 14/38] updated to use latest dataset schema in service --- src/datasets/datasets.controller.ts | 125 +++++++++++++++++-------- src/datasets/datasets.service.ts | 47 ++++------ src/datasets/dto/update-dataset.dto.ts | 20 ++++ 3 files changed, 123 insertions(+), 69 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 19c480a9d..9071f6e53 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -100,6 +100,10 @@ import configuration from "src/config/configuration"; import { DatasetType } from "./dataset-type.enum"; import { OutputDatasetObsoleteDto } from "./dto/output-dataset-obsolete.dto"; import { CreateDatasetDto } from "./dto/create-dataset.dto"; +import { + PartialUpdateDatasetDto, + UpdateDatasetDto, +} from "./dto/update-dataset.dto"; @ApiBearerAuth() @ApiExtraModels( @@ -393,60 +397,98 @@ export class DatasetsController { } convertObsoleteToCurrentSchema( - inputDataset: CreateRawDatasetObsoleteDto | CreateDerivedDatasetObsoleteDto, - ): CreateDatasetDto { + inputObsoleteDataset: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | UpdateRawDatasetObsoleteDto + | UpdateDerivedDatasetObsoleteDto + | PartialUpdateRawDatasetObsoleteDto + | PartialUpdateDerivedDatasetObsoleteDto, + ): CreateDatasetDto | UpdateDatasetDto | PartialUpdateDatasetDto { const propertiesModifier: Record = {}; - if (inputDataset.type == "raw") { - if ("proposalId" in inputDataset) { + + if ( + inputObsoleteDataset instanceof CreateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof UpdateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof PartialUpdateRawDatasetObsoleteDto + ) { + if ("proposalId" in inputObsoleteDataset) { propertiesModifier.proposalIds = [ - (inputDataset as CreateRawDatasetObsoleteDto).proposalId, + (inputObsoleteDataset as CreateRawDatasetObsoleteDto).proposalId, ]; } - if ("sampleId" in inputDataset) { + if ("sampleId" in inputObsoleteDataset) { propertiesModifier.sampleIds = [ - (inputDataset as CreateRawDatasetObsoleteDto).sampleId, + (inputObsoleteDataset as CreateRawDatasetObsoleteDto).sampleId, ]; } - if ("instrumentIds" in inputDataset) { + if ("instrumentIds" in inputObsoleteDataset) { propertiesModifier.instrumentIds = [ - (inputDataset as CreateRawDatasetObsoleteDto).instrumentId, + (inputObsoleteDataset as CreateRawDatasetObsoleteDto).instrumentId, ]; } } else { - if ("investigator" in inputDataset) { + if ("investigator" in inputObsoleteDataset) { propertiesModifier.principalInvestigator = [ - (inputDataset as CreateDerivedDatasetObsoleteDto).investigator, + (inputObsoleteDataset as CreateDerivedDatasetObsoleteDto) + .investigator, ]; } } - const outputDataset: CreateDatasetDto = { - ...(inputDataset as CreateDatasetDto), - ...propertiesModifier, - }; + let outputDataset: + | CreateDatasetDto + | UpdateDatasetDto + | PartialUpdateDatasetDto = {}; + if ( + inputObsoleteDataset instanceof CreateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof CreateDerivedDatasetObsoleteDto + ) { + outputDataset = { + ...(inputObsoleteDataset as CreateDatasetDto), + ...propertiesModifier, + } as CreateDatasetDto; + } else if ( + inputObsoleteDataset instanceof UpdateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof UpdateDerivedDatasetObsoleteDto + ) { + outputDataset = { + ...(inputObsoleteDataset as UpdateDatasetDto), + ...propertiesModifier, + } as UpdateDatasetDto; + } else if ( + inputObsoleteDataset instanceof PartialUpdateRawDatasetObsoleteDto || + inputObsoleteDataset instanceof PartialUpdateDerivedDatasetObsoleteDto + ) { + outputDataset = { + ...(inputObsoleteDataset as PartialUpdateDatasetDto), + ...propertiesModifier, + } as PartialUpdateDatasetDto; + } return outputDataset; } convertCurrentToObsoleteSchema( - inputDataset: DatasetClass, + inputDataset: DatasetClass | null, ): OutputDatasetObsoleteDto { const propertiesModifier: Record = {}; - if ("proposalIds" in inputDataset) { - propertiesModifier.proposalIds = inputDataset.proposalIds![0]; - } - if ("sampleIds" in inputDataset) { - propertiesModifier.sampleIds = inputDataset.sampleIds![0]; - } - if ("instrumentIds" in inputDataset) { - propertiesModifier.instrumentIds = inputDataset.instrumentIds![0]; - } - if (inputDataset.type == "raw") { - if ("investigator" in inputDataset) { - propertiesModifier.investigator = inputDataset.principalInvestigator; + if (inputDataset) { + if ("proposalIds" in inputDataset) { + propertiesModifier.proposalIds = inputDataset.proposalIds![0]; + } + if ("sampleIds" in inputDataset) { + propertiesModifier.sampleIds = inputDataset.sampleIds![0]; + } + if ("instrumentIds" in inputDataset) { + propertiesModifier.instrumentIds = inputDataset.instrumentIds![0]; + } + if (inputDataset.type == "raw") { + if ("investigator" in inputDataset) { + propertiesModifier.investigator = inputDataset.principalInvestigator; + } } } - const outputDataset: OutputDatasetObsoleteDto = { ...(inputDataset as OutputDatasetObsoleteDto), ...propertiesModifier, @@ -509,8 +551,9 @@ export class DatasetsController { ); try { - const datasetDto = - this.convertObsoleteToCurrentSchema(obsoleteDatasetDto); + const datasetDto = this.convertObsoleteToCurrentSchema( + obsoleteDatasetDto, + ) as CreateDatasetDto; const createdDataset = await this.datasetsService.create(datasetDto); const outputObsoleteDatasetDto = @@ -772,7 +815,7 @@ export class DatasetsController { async fullquery( @Req() request: Request, @Query() filters: { fields?: string; limits?: string }, - ): Promise { + ): Promise { const user: JWTUser = request.user as JWTUser; const fields: IDatasetFields = JSON.parse(filters.fields ?? "{}"); @@ -809,7 +852,9 @@ export class DatasetsController { limits: JSON.parse(filters.limits ?? "{}"), }; - return this.datasetsService.fullquery(parsedFilters); + const results = await this.datasetsService.fullquery(parsedFilters); + + return results as OutputDatasetObsoleteDto[]; } // GET /fullfacets @@ -1108,10 +1153,12 @@ export class DatasetsController { async findById( @Req() request: Request, @Param("pid") id: string, - ): Promise { - const dataset = await this.checkPermissionsForDatasetObsolete(request, id); + ): Promise { + const dataset = this.convertCurrentToObsoleteSchema( + await this.checkPermissionsForDatasetObsolete(request, id), + ); - return dataset; + return dataset as OutputDatasetObsoleteDto; } // PATCH /datasets/:id @@ -1165,7 +1212,7 @@ export class DatasetsController { updateDatasetDto: | PartialUpdateRawDatasetObsoleteDto | PartialUpdateDerivedDatasetObsoleteDto, - ): Promise { + ): Promise { const foundDataset = await this.datasetsService.findOne({ where: { pid } }); if (!foundDataset) { @@ -1196,7 +1243,9 @@ export class DatasetsController { throw new ForbiddenException("Unauthorized to update this dataset"); } - return this.datasetsService.findByIdAndUpdate(pid, updateDatasetDto); + return this.convertCurrentToObsoleteSchema( + await this.datasetsService.findByIdAndUpdate(pid, updateDatasetDto), + ); } // PUT /datasets/:id diff --git a/src/datasets/datasets.service.ts b/src/datasets/datasets.service.ts index 60793750d..723552172 100644 --- a/src/datasets/datasets.service.ts +++ b/src/datasets/datasets.service.ts @@ -25,20 +25,13 @@ import { InitialDatasetsService } from "src/initial-datasets/initial-datasets.se import { LogbooksService } from "src/logbooks/logbooks.service"; import { DatasetType } from "./dataset-type.enum"; import { CreateDatasetDto } from "./dto/create-dataset.dto"; -import { - PartialUpdateDatasetObsoleteDto, - UpdateDatasetObsoleteDto, -} from "./dto/update-dataset-obsolete.dto"; -import { - PartialUpdateDerivedDatasetDto, - UpdateDerivedDatasetDto, -} from "./dto/update-derived-dataset-obsolete.dto"; -import { - PartialUpdateRawDatasetDto, - UpdateRawDatasetDto, -} from "./dto/update-raw-dataset-obsolete.dto"; import { IDatasetFields } from "./interfaces/dataset-filters.interface"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; +import { + PartialUpdateDatasetDto, + PartialUpdateDatasetWithHistoryDto, + UpdateDatasetDto, +} from "./dto/update-dataset.dto"; @Injectable({ scope: Scope.REQUEST }) export class DatasetsService { @@ -205,10 +198,7 @@ export class DatasetsService { // we update the full dataset if exist or create a new one if it does not async findByIdAndReplace( id: string, - updateDatasetDto: - | UpdateDatasetObsoleteDto - | UpdateRawDatasetDto - | UpdateDerivedDatasetDto, + updateDatasetDto: UpdateDatasetDto, ): Promise { const username = (this.request.user as JWTUser).username; const existingDataset = await this.datasetModel.findOne({ pid: id }).exec(); @@ -252,10 +242,8 @@ export class DatasetsService { async findByIdAndUpdate( id: string, updateDatasetDto: - | PartialUpdateDatasetObsoleteDto - | PartialUpdateRawDatasetDto - | PartialUpdateDerivedDatasetDto - | UpdateQuery, + | PartialUpdateDatasetDto + | PartialUpdateDatasetWithHistoryDto, ): Promise { const existingDataset = await this.datasetModel.findOne({ pid: id }).exec(); // check if we were able to find the dataset @@ -434,7 +422,7 @@ export class DatasetsService { async updateHistory( req: Request, dataset: DatasetClass, - data: UpdateDatasetObsoleteDto, + data: PartialUpdateDatasetDto, ) { if (req.body.history) { delete req.body.history; @@ -442,17 +430,17 @@ export class DatasetsService { if (!req.body.size && !req.body.packedSize) { const updatedFields: Omit< - UpdateDatasetObsoleteDto, + PartialUpdateDatasetDto, "updatedAt" | "updatedBy" > = data; const historyItem: Record = {}; Object.keys(updatedFields).forEach((updatedField) => { - historyItem[updatedField as keyof UpdateDatasetObsoleteDto] = { - currentValue: data[updatedField as keyof UpdateDatasetObsoleteDto], + historyItem[updatedField as keyof UpdateDatasetDto] = { + currentValue: data[updatedField as keyof UpdateDatasetDto], previousValue: dataset[ updatedField as keyof Omit< - UpdateDatasetObsoleteDto, + UpdateDatasetDto, "attachments" | "origdatablocks" | "datablocks" > ], @@ -468,18 +456,15 @@ export class DatasetsService { if (logbookEnabled) { const user = (req.user as JWTUser).username.replace("ldap.", ""); const datasetPid = dataset.pid; - const proposalId = - dataset.type === DatasetType.Raw - ? (dataset as unknown as DatasetClass).proposalId - : undefined; - if (proposalId) { + const proposalIds = dataset.proposalIds || []; + (proposalIds as Array).forEach(async (proposalId) => { await Promise.all( Object.keys(updatedFields).map(async (updatedField) => { const message = `${user} updated "${updatedField}" of dataset with PID ${datasetPid}`; await this.logbooksService.sendMessage(proposalId, { message }); }), ); - } + }); } } } diff --git a/src/datasets/dto/update-dataset.dto.ts b/src/datasets/dto/update-dataset.dto.ts index ad928772f..26866705d 100644 --- a/src/datasets/dto/update-dataset.dto.ts +++ b/src/datasets/dto/update-dataset.dto.ts @@ -24,6 +24,7 @@ import { CreateTechniqueDto } from "./create-technique.dto"; import { RelationshipClass } from "../schemas/relationship.schema"; import { CreateRelationshipDto } from "./create-relationship.dto"; import { LifecycleClass } from "../schemas/lifecycle.schema"; +import { HistoryClass } from "../schemas/history.schema"; @ApiTags("datasets") export class UpdateDatasetDto extends OwnableDto { @@ -420,3 +421,22 @@ export class UpdateDatasetDto extends OwnableDto { } export class PartialUpdateDatasetDto extends PartialType(UpdateDatasetDto) {} + +export class UpdateDatasetWithHistoryDto extends UpdateDatasetDto { + @ApiProperty({ + type: "array", + items: { $ref: getSchemaPath(HistoryClass) }, + required: false, + default: [], + description: "List of history objects containing old and new values.", + }) + @IsArray() + @IsOptional() + @ValidateNested({ each: true }) + @Type(() => HistoryClass) + readonly history?: HistoryClass[]; +} + +export class PartialUpdateDatasetWithHistoryDto extends PartialType( + UpdateDatasetWithHistoryDto, +) {} From 15b2740fbbcb1daa95f9bd93f724e40cb17c7484 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 13 Sep 2024 16:04:08 +0200 Subject: [PATCH 15/38] refactoring data types --- src/datasets/datasets.controller.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 9071f6e53..575adc98b 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -1297,7 +1297,7 @@ export class DatasetsController { updateDatasetObsoleteDto: | UpdateRawDatasetObsoleteDto | UpdateDerivedDatasetObsoleteDto, - ): Promise { + ): Promise { const foundDataset = await this.datasetsService.findOne({ where: { pid } }); if (!foundDataset) { @@ -1305,7 +1305,7 @@ export class DatasetsController { } // NOTE: Default validation pipe does not validate union types. So we need custom validation. - const outputDto = await this.validateDatasetObsolete( + const updateValidatedDto = await this.validateDatasetObsolete( updateDatasetObsoleteDto, foundDataset.type === "raw" ? UpdateRawDatasetObsoleteDto @@ -1327,12 +1327,15 @@ export class DatasetsController { throw new ForbiddenException("Unauthorized to update this dataset"); } - return this.datasetsService.findByIdAndReplace( + const updateDatasetDto = + await this.convertObsoleteToCurrentSchema(updateValidatedDto); + + const outputDatasetDto = await this.datasetsService.findByIdAndReplace( pid, - outputDto as - | UpdateRawDatasetObsoleteDto - | UpdateDerivedDatasetObsoleteDto, + updateDatasetDto as UpdateDatasetDto, ); + + return await this.convertCurrentToObsoleteSchema(outputDatasetDto); } // DELETE /datasets/:id From 2244c18663facd6835d5350b39422587cff042b0 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Mon, 16 Sep 2024 14:31:38 +0200 Subject: [PATCH 16/38] First two dataset test passing --- src/datasets/datasets.controller.ts | 27 +++++++++----- src/datasets/schemas/dataset.schema.ts | 6 +-- .../origdatablocks.controller.ts | 9 +++-- .../published-data.controller.ts | 8 +++- test/DatasetAuthorization.js | 37 +++++++++---------- 5 files changed, 50 insertions(+), 37 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 575adc98b..9e1430701 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -61,7 +61,7 @@ import { DatablocksService } from "src/datablocks/datablocks.service"; import { Datablock } from "src/datablocks/schemas/datablock.schema"; import { CreateDatablockDto } from "src/datablocks/dto/create-datablock.dto"; import { PartialUpdateDatablockDto } from "src/datablocks/dto/update-datablock.dto"; -import { UpdateQuery } from "mongoose"; +import { Document, UpdateQuery } from "mongoose"; import { FilterPipe } from "src/common/pipes/filter.pipe"; import { UTCTimeInterceptor } from "src/common/interceptors/utc-time.interceptor"; import { DataFile } from "src/common/schemas/datafile.schema"; @@ -405,7 +405,9 @@ export class DatasetsController { | PartialUpdateRawDatasetObsoleteDto | PartialUpdateDerivedDatasetObsoleteDto, ): CreateDatasetDto | UpdateDatasetDto | PartialUpdateDatasetDto { - const propertiesModifier: Record = {}; + const propertiesModifier: Record = { + version: "v3", + }; if ( inputObsoleteDataset instanceof CreateRawDatasetObsoleteDto || @@ -489,8 +491,9 @@ export class DatasetsController { } } } + const outputDataset: OutputDatasetObsoleteDto = { - ...(inputDataset as OutputDatasetObsoleteDto), + ...(inputDataset as DatasetDocument).toObject(), ...propertiesModifier, }; @@ -537,17 +540,17 @@ export class DatasetsController { | CreateDerivedDatasetObsoleteDto, ): Promise { // validate dataset - await this.validateDatasetObsolete( + const validatedDatasetObsoleteDto = (await this.validateDatasetObsolete( createDatasetObsoleteDto, createDatasetObsoleteDto.type === "raw" ? CreateRawDatasetObsoleteDto : CreateDerivedDatasetObsoleteDto, - ); + )) as CreateRawDatasetObsoleteDto | CreateDerivedDatasetObsoleteDto; const obsoleteDatasetDto = await this.checkPermissionsForObsoleteDatasetCreate( request, - createDatasetObsoleteDto, + validatedDatasetObsoleteDto, ); try { @@ -598,11 +601,18 @@ export class DatasetsController { }, }; + // first we convert input object to the correct class + const outputDatasetDto = plainToInstance(dto, inputDatasetDto); + if ( - inputDatasetDto instanceof + outputDatasetDto instanceof (CreateRawDatasetObsoleteDto || CreateDerivedDatasetObsoleteDto) ) { - if (!(inputDatasetDto.type in DatasetType)) { + if ( + !(Object.values(DatasetType) as string[]).includes( + outputDatasetDto.type, + ) + ) { throw new HttpException( { status: HttpStatus.BAD_REQUEST, @@ -613,7 +623,6 @@ export class DatasetsController { } } - const outputDatasetDto = plainToInstance(dto, inputDatasetDto); const errors = await validate(outputDatasetDto, validateOptions); if (errors.length > 0) { diff --git a/src/datasets/schemas/dataset.schema.ts b/src/datasets/schemas/dataset.schema.ts index 58fdcd1e4..9b3d7f7e2 100644 --- a/src/datasets/schemas/dataset.schema.ts +++ b/src/datasets/schemas/dataset.schema.ts @@ -449,13 +449,13 @@ export class DatasetClass extends OwnableClass { dataFormat?: string; @ApiProperty({ - type: String, + type: [String], required: false, description: "The ID of the proposal to which the dataset belongs to and it has been acquired under.", }) - @Prop({ type: String, ref: "Proposal", required: false }) - proposalIds?: string; + @Prop({ type: [String], ref: "Proposal", required: false }) + proposalIds?: string[]; @ApiProperty({ type: [String], diff --git a/src/origdatablocks/origdatablocks.controller.ts b/src/origdatablocks/origdatablocks.controller.ts index 308eb32e9..97e21d50b 100644 --- a/src/origdatablocks/origdatablocks.controller.ts +++ b/src/origdatablocks/origdatablocks.controller.ts @@ -45,8 +45,8 @@ import { PartialUpdateDatasetDto } from "src/datasets/dto/update-dataset.dto"; import { filterDescription, filterExample } from "src/common/utils"; import { JWTUser } from "src/auth/interfaces/jwt-user.interface"; import { DatasetClass } from "src/datasets/schemas/dataset.schema"; -import { CreateRawDatasetDto } from "src/datasets/dto/create-raw-dataset-obsolete.dto"; -import { CreateDerivedDatasetDto } from "src/datasets/dto/create-derived-dataset-obsolete.dto"; +import { CreateRawDatasetObsoleteDto } from "src/datasets/dto/create-raw-dataset-obsolete.dto"; +import { CreateDerivedDatasetObsoleteDto } from "src/datasets/dto/create-derived-dataset-obsolete.dto"; import { logger } from "@user-office-software/duo-logger"; @ApiBearerAuth() @@ -103,7 +103,10 @@ export class OrigDatablocksController { // } async generateOrigDatablockInstanceInstanceForPermissions( - dataset: CreateRawDatasetDto | CreateDerivedDatasetDto | DatasetClass, + dataset: + | CreateRawDatasetObsoleteDto + | CreateDerivedDatasetObsoleteDto + | DatasetClass, ): Promise { const origDatablockInstance = new OrigDatablock(); origDatablockInstance.datasetId = dataset.pid || ""; diff --git a/src/published-data/published-data.controller.ts b/src/published-data/published-data.controller.ts index 3d8199c7d..0786e9a53 100644 --- a/src/published-data/published-data.controller.ts +++ b/src/published-data/published-data.controller.ts @@ -166,13 +166,17 @@ export class PublishedDataController { }) async formPopulate(@Query("pid") pid: string) { const formData: IFormPopulateData = {}; - const dataset = await this.datasetsService.findOne({ where: { pid } }); + const dataset = (await this.datasetsService.findOne({ + where: { pid }, + })) as unknown as DatasetClass; let proposalId; if (dataset) { formData.resourceType = dataset.type; formData.description = dataset.description; - proposalId = (dataset as unknown as DatasetClass).proposalId; + if ("proposalIds" in dataset) { + proposalId = dataset.proposalIds![0]; + } } let proposal; diff --git a/test/DatasetAuthorization.js b/test/DatasetAuthorization.js index 56a8b7717..63e4b21c5 100644 --- a/test/DatasetAuthorization.js +++ b/test/DatasetAuthorization.js @@ -83,7 +83,6 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { }); it("0010: adds dataset 1 as Admin Ingestor", async () => { - console.log(JSON.stringify(dataset1)); return request(appUrl) .post("/api/v3/Datasets") .send(dataset1) @@ -92,8 +91,6 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { .expect(TestData.EntryCreatedStatusCode) .expect("Content-Type", /json/) .then((res) => { - console.log("Results"); - console.log(res.body); res.body.should.have.property("ownerGroup").and.equal("group4"); res.body.should.have.property("type").and.equal("raw"); res.body.should.have.property("isPublished").and.equal(true); @@ -103,23 +100,23 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { }); }); - // it("0020: adds dataset 2 as Admin Ingestor", async () => { - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(dataset2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("ownerGroup").and.equal("group1"); - // res.body.should.have.property("type").and.equal("raw"); - // res.body.should.have.property("isPublished").and.equal(false); - // res.body.should.have.property("pid").and.be.string; - // datasetPid2 = res.body["pid"]; - // encodedDatasetPid2 = encodeURIComponent(datasetPid2); - // }); - // }); + it("0020: adds dataset 2 as Admin Ingestor", async () => { + return request(appUrl) + .post("/api/v3/Datasets") + .send(dataset2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("ownerGroup").and.equal("group1"); + res.body.should.have.property("type").and.equal("raw"); + res.body.should.have.property("isPublished").and.equal(false); + res.body.should.have.property("pid").and.be.string; + datasetPid2 = res.body["pid"]; + encodedDatasetPid2 = encodeURIComponent(datasetPid2); + }); + }); // it("0030: adds dataset 3 as Admin Ingestor", async () => { // return request(appUrl) From ebc2666f6c45bcb4c5cb95ede6145d0ec08644f5 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 17 Sep 2024 14:47:28 +0200 Subject: [PATCH 17/38] fixed tests in Datasets Simple --- src/datasets/datasets.controller.ts | 7 +- test/DatasetAuthorization.js | 2835 +++++++++++++-------------- 2 files changed, 1420 insertions(+), 1422 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 9e1430701..2b4b3aec1 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -431,10 +431,9 @@ export class DatasetsController { } } else { if ("investigator" in inputObsoleteDataset) { - propertiesModifier.principalInvestigator = [ - (inputObsoleteDataset as CreateDerivedDatasetObsoleteDto) - .investigator, - ]; + propertiesModifier.principalInvestigator = ( + inputObsoleteDataset as CreateDerivedDatasetObsoleteDto + ).investigator; } } diff --git a/test/DatasetAuthorization.js b/test/DatasetAuthorization.js index 63e4b21c5..3aeb7f749 100644 --- a/test/DatasetAuthorization.js +++ b/test/DatasetAuthorization.js @@ -118,1422 +118,1421 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { }); }); - // it("0030: adds dataset 3 as Admin Ingestor", async () => { - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(dataset3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("ownerGroup").and.equal("group2"); - // res.body.should.have.property("type").and.equal("raw"); - // res.body.should.have.property("isPublished").and.equal(false); - // res.body.should.have.property("pid").and.be.string; - // datasetPid3 = res.body["pid"]; - // encodedDatasetPid3 = encodeURIComponent(datasetPid3); - // }); - // }); - - // it("0040: adds a new origDatablock on the published dataset as Admin Ingestor", async () => { - // return request(appUrl) - // .post(`/api/v3/datasets/${encodedDatasetPid1}/origdatablocks`) - // .send(TestData.OrigDataBlockCorrect1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have - // .property("size") - // .and.equal(TestData.OrigDataBlockCorrect1.size); - // res.body.should.have.property("id").and.be.string; - // }); - // }); - - // it("0050: adds a new datablock on the published dataset as Admin Ingestor", async () => { - // const randomArchiveId = Math.random().toString(36).slice(2); - - // return request(appUrl) - // .post(`/api/v3/datasets/${encodedDatasetPid1}/datablocks`) - // .send({ ...TestData.DataBlockCorrect, archiveId: randomArchiveId }) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have - // .property("size") - // .and.equal(TestData.DataBlockCorrect.size); - // res.body.should.have.property("id").and.be.string; - // }); - // }); - - // it("0060: adds a new attachment on the published dataset as Admin Ingestor", async () => { - // return request(appUrl) - // .post(`/api/v3/datasets/${encodedDatasetPid1}/attachments`) - // .send(TestData.AttachmentCorrect) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0070: list of public datasets, aka as unauthenticated user", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // res.body[0]["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0080: access public dataset as unauthenticated user", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0090: access private dataset as unauthenticated user", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .expect("Content-Type", /json/) - // .expect(TestData.AccessForbiddenStatusCode); - // }); - - // it("0100: list of datasets for Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(3); - // }); - // }); - - // it("0110: datasets counts for Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/count") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body["count"].should.be.equal(3); - // }); - // }); - - // it("0120: access dataset 1 as Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0130: full query for datasets for Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/fullquery") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(3); - // }); - // }); - - // it("0140: access dataset 2 as Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0150: access dataset 3 as Admin Ingestor", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0160: list of datasets for User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(2); - // res.body[1]["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0170: datasets count for User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/count") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body["count"].should.be.equal(2); - // }); - // }); - - // it("0180: access dataset 1 as User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0190: access dataset 2 as User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0200: access dataset 3 as User 1, which should fail as forbidden", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.AccessForbiddenStatusCode); - // }); - - // it("0210: full query for datasets for User 1", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/fullquery") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // res.body[0]["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0220: list of datasets for User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(2); - // res.body[1]["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0230: datasets count for User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/count") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body["count"].should.be.equal(2); - // }); - // }); - - // it("0240: access dataset 1 as User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0250: access dataset 2 as User 2, which should fail as forbidden", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.AccessForbiddenStatusCode); - // }); - - // it("0260: access dataset 3 as User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0270: full query for datasets for User 2", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/fullquery") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // res.body[0]["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0280: list of datasets for User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(3); - // }); - // }); - - // it("0290: datasets count for User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/count") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body["count"].should.be.equal(3); - // }); - // }); - - // it("0300: access dataset 1 as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid1); - // }); - // }); - - // it("0310: access dataset 2 as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid2); - // }); - // }); - - // it("0320: access dataset 3 as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body["pid"].should.be.equal(datasetPid3); - // }); - // }); - - // it("0330: full query for datasets for User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/fullquery") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(2); - // }); - // }); - - // it("0340: update dataset 2 to be published as Admin Ingestor", async () => { - // return request(appUrl) - // .patch(`/api/v3/Datasets/${encodedDatasetPid2}`) - // .send({ isPublished: true }) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - // .expect(TestData.SuccessfulPatchStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0350: full query for datasets for User 2", async () => { - // const fields = { - // isPublished: true, - // }; - - // return request(appUrl) - // .get( - // `/api/v3/Datasets/fullquery?fields=${encodeURIComponent( - // JSON.stringify(fields), - // )}`, - // ) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(2); - // }); - // }); - - // it("0360: full facet for datasets for User 2", async () => { - // const fields = { - // isPublished: true, - // }; - // return request(appUrl) - // .get( - // `/api/v3/Datasets/fullfacet?fields=${encodeURIComponent( - // JSON.stringify(fields), - // )}`, - // ) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.SuccessfulGetStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body[0].all[0].totalSets.should.be.equal(2); - // }); - // }); - - // it("0370: access dataset 1 origdatablocks as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/origdatablocks") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // }); - // }); - - // it("0380: access dataset 1 datablocks as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/datablocks") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // }); - // }); - - // it("0390: access dataset 1 attachments as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/attachments") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode) - // .then((res) => { - // res.body.should.be.an("array").to.have.lengthOf(1); - // }); - // }); - - // it("0400: access dataset 1 thumbnail as User 3", async () => { - // return request(appUrl) - // .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/thumbnail") - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect("Content-Type", /json/) - // .expect(TestData.SuccessfulGetStatusCode); - // }); - - // it("0410: should delete dataset 1 as Archive Manager", async () => { - // return request(appUrl) - // .delete("/api/v3/datasets/" + encodedDatasetPid1) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - // .expect(TestData.SuccessfulDeleteStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0420: should delete dataset 2 as Archive Manager", async () => { - // return request(appUrl) - // .delete("/api/v3/datasets/" + encodedDatasetPid2) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - // .expect(TestData.SuccessfulDeleteStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0430: should delete dataset 3 as Archive Manager", async () => { - // return request(appUrl) - // .delete("/api/v3/datasets/" + encodedDatasetPid3) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) - // .expect(TestData.SuccessfulDeleteStatusCode) - // .expect("Content-Type", /json/); - // }); - - // it("0500: add a new raw dataset as Admin", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0501: add a new incomplete raw dataset as Admin, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0502: add a new raw dataset with specified pid as Admin", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "admin", - // }; - // console.log("0502: pid : " + datasetWithPid["pid"]); - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0503: add a new raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0504: add a new invalid raw dataset with specified pid as Admin, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: uuidv4(), - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0505: add a new invalid raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "admin", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0510: add a new raw dataset with different owner group as Admin", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0520: add a new incomplete raw dataset with different owner group as Admin, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0530: add a new raw dataset with specified pid and different owner group as Admin", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0540: add a new raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0550: add a new invalid raw dataset with specified pid and different owner group as Admin, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0560: add a new invalid raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenAdmin}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0600: add a new raw dataset as User 1 which belongs to a create dataset group", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0601: add a new incomplete raw dataset as User 1 which belongs to a create dataset group", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0602: add a new raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0603: add a new raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0604: add a new invalid raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0605: add a new invalid raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0610: add a new raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0620: add a new incomplete raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0630: add a new raw dataset with specified pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0640: add a new raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0650: add a new invalid raw dataset with specified pid and different owner group as User 1 which belongs to a ", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0660: add a new invalid raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser1}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0700: add a new raw dataset as User 2 which belongs to a create dataset with pid group", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0701: add a new incomplete raw dataset as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0702: add a new raw dataset with specified pid as User 2 which belongs to a create dataset with pid group", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0703: add a new raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0704: add a new invalid raw dataset with specified pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0705: add a new invalid raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group2", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0710: add a new raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0720: add a new incomplete raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0730: add a new raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0740: add a new raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.CreationForbiddenStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0750: add a new invalid raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0760: add a new invalid raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser2}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0800: add a new raw dataset as User 3 which belongs to a create dataset privileged group", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0801: add a new incomplete raw dataset as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0802: add a new raw dataset with specified pid as User 3 which belongs to a create dataset privileged group", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0803: add a new raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0804: add a new invalid raw dataset with specified pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0805: add a new invalid raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group3", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0810: add a new raw dataset with different owner group as User 3 which belongs to a create dataset privileged group", async () => { - // const newDataset = { - // ...TestData.RawCorrect, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.be.string; - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0820: add a new incomplete raw dataset with different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const newDataset = { - // ...TestData.RawWrong_1, - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(newDataset) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0830: add a new raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.EntryCreatedStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.have.property("pid").and.equal(datasetWithPid.pid); - // res.body.should.have.property("owner").and.be.string; - // res.body.should.have.property("type").and.equal("raw"); - // }); - // }); - - // it("0840: add a new raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const datasetWithPid = { - // ...TestData.RawCorrect, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(datasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0850: add a new invalid raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const invalidDatasetWithPid = { - // ...TestData.RawWrong_1, - // pid: TestData.PidPrefix + "/" + uuidv4(), - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); - - // it("0860: add a new invalid raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { - // const invalidDatasetWithInvalidPid = { - // ...TestData.RawWrong_1, - // pid: "this-is-invalid-pid-1", - // ownerGroup: "group1", - // }; - - // return request(appUrl) - // .post("/api/v3/Datasets") - // .send(invalidDatasetWithInvalidPid) - // .set("Accept", "application/json") - // .set({ Authorization: `Bearer ${accessTokenUser3}` }) - // .expect(TestData.BadRequestStatusCode) - // .expect("Content-Type", /json/) - // .then((res) => { - // res.body.should.not.have.property("pid"); - // }); - // }); + it("0030: adds dataset 3 as Admin Ingestor", async () => { + return request(appUrl) + .post("/api/v3/Datasets") + .send(dataset3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("ownerGroup").and.equal("group2"); + res.body.should.have.property("type").and.equal("raw"); + res.body.should.have.property("isPublished").and.equal(false); + res.body.should.have.property("pid").and.be.string; + datasetPid3 = res.body["pid"]; + encodedDatasetPid3 = encodeURIComponent(datasetPid3); + }); + }); + + it("0040: adds a new origDatablock on the published dataset as Admin Ingestor", async () => { + return request(appUrl) + .post(`/api/v3/datasets/${encodedDatasetPid1}/origdatablocks`) + .send(TestData.OrigDataBlockCorrect1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have + .property("size") + .and.equal(TestData.OrigDataBlockCorrect1.size); + res.body.should.have.property("id").and.be.string; + }); + }); + + it("0050: adds a new datablock on the published dataset as Admin Ingestor", async () => { + const randomArchiveId = Math.random().toString(36).slice(2); + + return request(appUrl) + .post(`/api/v3/datasets/${encodedDatasetPid1}/datablocks`) + .send({ ...TestData.DataBlockCorrect, archiveId: randomArchiveId }) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have + .property("size") + .and.equal(TestData.DataBlockCorrect.size); + res.body.should.have.property("id").and.be.string; + }); + }); + + it("0060: adds a new attachment on the published dataset as Admin Ingestor", async () => { + return request(appUrl) + .post(`/api/v3/datasets/${encodedDatasetPid1}/attachments`) + .send(TestData.AttachmentCorrect) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/); + }); + + it("0070: list of public datasets, aka as unauthenticated user", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + res.body[0]["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0080: access public dataset as unauthenticated user", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0090: access private dataset as unauthenticated user", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .expect("Content-Type", /json/) + .expect(TestData.AccessForbiddenStatusCode); + }); + + it("0100: list of datasets for Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(3); + }); + }); + + it("0110: datasets counts for Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/count") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body["count"].should.be.equal(3); + }); + }); + + it("0120: access dataset 1 as Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0130: full query for datasets for Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/fullquery") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(3); + }); + }); + + it("0140: access dataset 2 as Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0150: access dataset 3 as Admin Ingestor", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0160: list of datasets for User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(2); + res.body[1]["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0170: datasets count for User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets/count") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body["count"].should.be.equal(2); + }); + }); + + it("0180: access dataset 1 as User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0190: access dataset 2 as User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0200: access dataset 3 as User 1, which should fail as forbidden", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect("Content-Type", /json/) + .expect(TestData.AccessForbiddenStatusCode); + }); + + it("0210: full query for datasets for User 1", async () => { + return request(appUrl) + .get("/api/v3/Datasets/fullquery") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + res.body[0]["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0220: list of datasets for User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(2); + res.body[1]["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0230: datasets count for User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets/count") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body["count"].should.be.equal(2); + }); + }); + + it("0240: access dataset 1 as User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0250: access dataset 2 as User 2, which should fail as forbidden", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect("Content-Type", /json/) + .expect(TestData.AccessForbiddenStatusCode); + }); + + it("0260: access dataset 3 as User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0270: full query for datasets for User 2", async () => { + return request(appUrl) + .get("/api/v3/Datasets/fullquery") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + res.body[0]["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0280: list of datasets for User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(3); + }); + }); + + it("0290: datasets count for User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/count") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body["count"].should.be.equal(3); + }); + }); + + it("0300: access dataset 1 as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid1); + }); + }); + + it("0310: access dataset 2 as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid2); + }); + }); + + it("0320: access dataset 3 as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid3); + }); + }); + + it("0330: full query for datasets for User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/fullquery") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(2); + }); + }); + + it("0340: update dataset 2 to be published as Admin Ingestor", async () => { + return request(appUrl) + .patch(`/api/v3/Datasets/${encodedDatasetPid2}`) + .send({ isPublished: true }) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulPatchStatusCode) + .expect("Content-Type", /json/); + }); + + it("0350: full query for datasets for User 2", async () => { + const fields = { + isPublished: true, + }; + + return request(appUrl) + .get( + `/api/v3/Datasets/fullquery?fields=${encodeURIComponent( + JSON.stringify(fields), + )}`, + ) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(2); + }); + }); + + it("0360: full facet for datasets for User 2", async () => { + const fields = { + isPublished: true, + }; + return request(appUrl) + .get( + `/api/v3/Datasets/fullfacet?fields=${encodeURIComponent( + JSON.stringify(fields), + )}`, + ) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.SuccessfulGetStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body[0].all[0].totalSets.should.be.equal(2); + }); + }); + + it("0370: access dataset 1 origdatablocks as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/origdatablocks") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + }); + }); + + it("0380: access dataset 1 datablocks as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/datablocks") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + }); + }); + + it("0390: access dataset 1 attachments as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/attachments") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode) + .then((res) => { + res.body.should.be.an("array").to.have.lengthOf(1); + }); + }); + + it("0400: access dataset 1 thumbnail as User 3", async () => { + return request(appUrl) + .get("/api/v3/Datasets/" + encodedDatasetPid1 + "/thumbnail") + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect("Content-Type", /json/) + .expect(TestData.SuccessfulGetStatusCode); + }); + + it("0410: should delete dataset 1 as Archive Manager", async () => { + return request(appUrl) + .delete("/api/v3/datasets/" + encodedDatasetPid1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + .expect(TestData.SuccessfulDeleteStatusCode) + .expect("Content-Type", /json/); + }); + + it("0420: should delete dataset 2 as Archive Manager", async () => { + return request(appUrl) + .delete("/api/v3/datasets/" + encodedDatasetPid2) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + .expect(TestData.SuccessfulDeleteStatusCode) + .expect("Content-Type", /json/); + }); + + it("0430: should delete dataset 3 as Archive Manager", async () => { + return request(appUrl) + .delete("/api/v3/datasets/" + encodedDatasetPid3) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenArchiveManager}` }) + .expect(TestData.SuccessfulDeleteStatusCode) + .expect("Content-Type", /json/); + }); + + it("0500: add a new raw dataset as Admin", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0501: add a new incomplete raw dataset as Admin, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0502: add a new raw dataset with specified pid as Admin", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0503: add a new raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0504: add a new invalid raw dataset with specified pid as Admin, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: uuidv4(), + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0505: add a new invalid raw dataset with specified invalid pid as Admin, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "admin", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0510: add a new raw dataset with different owner group as Admin", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0520: add a new incomplete raw dataset with different owner group as Admin, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0530: add a new raw dataset with specified pid and different owner group as Admin", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0540: add a new raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0550: add a new invalid raw dataset with specified pid and different owner group as Admin, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0560: add a new invalid raw dataset with specified invalid pid and different owner group as Admin, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdmin}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0600: add a new raw dataset as User 1 which belongs to a create dataset group", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0601: add a new incomplete raw dataset as User 1 which belongs to a create dataset group", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0602: add a new raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0603: add a new raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0604: add a new invalid raw dataset with specified pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0605: add a new invalid raw dataset with specified invalid pid as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0610: add a new raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0620: add a new incomplete raw dataset with different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0630: add a new raw dataset with specified pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0640: add a new raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0650: add a new invalid raw dataset with specified pid and different owner group as User 1 which belongs to a ", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0660: add a new invalid raw dataset with specified invalid pid and different owner group as User 1 which belongs to a create dataset group, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser1}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0700: add a new raw dataset as User 2 which belongs to a create dataset with pid group", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0701: add a new incomplete raw dataset as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0702: add a new raw dataset with specified pid as User 2 which belongs to a create dataset with pid group", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0703: add a new raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0704: add a new invalid raw dataset with specified pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0705: add a new invalid raw dataset with specified invalid pid as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group2", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0710: add a new raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0720: add a new incomplete raw dataset with different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0730: add a new raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0740: add a new raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as forbidden", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.CreationForbiddenStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0750: add a new invalid raw dataset with specified pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0760: add a new invalid raw dataset with specified invalid pid and different owner group as User 2 which belongs to a create dataset with pid group, which should fail as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser2}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0800: add a new raw dataset as User 3 which belongs to a create dataset privileged group", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0801: add a new incomplete raw dataset as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0802: add a new raw dataset with specified pid as User 3 which belongs to a create dataset privileged group", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0803: add a new raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0804: add a new invalid raw dataset with specified pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0805: add a new invalid raw dataset with specified invalid pid as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group3", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0810: add a new raw dataset with different owner group as User 3 which belongs to a create dataset privileged group", async () => { + const newDataset = { + ...TestData.RawCorrect, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0820: add a new incomplete raw dataset with different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const newDataset = { + ...TestData.RawWrong_1, + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(newDataset) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0830: add a new raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("pid").and.equal(datasetWithPid.pid); + res.body.should.have.property("owner").and.be.string; + res.body.should.have.property("type").and.equal("raw"); + }); + }); + + it("0840: add a new raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const datasetWithPid = { + ...TestData.RawCorrect, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(datasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0850: add a new invalid raw dataset with specified pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const invalidDatasetWithPid = { + ...TestData.RawWrong_1, + pid: TestData.PidPrefix + "/" + uuidv4(), + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); + + it("0860: add a new invalid raw dataset with specified invalid pid and different owner group as User 3 which belongs to a create dataset privileged group, which fails as bad request", async () => { + const invalidDatasetWithInvalidPid = { + ...TestData.RawWrong_1, + pid: "this-is-invalid-pid-1", + ownerGroup: "group1", + }; + + return request(appUrl) + .post("/api/v3/Datasets") + .send(invalidDatasetWithInvalidPid) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenUser3}` }) + .expect(TestData.BadRequestStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.not.have.property("pid"); + }); + }); }); From b9cf5b338069aca506dbcda57cd9355d68b5780e Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 17 Sep 2024 17:35:20 +0200 Subject: [PATCH 18/38] making progress with tests --- src/datasets/datasets.controller.ts | 31 +++++++++++++++++------------ test/DerivedDatasetDatablock.js | 2 +- test/OrigDatablockForRawDataset.js | 3 ++- test/TestData.js | 4 +++- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 2b4b3aec1..741c41e79 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -556,6 +556,7 @@ export class DatasetsController { const datasetDto = this.convertObsoleteToCurrentSchema( obsoleteDatasetDto, ) as CreateDatasetDto; + console.log(datasetDto); const createdDataset = await this.datasetsService.create(datasetDto); const outputObsoleteDatasetDto = @@ -1063,30 +1064,34 @@ export class DatasetsController { ) as Record, ) as IFilters; - const dataset = (await this.datasetsService.findOne( - mergedFilters, - )) as OutputDatasetObsoleteDto; + const databaseDataset = await this.datasetsService.findOne(mergedFilters); - if (dataset) { + const outputDataset = + await this.convertCurrentToObsoleteSchema(databaseDataset); + + if (outputDataset) { const includeFilters = mergedFilters.include ?? []; await Promise.all( includeFilters.map(async ({ relation }) => { switch (relation) { case "attachments": { - dataset.attachments = await this.attachmentsService.findAll({ - datasetId: dataset.pid, - }); + outputDataset.attachments = await this.attachmentsService.findAll( + { + datasetId: outputDataset.pid, + }, + ); break; } case "origdatablocks": { - dataset.origdatablocks = await this.origDatablocksService.findAll( - { where: { datasetId: dataset.pid } }, - ); + outputDataset.origdatablocks = + await this.origDatablocksService.findAll({ + where: { datasetId: outputDataset.pid }, + }); break; } case "datablocks": { - dataset.datablocks = await this.datablocksService.findAll({ - datasetId: dataset.pid, + outputDataset.datablocks = await this.datablocksService.findAll({ + datasetId: outputDataset.pid, }); break; } @@ -1094,7 +1099,7 @@ export class DatasetsController { }), ); } - return dataset; + return outputDataset; } // GET /datasets/count diff --git a/test/DerivedDatasetDatablock.js b/test/DerivedDatasetDatablock.js index 8ef6ff8c7..6c223246c 100644 --- a/test/DerivedDatasetDatablock.js +++ b/test/DerivedDatasetDatablock.js @@ -13,7 +13,7 @@ describe("0750: DerivedDatasetDatablock: Test Datablocks and their relation to d before(() => { db.collection("Dataset").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], diff --git a/test/OrigDatablockForRawDataset.js b/test/OrigDatablockForRawDataset.js index 057134d35..859b49333 100644 --- a/test/OrigDatablockForRawDataset.js +++ b/test/OrigDatablockForRawDataset.js @@ -23,7 +23,7 @@ describe("1200: OrigDatablockForRawDataset: Test OrigDatablocks and their relati db.collection("Dataset").deleteMany({}); db.collection("OrigDatablock").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], @@ -304,6 +304,7 @@ describe("1200: OrigDatablockForRawDataset: Test OrigDatablocks and their relati .expect(TestData.SuccessfulGetStatusCode) .expect("Content-Type", /json/) .then((res) => { + console.log(res.body); res.body["pid"].should.be.equal(decodeURIComponent(datasetPid1)); res.body.origdatablocks.should.be .instanceof(Array) diff --git a/test/TestData.js b/test/TestData.js index 538f657bf..bee14fe4c 100644 --- a/test/TestData.js +++ b/test/TestData.js @@ -119,6 +119,7 @@ const TestData = { sourceFolder: faker.system.directoryPath(), owner: faker.internet.userName(), contactEmail: faker.internet.email(), + datasetName: faker.string.sample(), }, RawCorrect: { @@ -384,13 +385,14 @@ const TestData = { DerivedCorrectMin: { investigator: faker.internet.email(), - inputDatasets: [faker.system.filePath()], + inputDatasets: [faker.string.uuid()], usedSoftware: [faker.internet.url()], owner: faker.internet.userName(), contactEmail: faker.internet.email(), sourceFolder: faker.system.directoryPath(), creationTime: faker.date.past(), ownerGroup: faker.string.alphanumeric(6), + datasetName: faker.string.sample(), type: "derived", }, From 79b1ac6c3d47ba66ee343371ee8e216cfa347263 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 18 Sep 2024 15:00:32 +0200 Subject: [PATCH 19/38] all test passing --- src/datasets/datasets.controller.ts | 1 - test/DatasetLifecycle.js | 3 ++- test/OrigDatablockForRawDataset.js | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 741c41e79..11cbc7b69 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -556,7 +556,6 @@ export class DatasetsController { const datasetDto = this.convertObsoleteToCurrentSchema( obsoleteDatasetDto, ) as CreateDatasetDto; - console.log(datasetDto); const createdDataset = await this.datasetsService.create(datasetDto); const outputObsoleteDatasetDto = diff --git a/test/DatasetLifecycle.js b/test/DatasetLifecycle.js index 3b26585de..0611be077 100644 --- a/test/DatasetLifecycle.js +++ b/test/DatasetLifecycle.js @@ -15,8 +15,9 @@ const raw2 = { ...TestData.RawCorrect }; describe("0500: DatasetLifecycle: Test facet and filter queries", () => { before(() => { db.collection("Dataset").deleteMany({}); + db.collection("Policy").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], diff --git a/test/OrigDatablockForRawDataset.js b/test/OrigDatablockForRawDataset.js index 859b49333..d329d5867 100644 --- a/test/OrigDatablockForRawDataset.js +++ b/test/OrigDatablockForRawDataset.js @@ -304,7 +304,6 @@ describe("1200: OrigDatablockForRawDataset: Test OrigDatablocks and their relati .expect(TestData.SuccessfulGetStatusCode) .expect("Content-Type", /json/) .then((res) => { - console.log(res.body); res.body["pid"].should.be.equal(decodeURIComponent(datasetPid1)); res.body.origdatablocks.should.be .instanceof(Array) From 5da55445154582a71aa929ab9105e2d2a84965c0 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 18 Sep 2024 15:03:17 +0200 Subject: [PATCH 20/38] latest packages.json local version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 748681b4c..788025822 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:api": "npm run test:api:jest --maxWorkers=50% && concurrently -k -s first \"wait-on http://localhost:3000/explorer/ && npm run test:api:mocha\" \"npm run start\"", "test:api:jest": "jest --config ./test/config/jest-e2e.json --maxWorkers=50%", - "test:api:mocha": "mocha --config ./test/config/.mocharc.json -r chai/register-should.js ", + "test:api:mocha": "mocha --config ./test/config/.mocharc.json -r chai/register-should.js", "prepare:local": "docker-compose -f CI/E2E/docker-compose-local.yaml --env-file CI/E2E/.env.elastic-search up -d && cp functionalAccounts.json.test functionalAccounts.json" }, "dependencies": { From cc779858f775a2fdc82f8a4c7665824df878932f Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 18 Sep 2024 15:26:58 +0200 Subject: [PATCH 21/38] Renamed current dataset dtos to osbolete --- .../create-derived-dataset-obsolete.dto.ts | 27 +++++ .../dto/create-raw-dataset-obsolete.dto.ts | 27 +++++ .../update-derived-dataset-obsolete.dto.ts | 60 +++++++++++ .../dto/update-raw-dataset-obsolete.dto.ts | 100 ++++++++++++++++++ 4 files changed, 214 insertions(+) create mode 100644 src/datasets/dto/create-derived-dataset-obsolete.dto.ts create mode 100644 src/datasets/dto/create-raw-dataset-obsolete.dto.ts create mode 100644 src/datasets/dto/update-derived-dataset-obsolete.dto.ts create mode 100644 src/datasets/dto/update-raw-dataset-obsolete.dto.ts diff --git a/src/datasets/dto/create-derived-dataset-obsolete.dto.ts b/src/datasets/dto/create-derived-dataset-obsolete.dto.ts new file mode 100644 index 000000000..f6fcc180f --- /dev/null +++ b/src/datasets/dto/create-derived-dataset-obsolete.dto.ts @@ -0,0 +1,27 @@ +import { UpdateDerivedDatasetObsoleteDto } from "./update-derived-dataset-obsolete.dto"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsEnum, IsOptional, IsString } from "class-validator"; +import { DatasetType } from "../dataset-type.enum"; + +export class CreateDerivedDatasetObsoleteDto extends UpdateDerivedDatasetObsoleteDto { + @ApiProperty({ + type: String, + required: false, + description: "Persistent identifier of the dataset.", + }) + @IsOptional() + @IsString() + pid?: string; + + @IsEnum(DatasetType) + readonly type: string = DatasetType.Derived; + + @ApiProperty({ + type: String, + required: false, + description: "Version of the API used in creation of the dataset.", + }) + @IsOptional() + @IsString() + readonly version?: string; +} diff --git a/src/datasets/dto/create-raw-dataset-obsolete.dto.ts b/src/datasets/dto/create-raw-dataset-obsolete.dto.ts new file mode 100644 index 000000000..57f7d6ba9 --- /dev/null +++ b/src/datasets/dto/create-raw-dataset-obsolete.dto.ts @@ -0,0 +1,27 @@ +import { UpdateRawDatasetObsoleteDto } from "./update-raw-dataset-obsolete.dto"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsEnum, IsOptional, IsString } from "class-validator"; +import { DatasetType } from "../dataset-type.enum"; + +export class CreateRawDatasetObsoleteDto extends UpdateRawDatasetObsoleteDto { + @ApiProperty({ + type: String, + required: false, + description: "Persistent identifier of the dataset.", + }) + @IsOptional() + @IsString() + pid?: string; + + @IsEnum(DatasetType) + readonly type: string = DatasetType.Raw; + + @ApiProperty({ + type: String, + required: false, + description: "Version of the API used in creation of the dataset.", + }) + @IsOptional() + @IsString() + readonly version?: string; +} diff --git a/src/datasets/dto/update-derived-dataset-obsolete.dto.ts b/src/datasets/dto/update-derived-dataset-obsolete.dto.ts new file mode 100644 index 000000000..b6ec0bf4c --- /dev/null +++ b/src/datasets/dto/update-derived-dataset-obsolete.dto.ts @@ -0,0 +1,60 @@ +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; +import { ApiProperty, PartialType } from "@nestjs/swagger"; +import { IsObject, IsOptional, IsString } from "class-validator"; + +export class UpdateDerivedDatasetObsoleteDto extends UpdateDatasetObsoleteDto { + @ApiProperty({ + type: String, + required: true, + description: + "First name and last name of the person or people pursuing the data analysis. The string may contain a list of names, which should then be separated by semicolons.", + }) + @IsString() + readonly investigator: string; + + @ApiProperty({ + type: [String], + required: true, + description: + "Array of input dataset identifiers used in producing the derived dataset. Ideally these are the global identifier to existing datasets inside this or federated data catalogs.", + }) + @IsString({ + each: true, + }) + readonly inputDatasets: string[]; + + @ApiProperty({ + type: [String], + required: true, + description: + "A list of links to software repositories which uniquely identifies the pieces of software, including versions, used for yielding the derived data.", + }) + @IsString({ + each: true, + }) + readonly usedSoftware: string[]; + + @ApiProperty({ + type: Object, + required: false, + description: + "The creation process of the derived data will usually depend on input job parameters. The full structure of these input parameters are stored here.", + }) + @IsOptional() + @IsObject() + readonly jobParameters?: Record; + + @ApiProperty({ + type: String, + required: false, + description: + "The output job logfile. Keep the size of this log data well below 15 MB.", + }) + @IsOptional() + @IsString() + readonly jobLogData?: string; +} + +export class PartialUpdateDerivedDatasetObsoleteDto extends PartialType( + UpdateDerivedDatasetObsoleteDto, +) {} diff --git a/src/datasets/dto/update-raw-dataset-obsolete.dto.ts b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts new file mode 100644 index 000000000..020cbcf70 --- /dev/null +++ b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts @@ -0,0 +1,100 @@ +import { IsDateString, IsOptional, IsString } from "class-validator"; +import { UpdateDatasetObsoleteDto } from "./update-dataset-obsolete.dto"; +import { ApiProperty, PartialType } from "@nestjs/swagger"; + +export class UpdateRawDatasetObsoleteDto extends UpdateDatasetObsoleteDto { + /* we need to discuss if the naming is adequate. */ + @ApiProperty({ + type: String, + required: 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.", + }) + @IsString() + readonly principalInvestigator: string; + + @ApiProperty({ + type: Date, + required: false, + description: + "Start time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) + @IsOptional() + @IsDateString() + readonly startTime?: Date; + + @ApiProperty({ + type: Date, + required: false, + description: + "End time of data acquisition for the current dataset.
It is expected to be in ISO8601 format according to specifications for internet date/time format in RFC 3339, chapter 5.6 (https://www.rfc-editor.org/rfc/rfc3339#section-5).
Local times without timezone/offset info are automatically transformed to UTC using the timezone of the API server.", + }) + @IsOptional() + @IsDateString() + readonly endTime?: Date; + + @ApiProperty({ + type: String, + required: true, + description: + "Unique location identifier where data was taken, usually in the form /Site-name/facility-name/instrumentOrBeamline-name. This field is required if the dataset is a Raw dataset.", + }) + @IsString() + readonly creationLocation: string; + + @ApiProperty({ + type: String, + required: false, + description: + "Defines the format of the data files in this dataset, e.g Nexus Version x.y.", + }) + @IsOptional() + @IsString() + readonly dataFormat?: string; + + @ApiProperty({ + type: String, + required: false, + description: "The ID of the proposal to which the dataset belongs.", + }) + @IsOptional() + @IsString() + readonly proposalId?: string; + + @ApiProperty({ + type: String, + required: false, + description: "ID of the sample used when collecting the data.", + }) + @IsOptional() + @IsString() + readonly sampleId?: string; + + @ApiProperty({ + type: String, + required: false, + description: "ID of the instrument where the data was created.", + }) + @IsOptional() + @IsString() + readonly instrumentId: string; + + @IsOptional() + investigator?: string; + + @IsOptional() + inputDatasets?: string[]; + + @IsOptional() + usedSoftware?: string[]; + + @IsOptional() + jobParameters?: Record; + + @IsOptional() + jobLogData?: string; +} + +export class PartialUpdateRawDatasetObsoleteDto extends PartialType( + UpdateRawDatasetObsoleteDto, +) {} From 22abb54e4ad6d53cb0a66ea275c70c3776fc9cf8 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 18 Sep 2024 16:28:17 +0200 Subject: [PATCH 22/38] fixed test dataset used in elasticsearch tests --- test/ElasticSearch.js | 4 ++-- test/TestData.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/ElasticSearch.js b/test/ElasticSearch.js index cfec71f29..35ee5cb19 100644 --- a/test/ElasticSearch.js +++ b/test/ElasticSearch.js @@ -45,12 +45,12 @@ const scientificMetadata = (values) => { before(() => { db.collection("Dataset").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], }); - + accessTokenArchiveManager = await utils.getToken(appUrl, { username: "archiveManager", password: TestData.Accounts["archiveManager"]["password"], diff --git a/test/TestData.js b/test/TestData.js index bee14fe4c..7347a06aa 100644 --- a/test/TestData.js +++ b/test/TestData.js @@ -818,6 +818,7 @@ const TestData = { creationLocation: faker.location.city(), principalInvestigator: faker.internet.userName(), type: "raw", + datasetName: faker.string.sample(), creationTime: faker.date.past(), sourceFolder: faker.system.directoryPath(), owner: faker.internet.userName(), From dc3ff8dcf9692f389145c14d473717aa7cf86f36 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Thu, 19 Sep 2024 11:52:46 +0200 Subject: [PATCH 23/38] Updated datasets dto according to PR review --- src/datasets/dto/output-dataset.dto.ts | 6 +++--- src/datasets/dto/update-dataset.dto.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/datasets/dto/output-dataset.dto.ts b/src/datasets/dto/output-dataset.dto.ts index 8809e3756..6c070a73c 100644 --- a/src/datasets/dto/output-dataset.dto.ts +++ b/src/datasets/dto/output-dataset.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty } from "@nestjs/swagger"; import { CreateDatasetDto } from "./create-dataset.dto"; -import { IsString } from "class-validator"; +import { IsDateString, IsString } from "class-validator"; export class OutputDatasetDto extends CreateDatasetDto { @ApiProperty({ @@ -27,7 +27,7 @@ export class OutputDatasetDto extends CreateDatasetDto { description: "Date and time when this record was created. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", }) - @IsString() + @IsDateString() createdAt: Date; @ApiProperty({ @@ -36,6 +36,6 @@ export class OutputDatasetDto extends CreateDatasetDto { description: "Date and time when this record was updated last. This field is managed by mongoose with through the timestamp settings. The field should be a string containing a date in ISO 8601 format (2024-02-27T12:26:57.313Z)", }) - @IsString() + @IsDateString() updatedAt: Date; } diff --git a/src/datasets/dto/update-dataset.dto.ts b/src/datasets/dto/update-dataset.dto.ts index 26866705d..6592e57ec 100644 --- a/src/datasets/dto/update-dataset.dto.ts +++ b/src/datasets/dto/update-dataset.dto.ts @@ -209,7 +209,7 @@ export class UpdateDatasetDto extends OwnableDto { }) @IsOptional() @IsBoolean() - readonly isPublished?: boolean = false; + readonly isPublished?: boolean; @ApiProperty({ type: "array", @@ -371,7 +371,7 @@ export class UpdateDatasetDto extends OwnableDto { }) @IsOptional() @IsString({ - each: false, + each: true, }) readonly instrumentIds?: string[]; From 2778acfd126132ff829b1580851494011a2753db Mon Sep 17 00:00:00 2001 From: junjiequan Date: Thu, 19 Sep 2024 13:54:08 +0200 Subject: [PATCH 24/38] fix elastic search test fail --- .../configuration/datasetFieldMapping.ts | 4 ++-- test/ElasticSearch.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/elastic-search/configuration/datasetFieldMapping.ts b/src/elastic-search/configuration/datasetFieldMapping.ts index 429555ee8..c0d4a9213 100644 --- a/src/elastic-search/configuration/datasetFieldMapping.ts +++ b/src/elastic-search/configuration/datasetFieldMapping.ts @@ -42,11 +42,11 @@ export const datasetMappings: MappingObject = { type: "nested", dynamic: false, }, - proposalId: { + proposalIds: { type: "keyword", ignore_above: 256, }, - sampleId: { + sampleIds: { type: "keyword", ignore_above: 256, }, diff --git a/test/ElasticSearch.js b/test/ElasticSearch.js index 35ee5cb19..a027564cb 100644 --- a/test/ElasticSearch.js +++ b/test/ElasticSearch.js @@ -178,11 +178,11 @@ const scientificMetadata = (values) => { }); }); - it("0030: should fetching dataset with correct proposalId and size", async () => { + it("0030: should fetching dataset with correct proposalIds and size", async () => { return request(appUrl) .post("/api/v3/elastic-search/search") .send({ - proposalId: TestData.ScientificMetadataForElasticSearch.proposalId, + proposalIds: TestData.ScientificMetadataForElasticSearch.proposalId, size: TestData.ScientificMetadataForElasticSearch.size, }) .set("Accept", "application/json") @@ -194,11 +194,11 @@ const scientificMetadata = (values) => { }); }); - it("0031: should fail fetching dataset with correct proposalId but wrong size", async () => { + it("0031: should fail fetching dataset with correct proposalIds but wrong size", async () => { return request(appUrl) .post("/api/v3/elastic-search/search") .send({ - proposalId: TestData.ScientificMetadataForElasticSearch.proposalId, + proposalIds: [TestData.ScientificMetadataForElasticSearch.proposalId], size: faker.number.int({ min: 100000001, max: 100400000 }), }) .set("Accept", "application/json") @@ -209,11 +209,11 @@ const scientificMetadata = (values) => { res.body.data.should.be.length(0); }); }); - it("0032: should fail fetching dataset with wrong proposalId but correct size", async () => { + it("0032: should fail fetching dataset with wrong proposalIds but correct size", async () => { return request(appUrl) .post("/api/v3/elastic-search/search") .send({ - proposalId: "wrongProposalId", + proposalIds: ["wrongProposalId"], size: TestData.ScientificMetadataForElasticSearch.size, }) .set("Accept", "application/json") @@ -225,11 +225,11 @@ const scientificMetadata = (values) => { }); }); - it("0033: should fail fetching dataset with incorrect proposalId and size", async () => { + it("0033: should fail fetching dataset with incorrect proposalIds and size", async () => { return request(appUrl) .post("/api/v3/elastic-search/search") .send({ - proposalId: "wrongProposalId", + proposalIds: ["wrongProposalId"], size: faker.number.int({ min: 100000001, max: 100400000 }), }) .set("Accept", "application/json") From ef4854926503176dd192b0466eb2047da131d78d Mon Sep 17 00:00:00 2001 From: junjiequan Date: Thu, 19 Sep 2024 14:09:24 +0200 Subject: [PATCH 25/38] added instrumentIds to ES datasetFieldMapping --- src/elastic-search/configuration/datasetFieldMapping.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/elastic-search/configuration/datasetFieldMapping.ts b/src/elastic-search/configuration/datasetFieldMapping.ts index c0d4a9213..629d5f80f 100644 --- a/src/elastic-search/configuration/datasetFieldMapping.ts +++ b/src/elastic-search/configuration/datasetFieldMapping.ts @@ -50,6 +50,10 @@ export const datasetMappings: MappingObject = { type: "keyword", ignore_above: 256, }, + instrumentIds: { + type: "keyword", + ignore_above: 256, + }, sourceFolder: { type: "keyword", ignore_above: 256, From 2f55a3558f79673b8abdaa789194fea932102376 Mon Sep 17 00:00:00 2001 From: junjiequan Date: Thu, 19 Sep 2024 15:14:25 +0200 Subject: [PATCH 26/38] fix: swagger-schema artifact is missing commit ID --- .github/workflows/release-and-publish-sdk.yml | 4 ++-- .github/workflows/upload-sdk-artifact.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-and-publish-sdk.yml b/.github/workflows/release-and-publish-sdk.yml index 9a79e592f..c46b76036 100644 --- a/.github/workflows/release-and-publish-sdk.yml +++ b/.github/workflows/release-and-publish-sdk.yml @@ -121,7 +121,7 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: swagger-schema + name: swagger-schema-${{ github.sha }} path: ./swagger-schema.json generate-upload-sdk: @@ -139,7 +139,7 @@ jobs: - uses: actions/download-artifact@v4 with: - name: swagger-schema + name: swagger-schema-${{ github.sha }} path: . - name: Generate Client diff --git a/.github/workflows/upload-sdk-artifact.yml b/.github/workflows/upload-sdk-artifact.yml index 369426a08..a33c50a09 100644 --- a/.github/workflows/upload-sdk-artifact.yml +++ b/.github/workflows/upload-sdk-artifact.yml @@ -39,7 +39,7 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: swagger-schema + name: swagger-schema-${{ github.sha }} path: ./swagger-schema.json generate-and-upload-sdk: @@ -56,7 +56,7 @@ jobs: - uses: actions/download-artifact@v4 with: - name: swagger-schema + name: swagger-schema-${{ github.sha }} path: . - name: Generate Client From 72ccf7f2e87be6816157b35dde37f7063fd741f4 Mon Sep 17 00:00:00 2001 From: junjiequan Date: Thu, 19 Sep 2024 15:35:24 +0200 Subject: [PATCH 27/38] added sdk badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 103b8c3fd..b1ffe56a3 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![Test](https://github.com/SciCatProject/scicat-backend-next/actions/workflows/test.yml/badge.svg)](https://github.com/SciCatProject/scicat-backend-next/actions/workflows/test.yml) [![Deploy](https://github.com/SciCatProject/scicat-backend-next/actions/workflows/deploy.yml/badge.svg)](https://github.com/SciCatProject/scicat-backend-next/actions/workflows/deploy.yml) +[![Generate and upload latest SDK artifacts](https://github.com/SciCatProject/scicat-backend-next/actions/workflows/upload-sdk-artifact.yml/badge.svg?branch=master)](https://github.com/SciCatProject/scicat-backend-next/actions/workflows/upload-sdk-artifact.yml) [![DeepScan grade](https://deepscan.io/api/teams/8394/projects/19251/branches/494247/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=8394&pid=19251&bid=494247) [![Known Vulnerabilities](https://snyk.io/test/github/SciCatProject/scicat-backend-next/master/badge.svg?targetFile=package.json)](https://snyk.io/test/github/SciCatProject/scicat-backend-next/master?targetFile=package.json) From 4ef5b9fbf0eaef67424f5a299c1bd79e98bc6b2f Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Thu, 19 Sep 2024 21:02:55 +0200 Subject: [PATCH 28/38] implemented requested changes and fixed linting --- src/datasets/datasets.controller.ts | 2 +- src/datasets/datasets.service.ts | 1 - src/datasets/dto/update-dataset-obsolete.dto.ts | 3 --- src/datasets/dto/update-dataset.dto.ts | 2 +- src/datasets/schemas/dataset.schema.ts | 12 ------------ 5 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 11cbc7b69..bfc9dd843 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -61,7 +61,7 @@ import { DatablocksService } from "src/datablocks/datablocks.service"; import { Datablock } from "src/datablocks/schemas/datablock.schema"; import { CreateDatablockDto } from "src/datablocks/dto/create-datablock.dto"; import { PartialUpdateDatablockDto } from "src/datablocks/dto/update-datablock.dto"; -import { Document, UpdateQuery } from "mongoose"; +import { UpdateQuery } from "mongoose"; import { FilterPipe } from "src/common/pipes/filter.pipe"; import { UTCTimeInterceptor } from "src/common/interceptors/utc-time.interceptor"; import { DataFile } from "src/common/schemas/datafile.schema"; diff --git a/src/datasets/datasets.service.ts b/src/datasets/datasets.service.ts index 723552172..b43385a3f 100644 --- a/src/datasets/datasets.service.ts +++ b/src/datasets/datasets.service.ts @@ -23,7 +23,6 @@ import { import { ElasticSearchService } from "src/elastic-search/elastic-search.service"; import { InitialDatasetsService } from "src/initial-datasets/initial-datasets.service"; import { LogbooksService } from "src/logbooks/logbooks.service"; -import { DatasetType } from "./dataset-type.enum"; import { CreateDatasetDto } from "./dto/create-dataset.dto"; import { IDatasetFields } from "./interfaces/dataset-filters.interface"; import { DatasetClass, DatasetDocument } from "./schemas/dataset.schema"; diff --git a/src/datasets/dto/update-dataset-obsolete.dto.ts b/src/datasets/dto/update-dataset-obsolete.dto.ts index f2be1c2d2..ac0e996c8 100644 --- a/src/datasets/dto/update-dataset-obsolete.dto.ts +++ b/src/datasets/dto/update-dataset-obsolete.dto.ts @@ -24,9 +24,6 @@ import { CreateTechniqueDto } from "./create-technique.dto"; import { RelationshipClass } from "../schemas/relationship.schema"; import { CreateRelationshipDto } from "./create-relationship.dto"; import { LifecycleClass } from "../schemas/lifecycle.schema"; -import { Attachment } from "../../attachments/schemas/attachment.schema"; -import { OrigDatablock } from "../../origdatablocks/schemas/origdatablock.schema"; -import { Datablock } from "../../datablocks/schemas/datablock.schema"; @ApiTags("datasets") export class UpdateDatasetObsoleteDto extends OwnableDto { diff --git a/src/datasets/dto/update-dataset.dto.ts b/src/datasets/dto/update-dataset.dto.ts index 6592e57ec..99c6c3eaf 100644 --- a/src/datasets/dto/update-dataset.dto.ts +++ b/src/datasets/dto/update-dataset.dto.ts @@ -383,7 +383,7 @@ export class UpdateDatasetDto extends OwnableDto { }) @IsOptional() @IsString({ - each: false, + each: true, }) readonly inputDatasets?: string[]; diff --git a/src/datasets/schemas/dataset.schema.ts b/src/datasets/schemas/dataset.schema.ts index 9b3d7f7e2..a3fb81086 100644 --- a/src/datasets/schemas/dataset.schema.ts +++ b/src/datasets/schemas/dataset.schema.ts @@ -1,19 +1,7 @@ import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; import { ApiProperty, getSchemaPath } from "@nestjs/swagger"; import { Document } from "mongoose"; -import { - Attachment, - AttachmentSchema, -} from "src/attachments/schemas/attachment.schema"; import { OwnableClass } from "src/common/schemas/ownable.schema"; -import { - Datablock, - DatablockSchema, -} from "src/datablocks/schemas/datablock.schema"; -import { - OrigDatablock, - OrigDatablockSchema, -} from "src/origdatablocks/schemas/origdatablock.schema"; import { v4 as uuidv4 } from "uuid"; import { DatasetType } from "../dataset-type.enum"; import { HistoryClass, HistorySchema } from "./history.schema"; From a3b02f9d8e17e3bfcc63c38930ae257a326e921e Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 20 Sep 2024 13:29:02 +0200 Subject: [PATCH 29/38] added database migration --- .../20240920111733-dataset-unified-schema.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 migrations/20240920111733-dataset-unified-schema.js diff --git a/migrations/20240920111733-dataset-unified-schema.js b/migrations/20240920111733-dataset-unified-schema.js new file mode 100644 index 000000000..9a70776b5 --- /dev/null +++ b/migrations/20240920111733-dataset-unified-schema.js @@ -0,0 +1,51 @@ +module.exports = { + async up(db, client) { + // TODO write your migration here. + // See https://github.com/seppevs/migrate-mongo/#creating-a-new-migration-script + // Example: + // await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}}); + await db.collection("Dataset").updateMany( + {}, + { + $set: { + proposalIds: "$proposalId", + instrumentIds: "$instrumentId", + sampleIds: "$sampleId", + }, + }, + ); + await db.collection("Dataset").updateMany( + { type: "derived" }, + { + $set: { + principalInvestigator: "$investigator", + }, + }, + ); + }, + + async down(db, client) { + // TODO write the statements to rollback your migration (if possible) + // Example: + // await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}}); + + await db.collection("Dataset").updateMany( + {}, + { + $set: { + proposalId: "$proposalIds[0]", + instrumentId: "$instrumentId[0]", + sampleId: "$sampleId[0]", + }, + }, + ); + await db.collection("Dataset").updateMany( + { type: "derived" }, + { + $set: { + investigator: "$principalInvestigator", + }, + }, + ); + }, +}; From c5e1040a0d59f52e9a03a9666ceabd479858100a Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 20 Sep 2024 13:54:22 +0200 Subject: [PATCH 30/38] Fixed mongo migrate script for dataset unified schema --- .../20240920111733-dataset-unified-schema.js | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/migrations/20240920111733-dataset-unified-schema.js b/migrations/20240920111733-dataset-unified-schema.js index 9a70776b5..598d6db6c 100644 --- a/migrations/20240920111733-dataset-unified-schema.js +++ b/migrations/20240920111733-dataset-unified-schema.js @@ -4,24 +4,22 @@ module.exports = { // See https://github.com/seppevs/migrate-mongo/#creating-a-new-migration-script // Example: // await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}}); - await db.collection("Dataset").updateMany( - {}, + await db.collection("Dataset").updateMany({}, [ { $set: { - proposalIds: "$proposalId", - instrumentIds: "$instrumentId", - sampleIds: "$sampleId", + proposalIds: ["$proposalId"], + instrumentIds: ["$instrumentId"], + sampleIds: ["$sampleId"], }, }, - ); - await db.collection("Dataset").updateMany( - { type: "derived" }, + ]); + await db.collection("Dataset").updateMany({ type: "derived" }, [ { $set: { principalInvestigator: "$investigator", }, }, - ); + ]); }, async down(db, client) { @@ -29,8 +27,7 @@ module.exports = { // Example: // await db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}}); - await db.collection("Dataset").updateMany( - {}, + await db.collection("Dataset").updateMany({}, [ { $set: { proposalId: "$proposalIds[0]", @@ -38,14 +35,13 @@ module.exports = { sampleId: "$sampleId[0]", }, }, - ); - await db.collection("Dataset").updateMany( - { type: "derived" }, + ]); + await db.collection("Dataset").updateMany({ type: "derived" }, [ { $set: { investigator: "$principalInvestigator", }, }, - ); + ]); }, }; From 9ab8db2ef3f0988ad570ba399ee520bee13ebf83 Mon Sep 17 00:00:00 2001 From: junjiequan Date: Mon, 23 Sep 2024 14:21:37 +0200 Subject: [PATCH 31/38] fix: renamed instrumentIds key to instrumentId key in convertObsoleteToCurrentSchema function --- src/datasets/datasets.controller.ts | 4 ++-- src/datasets/dto/update-raw-dataset-obsolete.dto.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index bfc9dd843..920ba0aee 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -424,7 +424,7 @@ export class DatasetsController { (inputObsoleteDataset as CreateRawDatasetObsoleteDto).sampleId, ]; } - if ("instrumentIds" in inputObsoleteDataset) { + if ("instrumentId" in inputObsoleteDataset) { propertiesModifier.instrumentIds = [ (inputObsoleteDataset as CreateRawDatasetObsoleteDto).instrumentId, ]; @@ -557,7 +557,7 @@ export class DatasetsController { obsoleteDatasetDto, ) as CreateDatasetDto; const createdDataset = await this.datasetsService.create(datasetDto); - + console.log("====createdDataset====", createdDataset); const outputObsoleteDatasetDto = this.convertCurrentToObsoleteSchema(createdDataset); diff --git a/src/datasets/dto/update-raw-dataset-obsolete.dto.ts b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts index 020cbcf70..50096b914 100644 --- a/src/datasets/dto/update-raw-dataset-obsolete.dto.ts +++ b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts @@ -77,7 +77,7 @@ export class UpdateRawDatasetObsoleteDto extends UpdateDatasetObsoleteDto { }) @IsOptional() @IsString() - readonly instrumentId: string; + readonly instrumentId?: string; @IsOptional() investigator?: string; From bdde868767e546ab13b792ab38714298fbf1a6bb Mon Sep 17 00:00:00 2001 From: junjiequan Date: Mon, 23 Sep 2024 14:24:48 +0200 Subject: [PATCH 32/38] remove consolel.log --- src/datasets/datasets.controller.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 920ba0aee..f0ee5977c 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -557,7 +557,6 @@ export class DatasetsController { obsoleteDatasetDto, ) as CreateDatasetDto; const createdDataset = await this.datasetsService.create(datasetDto); - console.log("====createdDataset====", createdDataset); const outputObsoleteDatasetDto = this.convertCurrentToObsoleteSchema(createdDataset); From d1420aa558a34a3fc3ee21dea2274c68dc6dc14f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:54:33 +0000 Subject: [PATCH 33/38] build(deps): bump actions/setup-python from 4 to 5 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/release-and-publish-sdk.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-and-publish-sdk.yml b/.github/workflows/release-and-publish-sdk.yml index c46b76036..980cbe8d6 100644 --- a/.github/workflows/release-and-publish-sdk.yml +++ b/.github/workflows/release-and-publish-sdk.yml @@ -215,7 +215,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }} From 1d381be302c36df93877e962e6b9abc1f151723a Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 24 Sep 2024 14:40:13 +0200 Subject: [PATCH 34/38] fixing the dataset output dto --- src/datasets/datasets.controller.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index f0ee5977c..ba6faa208 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -746,7 +746,8 @@ export class DatasetsController { const includeFilters = mergedFilters.include ?? []; await Promise.all( datasets.map(async (dataset) => { - if (includeFilters) { + dataset = this.convertCurrentToObsoleteSchema(dataset); + if (includeFilters) { await Promise.all( includeFilters.map(async ({ relation }) => { switch (relation) { @@ -1169,7 +1170,7 @@ export class DatasetsController { await this.checkPermissionsForDatasetObsolete(request, id), ); - return dataset as OutputDatasetObsoleteDto; + return this.convertCurrentToObsoleteSchema(dataset) as OutputDatasetObsoleteDto; } // PATCH /datasets/:id From 441374fd0bfc52e321011b814172773057fb5319 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Tue, 24 Sep 2024 14:48:32 +0200 Subject: [PATCH 35/38] updated raw datasets to include instrument and sample id --- test/RawDataset.js | 3 +++ test/TestData.js | 2 ++ 2 files changed, 5 insertions(+) diff --git a/test/RawDataset.js b/test/RawDataset.js index c150faa40..6e9fcd748 100644 --- a/test/RawDataset.js +++ b/test/RawDataset.js @@ -93,6 +93,9 @@ describe("1900: RawDataset: Raw Datasets", () => { res.body.should.have.property("owner").and.be.string; res.body.should.have.property("type").and.equal("raw"); res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("instrumentId").and.be.string; + res.body.should.have.property("proposalId").and.be.string; + res.body.should.have.property("sampleId").and.be.string; pid = encodeURIComponent(res.body["pid"]); }); }); diff --git a/test/TestData.js b/test/TestData.js index 84a7090cb..09c806577 100644 --- a/test/TestData.js +++ b/test/TestData.js @@ -232,6 +232,8 @@ const TestData = { ownerGroup: "p13388", accessGroups: [], proposalId: "10.540.16635/20110123", + instrumentId: "1f016ec4-7a73-11ef-ae3e-439013069377", + sampleId: "20c32b4e-7a73-11ef-9aec-5b9688aa3791i", type: "raw", keywords: ["sls", "protein"], }, From 6ac5cc6ac0bd74e56bd2e471c49957500a8a33fb Mon Sep 17 00:00:00 2001 From: junjiequan Date: Wed, 25 Sep 2024 13:20:56 +0200 Subject: [PATCH 36/38] refactor: enable versioing for routes --- src/config/configuration.ts | 2 +- src/main.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/config/configuration.ts b/src/config/configuration.ts index 96e9e9bbd..94a190d89 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -59,7 +59,7 @@ const configuration = () => { const config = { versions: { - api: "v3", + api: "3", }, swaggerPath: process.env.SWAGGER_PATH || "explorer", loggerConfigs: jsonConfigMap.loggers || [defaultLogger], diff --git a/src/main.ts b/src/main.ts index 980dc66a8..3af41b802 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ import { SwaggerModule, } from "@nestjs/swagger"; import { AppModule } from "./app.module"; -import { Logger, ValidationPipe } from "@nestjs/common"; +import { Logger, ValidationPipe, VersioningType } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { AllExceptionsFilter, ScicatLogger } from "./loggers/logger.service"; @@ -29,11 +29,20 @@ async function bootstrap() { app.enableCors(); - app.setGlobalPrefix(`api/${apiVersion}`); + app.setGlobalPrefix("api"); + + // NOTE: This is a workaround to enable versioning for individual routes + // Version decorator can be used to specify the version for a route + // Read more on https://docs.nestjs.com/techniques/versioning + app.enableVersioning({ + type: VersioningType.URI, + defaultVersion: apiVersion, + }); + const config = new DocumentBuilder() .setTitle("SciCat backend API") .setDescription("This is the API for the SciCat Backend") - .setVersion(`api/${apiVersion}`) + .setVersion(`api/v${apiVersion}`) .addBearerAuth() .build(); From 2e9763b4a6fccfef9c24a32f1ddea161327f2d67 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Wed, 25 Sep 2024 16:34:40 +0200 Subject: [PATCH 37/38] fixed obsolete dataset dtos --- src/datasets/datasets.controller.ts | 37 ++++++++++--------- .../dto/output-dataset-obsolete.dto.ts | 16 ++++---- .../dto/update-dataset-obsolete.dto.ts | 9 +++++ .../dto/update-raw-dataset-obsolete.dto.ts | 16 ++++---- test/DerivedDataset.js | 3 ++ test/OrigDatablockForRawDataset.js | 1 - test/TestData.js | 3 ++ 7 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index ba6faa208..2f9491244 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -409,16 +409,16 @@ export class DatasetsController { version: "v3", }; + if ("proposalId" in inputObsoleteDataset) { + propertiesModifier.proposalIds = [ + (inputObsoleteDataset as CreateRawDatasetObsoleteDto).proposalId, + ]; + } if ( inputObsoleteDataset instanceof CreateRawDatasetObsoleteDto || inputObsoleteDataset instanceof UpdateRawDatasetObsoleteDto || inputObsoleteDataset instanceof PartialUpdateRawDatasetObsoleteDto ) { - if ("proposalId" in inputObsoleteDataset) { - propertiesModifier.proposalIds = [ - (inputObsoleteDataset as CreateRawDatasetObsoleteDto).proposalId, - ]; - } if ("sampleId" in inputObsoleteDataset) { propertiesModifier.sampleIds = [ (inputObsoleteDataset as CreateRawDatasetObsoleteDto).sampleId, @@ -476,15 +476,15 @@ export class DatasetsController { const propertiesModifier: Record = {}; if (inputDataset) { if ("proposalIds" in inputDataset) { - propertiesModifier.proposalIds = inputDataset.proposalIds![0]; + propertiesModifier.proposalId = inputDataset.proposalIds![0]; } if ("sampleIds" in inputDataset) { - propertiesModifier.sampleIds = inputDataset.sampleIds![0]; + propertiesModifier.sampleId = inputDataset.sampleIds![0]; } if ("instrumentIds" in inputDataset) { - propertiesModifier.instrumentIds = inputDataset.instrumentIds![0]; + propertiesModifier.instrumentId = inputDataset.instrumentIds![0]; } - if (inputDataset.type == "raw") { + if (inputDataset.type == "derived") { if ("investigator" in inputDataset) { propertiesModifier.investigator = inputDataset.principalInvestigator; } @@ -499,7 +499,7 @@ export class DatasetsController { return outputDataset; } - // POST /datasets + // POST https://scicat.ess.eu/api/v3/datasets @UseGuards(PoliciesGuard) @CheckPolicies("datasets", (ability: AppAbility) => ability.can(Action.DatasetCreate, DatasetClass), @@ -739,15 +739,16 @@ export class DatasetsController { ) as IFilters; // this should be implemented at database level - const datasets = (await this.datasetsService.findAll( - mergedFilters, - )) as OutputDatasetObsoleteDto[]; + const datasets = await this.datasetsService.findAll(mergedFilters); + let outputDatasets: OutputDatasetObsoleteDto[] = []; if (datasets && datasets.length > 0) { const includeFilters = mergedFilters.include ?? []; + outputDatasets = datasets.map((dataset) => + this.convertCurrentToObsoleteSchema(dataset), + ); await Promise.all( - datasets.map(async (dataset) => { - dataset = this.convertCurrentToObsoleteSchema(dataset); - if (includeFilters) { + outputDatasets.map(async (dataset) => { + if (includeFilters) { await Promise.all( includeFilters.map(async ({ relation }) => { switch (relation) { @@ -781,7 +782,7 @@ export class DatasetsController { }), ); } - return datasets; + return outputDatasets; } // GET /datasets/fullquery @@ -1170,7 +1171,7 @@ export class DatasetsController { await this.checkPermissionsForDatasetObsolete(request, id), ); - return this.convertCurrentToObsoleteSchema(dataset) as OutputDatasetObsoleteDto; + return dataset as OutputDatasetObsoleteDto; } // PATCH /datasets/:id diff --git a/src/datasets/dto/output-dataset-obsolete.dto.ts b/src/datasets/dto/output-dataset-obsolete.dto.ts index dced6bc31..bb511edcd 100644 --- a/src/datasets/dto/output-dataset-obsolete.dto.ts +++ b/src/datasets/dto/output-dataset-obsolete.dto.ts @@ -92,14 +92,14 @@ export class OutputDatasetObsoleteDto extends UpdateDatasetObsoleteDto { @IsString() readonly dataFormat?: string; - @ApiProperty({ - type: String, - required: false, - description: "The ID of the proposal to which the dataset belongs.", - }) - @IsOptional() - @IsString() - readonly proposalId?: string; + // @ApiProperty({ + // type: String, + // required: false, + // description: "The ID of the proposal to which the dataset belongs.", + // }) + // @IsOptional() + // @IsString() + // readonly proposalId?: string; @ApiProperty({ type: String, diff --git a/src/datasets/dto/update-dataset-obsolete.dto.ts b/src/datasets/dto/update-dataset-obsolete.dto.ts index ac0e996c8..73f4b34bd 100644 --- a/src/datasets/dto/update-dataset-obsolete.dto.ts +++ b/src/datasets/dto/update-dataset-obsolete.dto.ts @@ -288,6 +288,15 @@ export class UpdateDatasetObsoleteDto extends OwnableDto { @IsOptional() @IsNumber() readonly dataQualityMetrics?: number; + + @ApiProperty({ + type: String, + required: false, + description: "The ID of the proposal to which the dataset belongs.", + }) + @IsOptional() + @IsString() + readonly proposalId?: string; } export class PartialUpdateDatasetObsoleteDto extends PartialType( diff --git a/src/datasets/dto/update-raw-dataset-obsolete.dto.ts b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts index 50096b914..075406908 100644 --- a/src/datasets/dto/update-raw-dataset-obsolete.dto.ts +++ b/src/datasets/dto/update-raw-dataset-obsolete.dto.ts @@ -52,14 +52,14 @@ export class UpdateRawDatasetObsoleteDto extends UpdateDatasetObsoleteDto { @IsString() readonly dataFormat?: string; - @ApiProperty({ - type: String, - required: false, - description: "The ID of the proposal to which the dataset belongs.", - }) - @IsOptional() - @IsString() - readonly proposalId?: string; + // @ApiProperty({ + // type: String, + // required: false, + // description: "The ID of the proposal to which the dataset belongs.", + // }) + // @IsOptional() + // @IsString() + // readonly proposalId?: string; @ApiProperty({ type: String, diff --git a/test/DerivedDataset.js b/test/DerivedDataset.js index 1ccadc9ce..7e4c2e6ce 100644 --- a/test/DerivedDataset.js +++ b/test/DerivedDataset.js @@ -99,6 +99,9 @@ describe("0700: DerivedDataset: Derived Datasets", () => { .and.be.equal(TestData.DerivedCorrect.owner); res.body.should.have.property("type").and.be.equal("derived"); res.body.should.have.property("pid").and.be.string; + res.body.should.have.property("proposalId").and.be.string; + //res.body.should.have.property("sampleId").and.be.string; + //res.body.should.have.property("instrumentId").and.be.string; pid = res.body["pid"]; }); }); diff --git a/test/OrigDatablockForRawDataset.js b/test/OrigDatablockForRawDataset.js index 859b49333..d329d5867 100644 --- a/test/OrigDatablockForRawDataset.js +++ b/test/OrigDatablockForRawDataset.js @@ -304,7 +304,6 @@ describe("1200: OrigDatablockForRawDataset: Test OrigDatablocks and their relati .expect(TestData.SuccessfulGetStatusCode) .expect("Content-Type", /json/) .then((res) => { - console.log(res.body); res.body["pid"].should.be.equal(decodeURIComponent(datasetPid1)); res.body.origdatablocks.should.be .instanceof(Array) diff --git a/test/TestData.js b/test/TestData.js index 09c806577..801a45768 100644 --- a/test/TestData.js +++ b/test/TestData.js @@ -453,6 +453,9 @@ const TestData = { ownerGroup: "p34123", accessGroups: [], type: "derived", + proposalId: "10.540.16635/20110123", + //instrumentId: "1f016ec4-7a73-11ef-ae3e-439013069377", + //sampleId: "20c32b4e-7a73-11ef-9aec-5b9688aa3791i", }, DerivedWrong: { From dc9929248db2f56d62f5c56773ac19cd2ff0d662 Mon Sep 17 00:00:00 2001 From: Max Novelli Date: Fri, 27 Sep 2024 11:51:31 +0200 Subject: [PATCH 38/38] removed commented field from dataset dto --- src/datasets/dto/output-dataset-obsolete.dto.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/datasets/dto/output-dataset-obsolete.dto.ts b/src/datasets/dto/output-dataset-obsolete.dto.ts index bb511edcd..f99a7fe94 100644 --- a/src/datasets/dto/output-dataset-obsolete.dto.ts +++ b/src/datasets/dto/output-dataset-obsolete.dto.ts @@ -92,15 +92,6 @@ export class OutputDatasetObsoleteDto extends UpdateDatasetObsoleteDto { @IsString() readonly dataFormat?: string; - // @ApiProperty({ - // type: String, - // required: false, - // description: "The ID of the proposal to which the dataset belongs.", - // }) - // @IsOptional() - // @IsString() - // readonly proposalId?: string; - @ApiProperty({ type: String, required: false,