mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
Merge branch 'community-and-collection-forms' into w2p-58522_delete-collections-and-communities
Conflicts: src/app/core/data/data.service.ts src/app/shared/shared.module.ts
This commit is contained in:
@@ -8,7 +8,7 @@ import { GenericConstructor } from '../shared/generic-constructor';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { ResourceType } from '../shared/resource-type';
|
||||
import { RESTURLCombiner } from '../url-combiner/rest-url-combiner';
|
||||
import { isRestDataObject, isRestPaginatedList } from '../cache/builders/data-build.service';
|
||||
import { isRestDataObject, isRestPaginatedList } from '../cache/builders/normalized-object-build.service';
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
|
||||
export abstract class BaseResponseParsingService {
|
||||
|
20
src/app/core/data/change-analyzer.ts
Normal file
20
src/app/core/data/change-analyzer.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
||||
import { Operation } from 'fast-json-patch/lib/core';
|
||||
|
||||
/**
|
||||
* An interface to determine what differs between two
|
||||
* NormalizedObjects
|
||||
*/
|
||||
export interface ChangeAnalyzer<TNormalized extends NormalizedObject> {
|
||||
|
||||
/**
|
||||
* Compare two objects and return their differences as a
|
||||
* JsonPatch Operation Array
|
||||
*
|
||||
* @param {NormalizedObject} object1
|
||||
* The first object to compare
|
||||
* @param {NormalizedObject} object2
|
||||
* The second object to compare
|
||||
*/
|
||||
diff(object1: TNormalized, object2: TNormalized): Operation[];
|
||||
}
|
@@ -11,8 +11,8 @@ import { RequestService } from './request.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { DSOUpdateComparator } from './dso-update-comparator';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
|
||||
@Injectable()
|
||||
export class CollectionDataService extends ComColDataService<NormalizedCollection, Collection> {
|
||||
@@ -21,14 +21,14 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected dataBuildService: DataBuildService,
|
||||
protected dataBuildService: NormalizedObjectBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected cds: CommunityDataService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator
|
||||
protected comparator: DSOChangeAnalyzer
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
@@ -16,8 +16,8 @@ import { RequestEntry } from './request.reducer';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { DSOUpdateComparator } from './dso-update-comparator';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
|
||||
const LINK_NAME = 'test';
|
||||
|
||||
@@ -30,7 +30,7 @@ class TestService extends ComColDataService<NormalizedTestObject, any> {
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected dataBuildService: DataBuildService,
|
||||
protected dataBuildService: NormalizedObjectBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected EnvConfig: GlobalConfig,
|
||||
protected cds: CommunityDataService,
|
||||
@@ -38,7 +38,7 @@ class TestService extends ComColDataService<NormalizedTestObject, any> {
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator,
|
||||
protected comparator: DSOChangeAnalyzer,
|
||||
protected linkPath: string
|
||||
) {
|
||||
super();
|
||||
@@ -61,7 +61,7 @@ describe('ComColDataService', () => {
|
||||
const notificationsService = {} as NotificationsService;
|
||||
const http = {} as HttpClient;
|
||||
const comparator = {} as any;
|
||||
const dataBuildService = {} as DataBuildService;
|
||||
const dataBuildService = {} as NormalizedObjectBuildService;
|
||||
|
||||
const scopeID = 'd9d30c0c-69b7-4369-8397-ca67c888974d';
|
||||
const options = Object.assign(new FindAllOptions(), {
|
||||
|
@@ -17,8 +17,8 @@ import { Observable } from 'rxjs';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { DSOUpdateComparator } from './dso-update-comparator';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
|
||||
@Injectable()
|
||||
export class CommunityDataService extends ComColDataService<NormalizedCommunity, Community> {
|
||||
@@ -29,13 +29,13 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected dataBuildService: DataBuildService,
|
||||
protected dataBuildService: NormalizedObjectBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator
|
||||
protected comparator: DSOChangeAnalyzer
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
@@ -11,9 +11,9 @@ import { SortDirection, SortOptions } from '../cache/models/sort-options.model';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { Operation } from '../../../../node_modules/fast-json-patch';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { UpdateComparator } from './update-comparator';
|
||||
import { ChangeAnalyzer } from './change-analyzer';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { compare } from 'fast-json-patch';
|
||||
|
||||
@@ -27,14 +27,14 @@ class TestService extends DataService<NormalizedTestObject, any> {
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected dataBuildService: DataBuildService,
|
||||
protected dataBuildService: NormalizedObjectBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected linkPath: string,
|
||||
protected halService: HALEndpointService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: UpdateComparator<NormalizedTestObject>
|
||||
protected comparator: ChangeAnalyzer<NormalizedTestObject>
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -44,8 +44,8 @@ class TestService extends DataService<NormalizedTestObject, any> {
|
||||
}
|
||||
}
|
||||
|
||||
class DummyComparator implements UpdateComparator<NormalizedTestObject> {
|
||||
compare(object1: NormalizedTestObject, object2: NormalizedTestObject): Operation[] {
|
||||
class DummyChangeAnalyzer implements ChangeAnalyzer<NormalizedTestObject> {
|
||||
diff(object1: NormalizedTestObject, object2: NormalizedTestObject): Operation[] {
|
||||
return compare((object1 as any).metadata, (object2 as any).metadata);
|
||||
}
|
||||
|
||||
@@ -58,10 +58,10 @@ describe('DataService', () => {
|
||||
const rdbService = {} as RemoteDataBuildService;
|
||||
const notificationsService = {} as NotificationsService;
|
||||
const http = {} as HttpClient;
|
||||
const comparator = new DummyComparator() as any;
|
||||
const comparator = new DummyChangeAnalyzer() as any;
|
||||
const dataBuildService = {
|
||||
normalize: (object) => object
|
||||
} as DataBuildService;
|
||||
} as NormalizedObjectBuildService;
|
||||
const objectCache = {
|
||||
addPatch: () => {
|
||||
/* empty */
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import {
|
||||
delay,
|
||||
distinctUntilChanged,
|
||||
filter,
|
||||
find,
|
||||
switchMap,
|
||||
first,
|
||||
map,
|
||||
take,
|
||||
tap, first, mergeMap
|
||||
mergeMap,
|
||||
switchMap,
|
||||
take
|
||||
} from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Store } from '@ngrx/store';
|
||||
@@ -18,44 +18,41 @@ import { URLCombiner } from '../url-combiner/url-combiner';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { RemoteData } from './remote-data';
|
||||
import {
|
||||
CreateRequest, DeleteByIDRequest,
|
||||
CreateRequest,
|
||||
DeleteByIDRequest,
|
||||
FindAllOptions,
|
||||
FindAllRequest,
|
||||
FindByIDRequest,
|
||||
GetRequest, RestRequest
|
||||
GetRequest
|
||||
} from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
||||
import { compare, Operation } from 'fast-json-patch';
|
||||
import { Operation } from 'fast-json-patch';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {
|
||||
configureRequest,
|
||||
filterSuccessfulResponses, getFinishedRemoteData, getResourceLinksFromResponse,
|
||||
getResponseFromEntry
|
||||
} from '../shared/operators';
|
||||
import { DSOSuccessResponse, ErrorResponse, RestResponse } from '../cache/response.models';
|
||||
import { configureRequest, getResponseFromEntry } from '../shared/operators';
|
||||
import { ErrorResponse, RestResponse } from '../cache/response.models';
|
||||
import { NotificationOptions } from '../../shared/notifications/models/notification-options.model';
|
||||
import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer';
|
||||
import { NormalizedObjectFactory } from '../cache/models/normalized-object-factory';
|
||||
import { CacheableObject } from '../cache/object-cache.reducer';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { UpdateComparator } from './update-comparator';
|
||||
import { RequestEntry } from './request.reducer';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { ChangeAnalyzer } from './change-analyzer';
|
||||
|
||||
export abstract class DataService<TNormalized extends NormalizedObject, TDomain extends CacheableObject> {
|
||||
protected abstract requestService: RequestService;
|
||||
protected abstract rdbService: RemoteDataBuildService;
|
||||
protected abstract dataBuildService: DataBuildService;
|
||||
protected abstract dataBuildService: NormalizedObjectBuildService;
|
||||
protected abstract store: Store<CoreState>;
|
||||
protected abstract linkPath: string;
|
||||
protected abstract halService: HALEndpointService;
|
||||
protected abstract objectCache: ObjectCacheService;
|
||||
protected abstract notificationsService: NotificationsService;
|
||||
protected abstract http: HttpClient;
|
||||
protected abstract comparator: UpdateComparator<TNormalized>;
|
||||
protected abstract comparator: ChangeAnalyzer<TNormalized>;
|
||||
|
||||
public abstract getBrowseEndpoint(options: FindAllOptions, linkPath?: string): Observable<string>
|
||||
|
||||
@@ -139,7 +136,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
|
||||
const oldVersion$ = this.objectCache.getBySelfLink(object.self);
|
||||
return oldVersion$.pipe(first(), mergeMap((oldVersion: TNormalized) => {
|
||||
const newVersion = this.dataBuildService.normalize<TDomain, TNormalized>(object);
|
||||
const operations = this.comparator.compare(oldVersion, newVersion);
|
||||
const operations = this.comparator.diff(oldVersion, newVersion);
|
||||
if (isNotEmpty(operations)) {
|
||||
this.objectCache.addPatch(object.self, operations);
|
||||
}
|
||||
@@ -149,6 +146,15 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DSpaceObject on the server, and store the response
|
||||
* in the object cache
|
||||
*
|
||||
* @param {DSpaceObject} dso
|
||||
* The object to create
|
||||
* @param {string} parentUUID
|
||||
* The UUID of the parent to create the new object under
|
||||
*/
|
||||
create(dso: TDomain, parentUUID: string): Observable<RemoteData<TDomain>> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
|
||||
|
26
src/app/core/data/dso-change-analyzer.service.ts
Normal file
26
src/app/core/data/dso-change-analyzer.service.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Operation } from 'fast-json-patch/lib/core';
|
||||
import { compare } from 'fast-json-patch';
|
||||
import { ChangeAnalyzer } from './change-analyzer';
|
||||
import { NormalizedDSpaceObject } from '../cache/models/normalized-dspace-object.model';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
/**
|
||||
* A class to determine what differs between two
|
||||
* DSpaceObjects
|
||||
*/
|
||||
@Injectable()
|
||||
export class DSOChangeAnalyzer implements ChangeAnalyzer<NormalizedDSpaceObject> {
|
||||
|
||||
/**
|
||||
* Compare the metadata of two DSpaceObjects and return the differences as
|
||||
* a JsonPatch Operation Array
|
||||
*
|
||||
* @param {NormalizedDSpaceObject} object1
|
||||
* The first object to compare
|
||||
* @param {NormalizedDSpaceObject} object2
|
||||
* The second object to compare
|
||||
*/
|
||||
diff(object1: NormalizedDSpaceObject, object2: NormalizedDSpaceObject): Operation[] {
|
||||
return compare(object1.metadata, object2.metadata).map((operation: Operation) => Object.assign({}, operation, { path: '/metadata' + operation.path }));
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
import { Operation } from 'fast-json-patch/lib/core';
|
||||
import { compare } from 'fast-json-patch';
|
||||
import { UpdateComparator } from './update-comparator';
|
||||
import { NormalizedDSpaceObject } from '../cache/models/normalized-dspace-object.model';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class DSOUpdateComparator implements UpdateComparator<NormalizedDSpaceObject> {
|
||||
compare(object1: NormalizedDSpaceObject, object2: NormalizedDSpaceObject): Operation[] {
|
||||
return compare(object1.metadata, object2.metadata).map((operation: Operation) => Object.assign({}, operation, { path: '/metadata' + operation.path }));
|
||||
}
|
||||
}
|
@@ -9,7 +9,7 @@ import { DSpaceObjectDataService } from './dspace-object-data.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
|
||||
describe('DSpaceObjectDataService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
@@ -46,7 +46,7 @@ describe('DSpaceObjectDataService', () => {
|
||||
const notificationsService = {} as NotificationsService;
|
||||
const http = {} as HttpClient;
|
||||
const comparator = {} as any;
|
||||
const dataBuildService = {} as DataBuildService;
|
||||
const dataBuildService = {} as NormalizedObjectBuildService;
|
||||
|
||||
service = new DSpaceObjectDataService(
|
||||
requestService,
|
||||
|
@@ -13,8 +13,8 @@ import { FindAllOptions } from './request.models';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { DSOUpdateComparator } from './dso-update-comparator';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
class DataServiceImpl extends DataService<NormalizedDSpaceObject, DSpaceObject> {
|
||||
@@ -23,13 +23,13 @@ class DataServiceImpl extends DataService<NormalizedDSpaceObject, DSpaceObject>
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected dataBuildService: DataBuildService,
|
||||
protected dataBuildService: NormalizedObjectBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator) {
|
||||
protected comparator: DSOChangeAnalyzer) {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ export class DSpaceObjectDataService {
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected dataBuildService: DataBuildService,
|
||||
protected dataBuildService: NormalizedObjectBuildService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator) {
|
||||
protected comparator: DSOChangeAnalyzer) {
|
||||
this.dataService = new DataServiceImpl(requestService, rdbService, dataBuildService, null, objectCache, halService, notificationsService, http, comparator);
|
||||
}
|
||||
|
||||
|
@@ -7,21 +7,42 @@ import { CoreState } from '../core.reducers';
|
||||
import { ItemDataService } from './item-data.service';
|
||||
import { RequestService } from './request.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { FindAllOptions, RestRequest } from './request.models';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { FindAllOptions } from './request.models';
|
||||
import { Observable } from 'rxjs';
|
||||
import { RestResponse } from '../cache/response.models';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { RequestEntry } from './request.reducer';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
|
||||
describe('ItemDataService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
let service: ItemDataService;
|
||||
let bs: BrowseService;
|
||||
const requestService = {} as RequestService;
|
||||
const requestService = {
|
||||
generateRequestId(): string {
|
||||
return scopeID;
|
||||
},
|
||||
configure(request: RestRequest) {
|
||||
// Do nothing
|
||||
},
|
||||
getByHref(requestHref: string) {
|
||||
const responseCacheEntry = new RequestEntry();
|
||||
responseCacheEntry.response = new RestResponse(true, '200');
|
||||
return observableOf(responseCacheEntry);
|
||||
}
|
||||
} as RequestService;
|
||||
const rdbService = {} as RemoteDataBuildService;
|
||||
const objectCache = {} as ObjectCacheService;
|
||||
|
||||
const store = {} as Store<CoreState>;
|
||||
const halEndpointService = {} as HALEndpointService;
|
||||
const objectCache = {} as ObjectCacheService;
|
||||
const halEndpointService = {
|
||||
getEndpoint(linkPath: string): Observable<string> {
|
||||
return cold('a', {a: itemEndpoint});
|
||||
}
|
||||
} as HALEndpointService;
|
||||
|
||||
const scopeID = '4af28e99-6a9c-4036-a199-e1b587046d39';
|
||||
const options = Object.assign(new FindAllOptions(), {
|
||||
@@ -40,7 +61,9 @@ describe('ItemDataService', () => {
|
||||
const notificationsService = {} as NotificationsService;
|
||||
const http = {} as HttpClient;
|
||||
const comparator = {} as any;
|
||||
const dataBuildService = {} as DataBuildService;
|
||||
const dataBuildService = {} as NormalizedObjectBuildService;
|
||||
const itemEndpoint = 'https://rest.api/core/items';
|
||||
const ScopedItemEndpoint = `https://rest.api/core/items/${scopeID}`;
|
||||
|
||||
function initMockBrowseService(isSuccessful: boolean) {
|
||||
const obs = isSuccessful ?
|
||||
@@ -94,4 +117,70 @@ describe('ItemDataService', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getItemWithdrawEndpoint', () => {
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
service = initTestService();
|
||||
|
||||
});
|
||||
|
||||
it('should return the endpoint to withdraw and reinstate items', () => {
|
||||
const result = service.getItemWithdrawEndpoint(scopeID);
|
||||
const expected = cold('a', {a: ScopedItemEndpoint});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
|
||||
it('should setWithDrawn', () => {
|
||||
const expected = new RestResponse(true, '200');
|
||||
const result = service.setWithDrawn(scopeID, true);
|
||||
result.subscribe((v) => expect(v).toEqual(expected));
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('getItemDiscoverableEndpoint', () => {
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
service = initTestService();
|
||||
|
||||
});
|
||||
|
||||
it('should return the endpoint to make an item private or public', () => {
|
||||
const result = service.getItemDiscoverableEndpoint(scopeID);
|
||||
const expected = cold('a', {a: ScopedItemEndpoint});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
|
||||
it('should setDiscoverable', () => {
|
||||
const expected = new RestResponse(true, '200');
|
||||
const result = service.setDiscoverable(scopeID, false);
|
||||
result.subscribe((v) => expect(v).toEqual(expected));
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('getItemDeleteEndpoint', () => {
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
service = initTestService();
|
||||
});
|
||||
|
||||
it('should return the endpoint to make an item private or public', () => {
|
||||
const result = service.getItemDeleteEndpoint(scopeID);
|
||||
const expected = cold('a', {a: ScopedItemEndpoint});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
|
||||
it('should delete the item', () => {
|
||||
const expected = new RestResponse(true, '200');
|
||||
const result = service.delete(scopeID);
|
||||
result.subscribe((v) => expect(v).toEqual(expected));
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -14,12 +14,14 @@ import { URLCombiner } from '../url-combiner/url-combiner';
|
||||
import { DataService } from './data.service';
|
||||
import { RequestService } from './request.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { FindAllOptions } from './request.models';
|
||||
import { DeleteRequest, FindAllOptions, PatchRequest, RestRequest } from './request.models';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { DataBuildService } from '../cache/builders/data-build.service';
|
||||
import { DSOUpdateComparator } from './dso-update-comparator';
|
||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||
import { configureRequest, getRequestFromRequestHref } from '../shared/operators';
|
||||
import { RequestEntry } from './request.reducer';
|
||||
|
||||
@Injectable()
|
||||
export class ItemDataService extends DataService<NormalizedItem, Item> {
|
||||
@@ -28,14 +30,14 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected dataBuildService: DataBuildService,
|
||||
protected dataBuildService: NormalizedObjectBuildService,
|
||||
protected store: Store<CoreState>,
|
||||
private bs: BrowseService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
protected notificationsService: NotificationsService,
|
||||
protected http: HttpClient,
|
||||
protected comparator: DSOUpdateComparator) {
|
||||
protected comparator: DSOChangeAnalyzer) {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -56,4 +58,93 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
|
||||
distinctUntilChanged(),);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the endpoint for item withdrawal and reinstatement
|
||||
* @param itemId
|
||||
*/
|
||||
public getItemWithdrawEndpoint(itemId: string): Observable<string> {
|
||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the endpoint to make item private and public
|
||||
* @param itemId
|
||||
*/
|
||||
public getItemDiscoverableEndpoint(itemId: string): Observable<string> {
|
||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the endpoint to delete the item
|
||||
* @param itemId
|
||||
*/
|
||||
public getItemDeleteEndpoint(itemId: string): Observable<string> {
|
||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||
map((endpoint: string) => this.getFindByIDHref(endpoint, itemId))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the isWithdrawn state of an item to a specified state
|
||||
* @param itemId
|
||||
* @param withdrawn
|
||||
*/
|
||||
public setWithDrawn(itemId: string, withdrawn: boolean) {
|
||||
const patchOperation = [{
|
||||
op: 'replace', path: '/withdrawn', value: withdrawn
|
||||
}];
|
||||
return this.getItemWithdrawEndpoint(itemId).pipe(
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) =>
|
||||
new PatchRequest(this.requestService.generateRequestId(), endpointURL, patchOperation)
|
||||
),
|
||||
configureRequest(this.requestService),
|
||||
map((request: RestRequest) => request.href),
|
||||
getRequestFromRequestHref(this.requestService),
|
||||
map((requestEntry: RequestEntry) => requestEntry.response)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the isDiscoverable state of an item to a specified state
|
||||
* @param itemId
|
||||
* @param discoverable
|
||||
*/
|
||||
public setDiscoverable(itemId: string, discoverable: boolean) {
|
||||
const patchOperation = [{
|
||||
op: 'replace', path: '/discoverable', value: discoverable
|
||||
}];
|
||||
return this.getItemDiscoverableEndpoint(itemId).pipe(
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) =>
|
||||
new PatchRequest(this.requestService.generateRequestId(), endpointURL, patchOperation)
|
||||
),
|
||||
configureRequest(this.requestService),
|
||||
map((request: RestRequest) => request.href),
|
||||
getRequestFromRequestHref(this.requestService),
|
||||
map((requestEntry: RequestEntry) => requestEntry.response)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the item
|
||||
* @param itemId
|
||||
*/
|
||||
public delete(itemId: string) {
|
||||
return this.getItemDeleteEndpoint(itemId).pipe(
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) =>
|
||||
new DeleteRequest(this.requestService.generateRequestId(), endpointURL)
|
||||
),
|
||||
configureRequest(this.requestService),
|
||||
map((request: RestRequest) => request.href),
|
||||
getRequestFromRequestHref(this.requestService),
|
||||
map((requestEntry: RequestEntry) => requestEntry.response)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -86,7 +86,17 @@ function completeRequest(state: RequestState, action: RequestCompleteAction): Re
|
||||
});
|
||||
}
|
||||
|
||||
function resetResponseTimestamps(state: RequestState, action: ResetResponseTimestampsAction) {
|
||||
/**
|
||||
* Reset the timeAdded property of all responses
|
||||
*
|
||||
* @param state
|
||||
* the current state
|
||||
* @param action
|
||||
* a RequestCompleteAction
|
||||
* @return RequestState
|
||||
* the new state, with the timeAdded property reset
|
||||
*/
|
||||
function resetResponseTimestamps(state: RequestState, action: ResetResponseTimestampsAction): RequestState {
|
||||
const newState = Object.create(null);
|
||||
Object.keys(state).forEach((key) => {
|
||||
newState[key] = Object.assign({}, state[key],
|
||||
|
@@ -1,6 +0,0 @@
|
||||
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
||||
import { Operation } from 'fast-json-patch/lib/core';
|
||||
|
||||
export interface UpdateComparator<TNormalized extends NormalizedObject> {
|
||||
compare(object1: TNormalized, object2: TNormalized): Operation[];
|
||||
}
|
Reference in New Issue
Block a user