From c9519f44fbc93be7305c13a02532e4391cf54567 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Fri, 31 Jul 2020 13:30:23 +0200 Subject: [PATCH] Retrieve entries url from vocabulary's link --- src/app/core/data/data.service.ts | 2 +- .../vocabularies/vocabulary.service.spec.ts | 5 +++++ .../vocabularies/vocabulary.service.ts | 17 ++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index bb1a65cc3a..3b4e5f7d42 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -112,7 +112,7 @@ export abstract class DataService implements UpdateDa * Return an observable that emits created HREF * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved */ - protected buildHrefFromFindOptions(href: string, options: FindListOptions, extraArgs: string[] = [], ...linksToFollow: Array>): string { + public buildHrefFromFindOptions(href: string, options: FindListOptions, extraArgs: string[] = [], ...linksToFollow: Array>): string { let args = [...extraArgs]; if (hasValue(options.currentPage) && typeof options.currentPage === 'number') { diff --git a/src/app/core/submission/vocabularies/vocabulary.service.spec.ts b/src/app/core/submission/vocabularies/vocabulary.service.spec.ts index ca7711637e..a172ae2a45 100644 --- a/src/app/core/submission/vocabularies/vocabulary.service.spec.ts +++ b/src/app/core/submission/vocabularies/vocabulary.service.spec.ts @@ -187,6 +187,7 @@ describe('VocabularyService', () => { const paginatedListEntries = new PaginatedList(pageInfo, arrayEntries); const childrenPaginatedList = new PaginatedList(pageInfo, childrenEntries); const vocabularyRD = createSuccessfulRemoteDataObject(vocabulary); + const vocabularyRD$ = createSuccessfulRemoteDataObject$(vocabulary); const vocabularyEntriesRD = createSuccessfulRemoteDataObject$(paginatedListEntries); const vocabularyEntryDetailParentRD = createSuccessfulRemoteDataObject(vocabularyEntryParentDetail); const vocabularyEntryChildrenRD = createSuccessfulRemoteDataObject(childrenPaginatedList); @@ -342,9 +343,11 @@ describe('VocabularyService', () => { rdbService = getMockRemoteDataBuildService(undefined, vocabularyEntriesRD); spyOn(rdbService, 'toRemoteDataObservable').and.callThrough(); service = initTestService(); + spyOn(service, 'findVocabularyById').and.returnValue(vocabularyRD$); }); describe('getVocabularyEntries', () => { + it('should configure a new VocabularyEntriesRequest', () => { const expected = new VocabularyEntriesRequest(requestService.generateRequestId(), entriesRequestURL); @@ -363,6 +366,7 @@ describe('VocabularyService', () => { }); describe('getVocabularyEntriesByValue', () => { + it('should configure a new VocabularyEntriesRequest', () => { const expected = new VocabularyEntriesRequest(requestService.generateRequestId(), entriesByValueRequestURL); @@ -382,6 +386,7 @@ describe('VocabularyService', () => { }); describe('getVocabularyEntryByValue', () => { + it('should configure a new VocabularyEntriesRequest', () => { const expected = new VocabularyEntriesRequest(requestService.generateRequestId(), entryByValueRequestURL); diff --git a/src/app/core/submission/vocabularies/vocabulary.service.ts b/src/app/core/submission/vocabularies/vocabulary.service.ts index 5200d703b9..90438e77e9 100644 --- a/src/app/core/submission/vocabularies/vocabulary.service.ts +++ b/src/app/core/submission/vocabularies/vocabulary.service.ts @@ -26,6 +26,7 @@ import { hasValue, isNotEmpty, isNotEmptyOperator } from '../../../shared/empty. import { configureRequest, filterSuccessfulResponses, + getFirstSucceededRemoteDataPayload, getFirstSucceededRemoteListPayload, getRequestFromRequestHref } from '../../shared/operators'; @@ -158,11 +159,13 @@ export class VocabularyService { pageInfo.currentPage ); - return this.vocabularyDataService.getFindAllHref(options, `${vocabularyOptions.name}/entries`).pipe( + return this.findVocabularyById(vocabularyOptions.name).pipe( + getFirstSucceededRemoteDataPayload(), + map((vocabulary: Vocabulary) => this.vocabularyDataService.buildHrefFromFindOptions(vocabulary._links.entries.href, options)), isNotEmptyOperator(), distinctUntilChanged(), getVocabularyEntriesFor(this.requestService, this.rdbService) - ); + ) } /** @@ -185,11 +188,13 @@ export class VocabularyService { pageInfo.currentPage ); - return this.vocabularyDataService.getFindAllHref(options, `${vocabularyOptions.name}/entries`).pipe( + return this.findVocabularyById(vocabularyOptions.name).pipe( + getFirstSucceededRemoteDataPayload(), + map((vocabulary: Vocabulary) => this.vocabularyDataService.buildHrefFromFindOptions(vocabulary._links.entries.href, options)), isNotEmptyOperator(), distinctUntilChanged(), getVocabularyEntriesFor(this.requestService, this.rdbService) - ); + ) } /** @@ -233,7 +238,9 @@ export class VocabularyService { pageInfo.currentPage ); - return this.vocabularyDataService.getFindAllHref(options, `${vocabularyOptions.name}/entries`).pipe( + return this.findVocabularyById(vocabularyOptions.name).pipe( + getFirstSucceededRemoteDataPayload(), + map((vocabulary: Vocabulary) => this.vocabularyDataService.buildHrefFromFindOptions(vocabulary._links.entries.href, options)), isNotEmptyOperator(), distinctUntilChanged(), getVocabularyEntriesFor(this.requestService, this.rdbService),