Skip to content

Commit 14ce8c7

Browse files
rezartatisatarix83
authored andcommitted
Merged in DSC-747-use-new-find-method-to-retrieve-item-attachments (pull request DSpace#321)
DSC-747 use new find method to retrieve item attachments Approved-by: Giuseppe Digilio
2 parents 4a8b725 + d298ba3 commit 14ce8c7

7 files changed

Lines changed: 135 additions & 142 deletions

File tree

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.util
3030
import { PageInfo } from '../shared/page-info.model';
3131
import { RequestParam } from '../cache/models/request-param.model';
3232

33+
export interface MetadataFilter {
34+
metadataName: string;
35+
metadataValue: string;
36+
}
37+
3338
/**
3439
* A service to retrieve {@link Bitstream}s from the REST API
3540
*/
@@ -183,4 +188,53 @@ export class BitstreamDataService extends DataService<Bitstream> {
183188
);
184189
}
185190

191+
192+
/**
193+
* Returns an observable of {@link RemoteData} of a {@link Bitstream}, based on a handle and an
194+
* optional sequenceId or filename, with a list of {@link FollowLinkConfig}, to automatically
195+
* resolve {@link HALLink}s of the object
196+
*
197+
* @param uuid The item UUID to retrieve bitstreams from
198+
* @param bundlename Bundle type of the bitstreams
199+
* @param metadataFilters Array of object we want to filter by
200+
* @param options The {@link FindListOptions} for the request
201+
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
202+
* no valid cached version. Defaults to true
203+
* @param reRequestOnStale Whether or not the request should automatically be re-
204+
* requested after the response becomes stale
205+
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
206+
* {@link HALLink}s should be automatically resolved
207+
*/
208+
findByItem(
209+
uuid: string,
210+
bundlename: string,
211+
metadataFilters: MetadataFilter[],
212+
options: FindListOptions,
213+
useCachedVersionIfAvailable = true,
214+
reRequestOnStale = true,
215+
...linksToFollow: FollowLinkConfig<Bitstream>[]
216+
): Observable<RemoteData<PaginatedList<Bitstream>>> {
217+
const searchParams = [];
218+
searchParams.push(new RequestParam('uuid', uuid));
219+
searchParams.push(new RequestParam('name', bundlename));
220+
221+
metadataFilters.forEach((entry: MetadataFilter) => {
222+
searchParams.push(new RequestParam('filterMetadata', entry.metadataName));
223+
searchParams.push(new RequestParam('filterMetadataValue', entry.metadataValue));
224+
});
225+
226+
const hrefObs = this.getSearchByHref(
227+
'byItemId',
228+
{ searchParams },
229+
...linksToFollow
230+
);
231+
232+
return this.findAllByHref(
233+
hrefObs,
234+
options,
235+
useCachedVersionIfAvailable,
236+
reRequestOnStale,
237+
...linksToFollow
238+
);
239+
}
186240
}

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/advanced-attachment/advanced-attachment.component.spec.ts

Lines changed: 18 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ describe('AdvancedAttachmentComponent', () => {
130130
return createSuccessfulRemoteDataObject$(new Bitstream());
131131
},
132132
findAllByItemAndBundleName: jasmine.createSpy('findAllByItemAndBundleName'),
133+
findByItem: jasmine.createSpy('findByItem'),
133134
});
134135

135136
const mockAuthorizedService = jasmine.createSpyObj('AuthorizationDataService', {
@@ -169,7 +170,8 @@ describe('AdvancedAttachmentComponent', () => {
169170
mockAuthorizedService.isAuthorized.and.returnValues(of(true), of(true));
170171
component.envPagination.enabled = false;
171172
mockBitstreamDataService.findAllByItemAndBundleName.and.returnValues(createSuccessfulRemoteDataObject$(createPaginatedList([bitstream1])));
172-
let spy = spyOn(component, 'getBitstreams');
173+
mockBitstreamDataService.findByItem.and.returnValues(createSuccessfulRemoteDataObject$(createPaginatedList([bitstream1])));
174+
let spy = spyOn(component, 'getBitstreamsByItem');
173175
spy.and.returnValue(of(createPaginatedList(attachmentsMock)));
174176
component.item = testItem;
175177
fixture.detectChanges();
@@ -181,7 +183,7 @@ describe('AdvancedAttachmentComponent', () => {
181183

182184
it('should retrieve bitstreams without pagination', fakeAsync(() => {
183185
flush();
184-
expect(component.getBitstreams).toHaveBeenCalledWith();
186+
expect(component.getBitstreamsByItem).toHaveBeenCalled();
185187
}));
186188

187189
it('should not show view more button', fakeAsync(() => {
@@ -214,8 +216,8 @@ describe('AdvancedAttachmentComponent', () => {
214216
fixture = TestBed.createComponent(AdvancedAttachmentComponent);
215217
component = fixture.componentInstance;
216218
de = fixture.debugElement;
217-
let spy = spyOn(component, 'getBitstreams');
218-
spy.and.returnValue(of(createPaginatedList(attachmentsMock)));
219+
let spy = spyOn(component, 'getBitstreamsByItem');
220+
spy.and.returnValue(of(createPaginatedList([attachmentsMock[1]])));
219221
component.item = testItem;
220222
fixture.detectChanges();
221223
});
@@ -226,26 +228,6 @@ describe('AdvancedAttachmentComponent', () => {
226228

227229
});
228230

229-
describe('when the field has metadata key and value set as regex', () => {
230-
beforeEach(() => {
231-
// NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset
232-
TestBed.resetTestingModule();
233-
TestBed.configureTestingModule(getDefaultTestBedConf());
234-
TestBed.overrideProvider('fieldProvider', { useValue: mockFieldWithRegexMetadata });
235-
fixture = TestBed.createComponent(AdvancedAttachmentComponent);
236-
component = fixture.componentInstance;
237-
de = fixture.debugElement;
238-
let spy = spyOn(component, 'getBitstreams');
239-
spy.and.returnValue(of(createPaginatedList(attachmentsMock)));
240-
component.item = testItem;
241-
fixture.detectChanges();
242-
});
243-
244-
it('should show regex article attachment', () => {
245-
expect(de.query(By.css('[data-test="dc.title"]')).nativeElement.innerHTML).toContain('main-regex.pdf');
246-
});
247-
248-
});
249231
});
250232

251233
describe('when pagination is enabled', () => {
@@ -256,8 +238,8 @@ describe('AdvancedAttachmentComponent', () => {
256238
de = fixture.debugElement;
257239
mockAuthorizedService.isAuthorized.and.returnValues(of(true), of(true));
258240
component.envPagination.enabled = true;
259-
let spy = spyOn(component, 'getBitstreams');
260-
spy.and.returnValue(of(createPaginatedList([bitstream1, bitstream1, bitstream1, bitstream1])));
241+
let spy = spyOn(component, 'getBitstreamsByItem');
242+
spy.and.returnValue(of(createPaginatedList([bitstream1, bitstream1])));
261243
component.item = testItem;
262244
fixture.detectChanges();
263245
});
@@ -271,7 +253,9 @@ describe('AdvancedAttachmentComponent', () => {
271253
});
272254

273255
it('and view more button is clicked it should show 4 elements', () => {
256+
(component.getBitstreamsByItem as any).and.returnValue(of(createPaginatedList([bitstream1, bitstream1])));
274257
const btn = fixture.debugElement.query(By.css('button[data-test="view-more"]'));
258+
fixture.detectChanges();
275259
btn.nativeElement.click();
276260
fixture.detectChanges();
277261
expect(fixture.debugElement.queryAll(By.css('[data-test="attachment-info"]')).length).toEqual(4);
@@ -292,7 +276,7 @@ describe('AdvancedAttachmentComponent', () => {
292276
component.envPagination.enabled = false;
293277
component.envMetadata = [];
294278
mockBitstreamDataService.findAllByItemAndBundleName.and.returnValues(createSuccessfulRemoteDataObject$(createPaginatedList([bitstream1])));
295-
let spy = spyOn(component, 'getBitstreams');
279+
let spy = spyOn(component, 'getBitstreamsByItem');
296280
spy.and.returnValue(of(createPaginatedList(attachmentsMock)));
297281
component.item = testItem;
298282
fixture.detectChanges();
@@ -304,7 +288,7 @@ describe('AdvancedAttachmentComponent', () => {
304288

305289
it('should retrieve bitstreams without pagination', fakeAsync(() => {
306290
flush();
307-
expect(component.getBitstreams).toHaveBeenCalledWith();
291+
expect(component.getBitstreamsByItem).toHaveBeenCalled();
308292
}));
309293

310294
it('should not show view more button', fakeAsync(() => {
@@ -338,8 +322,8 @@ describe('AdvancedAttachmentComponent', () => {
338322
component = fixture.componentInstance;
339323
component.envMetadata = [];
340324
de = fixture.debugElement;
341-
let spy = spyOn(component, 'getBitstreams');
342-
spy.and.returnValue(of(createPaginatedList(attachmentsMock)));
325+
let spy = spyOn(component, 'getBitstreamsByItem');
326+
spy.and.returnValue(of(createPaginatedList([attachmentsMock[1]])));
343327
component.item = testItem;
344328
fixture.detectChanges();
345329
});
@@ -351,28 +335,6 @@ describe('AdvancedAttachmentComponent', () => {
351335

352336
});
353337

354-
describe('when the field has metadata key and value set as regex', () => {
355-
beforeEach(() => {
356-
// NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset
357-
TestBed.resetTestingModule();
358-
TestBed.configureTestingModule(getDefaultTestBedConf());
359-
TestBed.overrideProvider('fieldProvider', { useValue: mockFieldWithRegexMetadata });
360-
fixture = TestBed.createComponent(AdvancedAttachmentComponent);
361-
component = fixture.componentInstance;
362-
component.envMetadata = [];
363-
de = fixture.debugElement;
364-
let spy = spyOn(component, 'getBitstreams');
365-
spy.and.returnValue(of(createPaginatedList(attachmentsMock)));
366-
component.item = testItem;
367-
fixture.detectChanges();
368-
});
369-
370-
it('should show regex article attachment', () => {
371-
expect(de.queryAll(By.css('[data-test="attachment-info"]')).length).toBe(1);
372-
expect(de.query(By.css('[data-test="dc.title"]'))).toBeFalsy();
373-
});
374-
375-
});
376338
});
377339

378340
describe('when pagination is enabled', () => {
@@ -384,8 +346,8 @@ describe('AdvancedAttachmentComponent', () => {
384346
de = fixture.debugElement;
385347
mockAuthorizedService.isAuthorized.and.returnValues(of(true), of(true));
386348
component.envPagination.enabled = true;
387-
let spy = spyOn(component, 'getBitstreams');
388-
spy.and.returnValue(of(createPaginatedList([bitstream1, bitstream1, bitstream1, bitstream1])));
349+
let spy = spyOn(component, 'getBitstreamsByItem');
350+
spy.and.returnValue(of(createPaginatedList([bitstream1, bitstream1])));
389351
component.item = testItem;
390352
fixture.detectChanges();
391353
});
@@ -400,6 +362,8 @@ describe('AdvancedAttachmentComponent', () => {
400362

401363
it('and view more button is clicked it should show 4 elements', () => {
402364
const btn = fixture.debugElement.query(By.css('button[data-test="view-more"]'));
365+
(component.getBitstreamsByItem as any).and.returnValue(of(createPaginatedList([bitstream1, bitstream1])));
366+
fixture.detectChanges();
403367
btn.nativeElement.click();
404368
fixture.detectChanges();
405369
expect(fixture.debugElement.queryAll(By.css('[data-test="attachment-info"]')).length).toEqual(4);

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/attachment/attachment.component.spec.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ describe('AttachmentComponent', () => {
131131
return createSuccessfulRemoteDataObject$(new Bitstream());
132132
},
133133
findAllByItemAndBundleName: jasmine.createSpy('findAllByItemAndBundleName'),
134+
findByItem: jasmine.createSpy('findByItem'),
134135
});
135136

136137
const mockAuthorizedService = jasmine.createSpyObj('AuthorizationDataService', {
@@ -167,7 +168,8 @@ describe('AttachmentComponent', () => {
167168
mockAuthorizedService.isAuthorized.and.returnValues(of(true), of(true));
168169
component.envPagination.enabled = false;
169170
mockBitstreamDataService.findAllByItemAndBundleName.and.returnValues(createSuccessfulRemoteDataObject$(createPaginatedList([bitstream1])));
170-
let spy = spyOn(component, 'getBitstreams');
171+
mockBitstreamDataService.findByItem.and.returnValues(createSuccessfulRemoteDataObject$(createPaginatedList([bitstream1])));
172+
let spy = spyOn(component, 'getBitstreamsByItem');
171173
spy.and.returnValue(of(createPaginatedList(attachmentsMock)));
172174
component.item = testItem;
173175
fixture.detectChanges();
@@ -179,7 +181,7 @@ describe('AttachmentComponent', () => {
179181

180182
it('should retrieve bitstreams without pagination', fakeAsync(() => {
181183
flush();
182-
expect(component.getBitstreams).toHaveBeenCalledWith();
184+
expect(component.getBitstreamsByItem).toHaveBeenCalled();
183185
}));
184186

185187
it('should not show view more button', fakeAsync(() => {
@@ -217,8 +219,8 @@ describe('AttachmentComponent', () => {
217219
fixture = TestBed.createComponent(AttachmentComponent);
218220
component = fixture.componentInstance;
219221
de = fixture.debugElement;
220-
let spy = spyOn(component, 'getBitstreams');
221-
spy.and.returnValue(of(createPaginatedList(attachmentsMock)));
222+
let spy = spyOn(component, 'getBitstreamsByItem');
223+
spy.and.returnValue(of(createPaginatedList([attachmentsMock[1]])));
222224
component.item = testItem;
223225
fixture.detectChanges();
224226
});
@@ -238,8 +240,8 @@ describe('AttachmentComponent', () => {
238240
fixture = TestBed.createComponent(AttachmentComponent);
239241
component = fixture.componentInstance;
240242
de = fixture.debugElement;
241-
let spy = spyOn(component, 'getBitstreams');
242-
spy.and.returnValue(of(createPaginatedList(attachmentsMock)));
243+
let spy = spyOn(component, 'getBitstreamsByItem');
244+
spy.and.returnValue(of(createPaginatedList([attachmentsMock[2]])));
243245
component.item = testItem;
244246
fixture.detectChanges();
245247
});
@@ -259,7 +261,7 @@ describe('AttachmentComponent', () => {
259261
fixture = TestBed.createComponent(AttachmentComponent);
260262
component = fixture.componentInstance;
261263
de = fixture.debugElement;
262-
let spy = spyOn(component, 'getBitstreams');
264+
let spy = spyOn(component, 'getBitstreamsByItem');
263265
spy.and.returnValue(of(createPaginatedList([bitstream2])));
264266
component.item = testItem;
265267
fixture.detectChanges();
@@ -286,7 +288,7 @@ describe('AttachmentComponent', () => {
286288
fixture = TestBed.createComponent(AttachmentComponent);
287289
component = fixture.componentInstance;
288290
de = fixture.debugElement;
289-
let spy = spyOn(component, 'getBitstreams');
291+
let spy = spyOn(component, 'getBitstreamsByItem');
290292
spy.and.returnValue(of(createPaginatedList([bitstream1])));
291293
component.item = testItem;
292294
fixture.detectChanges();
@@ -312,8 +314,8 @@ describe('AttachmentComponent', () => {
312314
de = fixture.debugElement;
313315
mockAuthorizedService.isAuthorized.and.returnValues(of(true), of(true));
314316
component.envPagination.enabled = true;
315-
let spy = spyOn(component, 'getBitstreams');
316-
spy.and.returnValue(of(createPaginatedList([bitstream1, bitstream1, bitstream1, bitstream1])));
317+
let spy = spyOn(component, 'getBitstreamsByItem');
318+
spy.and.returnValue(of(createPaginatedList([bitstream1, bitstream1])));
317319
component.item = testItem;
318320
fixture.detectChanges();
319321
});
@@ -328,6 +330,8 @@ describe('AttachmentComponent', () => {
328330

329331
it('and view more button is clicked it should show 4 elements', () => {
330332
const btn = fixture.debugElement.query(By.css('a[data-test="view-more"]'));
333+
(component.getBitstreamsByItem as any).and.returnValue(of(createPaginatedList([bitstream1, bitstream1])));
334+
fixture.detectChanges();
331335
btn.nativeElement.click();
332336
fixture.detectChanges();
333337
expect(fixture.debugElement.queryAll(By.css('ds-file-download-link')).length).toEqual(4);

0 commit comments

Comments
 (0)