From 586a4ac35b002778e3d25753f9960b4fa1284c52 Mon Sep 17 00:00:00 2001 From: Art Lowel <art.lowel@atmire.com> Date: Thu, 17 Jan 2019 14:59:48 +0100 Subject: [PATCH] add docs, rename classes for clarity --- ....ts => normalized-object-build.service.ts} | 32 +++++++++++++------ src/app/core/cache/object-cache.reducer.ts | 10 ++++++ src/app/core/core.module.ts | 8 ++--- .../data/base-response-parsing.service.ts | 2 +- src/app/core/data/change-analyzer.ts | 20 ++++++++++++ src/app/core/data/collection-data.service.ts | 8 ++--- src/app/core/data/comcol-data.service.spec.ts | 10 +++--- src/app/core/data/community-data.service.ts | 8 ++--- src/app/core/data/data.service.spec.ts | 16 +++++----- src/app/core/data/data.service.ts | 19 ++++++++--- .../core/data/dso-change-analyzer.service.ts | 26 +++++++++++++++ src/app/core/data/dso-update-comparator.ts | 12 ------- .../data/dspace-object-data.service.spec.ts | 4 +-- .../core/data/dspace-object-data.service.ts | 12 +++---- src/app/core/data/item-data.service.spec.ts | 4 +-- src/app/core/data/item-data.service.ts | 8 ++--- src/app/core/data/request.reducer.ts | 12 ++++++- src/app/core/data/update-comparator.ts | 6 ---- .../dspace-rest-v2/dspace-rest-v2.service.ts | 8 +++++ .../core/metadata/metadata.service.spec.ts | 8 ++--- .../comcol-form/comcol-form.component.ts | 3 ++ src/app/shared/testing/utils.ts | 8 +++++ src/config/auto-sync-config.interface.ts | 19 +++++++++++ 23 files changed, 186 insertions(+), 77 deletions(-) rename src/app/core/cache/builders/{data-build.service.ts => normalized-object-build.service.ts} (63%) create mode 100644 src/app/core/data/change-analyzer.ts create mode 100644 src/app/core/data/dso-change-analyzer.service.ts delete mode 100644 src/app/core/data/dso-update-comparator.ts delete mode 100644 src/app/core/data/update-comparator.ts diff --git a/src/app/core/cache/builders/data-build.service.ts b/src/app/core/cache/builders/normalized-object-build.service.ts similarity index 63% rename from src/app/core/cache/builders/data-build.service.ts rename to src/app/core/cache/builders/normalized-object-build.service.ts index 8ba3ebee0c..9d97ccda75 100644 --- a/src/app/core/cache/builders/data-build.service.ts +++ b/src/app/core/cache/builders/normalized-object-build.service.ts @@ -3,24 +3,38 @@ import { NormalizedObject } from '../models/normalized-object.model'; import { CacheableObject } from '../object-cache.reducer'; import { getRelationships } from './build-decorators'; import { NormalizedObjectFactory } from '../models/normalized-object-factory'; -import { map, take } from 'rxjs/operators'; import { hasValue, isNotEmpty } from '../../../shared/empty.util'; -import { PaginatedList } from '../../data/paginated-list'; -export function isRestDataObject(halObj: any) { +/** + * Return true if halObj has a value for `_links.self` + * + * @param {any} halObj The object to test + */ +export function isRestDataObject(halObj: any): boolean { return isNotEmpty(halObj._links) && hasValue(halObj._links.self); } -export function isRestPaginatedList(halObj: any) { +/** + * Return true if halObj has a value for `page` and `_embedded` + * + * @param {any} halObj The object to test + */ +export function isRestPaginatedList(halObj: any): boolean { return hasValue(halObj.page) && hasValue(halObj._embedded); } -export function isPaginatedList(halObj: any) { - return hasValue(halObj.page) && hasValue(halObj.pageInfo); -} - +/** + * A service to turn domain models in to their normalized + * counterparts. + */ @Injectable() -export class DataBuildService { +export class NormalizedObjectBuildService { + + /** + * Returns the normalized model that corresponds to the given domain model + * + * @param {TDomain} domainModel a domain model + */ normalize<TDomain extends CacheableObject, TNormalized extends NormalizedObject>(domainModel: TDomain): TNormalized { const normalizedConstructor = NormalizedObjectFactory.getConstructor(domainModel.type); const relationships = getRelationships(normalizedConstructor) || []; diff --git a/src/app/core/cache/object-cache.reducer.ts b/src/app/core/cache/object-cache.reducer.ts index 991ae5466e..982c77341e 100644 --- a/src/app/core/cache/object-cache.reducer.ts +++ b/src/app/core/cache/object-cache.reducer.ts @@ -17,8 +17,18 @@ export enum DirtyType { Deleted = 'Deleted' } +/** + * An interface to represent a JsonPatch + */ export interface Patch { + /** + * The identifier for this Patch + */ uuid?: string; + + /** + * the list of operations this Patch is composed of + */ operations: Operation[]; } diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index b1904782bd..0868773550 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -65,8 +65,8 @@ import { BrowseItemsResponseParsingService } from './data/browse-items-response- import { DSpaceObjectDataService } from './data/dspace-object-data.service'; import { CSSVariableService } from '../shared/sass-helper/sass-helper.service'; import { MenuService } from '../shared/menu/menu.service'; -import { DataBuildService } from './cache/builders/data-build.service'; -import { DSOUpdateComparator } from './data/dso-update-comparator'; +import { NormalizedObjectBuildService } from './cache/builders/normalized-object-build.service'; +import { DSOChangeAnalyzer } from './data/dso-change-analyzer.service'; const IMPORTS = [ CommonModule, @@ -103,7 +103,7 @@ const PROVIDERS = [ ObjectCacheService, PaginationComponentOptions, RegistryService, - DataBuildService, + NormalizedObjectBuildService, RemoteDataBuildService, RequestService, EndpointMapResponseParsingService, @@ -131,7 +131,7 @@ const PROVIDERS = [ UploaderService, UUIDService, DSpaceObjectDataService, - DSOUpdateComparator, + DSOChangeAnalyzer, CSSVariableService, MenuService, // register AuthInterceptor as HttpInterceptor diff --git a/src/app/core/data/base-response-parsing.service.ts b/src/app/core/data/base-response-parsing.service.ts index d5c1c58296..925caa495c 100644 --- a/src/app/core/data/base-response-parsing.service.ts +++ b/src/app/core/data/base-response-parsing.service.ts @@ -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 { diff --git a/src/app/core/data/change-analyzer.ts b/src/app/core/data/change-analyzer.ts new file mode 100644 index 0000000000..caf9e38c7c --- /dev/null +++ b/src/app/core/data/change-analyzer.ts @@ -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[]; +} diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts index b08b1005b7..e8a682ba0e 100644 --- a/src/app/core/data/collection-data.service.ts +++ b/src/app/core/data/collection-data.service.ts @@ -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(); } diff --git a/src/app/core/data/comcol-data.service.spec.ts b/src/app/core/data/comcol-data.service.spec.ts index ca6c8dd855..1b520d83ce 100644 --- a/src/app/core/data/comcol-data.service.spec.ts +++ b/src/app/core/data/comcol-data.service.spec.ts @@ -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(), { diff --git a/src/app/core/data/community-data.service.ts b/src/app/core/data/community-data.service.ts index 63fbe3a21a..d09a0b9757 100644 --- a/src/app/core/data/community-data.service.ts +++ b/src/app/core/data/community-data.service.ts @@ -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(); } diff --git a/src/app/core/data/data.service.spec.ts b/src/app/core/data/data.service.spec.ts index 9a690e3c4b..9b39f0b68e 100644 --- a/src/app/core/data/data.service.spec.ts +++ b/src/app/core/data/data.service.spec.ts @@ -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 */ diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 47be86c296..045e82fbb6 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -41,20 +41,20 @@ import { NotificationOptions } from '../../shared/notifications/models/notificat 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 { 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> @@ -138,7 +138,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); } @@ -148,6 +148,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( diff --git a/src/app/core/data/dso-change-analyzer.service.ts b/src/app/core/data/dso-change-analyzer.service.ts new file mode 100644 index 0000000000..a47359e5c0 --- /dev/null +++ b/src/app/core/data/dso-change-analyzer.service.ts @@ -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 })); + } +} diff --git a/src/app/core/data/dso-update-comparator.ts b/src/app/core/data/dso-update-comparator.ts deleted file mode 100644 index 245fbfaef0..0000000000 --- a/src/app/core/data/dso-update-comparator.ts +++ /dev/null @@ -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 })); - } -} diff --git a/src/app/core/data/dspace-object-data.service.spec.ts b/src/app/core/data/dspace-object-data.service.spec.ts index 2d478b8f73..7047db6065 100644 --- a/src/app/core/data/dspace-object-data.service.spec.ts +++ b/src/app/core/data/dspace-object-data.service.spec.ts @@ -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, diff --git a/src/app/core/data/dspace-object-data.service.ts b/src/app/core/data/dspace-object-data.service.ts index 9a069c4d61..d485fd0bc4 100644 --- a/src/app/core/data/dspace-object-data.service.ts +++ b/src/app/core/data/dspace-object-data.service.ts @@ -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); } diff --git a/src/app/core/data/item-data.service.spec.ts b/src/app/core/data/item-data.service.spec.ts index 1be361cb9d..0cac6f901d 100644 --- a/src/app/core/data/item-data.service.spec.ts +++ b/src/app/core/data/item-data.service.spec.ts @@ -11,7 +11,7 @@ import { ObjectCacheService } from '../cache/object-cache.service'; import { FindAllOptions } from './request.models'; 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('ItemDataService', () => { let scheduler: TestScheduler; @@ -40,7 +40,7 @@ describe('ItemDataService', () => { const notificationsService = {} as NotificationsService; const http = {} as HttpClient; const comparator = {} as any; - const dataBuildService = {} as DataBuildService; + const dataBuildService = {} as NormalizedObjectBuildService; function initMockBrowseService(isSuccessful: boolean) { const obs = isSuccessful ? diff --git a/src/app/core/data/item-data.service.ts b/src/app/core/data/item-data.service.ts index 2fb2c017dc..32cb00c1a9 100644 --- a/src/app/core/data/item-data.service.ts +++ b/src/app/core/data/item-data.service.ts @@ -18,8 +18,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'; @Injectable() export class ItemDataService extends DataService<NormalizedItem, Item> { @@ -28,14 +28,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(); } diff --git a/src/app/core/data/request.reducer.ts b/src/app/core/data/request.reducer.ts index a680de2d6b..27b5a4188a 100644 --- a/src/app/core/data/request.reducer.ts +++ b/src/app/core/data/request.reducer.ts @@ -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], diff --git a/src/app/core/data/update-comparator.ts b/src/app/core/data/update-comparator.ts deleted file mode 100644 index f064d7f3f2..0000000000 --- a/src/app/core/data/update-comparator.ts +++ /dev/null @@ -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[]; -} diff --git a/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts index 59038228bb..20d6b1dfb3 100644 --- a/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts +++ b/src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts @@ -79,6 +79,14 @@ export class DSpaceRESTv2Service { })); } + /** + * Create a FormData object from a DSpaceObject + * + * @param {DSpaceObject} dso + * the DSpaceObject + * @return {FormData} + * the result + */ buildFormData(dso: DSpaceObject): FormData { const form: FormData = new FormData(); form.append('name', dso.name); diff --git a/src/app/core/metadata/metadata.service.spec.ts b/src/app/core/metadata/metadata.service.spec.ts index ef1d69b8b5..90c811db7a 100644 --- a/src/app/core/metadata/metadata.service.spec.ts +++ b/src/app/core/metadata/metadata.service.spec.ts @@ -35,8 +35,8 @@ import { AuthService } from '../auth/auth.service'; import { NotificationsService } from '../../shared/notifications/notifications.service'; import { HttpClient } from '@angular/common/http'; import { EmptyError } from 'rxjs/internal-compatibility'; -import { DataBuildService } from '../cache/builders/data-build.service'; -import { DSOUpdateComparator } from '../data/dso-update-comparator'; +import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service'; +import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service'; /* tslint:disable:max-classes-per-file */ @Component({ @@ -119,8 +119,8 @@ describe('MetadataService', () => { { provide: AuthService, useValue: {} }, { provide: NotificationsService, useValue: {} }, { provide: HttpClient, useValue: {} }, - { provide: DataBuildService, useValue: {} }, - { provide: DSOUpdateComparator, useValue: {} }, + { provide: NormalizedObjectBuildService, useValue: {} }, + { provide: DSOChangeAnalyzer, useValue: {} }, Meta, Title, ItemDataService, diff --git a/src/app/shared/comcol-forms/comcol-form/comcol-form.component.ts b/src/app/shared/comcol-forms/comcol-form/comcol-form.component.ts index 19050e2bc2..17710fd1c6 100644 --- a/src/app/shared/comcol-forms/comcol-form/comcol-form.component.ts +++ b/src/app/shared/comcol-forms/comcol-form/comcol-form.component.ts @@ -11,6 +11,9 @@ import { DSpaceObject } from '../../../core/shared/dspace-object.model'; import { isNotEmpty } from '../../empty.util'; import { ResourceType } from '../../../core/shared/resource-type'; +/** + * A form for creating and editing Communities or Collections + */ @Component({ selector: 'ds-comcol-form', styleUrls: ['./comcol-form.component.scss'], diff --git a/src/app/shared/testing/utils.ts b/src/app/shared/testing/utils.ts index cd17a1b1f5..770a554439 100644 --- a/src/app/shared/testing/utils.ts +++ b/src/app/shared/testing/utils.ts @@ -31,6 +31,14 @@ export const createTestComponent = <T>(html: string, type: { new(...args: any[]) return fixture as ComponentFixture<T>; }; +/** + * Allows you to spy on a read only property + * + * @param obj + * The object to spy on + * @param prop + * The property to spy on + */ export function spyOnOperator(obj: any, prop: string): any { const oldProp = obj[prop]; Object.defineProperty(obj, prop, { diff --git a/src/config/auto-sync-config.interface.ts b/src/config/auto-sync-config.interface.ts index 5285916b12..90e7ebee80 100644 --- a/src/config/auto-sync-config.interface.ts +++ b/src/config/auto-sync-config.interface.ts @@ -1,11 +1,30 @@ import { RestRequestMethod } from '../app/core/data/rest-request-method'; +/** + * The number of seconds between automatic syncs to the + * server for requests using a certain HTTP Method + */ type TimePerMethod = { [method in RestRequestMethod]: number; }; +/** + * The config that determines how the automatic syncing + * of changed data to the server works + */ export interface AutoSyncConfig { + /** + * The number of seconds between automatic syncs to the server + */ defaultTime: number; + + /** + * HTTP Method specific overrides of defaultTime + */ timePerMethod: TimePerMethod; + + /** + * The max number of requests in the buffer before a sync to the server + */ maxBufferSize: number; }; -- GitLab