diff --git a/src/app/core/data/access-status-data.service.spec.ts b/src/app/core/data/access-status-data.service.spec.ts index dbc2bd9bf1..27c4005460 100644 --- a/src/app/core/data/access-status-data.service.spec.ts +++ b/src/app/core/data/access-status-data.service.spec.ts @@ -11,7 +11,6 @@ import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { ObjectCacheService } from '../cache/object-cache.service'; -import { Bitstream } from '../shared/bitstream.model'; import { Item } from '../shared/item.model'; import { AccessStatusDataService } from './access-status-data.service'; import { RemoteData } from './remote-data'; @@ -42,20 +41,6 @@ describe('AccessStatusDataService', () => { }, }); - const bitstreamId = '3d4c730u-5a4b-438b-9686-be1d5b4a1c5a'; - const mockBitstream: Bitstream = Object.assign(new Bitstream(), { - id: bitstreamId, - name: 'test-bitstream', - _links: { - accessStatus: { - href: `https://rest.api/core/bitstreams/${bitstreamId}/accessStatus`, - }, - self: { - href: `https://rest.api/core/bitstreams/${bitstreamId}`, - }, - }, - }); - describe('when the requests are successful', () => { beforeEach(() => { createService(); @@ -74,20 +59,6 @@ describe('AccessStatusDataService', () => { expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true); })); }); - - describe('when calling findBitstreamAccessStatusFor', () => { - let contentSource$; - - beforeEach(() => { - contentSource$ = service.findBitstreamAccessStatusFor(mockBitstream); - }); - - it('should send a new GetRequest', fakeAsync(() => { - contentSource$.subscribe(); - tick(); - expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true); - })); - }); }); /** diff --git a/src/app/core/data/access-status-data.service.ts b/src/app/core/data/access-status-data.service.ts index 8ab206583d..576b972f56 100644 --- a/src/app/core/data/access-status-data.service.ts +++ b/src/app/core/data/access-status-data.service.ts @@ -4,7 +4,6 @@ import { AccessStatusObject } from 'src/app/shared/object-collection/shared/badg import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { ObjectCacheService } from '../cache/object-cache.service'; -import { Bitstream } from '../shared/bitstream.model'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { Item } from '../shared/item.model'; import { BaseDataService } from './base/base-data.service'; @@ -33,12 +32,4 @@ export class AccessStatusDataService extends BaseDataService findItemAccessStatusFor(item: Item): Observable> { return this.findByHref(item._links.accessStatus.href); } - - /** - * Returns {@link RemoteData} of {@link AccessStatusObject} that is the access status of the given bitstream - * @param bitstream Bitstream we want the access status of - */ - findBitstreamAccessStatusFor(bitstream: Bitstream): Observable> { - return this.findByHref(bitstream._links.accessStatus.href); - } } diff --git a/src/app/item-page/full/field-components/file-section/full-file-section.component.ts b/src/app/item-page/full/field-components/file-section/full-file-section.component.ts index 463ee85635..73d844214a 100644 --- a/src/app/item-page/full/field-components/file-section/full-file-section.component.ts +++ b/src/app/item-page/full/field-components/file-section/full-file-section.component.ts @@ -109,6 +109,7 @@ export class FullFileSectionComponent extends FileSectionComponent implements On true, followLink('format'), followLink('thumbnail'), + followLink('accessStatus'), )), tap((rd: RemoteData>) => { if (hasValue(rd.errorMessage)) { @@ -127,6 +128,7 @@ export class FullFileSectionComponent extends FileSectionComponent implements On true, followLink('format'), followLink('thumbnail'), + followLink('accessStatus'), )), tap((rd: RemoteData>) => { if (hasValue(rd.errorMessage)) { diff --git a/src/app/item-page/simple/field-components/file-section/file-section.component.ts b/src/app/item-page/simple/field-components/file-section/file-section.component.ts index 9df34e0d13..5a71188987 100644 --- a/src/app/item-page/simple/field-components/file-section/file-section.component.ts +++ b/src/app/item-page/simple/field-components/file-section/file-section.component.ts @@ -29,6 +29,7 @@ import { MetadataFieldWrapperComponent } from '../../../../shared/metadata-field import { NotificationsService } from '../../../../shared/notifications/notifications.service'; import { FileSizePipe } from '../../../../shared/utils/file-size-pipe'; import { VarDirective } from '../../../../shared/utils/var.directive'; +import { followLink } from '../../../../shared/utils/follow-link-config.model'; /** * This component renders the file section of the item @@ -109,7 +110,7 @@ export class FileSectionComponent implements OnInit { this.bitstreamDataService.findAllByItemAndBundleName(this.item, 'ORIGINAL', { currentPage: this.currentPage, elementsPerPage: this.pageSize, - }).pipe( + }, true, true, followLink('accessStatus')).pipe( getFirstCompletedRemoteData(), ).subscribe((bitstreamsRD: RemoteData>) => { if (bitstreamsRD.errorMessage) { diff --git a/src/app/shared/object-collection/shared/badges/embargo-badge/embargo-badge.component.ts b/src/app/shared/object-collection/shared/badges/embargo-badge/embargo-badge.component.ts index 166aa47e4d..5950ccdddd 100644 --- a/src/app/shared/object-collection/shared/badges/embargo-badge/embargo-badge.component.ts +++ b/src/app/shared/object-collection/shared/badges/embargo-badge/embargo-badge.component.ts @@ -14,12 +14,12 @@ import { Observable, of as observableOf, } from 'rxjs'; -import { AccessStatusDataService } from 'src/app/core/data/access-status-data.service'; import { Bitstream } from 'src/app/core/shared/bitstream.model'; import { hasValue } from 'src/app/shared/empty.util'; import { environment } from 'src/environments/environment'; import { AccessStatusObject } from '../access-status-badge/access-status.model'; +import { getFirstSucceededRemoteDataPayload } from 'src/app/core/shared/operators'; @Component({ selector: 'ds-base-embargo-badge', @@ -42,27 +42,14 @@ export class EmbargoBadgeComponent implements OnInit { */ showAccessStatus: boolean; - /** - * Initialize instance variables - * - * @param {AccessStatusDataService} accessStatusDataService - */ - constructor(private accessStatusDataService: AccessStatusDataService) { } - ngOnInit(): void { this.showAccessStatus = environment.item.bitstream.showAccessStatuses; - if (!this.showAccessStatus || this.bitstream == null) { + if (!this.showAccessStatus || this.bitstream == null || this.bitstream.accessStatus == null) { // Do not show the badge if the feature is inactive or if the bitstream is null. return; } - this.embargoDate$ = this.accessStatusDataService.findBitstreamAccessStatusFor(this.bitstream).pipe( - map((accessStatusRD) => { - if (accessStatusRD.statusCode !== 401 && hasValue(accessStatusRD.payload)) { - return accessStatusRD.payload; - } else { - return null; - } - }), + this.embargoDate$ = this.bitstream.accessStatus.pipe( + getFirstSucceededRemoteDataPayload(), map((accessStatus: AccessStatusObject) => hasValue(accessStatus) ? accessStatus.embargoDate : null), catchError(() => observableOf(null)), ); diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index b9b554aa6a..b712546050 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -6870,5 +6870,5 @@ "metadata-export-filtered-items.columns.warning": "CSV export automatically includes all relevant fields, so selections in this list are not taken into account.", - "embargo.listelement.badge": "embargo until {{ date }}", + "embargo.listelement.badge": "Embargo until {{ date }}", } diff --git a/src/assets/i18n/fr.json5 b/src/assets/i18n/fr.json5 index 53f6526dc1..48a0f3b0d9 100644 --- a/src/assets/i18n/fr.json5 +++ b/src/assets/i18n/fr.json5 @@ -8597,5 +8597,5 @@ "metadata-export-filtered-items.columns.warning": "L'exportation CSV inclut automatiquement tous les champs pertinents, sans égard au contenu sélectionné de cette liste.", // "embargo.listelement.badge": "embargo until {{ date }}", - "embargo.listelement.badge": "embargo jusqu'à {{ date }}", + "embargo.listelement.badge": "Embargo jusqu'à {{ date }}", }