ACS-7689 Save and delete to existing hold (#9841)

This commit is contained in:
tomson
2024-06-26 14:03:34 +02:00
committed by Darya Blavanovich
parent bf7f202b91
commit 206f2e02ea
6 changed files with 296 additions and 13 deletions

View File

@@ -5,7 +5,7 @@ Status: Active
Last reviewed: 2024-06-19
---
# [Legal Hold service](../../../lib/content-services/src/lib/legal-hold/services/legal-hold.service.ts "Defined in legal-hold.service.ts")
# [Legal Hold service](../../../lib/content-services/src/lib/legal-hold/services/legal-hold.service.ts) "Defined in legal-hold.service.ts"
Manages holds for nodes.
@@ -19,6 +19,25 @@ Manages holds for nodes.
- _options_: `ContentPagingQuery` - Optional parameters supported by JS-API
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`Hold`](../../../lib/js-api/src/api/gs-core-rest-api/docs/Hold.md)`[]>` - List of holds
- **assignHold**(nodeId: `string`, holdId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`Hold`](../../../lib/js-api/src/api/gs-core-rest-api/docs/Hold.md)`>`<br/>
Assign a node to a hold.
- _nodeId_: `string` - The Id of the node which will be assigned to a hold
- _holdId_: `string` - The Id of the hold to which nodes will be assigned
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`HoldEntry`](../../../lib/js-api/src/api/gs-core-rest-api/docs/HoldEntry.md)`>` - Entry with the hold
- **assignHolds**(nodeIds: `<{id: string}[]>`, holdId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`Hold`](../../../lib/js-api/src/api/gs-core-rest-api/docs/HoldPaging.md)`>`<br/>
Assign a node to a hold.
- _nodeIds_: `<{id: string}[]>` - The Ids of the nodes which will be assigned to a hold
- _holdId_: `string` - The Id of the hold to which nodes will be assigned
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`HoldPaging`](../../../lib/js-api/src/api/gs-core-rest-api/docs/Hold.md)`>` - Hold paging
- **unassignHold**(holdId: `string`, nodeId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`void`]`>`<br/>
Assign a node to a hold.
- _holdId_: `string` - The hold Id
- _nodeId_: `string` - The Id of the node which is unassigned
- **Returns** [`void`]
## Details
To create, delete or get holds Records Management should be created and user should be added to it.

View File

@@ -16,7 +16,7 @@
*/
import { AlfrescoApiService } from '@alfresco/adf-core';
import { ContentPagingQuery, Hold, LegalHoldApi } from '@alfresco/js-api';
import { ContentPagingQuery, Hold, HoldEntry, HoldPaging, LegalHoldApi } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { Observable, from } from 'rxjs';
import { map } from 'rxjs/operators';
@@ -50,4 +50,37 @@ export class LegalHoldService {
)
);
}
/**
* Assign a node to a hold.
*
* @param nodeId The Id of the node which will be assigned to a hold
* @param holdId The Id of the hold to which nodes will be assigned
* @returns Observable<HoldEntry>
*/
assignHold(nodeId: string, holdId: string): Observable<HoldEntry> {
return from(this.legalHoldApi.assignHold(nodeId, holdId));
}
/**
* Assign a node to a hold.
*
* @param nodeIds The list of managed node Ids
* @param holdId The Id of the hold to which nodes will be assigned
* @returns Observable<HoldPaging>
*/
assignHolds(nodeIds: { id: string }[], holdId: string): Observable<HoldPaging> {
return from(this.legalHoldApi.assignHolds(nodeIds, holdId));
}
/**
* Unassign the relationship between a child with id nodeId and a parent hold with id holdId.
*
* @param holdId The hold Id
* @param nodeId The Id of the node which is unassigned
* @returns Empty response
*/
unassignHold(holdId: string, nodeId: string): Observable<void> {
return from(this.legalHoldApi.unassignHold(holdId, nodeId));
}
}

View File

@@ -71,4 +71,47 @@ describe('LegalHoldsService', () => {
});
});
});
describe('assignHold', () => {
it('should assign node to existing hold', (done) => {
const nodeId = 'qwe';
const holdId = 'foo';
const mockResponse = { entry: { id: holdId } };
spyOn(service.legalHoldApi, 'assignHold').and.returnValue(Promise.resolve(mockResponse));
service.assignHold(nodeId, holdId).subscribe((holds) => {
expect(holds).toEqual(mockResponse);
expect(service.legalHoldApi.assignHold).toHaveBeenCalledWith(nodeId, holdId);
done();
});
});
});
describe('assignHolds', () => {
it('should assign nodes to existing hold', (done) => {
const nodeIds = [{ id: 'qwe' }, { id: 'abc'}];
const holdId = 'foo';
spyOn(service.legalHoldApi, 'assignHolds').and.returnValue(Promise.resolve(legalHolds));
service.assignHolds(nodeIds, holdId).subscribe((holds) => {
expect(holds).toEqual(legalHolds);
expect(service.legalHoldApi.assignHolds).toHaveBeenCalledWith(nodeIds, holdId);
done();
});
});
});
describe('unassignHold', () => {
it('should unassign node from existing hold', (done) => {
const nodeId = 'qwe';
const holdId = 'foo';
spyOn(service.legalHoldApi, 'unassignHold').and.returnValue(Promise.resolve(undefined));
service.unassignHold(holdId, nodeId).subscribe(() => {
expect(service.legalHoldApi.unassignHold).toHaveBeenCalledWith(holdId, nodeId);
done();
});
});
});
});

View File

@@ -19,6 +19,7 @@ import { BaseApi } from './base.api';
import { throwIfNotDefined } from '../../../assert';
import { ContentPagingQuery } from '../../content-rest-api';
import { HoldPaging } from '../model/holdPaging';
import { HoldEntry } from '../model';
/**
* Legal Holds service.
@@ -52,4 +53,59 @@ export class LegalHoldApi extends BaseApi {
returnType: HoldPaging
});
}
/**
* Assign node to legal hold
*
* @param holdId The identifier of a hold
* @param nodeId The id of the node to be assigned to existing hold
* @returns Promise<HoldEntry>
*/
assignHold(nodeId: string, holdId: string): Promise<HoldEntry> {
throwIfNotDefined(holdId, 'holdId');
throwIfNotDefined(nodeId, 'nodeId');
return this.post({
path: `/holds/{holdId}/children`,
pathParams: { holdId },
bodyParam: [nodeId],
returnType: HoldEntry
});
}
/**
* Assign nodes to legal hold
*
* @param holdId The identifier of a hold
* @param nodeIds The list with id of nodes to assign to existing hold
* @returns Promise<HoldPaging>
*/
assignHolds(nodeIds: { id: string }[], holdId: string): Promise<HoldPaging> {
throwIfNotDefined(holdId, 'holdId');
throwIfNotDefined(nodeIds, 'nodeIds');
return this.post({
path: `/holds/{holdId}/children`,
pathParams: { holdId },
bodyParam: nodeIds,
returnType: HoldPaging
});
}
/**
* Deletes the relationship between a child with id nodeId and a parent hold with id holdId
*
* @param holdId The identifier of a hold
* @param nodeId The Id of the node which is unassigned
* @returns Empty response
*/
unassignHold(holdId: string, nodeId: string): Promise<void> {
throwIfNotDefined(holdId, 'holdId');
throwIfNotDefined(nodeId, 'nodeId');
return this.delete({
path: `/holds/{holdId}/children/{nodeId}`,
pathParams: { holdId, nodeId }
});
}
}

View File

@@ -1,18 +1,24 @@
# LegalHoldApi
All URIs are relative to *https://localhost/alfresco/api/-default-/public/gs/versions/1*
All URIs are relative to _https://localhost/alfresco/api/-default-/public/gs/versions/1_
Method | HTTP request | Description
------------- | ------------- | -------------
[**getHolds**](LegalHoldApi.md#getHolds) | **GET** /file-plans/{filePlanId}/holds | Get legal holds list
| Method | HTTP request | Description |
| ------------------------------------------------ | -------------------------------------------- | ----------------------------- |
| [**getHolds**](LegalHoldApi.md#getHolds) | **GET** /file-plans/{filePlanId}/holds | Get legal holds list |
| [**assignHold**](LegalHoldApi.md#assignHold) | **POST** /holds/{holdId}/children | Assign node to legal hold |
| [**assignHolds**](LegalHoldApi.md#assignHolds) | **POST** /holds/{holdId}/children | Assign nodes to legal hold |
| [**unassignHold**](LegalHoldApi.md#unassignHold) | **DELETE** /holds/{holdId}/children/{nodeId} | Unassign node from legal hold |
<a name="getHolds"></a>
# **getHolds**
> HoldPaging getHolds(filePlanId, opts)
Get legal holds list.
### Example
```javascript
import LegalHoldApi from 'LegalHoldApi';
import { AlfrescoApi } from '@alfresco/js-api';
@@ -39,12 +45,138 @@ legalHoldApi.getHolds('-filePlan-', opts).then((data) => {
### Parameters
Name | Type | Default value | Description
------------- | ------------- | ------------- | -------------
**filePlanId** | **string** | | The site details
**skipCount** | **number**| `0` | The number of entities that exist in the collection before those included in this list. [optional]
**maxItems** | **number**| `100` | The maximum number of items to return in the list. [optional]
| Name | Type | Default value | Description |
| -------------- | ---------- | ------------- | -------------------------------------------------------------------------------------------------- |
| **filePlanId** | **string** | | The site details |
| **skipCount** | **number** | `0` | The number of entities that exist in the collection before those included in this list. [optional] |
| **maxItems** | **number** | `100` | The maximum number of items to return in the list. [optional] |
### Return type
[**HoldPaging**](HoldPaging.md)
<a name="assignHold"></a>
# **assignHold**
> HoldEntry assignHold(nodeId, holdId)
Assign node to legal hold.
### Example
```javascript
import LegalHoldApi from 'LegalHoldApi';
import { AlfrescoApi } from '@alfresco/js-api';
this.alfrescoApi = new AlfrescoApi();
this.alfrescoApi.setConfig({
hostEcm: 'http://127.0.0.1:8080'
});
let legalHoldApi = new LegalHoldApi(this.alfrescoApi);
legalHoldApi.assignHold('nodeId', 'holdId').then(
(data) => {
console.log('API called successfully. Returned data: ' + data);
},
function (error) {
console.error(error);
}
);
```
### Parameters
| Name | Type | Default value | Description |
| ---------- | ---------- | ------------- | ----------------------------------------- |
| **nodeId** | **string** | | The id of the node to be assigned to hold |
| **holdId** | **string** | | The identifier of a hold. |
### Return type
[**HoldEntry**](HoldEntry.md)
<a name="assignHolds"></a>
# **assignHolds**
> HoldPaging assignHolds(nodeIds, holdId)
Assign nodes to legal hold.
### Example
```javascript
import LegalHoldApi from 'LegalHoldApi';
import { AlfrescoApi } from '@alfresco/js-api';
this.alfrescoApi = new AlfrescoApi();
this.alfrescoApi.setConfig({
hostEcm: 'http://127.0.0.1:8080'
});
let legalHoldApi = new LegalHoldApi(this.alfrescoApi);
legalHoldApi.assignHolds([{ id: 'foo' }, { id: 'bar' }], 'holdId').then(
(data) => {
console.log('API called successfully. Returned data: ' + data);
},
function (error) {
console.error(error);
}
);
```
### Parameters
| Name | Type | Default value | Description |
| ----------- |----------------------| ------------- | ---------------------------------------------------- |
| **nodeIds** | **{ id: string }[]** | | The list with id of nodes to assign to existing hold |
| **holdId** | **string** | | The identifier of a hold. |
### Return type
[**HoldPaging**](HoldPaging.md)
<a name="unassignHold"></a>
# **unassignHold**
> void unassignHold(holdId, nodeId)
Unassign node from legal hold.
### Example
```javascript
import LegalHoldApi from 'LegalHoldApi';
import { AlfrescoApi } from '@alfresco/js-api';
this.alfrescoApi = new AlfrescoApi();
this.alfrescoApi.setConfig({
hostEcm: 'http://127.0.0.1:8080'
});
let legalHoldApi = new LegalHoldApi(this.alfrescoApi);
legalHoldApi.unassignHold('holdId', 'nodeId').then(
(data) => {
console.log('API called successfully. Returned data: ' + data);
},
function (error) {
console.error(error);
}
);
```
### Parameters
| Name | Type | Default value | Description |
| ---------- | ---------- | ------------- | ------------------------------------------ |
| **holdId** | **string** | | The identifier of a hold |
| **nodeId** | **string** | | The nodeId of the node which is unassigned |
### Return type
**void**

View File

@@ -16,8 +16,8 @@
*/
export interface Hold {
name: string;
id?: string;
name?: string;
reason?: string;
description?: string;
selected?: boolean;