1
0

73014: Remove sending patch to cache + small refactoring changes

This commit is contained in:
Kristof De Langhe
2020-09-16 12:01:43 +02:00
parent 2e8a78151e
commit 8c4f5002f5
5 changed files with 9 additions and 26 deletions

View File

@@ -20,7 +20,6 @@ import { AlertType } from '../../../shared/alert/aletr-type';
import { Operation } from 'fast-json-patch';
import { METADATA_PATCH_OPERATION_SERVICE_TOKEN } from '../../../core/data/object-updates/patch-operation-service/metadata-patch-operation.service';
import { DSOSuccessResponse } from '../../../core/cache/response.models';
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
@Component({
selector: 'ds-item-metadata',
@@ -57,7 +56,6 @@ export class ItemMetadataComponent extends AbstractItemUpdateComponent {
public translateService: TranslateService,
public route: ActivatedRoute,
public metadataFieldService: RegistryService,
public objectCacheService: ObjectCacheService,
) {
super(itemService, objectUpdatesService, router, notificationsService, translateService, route);
}
@@ -115,9 +113,7 @@ export class ItemMetadataComponent extends AbstractItemUpdateComponent {
return this.updateService.patch(this.item, patch).pipe(
switchMap((response: DSOSuccessResponse) => {
if (isNotEmpty(response.resourceSelfLinks)) {
const selfLink = response.resourceSelfLinks[0];
this.objectCacheService.addPatch(selfLink, patch, false);
return this.itemService.findByHref(selfLink);
return this.itemService.findByHref(response.resourceSelfLinks[0]);
}
}),
getSucceededRemoteData()

View File

@@ -270,16 +270,14 @@ export class ObjectCacheService {
/**
* Add operations to the existing list of operations for an ObjectCacheEntry
* Makes sure the ServerSyncBuffer for this ObjectCacheEntry is updated
* @param {string} uuid
* @param selfLink
* the uuid of the ObjectCacheEntry
* @param {Operation[]} patch
* list of operations to perform
*/
public addPatch(selfLink: string, patch: Operation[], addToSSD = true) {
public addPatch(selfLink: string, patch: Operation[]) {
this.store.dispatch(new AddPatchObjectCacheAction(selfLink, patch));
if (addToSSD) {
this.store.dispatch(new AddToSSBAction(selfLink, RestRequestMethod.PATCH));
}
this.store.dispatch(new AddToSSBAction(selfLink, RestRequestMethod.PATCH));
}
/**
@@ -297,8 +295,8 @@ export class ObjectCacheService {
/**
* Apply the existing operations on an ObjectCacheEntry in the store
* NB: this does not make any server side changes
* @param {string} uuid
* the uuid of the ObjectCacheEntry
* @param selfLink
* the link of the ObjectCacheEntry
*/
private applyPatchesToCachedObject(selfLink: string) {
this.store.dispatch(new ApplyPatchObjectCacheAction(selfLink));

View File

@@ -22,7 +22,6 @@ export class MetadataPatchAddOperation extends MetadataPatchOperation {
* using the information provided.
*/
toOperation(): Operation {
const path = `/metadata/${this.field}/-`;
return { op: this.op as any, path, value: this.value };
return { op: this.op as any, path: `/metadata/${this.field}/-`, value: this.value };
}
}

View File

@@ -1,6 +1,5 @@
import { MetadataPatchOperation } from './metadata-patch-operation.model';
import { Operation } from 'fast-json-patch';
import { hasValue } from '../../../../../../shared/empty.util';
/**
* Wrapper object for a metadata patch remove Operation
@@ -23,10 +22,6 @@ export class MetadataPatchRemoveOperation extends MetadataPatchOperation {
* using the information provided.
*/
toOperation(): Operation {
let path = `/metadata/${this.field}`;
if (hasValue(this.place)) {
path += `/${this.place}`;
}
return { op: this.op as any, path };
return { op: this.op as any, path: `/metadata/${this.field}/${this.place}` };
}
}

View File

@@ -1,6 +1,5 @@
import { MetadataPatchOperation } from './metadata-patch-operation.model';
import { Operation } from 'fast-json-patch';
import { hasValue } from '../../../../../../shared/empty.util';
/**
* Wrapper object for a metadata patch replace Operation
@@ -29,10 +28,6 @@ export class MetadataPatchReplaceOperation extends MetadataPatchOperation {
* using the information provided.
*/
toOperation(): Operation {
let path = `/metadata/${this.field}`;
if (hasValue(this.place)) {
path += `/${this.place}`;
}
return { op: this.op as any, path, value: this.value };
return { op: this.op as any, path: `/metadata/${this.field}/${this.place}`, value: this.value };
}
}