Skip to content

Commit

Permalink
Merge pull request #274 from IQSS/features/250-dataset-list-integration
Browse files Browse the repository at this point in the history
Features/250 dataset list integration
  • Loading branch information
GPortas authored Jan 11, 2024
2 parents b7fa0f5 + f7b6f61 commit baa7faf
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 118 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@faker-js/faker": "7.6.0",
"@iqss/dataverse-client-javascript": "2.0.0-pr105.302daff",
"@iqss/dataverse-client-javascript": "2.0.0-pr107.228a37e",
"@iqss/dataverse-design-system": "*",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@tanstack/react-table": "8.9.2",
Expand Down
105 changes: 59 additions & 46 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,64 @@ export class Dataset {
return false
}

static createDatasetLabels(version: DatasetVersion, isReleased: boolean): DatasetLabel[] {
const statusLabels = Dataset.createStatusLabels(
version.publishingStatus,
version.isInReview,
isReleased
)
const versionLabels = Dataset.createVersionLabel(version)
return [...statusLabels, ...versionLabels] // combine and return
}

static createStatusLabels(
publishingStatus: DatasetPublishingStatus,
isInReview: boolean,
isReleased: boolean
): DatasetLabel[] {
const labels: DatasetLabel[] = []

if (publishingStatus === DatasetPublishingStatus.DRAFT) {
labels.push(new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.DRAFT))
}

if (!isReleased) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.WARNING, DatasetLabelValue.UNPUBLISHED)
)
}

if (publishingStatus === DatasetPublishingStatus.DEACCESSIONED) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DANGER, DatasetLabelValue.DEACCESSIONED)
)
}

if (publishingStatus === DatasetPublishingStatus.EMBARGOED) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.EMBARGOED)
)
}

if (isInReview) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.SUCCESS, DatasetLabelValue.IN_REVIEW)
)
}

return labels
}

static createVersionLabel(version: DatasetVersion): DatasetLabel[] {
const labels: DatasetLabel[] = []
if (version.publishingStatus === DatasetPublishingStatus.RELEASED) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${version.toString()}`)
)
}
return labels
}

static Builder = class {
public readonly labels: DatasetLabel[] = []
public readonly alerts: Alert[] = []
Expand All @@ -376,55 +434,10 @@ export class Dataset {
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl
) {
this.withLabels()
this.labels = Dataset.createDatasetLabels(version, isReleased)
this.withAlerts()
}

withLabels() {
this.withStatusLabel()
this.withVersionLabel()
}

private withStatusLabel(): void {
if (this.version.publishingStatus === DatasetPublishingStatus.DRAFT) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.DRAFT)
)
}

if (!this.isReleased) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.WARNING, DatasetLabelValue.UNPUBLISHED)
)
}

if (this.version.publishingStatus === DatasetPublishingStatus.DEACCESSIONED) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DANGER, DatasetLabelValue.DEACCESSIONED)
)
}

if (this.version.publishingStatus === DatasetPublishingStatus.EMBARGOED) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.EMBARGOED)
)
}

if (this.version.isInReview) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.SUCCESS, DatasetLabelValue.IN_REVIEW)
)
}
}

private withVersionLabel(): void {
if (this.version.publishingStatus === DatasetPublishingStatus.RELEASED) {
this.labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${this.version.toString()}`)
)
}
}

private withAlerts(): void {
if (
this.version.publishingStatus === DatasetPublishingStatus.DRAFT &&
Expand Down
14 changes: 11 additions & 3 deletions src/dataset/domain/models/DatasetPreview.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { DatasetLabel, DatasetVersion } from './Dataset'
import { DatasetLabel, DatasetVersion, Dataset } from './Dataset'

export class DatasetPreview {
public labels: DatasetLabel[]

constructor(
public persistentId: string,
public title: string,
public version: DatasetVersion,
public isReleased: boolean,
public citation: string,
public labels: DatasetLabel[],
public isDeaccessioned: boolean,
public releaseOrCreateDate: Date,
public description: string,
public thumbnail?: string
) {}
) {
this.labels = Dataset.createStatusLabels(
version.publishingStatus,
version.isInReview,
this.isReleased
)
}

get abbreviatedDescription(): string {
if (this.description.length > 280) {
Expand Down
36 changes: 3 additions & 33 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
DatasetUserPermissions as JSDatasetPermissions,
DatasetVersionInfo as JSDatasetVersionInfo
} from '@iqss/dataverse-client-javascript'
import { DatasetVersionState as JSDatasetVersionState } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset'
import {
Dataset,
DatasetDownloadUrls,
Expand All @@ -17,12 +16,12 @@ import {
DatasetMetadataBlocks,
DatasetMetadataFields,
DatasetPermissions,
DatasetPublishingStatus,
DatasetVersion,
MetadataBlockName,
PrivateUrl
} from '../../domain/models/Dataset'
import { FileDownloadMode, FileDownloadSize, FileSizeUnit } from '../../../files/domain/models/File'
import { JSDatasetVersionMapper } from './JSDatasetVersionMapper'

export class JSDatasetMapper {
static toDataset(
Expand All @@ -36,7 +35,7 @@ export class JSDatasetMapper {
requestedVersion?: string,
privateUrl?: PrivateUrl
): Dataset {
const version = JSDatasetMapper.toVersion(
const version = JSDatasetVersionMapper.toDatasetVersion(
jsDataset.versionId,
jsDataset.versionInfo,
requestedVersion
Expand Down Expand Up @@ -69,36 +68,6 @@ export class JSDatasetMapper {
).build()
}

static toVersion(
jDatasetVersionId: number,
jsDatasetVersionInfo: JSDatasetVersionInfo,
requestedVersion?: string
): DatasetVersion {
return new DatasetVersion(
jDatasetVersionId,
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state),
true, // TODO Connect with dataset version isLatest
false, // TODO Connect with dataset version isInReview
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state), // TODO Connect with dataset version latestVersionState
jsDatasetVersionInfo.majorNumber,
jsDatasetVersionInfo.minorNumber,
requestedVersion
)
}

static toStatus(jsDatasetVersionState: JSDatasetVersionState): DatasetPublishingStatus {
switch (jsDatasetVersionState) {
case JSDatasetVersionState.DRAFT:
return DatasetPublishingStatus.DRAFT
case JSDatasetVersionState.DEACCESSIONED:
return DatasetPublishingStatus.DEACCESSIONED
case JSDatasetVersionState.RELEASED:
return DatasetPublishingStatus.RELEASED
default:
return DatasetPublishingStatus.DRAFT
}
}

static toSummaryFields(
jsDatasetMetadataBlocks: JSDatasetMetadataBlocks,
summaryFieldsNames: string[]
Expand Down Expand Up @@ -217,6 +186,7 @@ export class JSDatasetMapper {
canDeleteDataset: jsDatasetPermissions.canManageDatasetPermissions
}
}

static toLocks(jsDatasetLocks: JSDatasetLock[]): DatasetLock[] {
return jsDatasetLocks.map((jsDatasetLock) => {
return {
Expand Down
30 changes: 30 additions & 0 deletions src/dataset/infrastructure/mappers/JSDatasetPreviewMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DatasetPreview as JSDatasetPreview } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/DatasetPreview'
import { DatasetPreview } from '../../domain/models/DatasetPreview'
import {
DatasetVersionInfo as JSDatasetVersionInfo,
DatasetVersionState as JSDatasetVersionState
} from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset'
import { JSDatasetVersionMapper } from './JSDatasetVersionMapper'

export class JSDatasetPreviewMapper {
static toDatasetPreview(jsDatasetPreview: JSDatasetPreview): DatasetPreview {
return new DatasetPreview(
jsDatasetPreview.persistentId,
jsDatasetPreview.title,
JSDatasetVersionMapper.toDatasetVersion(
jsDatasetPreview.versionId,
jsDatasetPreview.versionInfo
),
jsDatasetPreview.versionInfo.releaseTime != undefined,
jsDatasetPreview.citation,
jsDatasetPreview.versionInfo.state === JSDatasetVersionState.DEACCESSIONED,
JSDatasetPreviewMapper.toPreviewDate(jsDatasetPreview.versionInfo),
jsDatasetPreview.description,
undefined // TODO: get dataset thumbnail from Dataverse https://github.com/IQSS/dataverse-frontend/issues/203
)
}

static toPreviewDate(jsVersionInfo: JSDatasetVersionInfo): Date {
return jsVersionInfo.releaseTime ? jsVersionInfo.releaseTime : jsVersionInfo.createTime
}
}
36 changes: 36 additions & 0 deletions src/dataset/infrastructure/mappers/JSDatasetVersionMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
DatasetVersionInfo as JSDatasetVersionInfo,
DatasetVersionState as JSDatasetVersionState
} from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset'
import { DatasetPublishingStatus, DatasetVersion } from '../../domain/models/Dataset'
export class JSDatasetVersionMapper {
static toDatasetVersion(
jDatasetVersionId: number,
jsDatasetVersionInfo: JSDatasetVersionInfo,
requestedVersion?: string
): DatasetVersion {
return new DatasetVersion(
jDatasetVersionId,
JSDatasetVersionMapper.toStatus(jsDatasetVersionInfo.state),
true, // TODO Connect with dataset version isLatest
false, // TODO Connect with dataset version isInReview
JSDatasetVersionMapper.toStatus(jsDatasetVersionInfo.state), // TODO Connect with dataset version latestVersionState
jsDatasetVersionInfo.majorNumber,
jsDatasetVersionInfo.minorNumber,
requestedVersion
)
}

static toStatus(jsDatasetVersionState: JSDatasetVersionState): DatasetPublishingStatus {
switch (jsDatasetVersionState) {
case JSDatasetVersionState.DRAFT:
return DatasetPublishingStatus.DRAFT
case JSDatasetVersionState.DEACCESSIONED:
return DatasetPublishingStatus.DEACCESSIONED
case JSDatasetVersionState.RELEASED:
return DatasetPublishingStatus.RELEASED
default:
return DatasetPublishingStatus.DRAFT
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { DatasetRepository } from '../../domain/repositories/DatasetRepository'
import { Dataset } from '../../domain/models/Dataset'
import {
getDataset,
getAllDatasetPreviews,
getDatasetCitation,
getDatasetSummaryFieldNames,
Dataset as JSDataset,
DatasetPreview as JSDatasetPreview,
DatasetUserPermissions as JSDatasetPermissions,
getPrivateUrlDataset,
getPrivateUrlDatasetCitation,
Expand All @@ -13,33 +15,32 @@ import {
getDatasetLocks,
DatasetLock as JSDatasetLock,
getDatasetFilesTotalDownloadSize,
FileDownloadSizeMode
FileDownloadSizeMode,
DatasetPreviewSubset
} from '@iqss/dataverse-client-javascript'
import { JSDatasetMapper } from '../mappers/JSDatasetMapper'
import { TotalDatasetsCount } from '../../domain/models/TotalDatasetsCount'
import { DatasetPaginationInfo } from '../../domain/models/DatasetPaginationInfo'
import { DatasetPreview } from '../../domain/models/DatasetPreview'
import { DatasetPreviewMother } from '../../../../tests/component/dataset/domain/models/DatasetPreviewMother'
import { JSDatasetPreviewMapper } from '../mappers/JSDatasetPreviewMapper'

const includeDeaccessioned = true

export class DatasetJSDataverseRepository implements DatasetRepository {
// eslint-disable-next-line unused-imports/no-unused-vars
getAll(paginationInfo: DatasetPaginationInfo): Promise<DatasetPreview[]> {
// TODO - Implement using the js-dataverse-client
return new Promise((resolve) => {
setTimeout(() => {
resolve(DatasetPreviewMother.createManyRealistic(10))
}, 1000)
})
return getAllDatasetPreviews
.execute(paginationInfo.pageSize, paginationInfo.offset)
.then((subset: DatasetPreviewSubset) => {
return subset.datasetPreviews.map((datasetPreview: JSDatasetPreview) =>
JSDatasetPreviewMapper.toDatasetPreview(datasetPreview)
)
})
}

getTotalDatasetsCount(): Promise<TotalDatasetsCount> {
// TODO - Implement using the js-dataverse-client
return new Promise((resolve) => {
setTimeout(() => {
resolve(200)
}, 1000)
// TODO: refactor this so we don't make the same call twice?
return getAllDatasetPreviews.execute(10, 0).then((subset: DatasetPreviewSubset) => {
return subset.totalDatasetCount
})
}

Expand Down
Loading

0 comments on commit baa7faf

Please sign in to comment.