mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 04:53:06 +00:00
Adapt the service to a LinkedRepository result
This commit is contained in:
@@ -10,12 +10,13 @@ import { ObjectCacheService } from '../cache/object-cache.service';
|
|||||||
import { RestResponse } from '../cache/response.models';
|
import { RestResponse } from '../cache/response.models';
|
||||||
import { ExternalSourceEntry } from '../shared/external-source-entry.model';
|
import { ExternalSourceEntry } from '../shared/external-source-entry.model';
|
||||||
import { ItemDataService } from './item-data.service';
|
import { ItemDataService } from './item-data.service';
|
||||||
import { DeleteRequest, PostRequest } from './request.models';
|
import { DeleteRequest, GetRequest, PostRequest } from './request.models';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock';
|
import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock';
|
||||||
import { CoreState } from '../core-state.model';
|
import { CoreState } from '../core-state.model';
|
||||||
import { RequestEntry } from './request-entry.model';
|
import { RequestEntry } from './request-entry.model';
|
||||||
import { FindListOptions } from './find-list-options.model';
|
import { FindListOptions } from './find-list-options.model';
|
||||||
|
import { HALEndpointServiceStub } from 'src/app/shared/testing/hal-endpoint-service.stub';
|
||||||
|
|
||||||
describe('ItemDataService', () => {
|
describe('ItemDataService', () => {
|
||||||
let scheduler: TestScheduler;
|
let scheduler: TestScheduler;
|
||||||
@@ -36,13 +37,11 @@ describe('ItemDataService', () => {
|
|||||||
}) as RequestService;
|
}) as RequestService;
|
||||||
const rdbService = getMockRemoteDataBuildService();
|
const rdbService = getMockRemoteDataBuildService();
|
||||||
|
|
||||||
const itemEndpoint = 'https://rest.api/core/items';
|
const itemEndpoint = 'https://rest.api/core';
|
||||||
|
|
||||||
const store = {} as Store<CoreState>;
|
const store = {} as Store<CoreState>;
|
||||||
const objectCache = {} as ObjectCacheService;
|
const objectCache = {} as ObjectCacheService;
|
||||||
const halEndpointService = jasmine.createSpyObj('halService', {
|
const halEndpointService: any = new HALEndpointServiceStub(itemEndpoint);
|
||||||
getEndpoint: observableOf(itemEndpoint)
|
|
||||||
});
|
|
||||||
const bundleService = jasmine.createSpyObj('bundleService', {
|
const bundleService = jasmine.createSpyObj('bundleService', {
|
||||||
findByHref: {}
|
findByHref: {}
|
||||||
});
|
});
|
||||||
@@ -185,6 +184,33 @@ describe('ItemDataService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getAccessStatusEndpoint', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
service = initTestService();
|
||||||
|
});
|
||||||
|
it('should retrieve the access status endpoint', () => {
|
||||||
|
const itemId = '3de6ea60-ec39-419b-ae6f-065930ac1429';
|
||||||
|
const result = service.getAccessStatusEndpoint(itemId);
|
||||||
|
result.subscribe(((value) => {
|
||||||
|
expect(value).toEqual(`${itemEndpoint}/items/${itemId}/accessStatus`);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getAccessStatus', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
service = initTestService();
|
||||||
|
});
|
||||||
|
it('should send a GET request', (done) => {
|
||||||
|
const itemId = '3de6ea60-ec39-419b-ae6f-065930ac1429';
|
||||||
|
const result = service.getAccessStatus(itemId);
|
||||||
|
result.subscribe(() => {
|
||||||
|
expect(requestService.send).toHaveBeenCalledWith(jasmine.any(GetRequest));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when cache is invalidated', () => {
|
describe('when cache is invalidated', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service = initTestService();
|
service = initTestService();
|
||||||
|
@@ -292,25 +292,31 @@ export class ItemDataService extends DataService<Item> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the endpoint for an item's access status
|
||||||
|
* @param itemId
|
||||||
|
*/
|
||||||
|
public getAccessStatusEndpoint(itemId: string): Observable<string> {
|
||||||
|
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||||
|
switchMap((url: string) => this.halService.getEndpoint('accessStatus', `${url}/${itemId}`))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the the access status
|
* Get the the access status
|
||||||
* @param itemId
|
* @param itemId
|
||||||
*/
|
*/
|
||||||
public getAccessStatus(itemId: string): Observable<RemoteData<AccessStatusObject>> {
|
public getAccessStatus(itemId: string): Observable<RemoteData<AccessStatusObject>> {
|
||||||
const requestId = this.requestService.generateRequestId();
|
const hrefObs = this.getAccessStatusEndpoint(itemId);
|
||||||
const href$ = this.halService.getEndpoint('accessStatus').pipe(
|
|
||||||
map((href) => href.replace('{?uuid}', `?uuid=${itemId}`))
|
|
||||||
);
|
|
||||||
|
|
||||||
href$.pipe(
|
hrefObs.pipe(
|
||||||
find((href: string) => hasValue(href)),
|
take(1)
|
||||||
map((href: string) => {
|
).subscribe((href) => {
|
||||||
const request = new GetRequest(requestId, href);
|
const request = new GetRequest(this.requestService.generateRequestId(), href);
|
||||||
this.requestService.send(request);
|
this.requestService.send(request);
|
||||||
})
|
});
|
||||||
).subscribe();
|
|
||||||
|
|
||||||
return this.rdbService.buildFromRequestUUID(requestId);
|
return this.rdbService.buildSingle<AccessStatusObject>(hrefObs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -151,7 +151,7 @@ describe('VersionHistoryDataService', () => {
|
|||||||
describe('when getVersionsEndpoint is called', () => {
|
describe('when getVersionsEndpoint is called', () => {
|
||||||
it('should return the correct value', () => {
|
it('should return the correct value', () => {
|
||||||
service.getVersionsEndpoint(versionHistoryId).subscribe((res) => {
|
service.getVersionsEndpoint(versionHistoryId).subscribe((res) => {
|
||||||
expect(res).toBe(url + '/versions');
|
expect(res).toBe(url + '/versionhistories/version-history-id/versions');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
import { autoserialize } from 'cerialize';
|
import { autoserialize, deserialize } from 'cerialize';
|
||||||
import { typedObject } from 'src/app/core/cache/builders/build-decorators';
|
import { typedObject } from 'src/app/core/cache/builders/build-decorators';
|
||||||
|
import { CacheableObject } from 'src/app/core/cache/object-cache.reducer';
|
||||||
|
import { HALLink } from 'src/app/core/shared/hal-link.model';
|
||||||
import { ResourceType } from 'src/app/core/shared/resource-type';
|
import { ResourceType } from 'src/app/core/shared/resource-type';
|
||||||
import { excludeFromEquals } from 'src/app/core/utilities/equals.decorators';
|
import { excludeFromEquals } from 'src/app/core/utilities/equals.decorators';
|
||||||
import { ACCESS_STATUS } from './access-status.resource-type';
|
import { ACCESS_STATUS } from './access-status.resource-type';
|
||||||
|
|
||||||
@typedObject
|
@typedObject
|
||||||
export class AccessStatusObject {
|
export class AccessStatusObject implements CacheableObject {
|
||||||
static type = ACCESS_STATUS;
|
static type = ACCESS_STATUS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,4 +22,12 @@ export class AccessStatusObject {
|
|||||||
*/
|
*/
|
||||||
@autoserialize
|
@autoserialize
|
||||||
status: string;
|
status: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link HALLink}s for this AccessStatusObject
|
||||||
|
*/
|
||||||
|
@deserialize
|
||||||
|
_links: {
|
||||||
|
self: HALLink;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,13 @@
|
|||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { hasValue } from '../empty.util';
|
||||||
|
|
||||||
export class HALEndpointServiceStub {
|
export class HALEndpointServiceStub {
|
||||||
|
|
||||||
constructor(private url: string) {}
|
constructor(private url: string) {}
|
||||||
getEndpoint(path: string) {
|
getEndpoint(path: string, startHref?: string) {
|
||||||
|
if (hasValue(startHref)) {
|
||||||
|
return observableOf(startHref + '/' + path);
|
||||||
|
}
|
||||||
return observableOf(this.url + '/' + path);
|
return observableOf(this.url + '/' + path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user