Skip to content

Commit 353d660

Browse files
authored
Merge pull request #4212 from jesielviana/fix-bitstream-unable-to-change-format
Fix: prevent bitstream format cache issue by disabling cached version
2 parents ff3784a + bb53619 commit 353d660

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/app/core/data/bitstream-data.service.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import {
3737
} from './request.models';
3838
import { RequestService } from './request.service';
3939
import objectContaining = jasmine.objectContaining;
40+
import { RestResponse } from '../cache/response.models';
41+
import { RequestEntry } from './request-entry.model';
4042

4143
describe('BitstreamDataService', () => {
4244
let service: BitstreamDataService;
@@ -47,6 +49,7 @@ describe('BitstreamDataService', () => {
4749
let rdbService: RemoteDataBuildService;
4850
let bundleDataService: BundleDataService;
4951
const bitstreamFormatHref = 'rest-api/bitstreamformats';
52+
let responseCacheEntry: RequestEntry;
5053

5154
const bitstream1 = Object.assign(new Bitstream(), {
5255
id: 'fake-bitstream1',
@@ -71,8 +74,13 @@ describe('BitstreamDataService', () => {
7174
const url = 'fake-bitstream-url';
7275

7376
beforeEach(() => {
77+
responseCacheEntry = new RequestEntry();
78+
responseCacheEntry.request = { href: 'https://rest.api/' } as any;
79+
responseCacheEntry.response = new RestResponse(true, 200, 'Success');
80+
7481
objectCache = jasmine.createSpyObj('objectCache', {
7582
remove: jasmine.createSpy('remove'),
83+
getByHref: observableOf(responseCacheEntry),
7684
});
7785
requestService = getMockRequestService();
7886
halService = Object.assign(new HALEndpointServiceStub(url));

src/app/core/data/bitstream-data.service.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,25 @@ export class BitstreamDataService extends IdentifiableDataService<Bitstream> imp
163163
sendRequest(this.requestService),
164164
take(1),
165165
).subscribe(() => {
166-
this.requestService.removeByHrefSubstring(bitstream.self + '/format');
166+
this.deleteFormatCache(bitstream);
167167
});
168-
169168
return this.rdbService.buildFromRequestUUID(requestId);
170169
}
171170

171+
private deleteFormatCache(bitstream: Bitstream) {
172+
const bitsreamFormatUrl = bitstream.self + '/format';
173+
this.requestService.setStaleByHrefSubstring(bitsreamFormatUrl);
174+
// Delete also cache by uuid as the format could be cached also there
175+
this.objectCache.getByHref(bitsreamFormatUrl).pipe(take(1)).subscribe((cachedRequest) => {
176+
if (cachedRequest.requestUUIDs && cachedRequest.requestUUIDs.length > 0){
177+
const requestUuid = cachedRequest.requestUUIDs[0];
178+
if (this.requestService.hasByUUID(requestUuid)) {
179+
this.requestService.setStaleByUUID(requestUuid);
180+
}
181+
}
182+
});
183+
}
184+
172185
/**
173186
* Returns an observable of {@link RemoteData} of a {@link Bitstream}, based on a handle and an
174187
* optional sequenceId or filename, with a list of {@link FollowLinkConfig}, to automatically

0 commit comments

Comments
 (0)