mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
Delegated PIDService's findByID to DataService
This commit is contained in:
@@ -7,7 +7,7 @@ import { PIDService } from './pid.service';
|
||||
import { FindByIDRequest } from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
|
||||
fdescribe('PIDService', () => {
|
||||
describe('PIDService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
let service: PIDService;
|
||||
let halService: HALEndpointService;
|
||||
|
@@ -1,36 +1,55 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { hasValue } from '../../shared/empty.util';
|
||||
import { BrowseService } from '../browse/browse.service';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { NormalizedDSpaceObject } from '../cache/models/normalized-dspace-object.model';
|
||||
import { ResponseCacheService } from '../cache/response-cache.service';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { DataService } from './data.service';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { FindByIDRequest } from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
class DataServiceImpl extends DataService<NormalizedDSpaceObject, DSpaceObject> {
|
||||
protected linkPath = 'pid';
|
||||
|
||||
constructor(
|
||||
protected responseCache: ResponseCacheService,
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
private bs: BrowseService,
|
||||
protected halService: HALEndpointService) {
|
||||
super();
|
||||
}
|
||||
|
||||
getScopedEndpoint(scope: string): Observable<string> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getFindByIDHref(endpoint, resourceID): string {
|
||||
return endpoint.replace(/\{\?id\}/,`?id=${resourceID}`);
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class PIDService {
|
||||
protected linkPath = 'pid';
|
||||
private dataService: DataServiceImpl;
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected halService: HALEndpointService) {
|
||||
this.dataService = new DataServiceImpl(null, requestService, rdbService, null, null, halService);
|
||||
}
|
||||
|
||||
findById(id: string): Observable<RemoteData<DSpaceObject>> {
|
||||
const hrefObs = this.halService.getEndpoint(this.linkPath)
|
||||
.map((endpoint: string) => endpoint.replace(/\{\?id\}/,`?id=${id}`));
|
||||
|
||||
hrefObs
|
||||
.filter((href: string) => hasValue(href))
|
||||
.take(1)
|
||||
.subscribe((href: string) => {
|
||||
const request = new FindByIDRequest(this.requestService.generateRequestId(), href, id);
|
||||
this.requestService.configure(request);
|
||||
});
|
||||
|
||||
return this.rdbService.buildSingle<NormalizedDSpaceObject, DSpaceObject>(hrefObs);
|
||||
return this.dataService.findById(id);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user