mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 05:23:06 +00:00
Added TypeDoc/comments
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
/**
|
||||
* Combines a variable number of strings representing parts
|
||||
* of a relative REST URL in to a single, absolute REST URL
|
||||
*
|
||||
*/
|
||||
import { isNotUndefined } from '../../../shared/empty.util';
|
||||
|
||||
/**
|
||||
* Interface used to represent a JSON-PATCH path member
|
||||
* in JsonPatchOperationsState
|
||||
*/
|
||||
export interface JsonPatchOperationPathObject {
|
||||
rootElement: string;
|
||||
subRootElement: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines a variable number of strings representing parts
|
||||
* of a JSON-PATCH path
|
||||
*/
|
||||
export class JsonPatchOperationPathCombiner {
|
||||
private _rootElement: string;
|
||||
private _subRootElement: string;
|
||||
@@ -28,6 +31,15 @@ export class JsonPatchOperationPathCombiner {
|
||||
return this._subRootElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return {string}
|
||||
* The combined path
|
||||
*/
|
||||
public getPath(fragment?: string|string[]): JsonPatchOperationPathObject {
|
||||
if (isNotUndefined(fragment) && Array.isArray(fragment)) {
|
||||
fragment = fragment.join('/');
|
||||
|
@@ -13,12 +13,27 @@ import { AuthorityValue } from '../../integration/models/authority.value';
|
||||
import { FormFieldMetadataValueObject } from '../../../shared/form/builder/models/form-field-metadata-value.model';
|
||||
import { FormFieldLanguageValueObject } from '../../../shared/form/builder/models/form-field-language-value.model';
|
||||
|
||||
/**
|
||||
* Provides methods to dispatch JsonPatch Operations Actions
|
||||
*/
|
||||
@Injectable()
|
||||
export class JsonPatchOperationsBuilder {
|
||||
|
||||
constructor(private store: Store<CoreState>) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a new NewPatchAddOperationAction
|
||||
*
|
||||
* @param path
|
||||
* a JsonPatchOperationPathObject representing path
|
||||
* @param value
|
||||
* The value to update the referenced path
|
||||
* @param first
|
||||
* A boolean representing if the value to be added is the first of an array
|
||||
* @param plain
|
||||
* A boolean representing if the value to be added is a plain text value
|
||||
*/
|
||||
add(path: JsonPatchOperationPathObject, value, first = false, plain = false) {
|
||||
this.store.dispatch(
|
||||
new NewPatchAddOperationAction(
|
||||
@@ -27,6 +42,16 @@ export class JsonPatchOperationsBuilder {
|
||||
path.path, this.prepareValue(value, plain, first)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a new NewPatchReplaceOperationAction
|
||||
*
|
||||
* @param path
|
||||
* a JsonPatchOperationPathObject representing path
|
||||
* @param value
|
||||
* the value to update the referenced path
|
||||
* @param plain
|
||||
* a boolean representing if the value to be added is a plain text value
|
||||
*/
|
||||
replace(path: JsonPatchOperationPathObject, value, plain = false) {
|
||||
this.store.dispatch(
|
||||
new NewPatchReplaceOperationAction(
|
||||
@@ -36,6 +61,12 @@ export class JsonPatchOperationsBuilder {
|
||||
this.prepareValue(value, plain, false)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a new NewPatchRemoveOperationAction
|
||||
*
|
||||
* @param path
|
||||
* a JsonPatchOperationPathObject representing path
|
||||
*/
|
||||
remove(path: JsonPatchOperationPathObject) {
|
||||
this.store.dispatch(
|
||||
new NewPatchRemoveOperationAction(
|
||||
@@ -57,8 +88,6 @@ export class JsonPatchOperationsBuilder {
|
||||
operationValue.push(this.prepareObjectValue(entry));
|
||||
} else {
|
||||
operationValue.push(new FormFieldMetadataValueObject(entry));
|
||||
// operationValue.push({value: entry});
|
||||
// operationValue.push(entry);
|
||||
}
|
||||
});
|
||||
} else if (typeof value === 'object') {
|
||||
@@ -83,7 +112,6 @@ export class JsonPatchOperationsBuilder {
|
||||
operationValue = new FormFieldMetadataValueObject(value.value, value.language);
|
||||
} else if (value.hasOwnProperty('value')) {
|
||||
operationValue = new FormFieldMetadataValueObject(value.value);
|
||||
// operationValue = value;
|
||||
} else {
|
||||
Object.keys(value)
|
||||
.forEach((key) => {
|
||||
@@ -93,7 +121,6 @@ export class JsonPatchOperationsBuilder {
|
||||
operationValue[key] = value[key];
|
||||
}
|
||||
});
|
||||
// operationValue = {value: value};
|
||||
}
|
||||
return operationValue;
|
||||
}
|
||||
|
@@ -8,9 +8,15 @@ import {
|
||||
JsonPatchOperationsActionTypes
|
||||
} from './json-patch-operations.actions';
|
||||
|
||||
/**
|
||||
* Provides effect methods for jsonPatch Operations actions
|
||||
*/
|
||||
@Injectable()
|
||||
export class JsonPatchOperationsEffects {
|
||||
|
||||
/**
|
||||
* Dispatches a FlushPatchOperationsAction for every dispatched CommitPatchOperationsAction
|
||||
*/
|
||||
@Effect() commit$ = this.actions$.pipe(
|
||||
ofType(JsonPatchOperationsActionTypes.COMMIT_JSON_PATCH_OPERATIONS),
|
||||
map((action: CommitPatchOperationsAction) => {
|
||||
|
@@ -15,15 +15,25 @@ import {
|
||||
} from './json-patch-operations.actions';
|
||||
import { JsonPatchOperationModel, JsonPatchOperationType } from './json-patch.model';
|
||||
|
||||
/**
|
||||
* An interface to represent JSON-PATCH Operation objects to execute
|
||||
*/
|
||||
export interface JsonPatchOperationObject {
|
||||
operation: JsonPatchOperationModel;
|
||||
timeAdded: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* An interface to represent the body containing a list of JsonPatchOperationObject
|
||||
*/
|
||||
export interface JsonPatchOperationsEntry {
|
||||
body: JsonPatchOperationObject[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface used to represent a JSON-PATCH path member
|
||||
* in JsonPatchOperationsState
|
||||
*/
|
||||
export interface JsonPatchOperationsResourceEntry {
|
||||
children: { [resourceId: string]: JsonPatchOperationsEntry };
|
||||
transactionStartTime: number;
|
||||
@@ -42,6 +52,16 @@ export interface JsonPatchOperationsState {
|
||||
|
||||
const initialState: JsonPatchOperationsState = Object.create(null);
|
||||
|
||||
/**
|
||||
* The JSON-PATCH operations Reducer
|
||||
*
|
||||
* @param state
|
||||
* the current state
|
||||
* @param action
|
||||
* the action to perform on the state
|
||||
* @return JsonPatchOperationsState
|
||||
* the new state
|
||||
*/
|
||||
export function jsonPatchOperationsReducer(state = initialState, action: PatchOperationsActions): JsonPatchOperationsState {
|
||||
switch (action.type) {
|
||||
|
||||
|
@@ -19,6 +19,9 @@ import {
|
||||
} from './json-patch-operations.actions';
|
||||
import { JsonPatchOperationModel } from './json-patch.model';
|
||||
|
||||
/**
|
||||
* An abstract class that provides methods to make JSON Patch requests.
|
||||
*/
|
||||
export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, PatchRequestDefinition extends PatchRequest> {
|
||||
protected abstract responseCache: ResponseCacheService;
|
||||
protected abstract requestService: RequestService;
|
||||
@@ -40,6 +43,18 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
|
||||
return observableMerge(errorResponses, successResponses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a new JSON Patch request with all operations stored in the state that are ready to be dispatched
|
||||
*
|
||||
* @param hrefObs
|
||||
* Observable of request href
|
||||
* @param resourceType
|
||||
* The resource type value
|
||||
* @param resourceId
|
||||
* The resource id value
|
||||
* @return Observable<ResponseDefinitionDomain>
|
||||
* observable of response
|
||||
*/
|
||||
protected submitJsonPatchOperations(hrefObs: Observable<string>, resourceType: string, resourceId?: string): Observable<ResponseDefinitionDomain> {
|
||||
let startTransactionTime = null;
|
||||
const [patchRequest$, emptyRequest$] = partition((request: PatchRequestDefinition) => isNotEmpty(request.body))(hrefObs.pipe(
|
||||
@@ -101,6 +116,18 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance for RestRequest class
|
||||
*
|
||||
* @param uuid
|
||||
* The request uuid
|
||||
* @param href
|
||||
* The request href
|
||||
* @param body
|
||||
* The request body
|
||||
* @return Object<PatchRequestDefinition>
|
||||
* instance of PatchRequestDefinition
|
||||
*/
|
||||
protected getRequestInstance(uuid: string, href: string, body?: any): PatchRequestDefinition {
|
||||
return new this.patchRequestConstructor(uuid, href, body);
|
||||
}
|
||||
@@ -109,8 +136,20 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
|
||||
return isNotEmpty(resourceID) ? `${endpoint}/${resourceID}` : `${endpoint}`;
|
||||
}
|
||||
|
||||
public jsonPatchByResourceType(linkName: string, scopeId: string, resourceType: string): Observable<ResponseDefinitionDomain> {
|
||||
const href$ = this.halService.getEndpoint(linkName).pipe(
|
||||
/**
|
||||
* Make a new JSON Patch request with all operations related to the specified resource type
|
||||
*
|
||||
* @param linkPath
|
||||
* The link path of the request
|
||||
* @param scopeId
|
||||
* The scope id
|
||||
* @param resourceType
|
||||
* The resource type value
|
||||
* @return Observable<ResponseDefinitionDomain>
|
||||
* observable of response
|
||||
*/
|
||||
public jsonPatchByResourceType(linkPath: string, scopeId: string, resourceType: string): Observable<ResponseDefinitionDomain> {
|
||||
const href$ = this.halService.getEndpoint(linkPath).pipe(
|
||||
filter((href: string) => isNotEmpty(href)),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)));
|
||||
@@ -118,8 +157,22 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
|
||||
return this.submitJsonPatchOperations(href$, resourceType);
|
||||
}
|
||||
|
||||
public jsonPatchByResourceID(linkName: string, scopeId: string, resourceType: string, resourceId: string): Observable<ResponseDefinitionDomain> {
|
||||
const hrefObs = this.halService.getEndpoint(linkName).pipe(
|
||||
/**
|
||||
* Make a new JSON Patch request with all operations related to the specified resource id
|
||||
*
|
||||
* @param linkPath
|
||||
* The link path of the request
|
||||
* @param scopeId
|
||||
* The scope id
|
||||
* @param resourceType
|
||||
* The resource type value
|
||||
* @param resourceId
|
||||
* The resource id value
|
||||
* @return Observable<ResponseDefinitionDomain>
|
||||
* observable of response
|
||||
*/
|
||||
public jsonPatchByResourceID(linkPath: string, scopeId: string, resourceType: string, resourceId: string): Observable<ResponseDefinitionDomain> {
|
||||
const hrefObs = this.halService.getEndpoint(linkPath).pipe(
|
||||
filter((href: string) => isNotEmpty(href)),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)));
|
||||
|
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* Represents all JSON Patch operations type.
|
||||
*/
|
||||
export enum JsonPatchOperationType {
|
||||
test = 'test',
|
||||
remove = 'remove',
|
||||
@@ -7,6 +10,9 @@ export enum JsonPatchOperationType {
|
||||
copy = 'copy',
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a JSON Patch operations.
|
||||
*/
|
||||
export class JsonPatchOperationModel {
|
||||
op: JsonPatchOperationType;
|
||||
path: string;
|
||||
|
@@ -24,11 +24,29 @@ export function subStateSelector<T, V>(parentSelector: Selector<any, any>, subSt
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return MemoizedSelector to select all jsonPatchOperations for a specified resource type, stored in the state
|
||||
*
|
||||
* @param resourceType
|
||||
* the resource type
|
||||
* @return MemoizedSelector<CoreState, JsonPatchOperationsResourceEntry>
|
||||
* MemoizedSelector
|
||||
*/
|
||||
export function jsonPatchOperationsByResourceType(resourceType: string): MemoizedSelector<CoreState, JsonPatchOperationsResourceEntry> {
|
||||
return keySelector<CoreState, JsonPatchOperationsResourceEntry>(coreSelector,'json/patch', resourceType);
|
||||
}
|
||||
|
||||
export function jsonPatchOperationsByResourcId(resourceType: string, resourceId: string): MemoizedSelector<CoreState, JsonPatchOperationsEntry> {
|
||||
/**
|
||||
* Return MemoizedSelector to select all jsonPatchOperations for a specified resource id, stored in the state
|
||||
*
|
||||
* @param resourceType
|
||||
* the resource type
|
||||
* @param resourceId
|
||||
* the resourceId type
|
||||
* @return MemoizedSelector<CoreState, JsonPatchOperationsResourceEntry>
|
||||
* MemoizedSelector
|
||||
*/
|
||||
export function jsonPatchOperationsByResourceId(resourceType: string, resourceId: string): MemoizedSelector<CoreState, JsonPatchOperationsEntry> {
|
||||
const resourceTypeSelector = jsonPatchOperationsByResourceType(resourceType);
|
||||
return subStateSelector<CoreState, JsonPatchOperationsEntry>(resourceTypeSelector, resourceId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user