mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 14:03:06 +00:00
Added PIDService
This commit is contained in:
@@ -20,6 +20,7 @@ import { CollectionDataService } from './data/collection-data.service';
|
|||||||
import { CommunityDataService } from './data/community-data.service';
|
import { CommunityDataService } from './data/community-data.service';
|
||||||
import { DebugResponseParsingService } from './data/debug-response-parsing.service';
|
import { DebugResponseParsingService } from './data/debug-response-parsing.service';
|
||||||
import { DSOResponseParsingService } from './data/dso-response-parsing.service';
|
import { DSOResponseParsingService } from './data/dso-response-parsing.service';
|
||||||
|
import { PIDService } from './data/pid.service';
|
||||||
import { SearchResponseParsingService } from './data/search-response-parsing.service';
|
import { SearchResponseParsingService } from './data/search-response-parsing.service';
|
||||||
import { DSpaceRESTv2Service } from './dspace-rest-v2/dspace-rest-v2.service';
|
import { DSpaceRESTv2Service } from './dspace-rest-v2/dspace-rest-v2.service';
|
||||||
import { HostWindowService } from '../shared/host-window.service';
|
import { HostWindowService } from '../shared/host-window.service';
|
||||||
@@ -110,6 +111,7 @@ const PROVIDERS = [
|
|||||||
SubmissionFormsConfigService,
|
SubmissionFormsConfigService,
|
||||||
SubmissionSectionsConfigService,
|
SubmissionSectionsConfigService,
|
||||||
UUIDService,
|
UUIDService,
|
||||||
|
PIDService,
|
||||||
// register AuthInterceptor as HttpInterceptor
|
// register AuthInterceptor as HttpInterceptor
|
||||||
{
|
{
|
||||||
provide: HTTP_INTERCEPTORS,
|
provide: HTTP_INTERCEPTORS,
|
||||||
|
73
src/app/core/data/pid.service.spec.ts
Normal file
73
src/app/core/data/pid.service.spec.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import { cold, getTestScheduler } from 'jasmine-marbles';
|
||||||
|
import { TestScheduler } from '../../../../node_modules/rxjs';
|
||||||
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
|
import { PIDService } from './pid.service';
|
||||||
|
import { FindByIDRequest } from './request.models';
|
||||||
|
import { RequestService } from './request.service';
|
||||||
|
|
||||||
|
fdescribe('PIDService', () => {
|
||||||
|
let scheduler: TestScheduler;
|
||||||
|
let service: PIDService;
|
||||||
|
let halService: HALEndpointService;
|
||||||
|
let requestService: RequestService;
|
||||||
|
let rdbService: RemoteDataBuildService;
|
||||||
|
const testObject = {
|
||||||
|
id: '9b4f22f4-164a-49db-8817-3316b6ee5746'
|
||||||
|
} as DSpaceObject;
|
||||||
|
const pidLink = 'https://rest.api/rest/api/pid/find{?id}';
|
||||||
|
const requestURL = `https://rest.api/rest/api/pid/find?id=${testObject.id}`;
|
||||||
|
const requestUUID = '34cfed7c-f597-49ef-9cbe-ea351f0023c2';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
scheduler = getTestScheduler();
|
||||||
|
|
||||||
|
halService = jasmine.createSpyObj('halService', {
|
||||||
|
getEndpoint: cold('a', { a: pidLink })
|
||||||
|
});
|
||||||
|
requestService = jasmine.createSpyObj('requestService', {
|
||||||
|
generateRequestId: requestUUID,
|
||||||
|
configure: true
|
||||||
|
});
|
||||||
|
rdbService = jasmine.createSpyObj('rdbService', {
|
||||||
|
buildSingle: cold('a', {
|
||||||
|
a: {
|
||||||
|
payload: testObject
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
service = new PIDService(
|
||||||
|
requestService,
|
||||||
|
rdbService,
|
||||||
|
halService
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('findById', () => {
|
||||||
|
it('should call HALEndpointService with the path to the pid endpoint', () => {
|
||||||
|
scheduler.schedule(() => service.findById(testObject.id));
|
||||||
|
scheduler.flush();
|
||||||
|
|
||||||
|
expect(halService.getEndpoint).toHaveBeenCalledWith('pid');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should configure the proper FindByIDRequest', () => {
|
||||||
|
scheduler.schedule(() => service.findById(testObject.id));
|
||||||
|
scheduler.flush();
|
||||||
|
|
||||||
|
expect(requestService.configure).toHaveBeenCalledWith(new FindByIDRequest(requestUUID, requestURL, testObject.id));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a RemoteData<DSpaceObject> for the object with the given ID', () => {
|
||||||
|
const result = service.findById(testObject.id);
|
||||||
|
const expected = cold('a', {
|
||||||
|
a: {
|
||||||
|
payload: testObject
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
36
src/app/core/data/pid.service.ts
Normal file
36
src/app/core/data/pid.service.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { hasValue } from '../../shared/empty.util';
|
||||||
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
|
import { NormalizedDSpaceObject } from '../cache/models/normalized-dspace-object.model';
|
||||||
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
|
import { RemoteData } from './remote-data';
|
||||||
|
import { FindByIDRequest } from './request.models';
|
||||||
|
import { RequestService } from './request.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PIDService {
|
||||||
|
protected linkPath = 'pid';
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
protected requestService: RequestService,
|
||||||
|
protected rdbService: RemoteDataBuildService,
|
||||||
|
protected halService: HALEndpointService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user