11import { Injectable } from '@angular/core' ;
2- import { Observable } from 'rxjs' ;
2+ import { Observable , of } from 'rxjs' ;
33import { first , map , mergeMap , switchMap } from 'rxjs/operators' ;
44import { followLink , FollowLinkConfig } from '../../../shared/utils/follow-link-config.model' ;
55import { RequestService } from '../../data/request.service' ;
@@ -8,7 +8,11 @@ import { PaginatedList } from '../../data/paginated-list.model';
88import { Vocabulary } from './models/vocabulary.model' ;
99import { VocabularyEntry } from './models/vocabulary-entry.model' ;
1010import { hasValue , isNotEmpty } from '../../../shared/empty.util' ;
11- import { getFirstSucceededRemoteDataPayload , getFirstSucceededRemoteListPayload } from '../../shared/operators' ;
11+ import {
12+ getFirstCompletedRemoteData ,
13+ getFirstSucceededRemoteDataPayload ,
14+ getFirstSucceededRemoteListPayload
15+ } from '../../shared/operators' ;
1216import { VocabularyFindOptions } from './models/vocabulary-find-options.model' ;
1317import { VocabularyEntryDetail } from './models/vocabulary-entry-detail.model' ;
1418import { RequestParam } from '../../cache/models/request-param.model' ;
@@ -17,6 +21,7 @@ import { PageInfo } from '../../shared/page-info.model';
1721import { FindListOptions } from '../../data/find-list-options.model' ;
1822import { VocabularyEntryDetailsDataService } from './vocabulary-entry-details.data.service' ;
1923import { VocabularyDataService } from './vocabulary.data.service' ;
24+ import { createFailedRemoteDataObject } from '../../../shared/remote-data.utils' ;
2025
2126/**
2227 * A service responsible for fetching/sending data from/to the REST API on the vocabularies endpoint
@@ -249,7 +254,7 @@ export class VocabularyService {
249254 searchVocabularyByMetadataAndCollection ( vocabularyOptions : VocabularyOptions , ...linksToFollow : FollowLinkConfig < Vocabulary > [ ] ) : Observable < RemoteData < Vocabulary > > {
250255 const options : VocabularyFindOptions = new VocabularyFindOptions ( vocabularyOptions . scope , vocabularyOptions . metadata ) ;
251256
252- return this . vocabularyDataService . getSearchByHref ( this . searchByMetadataAndCollectionMethod , options ) . pipe (
257+ return this . vocabularyDataService . getSearchByHref ( this . searchByMetadataAndCollectionMethod , options , ... linksToFollow ) . pipe (
253258 first ( ( href : string ) => hasValue ( href ) ) ,
254259 mergeMap ( ( href : string ) => this . vocabularyDataService . findByHref ( href ) )
255260 ) ;
@@ -309,11 +314,20 @@ export class VocabularyService {
309314 * Return an observable that emits a PaginatedList of VocabularyEntryDetail
310315 */
311316 getEntryDetailParent ( value : string , name : string , useCachedVersionIfAvailable = true , reRequestOnStale = true , ...linksToFollow : FollowLinkConfig < VocabularyEntryDetail > [ ] ) : Observable < RemoteData < VocabularyEntryDetail > > {
312- const linkPath = `${ name } :${ value } /parent` ;
313-
314- return this . vocabularyEntryDetailDataService . getBrowseEndpoint ( ) . pipe (
315- map ( ( href : string ) => `${ href } /${ linkPath } ` ) ,
316- mergeMap ( ( href ) => this . vocabularyEntryDetailDataService . findByHref ( href , useCachedVersionIfAvailable , reRequestOnStale , ...linksToFollow ) )
317+ return this . findEntryDetailById ( value , name , useCachedVersionIfAvailable , reRequestOnStale , true , ...linksToFollow ) . pipe (
318+ getFirstCompletedRemoteData ( ) ,
319+ switchMap ( ( entryRD : RemoteData < VocabularyEntryDetail > ) => {
320+ if ( entryRD . hasSucceeded ) {
321+ return this . vocabularyEntryDetailDataService . findByHref (
322+ entryRD . payload . _links . parent . href ,
323+ useCachedVersionIfAvailable ,
324+ reRequestOnStale ,
325+ ...linksToFollow
326+ ) ;
327+ } else {
328+ return of ( createFailedRemoteDataObject < VocabularyEntryDetail > ( entryRD . errorMessage ) ) ;
329+ }
330+ } )
317331 ) ;
318332 }
319333
@@ -344,9 +358,21 @@ export class VocabularyService {
344358 pageInfo . currentPage
345359 ) ;
346360
347- return this . vocabularyEntryDetailDataService . getBrowseEndpoint ( ) . pipe (
348- map ( href => `${ href } /${ name } :${ value } /children` ) ,
349- switchMap ( href => this . vocabularyEntryDetailDataService . findListByHref ( href , options , useCachedVersionIfAvailable , reRequestOnStale , ...linksToFollow ) )
361+ return this . findEntryDetailById ( value , name , useCachedVersionIfAvailable , reRequestOnStale , true , ...linksToFollow ) . pipe (
362+ getFirstCompletedRemoteData ( ) ,
363+ switchMap ( ( entryRD : RemoteData < VocabularyEntryDetail > ) => {
364+ if ( entryRD . hasSucceeded ) {
365+ return this . vocabularyEntryDetailDataService . findListByHref (
366+ entryRD . payload . _links . children . href ,
367+ options ,
368+ useCachedVersionIfAvailable ,
369+ reRequestOnStale ,
370+ ...linksToFollow
371+ ) ;
372+ } else {
373+ return of ( createFailedRemoteDataObject < PaginatedList < VocabularyEntryDetail > > ( entryRD . errorMessage ) ) ;
374+ }
375+ } )
350376 ) ;
351377 }
352378
0 commit comments