Commits
Tim Donohue authored and GitHub committed 8d44b5d2f09 Merge
1 1 | import { HttpClient } from '@angular/common/http'; |
2 2 | import { Injectable } from '@angular/core'; |
3 3 | import { Router } from '@angular/router'; |
4 4 | import { Store } from '@ngrx/store'; |
5 5 | import { Observable } from 'rxjs'; |
6 - | import { take, tap } from 'rxjs/operators'; |
6 + | import { filter, take, tap } from 'rxjs/operators'; |
7 7 | import { hasValue } from '../../shared/empty.util'; |
8 8 | import { NotificationsService } from '../../shared/notifications/notifications.service'; |
9 9 | import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; |
10 10 | import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; |
11 11 | import { ObjectCacheService } from '../cache/object-cache.service'; |
12 12 | import { CoreState } from '../core.reducers'; |
13 13 | import { HALEndpointService } from '../shared/hal-endpoint.service'; |
14 - | import { getFinishedRemoteData } from '../shared/operators'; |
15 14 | import { DataService } from './data.service'; |
16 15 | import { DSOChangeAnalyzer } from './dso-change-analyzer.service'; |
17 16 | import { RemoteData } from './remote-data'; |
18 17 | import { FindByIDRequest, IdentifierType } from './request.models'; |
19 18 | import { RequestService } from './request.service'; |
20 19 | |
21 20 | @Injectable() |
22 21 | export class DsoRedirectDataService extends DataService<any> { |
23 22 | |
24 23 | // Set the default link path to the identifier lookup endpoint. |
49 48 | getIDHref(endpoint, resourceID, linksToFollow: Array<FollowLinkConfig<any>>): string { |
50 49 | // Supporting both identifier (pid) and uuid (dso) endpoints |
51 50 | return this.buildHrefFromFindOptions( endpoint.replace(/\{\?id\}/, `?id=${resourceID}`) |
52 51 | .replace(/\{\?uuid\}/, `?uuid=${resourceID}`), |
53 52 | {}, [], linksToFollow); |
54 53 | } |
55 54 | |
56 55 | findByIdAndIDType(id: string, identifierType = IdentifierType.UUID): Observable<RemoteData<FindByIDRequest>> { |
57 56 | this.setLinkPath(identifierType); |
58 57 | return this.findById(id).pipe( |
59 - | getFinishedRemoteData(), |
58 + | filter((response) => hasValue(response.error) || hasValue(response.payload)), |
60 59 | take(1), |
61 60 | tap((response) => { |
62 61 | if (response.hasSucceeded) { |
63 62 | const uuid = response.payload.uuid; |
64 63 | const newRoute = this.getEndpointFromDSOType(response.payload.type); |
65 64 | if (hasValue(uuid) && hasValue(newRoute)) { |
66 65 | this.router.navigate([newRoute + '/' + uuid]); |
67 66 | } |
68 67 | } |
69 68 | }) |