From ce06b1af2a295fd1ff4d1e03f7832a06e37413cb Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 28 Feb 2019 15:52:43 +0100 Subject: [PATCH] Refactored JsonPatchOperationPathCombiner extending URLCombiner --- .../json-patch-operation-path-combiner.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/core/json-patch/builder/json-patch-operation-path-combiner.ts b/src/app/core/json-patch/builder/json-patch-operation-path-combiner.ts index 0ee798fbfc..d29bf993cc 100644 --- a/src/app/core/json-patch/builder/json-patch-operation-path-combiner.ts +++ b/src/app/core/json-patch/builder/json-patch-operation-path-combiner.ts @@ -1,4 +1,5 @@ import { isNotUndefined } from '../../../shared/empty.util'; +import { URLCombiner } from '../../url-combiner/url-combiner'; /** * Interface used to represent a JSON-PATCH path member @@ -14,11 +15,12 @@ export interface JsonPatchOperationPathObject { * Combines a variable number of strings representing parts * of a JSON-PATCH path */ -export class JsonPatchOperationPathCombiner { +export class JsonPatchOperationPathCombiner extends URLCombiner { private _rootElement: string; private _subRootElement: string; constructor(rootElement, ...subRootElements: string[]) { + super(rootElement, ...subRootElements); this._rootElement = rootElement; this._subRootElement = subRootElements.join('/'); } @@ -35,21 +37,19 @@ export class JsonPatchOperationPathCombiner { * Combines the parts of this JsonPatchOperationPathCombiner in to a JSON-PATCH path member * * e.g. new JsonPatchOperationPathCombiner('sections', 'basic').getPath(['dc.title', '0']) - * returns: sections/basic/dc.title/0 + * returns: {rootElement: 'sections', subRootElement: 'basic', path: '/sections/basic/dc.title/0'} * - * @return {string} - * The combined path + * @return {JsonPatchOperationPathObject} + * The combined path object */ public getPath(fragment?: string|string[]): JsonPatchOperationPathObject { if (isNotUndefined(fragment) && Array.isArray(fragment)) { fragment = fragment.join('/'); } - let path; + let path = '/' + this.toString(); if (isNotUndefined(fragment)) { - path = '/' + this._rootElement + '/' + this._subRootElement + '/' + fragment; - } else { - path = '/' + this._rootElement + '/' + this._subRootElement; + path += '/' + fragment; } return {rootElement: this._rootElement, subRootElement: this._subRootElement, path: path};