Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into feature/249-boilerplate-file-page
  • Loading branch information
MellyGray committed Jan 17, 2024
2 parents b5f65e2 + baa7faf commit 1f28e78
Show file tree
Hide file tree
Showing 17 changed files with 252 additions and 107 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-pr99.c36f1db",
"@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
33 changes: 19 additions & 14 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,52 +252,57 @@ export class DatasetVersion {
public readonly latestVersionPublishingStatus: DatasetPublishingStatus,
public readonly someDatasetVersionHasBeenReleased: boolean
) {
this.withLabels()
this.createLabels()
}

withLabels() {
this.withStatusLabel()
this.withVersionLabel()
createLabels() {
const statusLabels = this.createStatusLabels()
const versionLabels = this.createVersionNumberLabel()
this.labels.push(...statusLabels, ...versionLabels)
}

private withStatusLabel(): void {
createStatusLabels(): DatasetLabel[] {
const labels: DatasetLabel[] = []

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

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

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

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

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

return labels
}

private withVersionLabel(): void {
createVersionNumberLabel(): DatasetLabel[] {
const labels: DatasetLabel[] = []
if (this.publishingStatus === DatasetPublishingStatus.RELEASED) {
this.labels.push(
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${this.number.toString()}`)
)
}
return labels
}

build(): DatasetVersion {
Expand Down
60 changes: 6 additions & 54 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import {
DatasetMetadataBlock as JSDatasetMetadataBlock,
DatasetMetadataBlocks as JSDatasetMetadataBlocks,
DatasetMetadataFields as JSDatasetMetadataFields,
DatasetUserPermissions as JSDatasetPermissions,
DatasetVersionInfo as JSDatasetVersionInfo
DatasetUserPermissions as JSDatasetPermissions
} 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,17 +15,16 @@ import {
DatasetMetadataBlocks,
DatasetMetadataFields,
DatasetPermissions,
DatasetPublishingStatus,
DatasetVersion,
MetadataBlockName,
PrivateUrl,
DatasetVersionNumber
PrivateUrl
} from '../../domain/models/Dataset'
import {
FileDownloadMode,
FileDownloadSize,
FileSizeUnit
} from '../../../files/domain/models/FilePreview'
import { JSDatasetVersionMapper } from './JSDatasetVersionMapper'

export class JSDatasetMapper {
static toDataset(
Expand All @@ -41,10 +38,10 @@ export class JSDatasetMapper {
requestedVersion?: string,
privateUrl?: PrivateUrl
): Dataset {
const version = JSDatasetMapper.toVersion(
const version = JSDatasetVersionMapper.toVersion(
jsDataset.versionId,
jsDataset.versionInfo,
jsDataset.metadataBlocks,
JSDatasetMapper.toDatasetTitle(jsDataset.metadataBlocks),
jsDatasetCitation
)
return new Dataset.Builder(
Expand Down Expand Up @@ -74,49 +71,10 @@ export class JSDatasetMapper {
).build()
}

static toVersion(
jDatasetVersionId: number,
jsDatasetVersionInfo: JSDatasetVersionInfo,
jsDatasetMetadataBlocks: JSDatasetMetadataBlocks,
jsDatasetCitation: string
): DatasetVersion {
return new DatasetVersion.Builder(
jDatasetVersionId,
JSDatasetMapper.toDatasetTitle(jsDatasetMetadataBlocks),
JSDatasetMapper.toVersionNumber(jsDatasetVersionInfo),
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state),
jsDatasetCitation,
true, // TODO Connect with dataset version isLatest
false, // TODO Connect with dataset version isInReview
JSDatasetMapper.toStatus(jsDatasetVersionInfo.state),
JSDatasetMapper.toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo)
)
}

static toDatasetTitle(jsDatasetMetadataBlocks: JSDatasetMetadataBlocks): string {
return jsDatasetMetadataBlocks[0].fields.title
}

static toVersionNumber(jsDatasetVersionInfo: JSDatasetVersionInfo): DatasetVersionNumber {
return new DatasetVersionNumber(
jsDatasetVersionInfo.majorNumber,
jsDatasetVersionInfo.minorNumber
)
}

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 @@ -228,13 +186,6 @@ export class JSDatasetMapper {
}
}

static toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean {
return (
jsDatasetVersionInfo.releaseTime !== undefined &&
!isNaN(jsDatasetVersionInfo.releaseTime.getTime())
)
}

static toDatasetPermissions(jsDatasetPermissions: JSDatasetPermissions): DatasetPermissions {
return {
canDownloadFiles: true, // TODO: connect with js-dataverse
Expand All @@ -245,6 +196,7 @@ export class JSDatasetMapper {
canDeleteDataset: jsDatasetPermissions.canManageDatasetPermissions
}
}

static toLocks(jsDatasetLocks: JSDatasetLock[]): DatasetLock[] {
return jsDatasetLocks.map((jsDatasetLock) => {
return {
Expand Down
25 changes: 25 additions & 0 deletions src/dataset/infrastructure/mappers/JSDatasetPreviewMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DatasetPreview as JSDatasetPreview } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/DatasetPreview'
import { DatasetPreview } from '../../domain/models/DatasetPreview'
import { DatasetVersionInfo as JSDatasetVersionInfo } 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,
JSDatasetVersionMapper.toVersion(
jsDatasetPreview.versionId,
jsDatasetPreview.versionInfo,
jsDatasetPreview.title,
jsDatasetPreview.citation
),
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
}
}
56 changes: 56 additions & 0 deletions src/dataset/infrastructure/mappers/JSDatasetVersionMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
DatasetVersionInfo as JSDatasetVersionInfo,
DatasetVersionState as JSDatasetVersionState
} from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset'
import {
DatasetPublishingStatus,
DatasetVersion,
DatasetVersionNumber
} from '../../domain/models/Dataset'
export class JSDatasetVersionMapper {
static toVersion(
jDatasetVersionId: number,
jsDatasetVersionInfo: JSDatasetVersionInfo,
jsDatasetTitle: string,
jsDatasetCitation: string
): DatasetVersion {
return new DatasetVersion.Builder(
jDatasetVersionId,
jsDatasetTitle,
this.toVersionNumber(jsDatasetVersionInfo),
this.toStatus(jsDatasetVersionInfo.state),
jsDatasetCitation,
true, // TODO Connect with dataset version isLatest
false, // TODO Connect with dataset version isInReview
this.toStatus(jsDatasetVersionInfo.state),
this.toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo)
)
}

static toVersionNumber(jsDatasetVersionInfo: JSDatasetVersionInfo): DatasetVersionNumber {
return new DatasetVersionNumber(
jsDatasetVersionInfo.majorNumber,
jsDatasetVersionInfo.minorNumber
)
}

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 toSomeDatasetVersionHasBeenReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean {
return (
jsDatasetVersionInfo.releaseTime !== undefined &&
!isNaN(jsDatasetVersionInfo.releaseTime.getTime())
)
}
}
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,32 +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 All @@ -53,7 +55,11 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
Promise.all([
jsDataset,
getDatasetSummaryFieldNames.execute(),
getDatasetCitation.execute(jsDataset.id, this.versionToVersionId(version)),
getDatasetCitation.execute(
jsDataset.id,
this.versionToVersionId(version),
includeDeaccessioned
),
getDatasetUserPermissions.execute(jsDataset.id),
getDatasetLocks.execute(jsDataset.id),
getDatasetFilesTotalDownloadSize.execute(
Expand Down
5 changes: 2 additions & 3 deletions src/files/infrastructure/FileJSDataverseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ export class FileJSDataverseRepository implements FileRepository {
paginationInfo: FilePaginationInfo = new FilePaginationInfo(),
criteria: FileCriteria = new FileCriteria()
): Promise<FilePreview[]> {
const jsPagination = DomainFileMapper.toJSPagination(paginationInfo)
return getDatasetFiles
.execute(
datasetPersistentId,
datasetVersion.number.toString(),
includeDeaccessioned,
jsPagination.limit,
jsPagination.offset,
paginationInfo.pageSize,
paginationInfo.offset,
DomainFileMapper.toJSFileSearchCriteria(criteria),
DomainFileMapper.toJSFileOrderCriteria(criteria.sortBy)
)
Expand Down
Loading

0 comments on commit 1f28e78

Please sign in to comment.