Skip to content

Commit d72bc0d

Browse files
committed
Remove findBitstreamAccessStatusFor and replace it with followLink('accessStatus')
1 parent 5f83139 commit d72bc0d

7 files changed

Lines changed: 10 additions & 58 deletions

File tree

src/app/core/data/access-status-data.service.spec.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic
1111
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
1212
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
1313
import { ObjectCacheService } from '../cache/object-cache.service';
14-
import { Bitstream } from '../shared/bitstream.model';
1514
import { Item } from '../shared/item.model';
1615
import { AccessStatusDataService } from './access-status-data.service';
1716
import { RemoteData } from './remote-data';
@@ -42,20 +41,6 @@ describe('AccessStatusDataService', () => {
4241
},
4342
});
4443

45-
const bitstreamId = '3d4c730u-5a4b-438b-9686-be1d5b4a1c5a';
46-
const mockBitstream: Bitstream = Object.assign(new Bitstream(), {
47-
id: bitstreamId,
48-
name: 'test-bitstream',
49-
_links: {
50-
accessStatus: {
51-
href: `https://rest.api/core/bitstreams/${bitstreamId}/accessStatus`,
52-
},
53-
self: {
54-
href: `https://rest.api/core/bitstreams/${bitstreamId}`,
55-
},
56-
},
57-
});
58-
5944
describe('when the requests are successful', () => {
6045
beforeEach(() => {
6146
createService();
@@ -74,20 +59,6 @@ describe('AccessStatusDataService', () => {
7459
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true);
7560
}));
7661
});
77-
78-
describe('when calling findBitstreamAccessStatusFor', () => {
79-
let contentSource$;
80-
81-
beforeEach(() => {
82-
contentSource$ = service.findBitstreamAccessStatusFor(mockBitstream);
83-
});
84-
85-
it('should send a new GetRequest', fakeAsync(() => {
86-
contentSource$.subscribe();
87-
tick();
88-
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest), true);
89-
}));
90-
});
9162
});
9263

9364
/**

src/app/core/data/access-status-data.service.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { AccessStatusObject } from 'src/app/shared/object-collection/shared/badg
44

55
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
66
import { ObjectCacheService } from '../cache/object-cache.service';
7-
import { Bitstream } from '../shared/bitstream.model';
87
import { HALEndpointService } from '../shared/hal-endpoint.service';
98
import { Item } from '../shared/item.model';
109
import { BaseDataService } from './base/base-data.service';
@@ -33,12 +32,4 @@ export class AccessStatusDataService extends BaseDataService<AccessStatusObject>
3332
findItemAccessStatusFor(item: Item): Observable<RemoteData<AccessStatusObject>> {
3433
return this.findByHref(item._links.accessStatus.href);
3534
}
36-
37-
/**
38-
* Returns {@link RemoteData} of {@link AccessStatusObject} that is the access status of the given bitstream
39-
* @param bitstream Bitstream we want the access status of
40-
*/
41-
findBitstreamAccessStatusFor(bitstream: Bitstream): Observable<RemoteData<AccessStatusObject>> {
42-
return this.findByHref(bitstream._links.accessStatus.href);
43-
}
4435
}

src/app/item-page/full/field-components/file-section/full-file-section.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class FullFileSectionComponent extends FileSectionComponent implements On
109109
true,
110110
followLink('format'),
111111
followLink('thumbnail'),
112+
followLink('accessStatus'),
112113
)),
113114
tap((rd: RemoteData<PaginatedList<Bitstream>>) => {
114115
if (hasValue(rd.errorMessage)) {
@@ -127,6 +128,7 @@ export class FullFileSectionComponent extends FileSectionComponent implements On
127128
true,
128129
followLink('format'),
129130
followLink('thumbnail'),
131+
followLink('accessStatus'),
130132
)),
131133
tap((rd: RemoteData<PaginatedList<Bitstream>>) => {
132134
if (hasValue(rd.errorMessage)) {

src/app/item-page/simple/field-components/file-section/file-section.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { MetadataFieldWrapperComponent } from '../../../../shared/metadata-field
2929
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
3030
import { FileSizePipe } from '../../../../shared/utils/file-size-pipe';
3131
import { VarDirective } from '../../../../shared/utils/var.directive';
32+
import { followLink } from '../../../../shared/utils/follow-link-config.model';
3233

3334
/**
3435
* This component renders the file section of the item
@@ -109,7 +110,7 @@ export class FileSectionComponent implements OnInit {
109110
this.bitstreamDataService.findAllByItemAndBundleName(this.item, 'ORIGINAL', {
110111
currentPage: this.currentPage,
111112
elementsPerPage: this.pageSize,
112-
}).pipe(
113+
}, true, true, followLink('accessStatus')).pipe(
113114
getFirstCompletedRemoteData(),
114115
).subscribe((bitstreamsRD: RemoteData<PaginatedList<Bitstream>>) => {
115116
if (bitstreamsRD.errorMessage) {

src/app/shared/object-collection/shared/badges/embargo-badge/embargo-badge.component.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import {
1414
Observable,
1515
of as observableOf,
1616
} from 'rxjs';
17-
import { AccessStatusDataService } from 'src/app/core/data/access-status-data.service';
1817
import { Bitstream } from 'src/app/core/shared/bitstream.model';
1918
import { hasValue } from 'src/app/shared/empty.util';
2019
import { environment } from 'src/environments/environment';
2120

2221
import { AccessStatusObject } from '../access-status-badge/access-status.model';
22+
import { getFirstSucceededRemoteDataPayload } from 'src/app/core/shared/operators';
2323

2424
@Component({
2525
selector: 'ds-base-embargo-badge',
@@ -42,27 +42,14 @@ export class EmbargoBadgeComponent implements OnInit {
4242
*/
4343
showAccessStatus: boolean;
4444

45-
/**
46-
* Initialize instance variables
47-
*
48-
* @param {AccessStatusDataService} accessStatusDataService
49-
*/
50-
constructor(private accessStatusDataService: AccessStatusDataService) { }
51-
5245
ngOnInit(): void {
5346
this.showAccessStatus = environment.item.bitstream.showAccessStatuses;
54-
if (!this.showAccessStatus || this.bitstream == null) {
47+
if (!this.showAccessStatus || this.bitstream == null || this.bitstream.accessStatus == null) {
5548
// Do not show the badge if the feature is inactive or if the bitstream is null.
5649
return;
5750
}
58-
this.embargoDate$ = this.accessStatusDataService.findBitstreamAccessStatusFor(this.bitstream).pipe(
59-
map((accessStatusRD) => {
60-
if (accessStatusRD.statusCode !== 401 && hasValue(accessStatusRD.payload)) {
61-
return accessStatusRD.payload;
62-
} else {
63-
return null;
64-
}
65-
}),
51+
this.embargoDate$ = this.bitstream.accessStatus.pipe(
52+
getFirstSucceededRemoteDataPayload(),
6653
map((accessStatus: AccessStatusObject) => hasValue(accessStatus) ? accessStatus.embargoDate : null),
6754
catchError(() => observableOf(null)),
6855
);

src/assets/i18n/en.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6870,5 +6870,5 @@
68706870

68716871
"metadata-export-filtered-items.columns.warning": "CSV export automatically includes all relevant fields, so selections in this list are not taken into account.",
68726872

6873-
"embargo.listelement.badge": "embargo until {{ date }}",
6873+
"embargo.listelement.badge": "Embargo until {{ date }}",
68746874
}

src/assets/i18n/fr.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8597,5 +8597,5 @@
85978597
"metadata-export-filtered-items.columns.warning": "L'exportation CSV inclut automatiquement tous les champs pertinents, sans égard au contenu sélectionné de cette liste.",
85988598

85998599
// "embargo.listelement.badge": "embargo until {{ date }}",
8600-
"embargo.listelement.badge": "embargo jusqu'à {{ date }}",
8600+
"embargo.listelement.badge": "Embargo jusqu'à {{ date }}",
86018601
}

0 commit comments

Comments
 (0)