diff --git a/src/app/core/submission/vocabularies/models/vocabulary-find-options.model.ts b/src/app/core/submission/vocabularies/models/vocabulary-find-options.model.ts new file mode 100644 index 0000000000..18309ed1fe --- /dev/null +++ b/src/app/core/submission/vocabularies/models/vocabulary-find-options.model.ts @@ -0,0 +1,45 @@ +import { SortOptions } from '../../../cache/models/sort-options.model'; +import { FindListOptions } from '../../../data/request.models'; +import { RequestParam } from '../../../cache/models/request-param.model'; +import { isNotEmpty } from '../../../../shared/empty.util'; + +/** + * Representing properties used to build a vocabulary find request + */ +export class VocabularyFindOptions extends FindListOptions { + + constructor(public collection: string = '', + public name: string = '', + public metadata: string = '', + public query: string = '', + public elementsPerPage?: number, + public currentPage?: number, + public sort?: SortOptions, + public filter?: string, + public exact?: string, + public entryID?: string, + ) { + super(); + + const searchParams = []; + if (isNotEmpty(metadata)) { + searchParams.push(new RequestParam('metadata', metadata)) + } + if (isNotEmpty(collection)) { + searchParams.push(new RequestParam('collection', collection)) + } + if (isNotEmpty(query)) { + searchParams.push(new RequestParam('query', query)) + } + if (isNotEmpty(filter)) { + searchParams.push(new RequestParam('filter', filter)) + } + if (isNotEmpty(exact)) { + searchParams.push(new RequestParam('exact', exact)) + } + if (isNotEmpty(entryID)) { + searchParams.push(new RequestParam('entryID', entryID)) + } + this.searchParams = searchParams; + } +} diff --git a/src/app/core/submission/vocabularies/vocabulary-entries-response-parsing.service.spec.ts b/src/app/core/submission/vocabularies/vocabulary-entries-response-parsing.service.spec.ts index 592ed234a7..9f28ccea17 100644 --- a/src/app/core/submission/vocabularies/vocabulary-entries-response-parsing.service.spec.ts +++ b/src/app/core/submission/vocabularies/vocabulary-entries-response-parsing.service.spec.ts @@ -4,7 +4,7 @@ import { DSpaceRESTV2Response } from '../../dspace-rest-v2/dspace-rest-v2-respon import { VocabularyEntriesResponseParsingService } from './vocabulary-entries-response-parsing.service'; import { VocabularyEntriesRequest } from '../../data/request.models'; -fdescribe('VocabularyEntriesResponseParsingService', () => { +describe('VocabularyEntriesResponseParsingService', () => { let service: VocabularyEntriesResponseParsingService; const metadata = 'dc.type'; const collectionUUID = '8b39g7ya-5a4b-438b-851f-be1d5b4a1c5a'; diff --git a/src/app/core/submission/vocabularies/vocabulary.service.spec.ts b/src/app/core/submission/vocabularies/vocabulary.service.spec.ts index 2596e368b5..5323c29f30 100644 --- a/src/app/core/submission/vocabularies/vocabulary.service.spec.ts +++ b/src/app/core/submission/vocabularies/vocabulary.service.spec.ts @@ -19,6 +19,7 @@ import { RestResponse } from '../../cache/response.models'; import { VocabularyService } from './vocabulary.service'; import { getMockRequestService } from '../../../shared/mocks/request.service.mock'; import { getMockRemoteDataBuildService } from '../../../shared/mocks/remote-data-build.service.mock'; +import { VocabularyFindOptions } from './models/vocabulary-find-options.model'; describe('VocabularyService', () => { let scheduler: TestScheduler; @@ -95,6 +96,7 @@ describe('VocabularyService', () => { const vocabularyId = 'types'; const metadata = 'dc.type'; const collectionUUID = '8b39g7ya-5a4b-438b-851f-be1d5b4a1c5a'; + const vocabularyOptions = new VocabularyFindOptions(collectionUUID, vocabularyId, metadata); const searchRequestURL = `https://rest.api/rest/api/submission/vocabularies/search/byMetadataAndCollection?metadata=${metadata}&collection=${collectionUUID}`; const entriesRequestURL = `https://rest.api/rest/api/submission/vocabularies/${vocabulary.id}/entries?metadata=${metadata}&collection=${collectionUUID}`; @@ -223,14 +225,14 @@ describe('VocabularyService', () => { new RequestParam('metadata', metadata), new RequestParam('collection', collectionUUID) ]; - scheduler.schedule(() => service.searchByMetadataAndCollection(metadata, collectionUUID).subscribe()); + scheduler.schedule(() => service.searchByMetadataAndCollection(vocabularyOptions).subscribe()); scheduler.flush(); expect((service as any).dataService.findByHref).toHaveBeenCalledWith(searchRequestURL); }); it('should return a RemoteData for the search', () => { - const result = service.searchByMetadataAndCollection(metadata, collectionUUID); + const result = service.searchByMetadataAndCollection(vocabularyOptions); const expected = cold('a|', { a: vocabularyRD }); @@ -251,14 +253,14 @@ describe('VocabularyService', () => { it('should configure a new VocabularyEntriesRequest', () => { const expected = new VocabularyEntriesRequest(requestService.generateRequestId(), entriesRequestURL); - scheduler.schedule(() => service.getVocabularyEntries(vocabularyId, metadata, collectionUUID).subscribe()); + scheduler.schedule(() => service.getVocabularyEntries(vocabularyOptions).subscribe()); scheduler.flush(); expect(requestService.configure).toHaveBeenCalledWith(expected); }); it('should call RemoteDataBuildService to create the RemoteData Observable', () => { - service.getVocabularyEntries(vocabularyId, metadata, collectionUUID); + service.getVocabularyEntries(vocabularyOptions); expect(rdbService.toRemoteDataObservable).toHaveBeenCalled(); diff --git a/src/app/core/submission/vocabularies/vocabulary.service.ts b/src/app/core/submission/vocabularies/vocabulary.service.ts index cfb795c942..094f87544f 100644 --- a/src/app/core/submission/vocabularies/vocabulary.service.ts +++ b/src/app/core/submission/vocabularies/vocabulary.service.ts @@ -19,13 +19,13 @@ import { NotificationsService } from '../../../shared/notifications/notification import { ChangeAnalyzer } from '../../data/change-analyzer'; import { DefaultChangeAnalyzer } from '../../data/default-change-analyzer.service'; import { PaginatedList } from '../../data/paginated-list'; -import { RequestParam } from '../../cache/models/request-param.model'; import { Vocabulary } from './models/vocabulary.model'; import { VOCABULARY } from './models/vocabularies.resource-type'; import { VocabularyEntry } from './models/vocabulary-entry.model'; import { hasValue, isNotEmptyOperator } from '../../../shared/empty.util'; import { configureRequest, filterSuccessfulResponses, getRequestFromRequestHref } from '../../shared/operators'; import { GenericSuccessResponse } from '../../cache/response.models'; +import { VocabularyFindOptions } from './models/vocabulary-find-options.model'; /* tslint:disable:max-classes-per-file */ @@ -111,22 +111,13 @@ export class VocabularyService { /** * Return the {@link VocabularyEntry} list for a given {@link Vocabulary} * - * @param id The vocabulary id to retrieve the entries for - * @param metadata The metadata name - * @param collectionUUID The collection UUID - * @param options The {@link FindListOptions} for the request + * @param options The {@link VocabularyFindOptions} for the request * @return {Observable>>} * Return an observable that emits object list */ - getVocabularyEntries(id: string, metadata: string, collectionUUID: string, options: FindListOptions = {}): Observable>> { - options = Object.assign({}, options, { - searchParams: [ - new RequestParam('metadata', metadata), - new RequestParam('collection', collectionUUID) - ] - }); + getVocabularyEntries(options: VocabularyFindOptions): Observable>> { - return this.dataService.getFindAllHref(options, `${id}/entries`).pipe( + return this.dataService.getFindAllHref(options, `${options.name}/entries`).pipe( isNotEmptyOperator(), distinctUntilChanged(), getVocabularyEntriesFor(this.requestService, this.rdbService) @@ -136,18 +127,12 @@ export class VocabularyService { /** * Return the controlled {@link Vocabulary} configured for the specified metadata and collection if any. * - * @param metadata The metadata name - * @param collectionUUID The collection UUID + * @param options The {@link VocabularyFindOptions} for the request * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved * @return {Observable>>} * Return an observable that emits object list */ - searchByMetadataAndCollection(metadata: string, collectionUUID: string, ...linksToFollow: Array>): Observable> { - const options = new FindListOptions(); - options.searchParams = [ - new RequestParam('metadata', metadata), - new RequestParam('collection', collectionUUID) - ]; + searchByMetadataAndCollection(options: VocabularyFindOptions, ...linksToFollow: Array>): Observable> { return this.dataService.getSearchByHref(this.searchByMetadataAndCollectionMethod, options).pipe( first((href: string) => hasValue(href)),