1
1
import { Injectable } from '@angular/core' ;
2
- import { Observable } from 'rxjs' ;
2
+ import { Observable , of } from 'rxjs' ;
3
3
import { first , map , mergeMap , switchMap } from 'rxjs/operators' ;
4
4
import { followLink , FollowLinkConfig } from '../../../shared/utils/follow-link-config.model' ;
5
5
import { RequestService } from '../../data/request.service' ;
@@ -8,7 +8,11 @@ import { PaginatedList } from '../../data/paginated-list.model';
8
8
import { Vocabulary } from './models/vocabulary.model' ;
9
9
import { VocabularyEntry } from './models/vocabulary-entry.model' ;
10
10
import { 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' ;
12
16
import { VocabularyFindOptions } from './models/vocabulary-find-options.model' ;
13
17
import { VocabularyEntryDetail } from './models/vocabulary-entry-detail.model' ;
14
18
import { RequestParam } from '../../cache/models/request-param.model' ;
@@ -17,6 +21,7 @@ import { PageInfo } from '../../shared/page-info.model';
17
21
import { FindListOptions } from '../../data/find-list-options.model' ;
18
22
import { VocabularyEntryDetailsDataService } from './vocabulary-entry-details.data.service' ;
19
23
import { VocabularyDataService } from './vocabulary.data.service' ;
24
+ import { createFailedRemoteDataObject } from '../../../shared/remote-data.utils' ;
20
25
21
26
/**
22
27
* A service responsible for fetching/sending data from/to the REST API on the vocabularies endpoint
@@ -249,7 +254,7 @@ export class VocabularyService {
249
254
searchVocabularyByMetadataAndCollection ( vocabularyOptions : VocabularyOptions , ...linksToFollow : FollowLinkConfig < Vocabulary > [ ] ) : Observable < RemoteData < Vocabulary > > {
250
255
const options : VocabularyFindOptions = new VocabularyFindOptions ( vocabularyOptions . scope , vocabularyOptions . metadata ) ;
251
256
252
- return this . vocabularyDataService . getSearchByHref ( this . searchByMetadataAndCollectionMethod , options ) . pipe (
257
+ return this . vocabularyDataService . getSearchByHref ( this . searchByMetadataAndCollectionMethod , options , ... linksToFollow ) . pipe (
253
258
first ( ( href : string ) => hasValue ( href ) ) ,
254
259
mergeMap ( ( href : string ) => this . vocabularyDataService . findByHref ( href ) )
255
260
) ;
@@ -309,11 +314,20 @@ export class VocabularyService {
309
314
* Return an observable that emits a PaginatedList of VocabularyEntryDetail
310
315
*/
311
316
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
+ } )
317
331
) ;
318
332
}
319
333
@@ -344,9 +358,21 @@ export class VocabularyService {
344
358
pageInfo . currentPage
345
359
) ;
346
360
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
+ } )
350
376
) ;
351
377
}
352
378
0 commit comments