mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge branch 'master' into angular-cli
This commit is contained in:
4
src/app/core/cache/object-cache.service.ts
vendored
4
src/app/core/cache/object-cache.service.ts
vendored
@@ -10,6 +10,7 @@ import { coreSelector } from '../core.selectors';
|
||||
import { RestRequestMethod } from '../data/rest-request-method';
|
||||
import { selfLinkFromUuidSelector } from '../index/index.selectors';
|
||||
import { GenericConstructor } from '../shared/generic-constructor';
|
||||
import { getClassForType } from './builders/build-decorators';
|
||||
import { LinkService } from './builders/link.service';
|
||||
import {
|
||||
AddPatchObjectCacheAction,
|
||||
@@ -20,7 +21,6 @@ import {
|
||||
|
||||
import { CacheableObject, ObjectCacheEntry, ObjectCacheState } from './object-cache.reducer';
|
||||
import { AddToSSBAction } from './server-sync-buffer.actions';
|
||||
import { getClassForType } from './builders/build-decorators';
|
||||
|
||||
/**
|
||||
* The base selector function to select the object cache in the store
|
||||
@@ -48,7 +48,7 @@ export class ObjectCacheService {
|
||||
constructor(
|
||||
private store: Store<CoreState>,
|
||||
private linkService: LinkService
|
||||
) {
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -50,6 +50,14 @@ describe('ServerSyncBufferEffects', () => {
|
||||
_links: { self: { href: link } }
|
||||
});
|
||||
return observableOf(object);
|
||||
},
|
||||
getBySelfLink: (link) => {
|
||||
const object = Object.assign(new DSpaceObject(), {
|
||||
_links: {
|
||||
self: { href: link }
|
||||
}
|
||||
});
|
||||
return observableOf(object);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
18
src/app/core/cache/server-sync-buffer.effects.ts
vendored
18
src/app/core/cache/server-sync-buffer.effects.ts
vendored
@@ -14,7 +14,7 @@ import { Action, createSelector, MemoizedSelector, select, Store } from '@ngrx/s
|
||||
import { ServerSyncBufferEntry, ServerSyncBufferState } from './server-sync-buffer.reducer';
|
||||
import { combineLatest as observableCombineLatest, of as observableOf } from 'rxjs';
|
||||
import { RequestService } from '../data/request.service';
|
||||
import { PutRequest } from '../data/request.models';
|
||||
import { PatchRequest, PutRequest } from '../data/request.models';
|
||||
import { ObjectCacheService } from './object-cache.service';
|
||||
import { ApplyPatchObjectCacheAction } from './object-cache.actions';
|
||||
import { GenericConstructor } from '../shared/generic-constructor';
|
||||
@@ -22,6 +22,8 @@ import { hasValue, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { RestRequestMethod } from '../data/rest-request-method';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { ObjectCacheEntry } from './object-cache.reducer';
|
||||
import { Operation } from 'fast-json-patch';
|
||||
|
||||
@Injectable()
|
||||
export class ServerSyncBufferEffects {
|
||||
@@ -95,14 +97,16 @@ export class ServerSyncBufferEffects {
|
||||
* @returns {Observable<Action>} ApplyPatchObjectCacheAction to be dispatched
|
||||
*/
|
||||
private applyPatch(href: string): Observable<Action> {
|
||||
const patchObject = this.objectCache.getObjectBySelfLink(href).pipe(take(1));
|
||||
const patchObject = this.objectCache.getBySelfLink(href).pipe(take(1));
|
||||
|
||||
return patchObject.pipe(
|
||||
map((object) => {
|
||||
const serializedObject = new DSpaceSerializer(object.constructor as GenericConstructor<{}>).serialize(object);
|
||||
|
||||
this.requestService.configure(new PutRequest(this.requestService.generateRequestId(), href, serializedObject));
|
||||
|
||||
map((entry: ObjectCacheEntry) => {
|
||||
if (isNotEmpty(entry.patches)) {
|
||||
const flatPatch: Operation[] = [].concat(...entry.patches.map((patch) => patch.operations));
|
||||
if (isNotEmpty(flatPatch)) {
|
||||
this.requestService.configure(new PatchRequest(this.requestService.generateRequestId(), href, flatPatch));
|
||||
}
|
||||
}
|
||||
return new ApplyPatchObjectCacheAction(href);
|
||||
})
|
||||
);
|
||||
|
Reference in New Issue
Block a user