mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[ACA-1635][ACA-1636] update favoritesApi and nodesApi to use alfresco-js-api-node (#564)
* refactor favoritesApi and nodesApi to use alfresco-js-api-node * remove node-rest-client
This commit is contained in:
committed by
Cilibiu Bogdan
parent
213c2deedc
commit
86a90d33e2
@@ -23,127 +23,125 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { NodeBodyLock } from 'alfresco-js-api-node';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { NodeBodyCreate, NODE_TYPE_FILE, NODE_TYPE_FOLDER } from './node-body-create';
|
||||
import { NodeBodyCreate } from './node-body-create';
|
||||
import { NodeContentTree, flattenNodeContentTree } from './node-content-tree';
|
||||
|
||||
export class NodesApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
// nodes
|
||||
getNodeByPath(relativePath: string = '/'): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/-my-`, { parameters: { relativePath } })
|
||||
.catch(this.handleError);
|
||||
|
||||
async getNodeByPath(relativePath: string = '/') {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNode('-my-', { relativePath });
|
||||
}
|
||||
|
||||
getNodeById(id: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${id}`)
|
||||
.catch(this.handleError);
|
||||
async getNodeById(id: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNode(id);
|
||||
}
|
||||
|
||||
getNodeDescription(name: string, relativePath: string = '/') {
|
||||
async getNodeDescription(name: string, relativePath: string = '/') {
|
||||
relativePath = (relativePath === '/')
|
||||
? `${name}`
|
||||
: `${relativePath}/${name}`;
|
||||
|
||||
return this.getNodeByPath(`${relativePath}`)
|
||||
.then(response => response.data.entry.properties['cm:description']);
|
||||
return (await this.getNodeByPath(`${relativePath}`)).entry.properties['cm:description'];
|
||||
}
|
||||
|
||||
deleteNodeById(id: string, permanent: boolean = true): Promise<any> {
|
||||
return this
|
||||
.delete(`/nodes/${id}?permanent=${permanent}`)
|
||||
.catch(this.handleError);
|
||||
async deleteNodeById(id: string, permanent: boolean = true) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.deleteNode(id, { permanent });
|
||||
}
|
||||
|
||||
deleteNodeByPath(path: string, permanent: boolean = true): Promise<any> {
|
||||
return this
|
||||
.getNodeByPath(path)
|
||||
.then((response: any): string => response.data.entry.id)
|
||||
.then((id: string): any => this.deleteNodeById(id, permanent))
|
||||
.catch(this.handleError);
|
||||
async deleteNodeByPath(path: string, permanent: boolean = true) {
|
||||
const id = (await this.getNodeByPath(path)).entry.id;
|
||||
return await this.deleteNodeById(id, permanent);
|
||||
}
|
||||
|
||||
deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true): Promise<any[]> {
|
||||
return names.reduce((previous, current) => (
|
||||
previous.then(() => this.deleteNodeByPath(`${relativePath}/${current}`, permanent))
|
||||
), Promise.resolve());
|
||||
async deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true) {
|
||||
return await names.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteNodeByPath(`${relativePath}/${current}`, permanent);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
deleteNodesById(ids: string[], permanent: boolean = true): Promise<any[]> {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.deleteNodeById(current, permanent))
|
||||
), Promise.resolve());
|
||||
async deleteNodesById(ids: string[], permanent: boolean = true) {
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteNodeById(current, permanent);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
// children
|
||||
getNodeChildren(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}/children`)
|
||||
.catch(this.handleError);
|
||||
|
||||
async getNodeChildren(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNodeChildren(nodeId);
|
||||
}
|
||||
|
||||
createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
const data = {
|
||||
name: name,
|
||||
nodeType: nodeType,
|
||||
async createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
const nodeBody = {
|
||||
name,
|
||||
nodeType,
|
||||
properties: {
|
||||
'cm:title': title, 'cm:description': description
|
||||
'cm:title': title,
|
||||
'cm:description': description
|
||||
}
|
||||
};
|
||||
|
||||
return this
|
||||
.post(`/nodes/${parentId}/children`, { data })
|
||||
.catch(this.handleError);
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.addNode(parentId, nodeBody);
|
||||
}
|
||||
|
||||
createFile(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
return this.createNode('cm:content', name, parentId, title, description);
|
||||
async createFile(name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
return await this.createNode('cm:content', name, parentId, title, description);
|
||||
}
|
||||
|
||||
createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
return this.createNode('cm:folder', name, parentId, title, description);
|
||||
async createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
return await this.createNode('cm:folder', name, parentId, title, description);
|
||||
}
|
||||
|
||||
createChildren(data: NodeBodyCreate[]): Promise<any> {
|
||||
return this
|
||||
.post(`/nodes/-my-/children`, { data })
|
||||
.catch(this.handleError);
|
||||
async createChildren(data: NodeBodyCreate[]) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.addNode('-my-', data);
|
||||
}
|
||||
|
||||
createContent(content: NodeContentTree, relativePath: string = '/'): Promise<any> {
|
||||
return this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
async createContent(content: NodeContentTree, relativePath: string = '/') {
|
||||
return await this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
}
|
||||
|
||||
createFolders(names: string[], relativePath: string = '/'): Promise<any> {
|
||||
return this.createContent({ folders: names }, relativePath);
|
||||
async createFolders(names: string[], relativePath: string = '/') {
|
||||
return await this.createContent({ folders: names }, relativePath);
|
||||
}
|
||||
|
||||
createFiles(names: string[], relativePath: string = '/'): Promise<any> {
|
||||
return this.createContent({ files: names }, relativePath);
|
||||
async createFiles(names: string[], relativePath: string = '/') {
|
||||
return await this.createContent({ files: names }, relativePath);
|
||||
}
|
||||
|
||||
// node content
|
||||
getNodeContent(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}/content`)
|
||||
.catch(this.handleError);
|
||||
async getNodeContent(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNodeContent(nodeId);
|
||||
}
|
||||
|
||||
editNodeContent(nodeId: string, content: string): Promise<any> {
|
||||
return this
|
||||
.put(`/nodes/${nodeId}/content`, { data: content })
|
||||
.catch(this.handleError);
|
||||
async editNodeContent(nodeId: string, content: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.updateNodeContent(nodeId, content);
|
||||
}
|
||||
|
||||
renameNode(nodeId: string, newName: string): Promise<any> {
|
||||
return this
|
||||
.put(`/nodes/${nodeId}`, { data: { name: newName } })
|
||||
.catch(this.handleError);
|
||||
async renameNode(nodeId: string, newName: string) {
|
||||
await this.apiAuth();
|
||||
return this.alfrescoJsApi.core.nodesApi.updateNode(nodeId, { name: newName });
|
||||
}
|
||||
|
||||
// node permissions
|
||||
setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string): Promise<any> {
|
||||
async setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string) {
|
||||
const data = {
|
||||
permissions: {
|
||||
isInheritanceEnabled: inheritPermissions,
|
||||
@@ -156,27 +154,26 @@ export class NodesApi extends RepoApi {
|
||||
}
|
||||
};
|
||||
|
||||
return this
|
||||
.put(`/nodes/${nodeId}`, { data })
|
||||
.catch(this.handleError);
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.updateNode(nodeId, data);
|
||||
}
|
||||
|
||||
getNodePermissions(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}?include=permissions`)
|
||||
.catch(this.handleError);
|
||||
async getNodePermissions(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNode(nodeId, { include: ['permissions'] });
|
||||
}
|
||||
|
||||
// lock node
|
||||
lockFile(nodeId: string, lockType: string = 'FULL') {
|
||||
return this
|
||||
.post(`/nodes/${nodeId}/lock?include=isLocked`, { data: { 'type': lockType } })
|
||||
.catch(this.handleError);
|
||||
async lockFile(nodeId: string, lockType: string = 'FULL') {
|
||||
const data = <NodeBodyLock>{
|
||||
type: lockType
|
||||
};
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.lockNode(nodeId, data );
|
||||
}
|
||||
|
||||
unlockFile(nodeId: string) {
|
||||
return this
|
||||
.post(`/nodes/${nodeId}/unlock`)
|
||||
.catch(this.handleError);
|
||||
async unlockFile(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.unlockNode(nodeId);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user