Skip to content

Commit a534be0

Browse files
enea4scienceDavide Negretti
authored andcommitted
Merged in DSC-975 (pull request DSpace#570)
DSC-975 Approved-by: Davide Negretti
2 parents 5cba103 + 24f588f commit a534be0

3 files changed

Lines changed: 48 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export class BitstreamDataService extends IdentifiableDataService<Bitstream> imp
352352
uuid: string,
353353
bundlename: string,
354354
metadataFilters: MetadataFilter[],
355-
options: FindListOptions,
355+
options?: FindListOptions,
356356
useCachedVersionIfAvailable = true,
357357
reRequestOnStale = true,
358358
...linksToFollow: FollowLinkConfig<Bitstream>[]

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/row/metadata-container/metadata-container.component.spec.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('MetadataContainerComponent', () => {
145145
});
146146

147147
const mockBitstreamDataService = jasmine.createSpyObj('BitstreamDataService', {
148-
findAllByItemAndBundleName: jasmine.createSpy('findAllByItemAndBundleName')
148+
findShowableBitstreamsByItem: jasmine.createSpy('findShowableBitstreamsByItem')
149149
});
150150

151151
beforeEach(async () => {
@@ -172,7 +172,10 @@ describe('MetadataContainerComponent', () => {
172172
component = fixture.componentInstance;
173173
component.item = testItem;
174174
component.box = boxMetadata;
175-
mockBitstreamDataService.findAllByItemAndBundleName.and.returnValue(createSuccessfulRemoteDataObject$(createPaginatedList([])));
175+
176+
mockBitstreamDataService.findShowableBitstreamsByItem.and.returnValue(
177+
createSuccessfulRemoteDataObject$(createPaginatedList([]))
178+
);
176179
});
177180

178181
describe('When field rendering type is not structured', () => {
@@ -283,15 +286,15 @@ describe('MetadataContainerComponent', () => {
283286
describe('and item has bitstream', () => {
284287

285288
beforeEach(() => {
286-
mockBitstreamDataService.findAllByItemAndBundleName.and.returnValue(createSuccessfulRemoteDataObject$(createPaginatedList([bitstream1])));
289+
mockBitstreamDataService.findShowableBitstreamsByItem.and.returnValue(createSuccessfulRemoteDataObject$(createPaginatedList([bitstream1])));
287290
fixture.detectChanges();
288291
});
289292

290293
it('should create', () => {
291294
expect(component).toBeTruthy();
292295
});
293296

294-
it('should not render metadata ', (done) => {
297+
it('should render metadata ', (done) => {
295298
const spanValueFound = fixture.debugElement.queryAll(By.css('.test-style-label'));
296299
expect(spanValueFound.length).toBe(1);
297300

@@ -301,6 +304,35 @@ describe('MetadataContainerComponent', () => {
301304
});
302305
});
303306

307+
describe('and bitstream has metadata', () => {
308+
beforeEach(() => {
309+
component.field.bitstream.metadataField = 'metadataFieldTest';
310+
component.field.bitstream.metadataValue = 'metadataValueTest';
311+
fixture.detectChanges();
312+
});
313+
314+
it('should use the metadata in filters', () => {
315+
expect(mockBitstreamDataService.findShowableBitstreamsByItem).toHaveBeenCalledWith(
316+
testItem.uuid,
317+
bitstreamField.bitstream.bundle,
318+
[ { metadataName: 'metadataFieldTest', metadataValue: 'metadataValueTest' } ]
319+
);
320+
});
321+
});
322+
323+
describe('and bitstream doesnt have metadataValue', () => {
324+
beforeEach(() => {
325+
component.field.bitstream.metadataValue = undefined;
326+
fixture.detectChanges();
327+
});
328+
329+
it('should use empty array in filters', () => {
330+
expect(mockBitstreamDataService.findShowableBitstreamsByItem).toHaveBeenCalledWith(
331+
testItem.uuid,
332+
bitstreamField.bitstream.bundle,
333+
[] // <--- empty array of filters
334+
);
335+
});
336+
});
304337
});
305-
})
306-
;
338+
});

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/row/metadata-container/metadata-container.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Bitstream } from '../../../../../../../core/shared/bitstream.model';
1414
import { getFirstCompletedRemoteData } from '../../../../../../../core/shared/operators';
1515
import { map, take } from 'rxjs/operators';
1616
import { BitstreamDataService } from '../../../../../../../core/data/bitstream-data.service';
17+
import { MetadataFilter } from '../../../../../../../core/data/bitstream-data.service';
1718
import { RemoteData } from '../../../../../../../core/data/remote-data';
1819
import { PaginatedList } from '../../../../../../../core/data/paginated-list.model';
1920
import { Observable } from 'rxjs';
@@ -126,7 +127,14 @@ export class MetadataContainerComponent implements OnInit {
126127
}
127128

128129
hasBitstream(): Observable<boolean> {
129-
return this.bitstreamDataService.findAllByItemAndBundleName(this.item, this.field.bitstream.bundle)
130+
let filters: MetadataFilter[] = [];
131+
if (isNotEmpty(this.field.bitstream.metadataValue)) {
132+
filters.push({
133+
metadataName: this.field.bitstream.metadataField,
134+
metadataValue: this.field.bitstream.metadataValue
135+
});
136+
}
137+
return this.bitstreamDataService.findShowableBitstreamsByItem(this.item.uuid, this.field.bitstream.bundle, filters)
130138
.pipe(
131139
getFirstCompletedRemoteData(),
132140
map((response: RemoteData<PaginatedList<Bitstream>>) => {

0 commit comments

Comments
 (0)