mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
- remove some awaits
- add try catch - small refactoring
This commit is contained in:
@@ -32,7 +32,11 @@ export class AuthenticationApi extends RepoApi {
|
||||
}
|
||||
|
||||
async logout() {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.logout();
|
||||
await this.alfrescoJsApi.logout();
|
||||
} catch (error) {
|
||||
console.log('--- authentication api logout catch error: ', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,23 +27,39 @@ import { RepoApi } from '../repo-api';
|
||||
import { CommentsApi as AdfCommentsApi } from '@alfresco/js-api';
|
||||
|
||||
export class CommentsApi extends RepoApi {
|
||||
commentsApi = new AdfCommentsApi(this.alfrescoJsApi);
|
||||
commentsApi = new AdfCommentsApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async getNodeComments(nodeId: string) {
|
||||
async getNodeComments(nodeId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.commentsApi.listComments(nodeId);
|
||||
} catch (error) {
|
||||
console.log('--- comments api getNodeComments catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async addComment(nodeId: string, comment: string) {
|
||||
async addComment(nodeId: string, comment: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.commentsApi.createComment(nodeId, { "content": comment });
|
||||
} catch (error) {
|
||||
console.log('--- comments api addComment catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
async addComments(nodeId: string, comment: any) {
|
||||
}
|
||||
|
||||
async addComments(nodeId: string, comment: any) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.commentsApi.createComment(nodeId, comment);
|
||||
} catch (error) {
|
||||
console.log('--- comments api addComments catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,119 +29,146 @@ import { Utils } from '../../../../utilities/utils';
|
||||
import { FavoritesApi as AdfFavoritesApi, SitesApi as AdfSiteApi, FavoriteEntry } from '@alfresco/js-api';
|
||||
|
||||
export class FavoritesApi extends RepoApi {
|
||||
favoritesApi = new AdfFavoritesApi(this.alfrescoJsApi);
|
||||
sitesApi = new AdfSiteApi(this.alfrescoJsApi);
|
||||
favoritesApi = new AdfFavoritesApi(this.alfrescoJsApi);
|
||||
sitesApi = new AdfSiteApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async addFavorite(api: RepoClient, nodeType: string, name: string) {
|
||||
const nodeId = (await api.nodes.getNodeByPath(name)).entry.id;
|
||||
const data = {
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: nodeId
|
||||
}
|
||||
}
|
||||
};
|
||||
return await this.favoritesApi.createFavorite('-me-', data);
|
||||
}
|
||||
|
||||
async addFavoriteById(nodeType: 'file' | 'folder' | 'site', id: string): Promise<FavoriteEntry|null> {
|
||||
let guid;
|
||||
await this.apiAuth();
|
||||
|
||||
if ( nodeType === 'site' ) {
|
||||
guid = (await this.sitesApi.getSite(id)).entry.guid;
|
||||
} else {
|
||||
guid = id;
|
||||
}
|
||||
const data = {
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: guid
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
return await this.favoritesApi.createFavorite('-me-', data);
|
||||
} catch (error) {
|
||||
console.log('--- add favorite by id catch ');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async addFavoritesByIds(nodeType: 'file' | 'folder' | 'site', ids: string[]) {
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
await this.addFavoriteById(nodeType, current);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
async getFavorites() {
|
||||
await this.apiAuth();
|
||||
return await this.favoritesApi.listFavorites(this.getUsername());
|
||||
}
|
||||
|
||||
async getFavoriteById(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.favoritesApi.getFavorite('-me-', nodeId);
|
||||
}
|
||||
|
||||
async isFavorite(nodeId: string) {
|
||||
return JSON.stringify((await this.getFavorites()).list.entries).includes(nodeId);
|
||||
}
|
||||
|
||||
async isFavoriteWithRetry(nodeId: string, data) {
|
||||
let isFavorite;
|
||||
try {
|
||||
const favorite = async () => {
|
||||
isFavorite = await this.isFavorite(nodeId);
|
||||
if ( isFavorite !== data.expect ) {
|
||||
return Promise.reject(isFavorite);
|
||||
} else {
|
||||
return Promise.resolve(isFavorite);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(favorite);
|
||||
} catch (error) {
|
||||
console.log('-----> catch isFavoriteWithRetry: ', error);
|
||||
}
|
||||
return isFavorite;
|
||||
}
|
||||
|
||||
async removeFavoriteById(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
try {
|
||||
return await this.favoritesApi.deleteFavorite('-me-', nodeId);
|
||||
} catch (error) {
|
||||
console.log('--- remove favorite by id catch ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async removeFavoritesByIds(ids: string[]) {
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
await this.removeFavoriteById(current);
|
||||
}, Promise.resolve());
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async waitForApi(data) {
|
||||
try {
|
||||
const favoriteFiles = async () => {
|
||||
const totalItems = (await this.getFavorites()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
async addFavorite(api: RepoClient, nodeType: string, name: string) {
|
||||
try {
|
||||
const nodeId = (await api.nodes.getNodeByPath(name)).entry.id;
|
||||
const data = {
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: nodeId
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(favoriteFiles);
|
||||
} catch (error) {
|
||||
console.log('-----> catch favorites: ', error);
|
||||
}
|
||||
};
|
||||
return await this.favoritesApi.createFavorite('-me-', data);
|
||||
} catch (error) {
|
||||
console.log('--- favorites api addFavorite catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async addFavoriteById(nodeType: 'file' | 'folder' | 'site', id: string): Promise<FavoriteEntry|null> {
|
||||
let guid;
|
||||
try {
|
||||
await this.apiAuth();
|
||||
if ( nodeType === 'site' ) {
|
||||
guid = (await this.sitesApi.getSite(id)).entry.guid;
|
||||
} else {
|
||||
guid = id;
|
||||
}
|
||||
const data = {
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: guid
|
||||
}
|
||||
}
|
||||
};
|
||||
return await this.favoritesApi.createFavorite('-me-', data);
|
||||
} catch (error) {
|
||||
console.log('--- favorites api addFavoriteById catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async addFavoritesByIds(nodeType: 'file' | 'folder' | 'site', ids: string[]) {
|
||||
try {
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
await this.addFavoriteById(nodeType, current);
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- favorites api addFavoritesByIds catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getFavorites() {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.favoritesApi.listFavorites(this.getUsername());
|
||||
} catch (error) {
|
||||
console.log('--- favorites api getFavorites catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getFavoriteById(nodeId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.favoritesApi.getFavorite('-me-', nodeId);
|
||||
} catch (error) {
|
||||
console.log('--- favorites api getFavoriteById catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async isFavorite(nodeId: string) {
|
||||
try {
|
||||
return JSON.stringify((await this.getFavorites()).list.entries).includes(nodeId);
|
||||
} catch (error) {
|
||||
console.log('--- favorites api isFavorite catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async isFavoriteWithRetry(nodeId: string, data) {
|
||||
let isFavorite;
|
||||
try {
|
||||
const favorite = async () => {
|
||||
isFavorite = await this.isFavorite(nodeId);
|
||||
if ( isFavorite !== data.expect ) {
|
||||
return Promise.reject(isFavorite);
|
||||
} else {
|
||||
return Promise.resolve(isFavorite);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(favorite);
|
||||
} catch (error) {
|
||||
console.log('--- favorites api isFavoriteWithRetry catch error: ', error);
|
||||
}
|
||||
return isFavorite;
|
||||
}
|
||||
|
||||
async removeFavoriteById(nodeId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.favoritesApi.deleteFavorite('-me-', nodeId);
|
||||
} catch (error) {
|
||||
console.log('--- favorites api removeFavoriteById catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async removeFavoritesByIds(ids: string[]) {
|
||||
try {
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
await this.removeFavoriteById(current);
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- favorites api removeFavoritesByIds catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async waitForApi(data: { expect: number }) {
|
||||
try {
|
||||
const favoriteFiles = async () => {
|
||||
const totalItems = (await this.getFavorites()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(favoriteFiles);
|
||||
} catch (error) {
|
||||
console.log('favorites api waitForApi catch error: ', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,269 +30,411 @@ import { NodesApi as AdfNodeApi, NodeBodyLock} from '@alfresco/js-api';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class NodesApi extends RepoApi {
|
||||
nodesApi = new AdfNodeApi(this.alfrescoJsApi);
|
||||
nodesApi = new AdfNodeApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async getNodeByPath(relativePath: string = '/') {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNode('-my-', { relativePath });
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getNodeByPath catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getNodeByPath(relativePath: string = '/') {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNode('-my-', { relativePath });
|
||||
async getNodeById(id: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNode(id);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getNodeById catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getNodeById(id: string) {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNode(id);
|
||||
}
|
||||
|
||||
async getNodeIdFromParent(name: string, parentId: string) {
|
||||
async getNodeIdFromParent(name: string, parentId: string) {
|
||||
try {
|
||||
const children = (await this.getNodeChildren(parentId)).list.entries;
|
||||
return children.find(elem => elem.entry.name === name).entry.id;
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getNodeIdFromParent catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getNodeDescription(name: string, parentId: string) {
|
||||
async getNodeDescription(name: string, parentId: string) {
|
||||
try {
|
||||
const children = (await this.getNodeChildren(parentId)).list.entries;
|
||||
return children.find(elem => elem.entry.name === name).entry.properties['cm:description'];
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getNodeDescription catch error: ', error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
async getNodeProperty(nodeId: string, property: string) {
|
||||
async getNodeProperty(nodeId: string, property: string) {
|
||||
try {
|
||||
const node = await this.getNodeById(nodeId);
|
||||
if (node.entry.properties) {
|
||||
return node.entry.properties[property];
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getNodeProperty catch error: ', error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
async getFileVersionType(nodeId: string) {
|
||||
async getFileVersionType(nodeId: string) {
|
||||
try {
|
||||
const prop = await this.getNodeProperty(nodeId, 'cm:versionType');
|
||||
if ( prop ) {
|
||||
return prop;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getFileVersionType catch error: ', error);
|
||||
return '';
|
||||
}
|
||||
async getFileVersionLabel(nodeId: string) {
|
||||
}
|
||||
|
||||
async getFileVersionLabel(nodeId: string) {
|
||||
try {
|
||||
const prop = await this.getNodeProperty(nodeId, 'cm:versionLabel');
|
||||
if ( prop ) {
|
||||
return prop;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getFileVersionLabel catch error: ', error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async getSharedId(nodeId: string) {
|
||||
async getSharedId(nodeId: string) {
|
||||
try {
|
||||
return await this.getNodeProperty(nodeId, 'qshare:sharedId');
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getSharedId catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getSharedExpiryDate(nodeId: string) {
|
||||
async getSharedExpiryDate(nodeId: string) {
|
||||
try {
|
||||
return await this.getNodeProperty(nodeId, 'qshare:expiryDate');
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getSharedExpiryDate catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async isFileShared(nodeId: string) {
|
||||
async isFileShared(nodeId: string) {
|
||||
try {
|
||||
return (await this.getSharedId(nodeId)) !== '';
|
||||
} catch (error) {
|
||||
console.log('--- nodes api isFileShared catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async deleteNodeById(id: string, permanent: boolean = true) {
|
||||
await this.apiAuth();
|
||||
try {
|
||||
return await this.nodesApi.deleteNode(id, { permanent });
|
||||
} catch (error) {
|
||||
console.log('------ deleteNodeById failed ');
|
||||
}
|
||||
async deleteNodeById(id: string, permanent: boolean = true) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.deleteNode(id, { permanent });
|
||||
} catch (error) {
|
||||
console.log('--- nodes api deleteNodeById catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteNodeByPath(path: string, permanent: boolean = true) {
|
||||
const id = (await this.getNodeByPath(path)).entry.id;
|
||||
return await this.deleteNodeById(id, permanent);
|
||||
async deleteNodeByPath(path: string, permanent: boolean = true) {
|
||||
try {
|
||||
const id = (await this.getNodeByPath(path)).entry.id;
|
||||
return await this.deleteNodeById(id, permanent);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api deleteNodeByPath catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
async deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true) {
|
||||
try {
|
||||
return await names.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
const req = await this.deleteNodeByPath(`${relativePath}/${current}`, permanent);
|
||||
return req;
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- nodes api deleteNodes catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteNodesById(ids: string[], permanent: boolean = true) {
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteNodeById(current, permanent);
|
||||
}, Promise.resolve());
|
||||
async deleteNodesById(ids: string[], permanent: boolean = true) {
|
||||
try {
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
const req = await this.deleteNodeById(current, permanent);
|
||||
return req;
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- nodes api deleteNodesById catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getNodeChildren(nodeId: string) {
|
||||
const opts = {
|
||||
include: [ 'properties' ]
|
||||
};
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.listNodeChildren(nodeId, opts);
|
||||
async getNodeChildren(nodeId: string) {
|
||||
try {
|
||||
const opts = {
|
||||
include: [ 'properties' ]
|
||||
};
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.listNodeChildren(nodeId, opts);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getNodeChildren catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async deleteNodeChildren(parentId: string) {
|
||||
async deleteNodeChildren(parentId: string) {
|
||||
try {
|
||||
const listEntries = (await this.getNodeChildren(parentId)).list.entries;
|
||||
const nodeIds = listEntries.map(entries => entries.entry.id);
|
||||
return await this.deleteNodesById(nodeIds);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api deleteNodeChildren catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async createImageNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
const imageProps = {
|
||||
'exif:pixelXDimension': 1000,
|
||||
'exif:pixelYDimension': 1200
|
||||
};
|
||||
async createImageNode(name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
const imageProps = {
|
||||
'exif:pixelXDimension': 1000,
|
||||
'exif:pixelYDimension': 1200
|
||||
};
|
||||
try {
|
||||
return await this.createNode('cm:content', name, parentId, title, description, imageProps);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api createImageNode catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = '', imageProps: any = null, author: string = '', majorVersion: boolean = true) {
|
||||
const nodeBody = {
|
||||
name,
|
||||
nodeType,
|
||||
properties: {
|
||||
'cm:title': title,
|
||||
'cm:description': description,
|
||||
'cm:author': author
|
||||
}
|
||||
};
|
||||
if (imageProps) {
|
||||
nodeBody.properties = Object.assign(nodeBody.properties, imageProps);
|
||||
async createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = '', imageProps: any = null, author: string = '', majorVersion: boolean = true) {
|
||||
const nodeBody = {
|
||||
name,
|
||||
nodeType,
|
||||
properties: {
|
||||
'cm:title': title,
|
||||
'cm:description': description,
|
||||
'cm:author': author
|
||||
}
|
||||
|
||||
await this.apiAuth();
|
||||
|
||||
try {
|
||||
return await this.nodesApi.createNode(parentId, nodeBody, { majorVersion });
|
||||
} catch (error) {
|
||||
console.log('===========> API create node catch ===========');
|
||||
}
|
||||
|
||||
};
|
||||
if (imageProps) {
|
||||
nodeBody.properties = Object.assign(nodeBody.properties, imageProps);
|
||||
}
|
||||
|
||||
async createFile(name: string, parentId: string = '-my-', title: string = '', description: string = '', author: string = '', majorVersion: boolean = true) {
|
||||
try {
|
||||
return await this.createNode('cm:content', name, parentId, title, description, null, author, majorVersion);
|
||||
} catch (error) {
|
||||
console.log('==== catch createFile: ', error);
|
||||
}
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.createNode(parentId, nodeBody, { majorVersion });
|
||||
} catch (error) {
|
||||
console.log('--- nodes api createNode catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async createImage(name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
return await this.createImageNode('cm:content', name, parentId, title, description);
|
||||
async createFile(name: string, parentId: string = '-my-', title: string = '', description: string = '', author: string = '', majorVersion: boolean = true) {
|
||||
try {
|
||||
return await this.createNode('cm:content', name, parentId, title, description, null, author, majorVersion);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api createFile catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = '', author: string = '') {
|
||||
try {
|
||||
return await this.createNode('cm:folder', name, parentId, title, description, null, author);
|
||||
} catch (error) {
|
||||
console.log('======> API create folder catch ==========');
|
||||
}
|
||||
async createImage(name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
try {
|
||||
return await this.createImageNode(name, parentId, title, description);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api createImage catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async createChildren(data: NodeBodyCreate[]) {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.createNode('-my-', <any>data);
|
||||
async createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = '', author: string = '') {
|
||||
try {
|
||||
return await this.createNode('cm:folder', name, parentId, title, description, null, author);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api createFolder catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async createContent(content: NodeContentTree, relativePath: string = '/') {
|
||||
return await this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
async createChildren(data: NodeBodyCreate[]) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.createNode('-my-', <any>data);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api createChildren catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async createFolders(names: string[], relativePath: string = '/') {
|
||||
return await this.createContent({ folders: names }, relativePath);
|
||||
async createContent(content: NodeContentTree, relativePath: string = '/') {
|
||||
try {
|
||||
return await this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
} catch (error) {
|
||||
console.log('--- nodes api createContent catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async createFiles(names: string[], relativePath: string = '/') {
|
||||
return await this.createContent({ files: names }, relativePath);
|
||||
async createFolders(names: string[], relativePath: string = '/') {
|
||||
try {
|
||||
return await this.createContent({ folders: names }, relativePath);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api createFolders catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
// node content
|
||||
async getNodeContent(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNodeContent(nodeId);
|
||||
async createFiles(names: string[], relativePath: string = '/') {
|
||||
try {
|
||||
return await this.createContent({ files: names }, relativePath);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api createFiles catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async editNodeContent(nodeId: string, content: string) {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.updateNodeContent(nodeId, content);
|
||||
// node content
|
||||
async getNodeContent(nodeId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNodeContent(nodeId);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getNodeContent catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async renameNode(nodeId: string, newName: string) {
|
||||
await this.apiAuth();
|
||||
return this.nodesApi.updateNode(nodeId, { name: newName });
|
||||
async editNodeContent(nodeId: string, content: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.updateNodeContent(nodeId, content);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api editNodeContent catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// node permissions
|
||||
async setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string) {
|
||||
const data = {
|
||||
permissions: {
|
||||
isInheritanceEnabled: inheritPermissions,
|
||||
locallySet: [
|
||||
{
|
||||
authorityId: username,
|
||||
name: role
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.updateNode(nodeId, data);
|
||||
async renameNode(nodeId: string, newName: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return this.nodesApi.updateNode(nodeId, { name: newName });
|
||||
} catch (error) {
|
||||
console.log('--- nodes api renameNode catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getNodePermissions(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNode(nodeId, { include: ['permissions'] });
|
||||
}
|
||||
|
||||
// lock node
|
||||
async lockFile(nodeId: string, lockType: string = 'ALLOW_OWNER_CHANGES') {
|
||||
const data = <NodeBodyLock>{
|
||||
type: lockType
|
||||
};
|
||||
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.lockNode(nodeId, data );
|
||||
}
|
||||
|
||||
async unlockFile(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.unlockNode(nodeId);
|
||||
}
|
||||
|
||||
async getLockType(nodeId: string) {
|
||||
return await this.getNodeProperty(nodeId, 'cm:lockType');
|
||||
}
|
||||
|
||||
async getLockOwner(nodeId: string) {
|
||||
return await this.getNodeProperty(nodeId, 'cm:lockOwner');
|
||||
}
|
||||
|
||||
async isFileLockedWrite(nodeId: string) {
|
||||
return (await this.getLockType(nodeId)) === 'WRITE_LOCK';
|
||||
}
|
||||
|
||||
async isFileLockedWriteWithRetry(nodeId: string, expect: boolean) {
|
||||
const data = {
|
||||
expect: expect,
|
||||
retry: 5
|
||||
};
|
||||
let isLocked;
|
||||
try {
|
||||
const locked = async () => {
|
||||
isLocked = (await this.getLockType(nodeId)) === 'WRITE_LOCK';
|
||||
if ( isLocked !== data.expect ) {
|
||||
return Promise.reject(isLocked);
|
||||
} else {
|
||||
return Promise.resolve(isLocked);
|
||||
// node permissions
|
||||
async setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string) {
|
||||
const data = {
|
||||
permissions: {
|
||||
isInheritanceEnabled: inheritPermissions,
|
||||
locallySet: [
|
||||
{
|
||||
authorityId: username,
|
||||
name: role
|
||||
}
|
||||
}
|
||||
return await Utils.retryCall(locked, data.retry);
|
||||
} catch (error) {
|
||||
console.log('-----> catch isLockedWriteWithRetry: ', error);
|
||||
]
|
||||
}
|
||||
return isLocked;
|
||||
}
|
||||
};
|
||||
|
||||
async isFileLockedByName(fileName: string, parentId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.updateNode(nodeId, data);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api setGranularPermission catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getNodePermissions(nodeId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNode(nodeId, { include: ['permissions'] });
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getNodePermissions catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// lock node
|
||||
async lockFile(nodeId: string, lockType: string = 'ALLOW_OWNER_CHANGES') {
|
||||
const data = <NodeBodyLock>{
|
||||
type: lockType
|
||||
};
|
||||
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.lockNode(nodeId, data );
|
||||
} catch (error) {
|
||||
console.log('--- nodes api lockFile catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async unlockFile(nodeId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.unlockNode(nodeId);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api unlockFile catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getLockType(nodeId: string) {
|
||||
try {
|
||||
return await this.getNodeProperty(nodeId, 'cm:lockType');
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getLockType catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getLockOwner(nodeId: string) {
|
||||
try {
|
||||
return await this.getNodeProperty(nodeId, 'cm:lockOwner');
|
||||
} catch (error) {
|
||||
console.log('--- nodes api getLockOwner catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async isFileLockedWrite(nodeId: string) {
|
||||
try {
|
||||
return (await this.getLockType(nodeId)) === 'WRITE_LOCK';
|
||||
} catch (error) {
|
||||
console.log('--- nodes api isFileLockedWrite catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async isFileLockedWriteWithRetry(nodeId: string, expect: boolean) {
|
||||
const data = {
|
||||
expect: expect,
|
||||
retry: 5
|
||||
};
|
||||
let isLocked;
|
||||
try {
|
||||
const locked = async () => {
|
||||
isLocked = (await this.getLockType(nodeId)) === 'WRITE_LOCK';
|
||||
if ( isLocked !== data.expect ) {
|
||||
return Promise.reject(isLocked);
|
||||
} else {
|
||||
return Promise.resolve(isLocked);
|
||||
}
|
||||
}
|
||||
return await Utils.retryCall(locked, data.retry);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api isFileLockedWriteWithRetry catch error: ', error);
|
||||
}
|
||||
return isLocked;
|
||||
}
|
||||
|
||||
async isFileLockedByName(fileName: string, parentId: string) {
|
||||
try {
|
||||
const id = await this.getNodeIdFromParent(fileName, parentId);
|
||||
return await this.isFileLockedWrite(id);
|
||||
} catch (error) {
|
||||
console.log('--- nodes api isFileLockedByName catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,33 +28,58 @@ import { RepoApi } from '../repo-api';
|
||||
import { PeopleApi as AdfPeopleApi} from '@alfresco/js-api';
|
||||
|
||||
export class PeopleApi extends RepoApi {
|
||||
peopleApi = new AdfPeopleApi(this.alfrescoJsApi);
|
||||
peopleApi = new AdfPeopleApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async createUser(user: PersonModel) {
|
||||
const person = new Person(user);
|
||||
await this.apiAuth();
|
||||
return await this.peopleApi.createPerson(person);
|
||||
async createUser(user: PersonModel) {
|
||||
try {
|
||||
const person = new Person(user);
|
||||
await this.apiAuth();
|
||||
return await this.peopleApi.createPerson(person);
|
||||
} catch (error) {
|
||||
console.log('--- people api createUser catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getUser(username: string) {
|
||||
await this.apiAuth();
|
||||
return await this.peopleApi.getPerson(username);
|
||||
async getUser(username: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.peopleApi.getPerson(username);
|
||||
} catch (error) {
|
||||
console.log('--- people api getUser catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async updateUser(username: string, userDetails?: PersonModel) {
|
||||
await this.apiAuth();
|
||||
return this.peopleApi.updatePerson(username, userDetails);
|
||||
async updateUser(username: string, userDetails?: PersonModel) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return this.peopleApi.updatePerson(username, userDetails);
|
||||
} catch (error) {
|
||||
console.log('--- people api updateUser catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async disableUser(username: string) {
|
||||
return await this.updateUser(username, { enabled: false });
|
||||
async disableUser(username: string) {
|
||||
try {
|
||||
return await this.updateUser(username, { enabled: false });
|
||||
} catch (error) {
|
||||
console.log('--- people api disableUser catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async changePassword(username: string, newPassword: string) {
|
||||
return await this.updateUser(username, { password: newPassword });
|
||||
async changePassword(username: string, newPassword: string) {
|
||||
try {
|
||||
return await this.updateUser(username, { password: newPassword });
|
||||
} catch (error) {
|
||||
console.log('--- people api changePassword catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ export class QueriesApi extends RepoApi {
|
||||
queriesApi = new AdfQueriesApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?: string, password?: string) {
|
||||
super(username, password);
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async findSites(searchTerm: string) {
|
||||
@@ -40,18 +40,28 @@ export class QueriesApi extends RepoApi {
|
||||
fields: ['title']
|
||||
};
|
||||
|
||||
await this.apiAuth();
|
||||
return this.queriesApi.findSites(searchTerm, data);
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return this.queriesApi.findSites(searchTerm, data);
|
||||
} catch (error) {
|
||||
console.log('--- queries api findSites catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async findNodes(searchTerm: string) {
|
||||
const data = {
|
||||
term: searchTerm,
|
||||
fields: ['name']
|
||||
term: searchTerm,
|
||||
fields: ['name']
|
||||
};
|
||||
|
||||
await this.apiAuth();
|
||||
return this.queriesApi.findNodes(searchTerm, data);
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return this.queriesApi.findNodes(searchTerm, data);
|
||||
} catch (error) {
|
||||
console.log('--- queries api findNodes catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async waitForSites(searchTerm: string, data: any) {
|
||||
@@ -67,7 +77,7 @@ export class QueriesApi extends RepoApi {
|
||||
|
||||
return await Utils.retryCall(sites);
|
||||
} catch (error) {
|
||||
console.log('-----> catch queries findSites: ', error);
|
||||
console.log('--- queries api waitForSites catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +94,7 @@ export class QueriesApi extends RepoApi {
|
||||
|
||||
return await Utils.retryCall(nodes);
|
||||
} catch (error) {
|
||||
console.log('-----> catch queries findFilesAndFolders: ', error);
|
||||
console.log('--- queries api waitForFilesAndFolders catch error: ', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,90 +28,105 @@ import { Utils } from '../../../../utilities/utils';
|
||||
import { SearchApi as AdfSearchApi } from '@alfresco/js-api';
|
||||
|
||||
export class SearchApi extends RepoApi {
|
||||
searchApi = new AdfSearchApi(this.alfrescoJsApi);
|
||||
searchApi = new AdfSearchApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async queryRecentFiles(username: string) {
|
||||
const data = {
|
||||
query: {
|
||||
query: '*',
|
||||
language: 'afts'
|
||||
},
|
||||
filterQueries: [
|
||||
{ query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` },
|
||||
{ query: `cm:modifier:${username} OR cm:creator:${username}` },
|
||||
{ query: `TYPE:"content" AND -TYPE:"app:filelink" AND -TYPE:"fm:post"` }
|
||||
]
|
||||
};
|
||||
|
||||
await this.apiAuth();
|
||||
return this.searchApi.search(data);
|
||||
}
|
||||
|
||||
async queryNodesNames(searchTerm: string) {
|
||||
const data = {
|
||||
async queryRecentFiles(username: string) {
|
||||
const data = {
|
||||
query: {
|
||||
query: `cm:name:\"${searchTerm}*\"`,
|
||||
language: 'afts'
|
||||
query: '*',
|
||||
language: 'afts'
|
||||
},
|
||||
filterQueries: [
|
||||
{ query: `+TYPE:'cm:folder' OR +TYPE:'cm:content'`}
|
||||
{ query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` },
|
||||
{ query: `cm:modifier:${username} OR cm:creator:${username}` },
|
||||
{ query: `TYPE:"content" AND -TYPE:"app:filelink" AND -TYPE:"fm:post"` }
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return this.searchApi.search(data);
|
||||
} catch (error) {
|
||||
console.log('--- search api queryRecentFiles catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async queryNodesExactNames(searchTerm: string) {
|
||||
const data = {
|
||||
query: {
|
||||
query: `cm:name:\"${searchTerm}\"`,
|
||||
language: 'afts'
|
||||
},
|
||||
filterQueries: [
|
||||
{ query: `+TYPE:'cm:folder' OR +TYPE:'cm:content'`}
|
||||
]
|
||||
};
|
||||
async queryNodesNames(searchTerm: string) {
|
||||
const data = {
|
||||
query: {
|
||||
query: `cm:name:\"${searchTerm}*\"`,
|
||||
language: 'afts'
|
||||
},
|
||||
filterQueries: [
|
||||
{ query: `+TYPE:'cm:folder' OR +TYPE:'cm:content'`}
|
||||
]
|
||||
};
|
||||
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return this.searchApi.search(data);
|
||||
} catch (error) {
|
||||
console.log('--- search api queryNodesNames catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async waitForApi(username, data) {
|
||||
try {
|
||||
const recentFiles = async () => {
|
||||
const totalItems = (await this.queryRecentFiles(username)).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
async queryNodesExactNames(searchTerm: string) {
|
||||
const data = {
|
||||
query: {
|
||||
query: `cm:name:\"${searchTerm}\"`,
|
||||
language: 'afts'
|
||||
},
|
||||
filterQueries: [
|
||||
{ query: `+TYPE:'cm:folder' OR +TYPE:'cm:content'`}
|
||||
]
|
||||
};
|
||||
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return this.searchApi.search(data);
|
||||
} catch (error) {
|
||||
console.log('--- search api queryNodesExactNames catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async waitForApi(username, data) {
|
||||
try {
|
||||
const recentFiles = async () => {
|
||||
const totalItems = (await this.queryRecentFiles(username)).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(recentFiles);
|
||||
} catch (error) {
|
||||
console.log('-----> catch search: ', error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('--- search api waitForApi catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async waitForNodes(searchTerm: string, data) {
|
||||
try {
|
||||
const nodes = async () => {
|
||||
const totalItems = (await this.queryNodesNames(searchTerm)).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
async waitForNodes(searchTerm: string, data) {
|
||||
try {
|
||||
const nodes = async () => {
|
||||
const totalItems = (await this.queryNodesNames(searchTerm)).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(nodes);
|
||||
} catch (error) {
|
||||
console.log('-----> catch search nodes: ', error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('--- search api waitForNodes catch error: ', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,63 +28,81 @@ import { Utils } from '../../../../utilities/utils';
|
||||
import { SharedlinksApi as AdfSharedlinksApi, SharedLinkEntry } from '@alfresco/js-api';
|
||||
|
||||
export class SharedLinksApi extends RepoApi {
|
||||
sharedlinksApi = new AdfSharedlinksApi(this.alfrescoJsApi);
|
||||
sharedlinksApi = new AdfSharedlinksApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async shareFileById(id: string, expireDate?: Date): Promise<SharedLinkEntry|null> {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
const data = {
|
||||
nodeId: id,
|
||||
expiresAt: expireDate
|
||||
};
|
||||
async shareFileById(id: string, expireDate?: Date): Promise<SharedLinkEntry|null> {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
const data = {
|
||||
nodeId: id,
|
||||
expiresAt: expireDate
|
||||
};
|
||||
return await this.sharedlinksApi.createSharedLink(data);
|
||||
} catch (error) {
|
||||
console.log('---- shareFileById error: ', error);
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('---- shareFileById error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async shareFilesByIds(ids: string[]) {
|
||||
return await ids.reduce(async (previous: any, current: any) => {
|
||||
await previous;
|
||||
return await this.shareFileById(current);
|
||||
}, Promise.resolve());
|
||||
async shareFilesByIds(ids: string[]) {
|
||||
try {
|
||||
return await ids.reduce(async (previous: any, current: any) => {
|
||||
await previous;
|
||||
return await this.shareFileById(current);
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- shared links api shareFilesByIds catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getSharedIdOfNode(name: string) {
|
||||
const sharedLinks = (await this.getSharedLinks()).list.entries;
|
||||
const found = sharedLinks.find(sharedLink => sharedLink.entry.name === name);
|
||||
return (found || { entry: { id: null } }).entry.id;
|
||||
async getSharedIdOfNode(name: string) {
|
||||
try {
|
||||
const sharedLinks = (await this.getSharedLinks()).list.entries;
|
||||
const found = sharedLinks.find(sharedLink => sharedLink.entry.name === name);
|
||||
return (found || { entry: { id: null } }).entry.id;
|
||||
} catch (error) {
|
||||
console.log('--- shared links api getSharedIdOfNode catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async unshareFile(name: string) {
|
||||
const id = await this.getSharedIdOfNode(name);
|
||||
return await this.sharedlinksApi.deleteSharedLink(id);
|
||||
async unshareFile(name: string) {
|
||||
try {
|
||||
const id = await this.getSharedIdOfNode(name);
|
||||
return await this.sharedlinksApi.deleteSharedLink(id);
|
||||
} catch (error) {
|
||||
console.log('--- shared links api unshareFile catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getSharedLinks() {
|
||||
await this.apiAuth();
|
||||
return await this.sharedlinksApi.listSharedLinks();
|
||||
async getSharedLinks() {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sharedlinksApi.listSharedLinks();
|
||||
} catch (error) {
|
||||
console.log('--- shared links api getSharedLinks catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async waitForApi(data) {
|
||||
try {
|
||||
const sharedFiles = async () => {
|
||||
const totalItems = (await this.getSharedLinks()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect ) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
async waitForApi(data: { expect: number }) {
|
||||
try {
|
||||
const sharedFiles = async () => {
|
||||
const totalItems = (await this.getSharedLinks()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect ) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(sharedFiles);
|
||||
} catch (error) {
|
||||
console.log('-----> catch shared: ', error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('--- shared links api waitForApi catch error: ', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,144 +30,210 @@ import { Utils } from '../../../../utilities/utils';
|
||||
import { SitesApi as AdfSiteApi } from '@alfresco/js-api';
|
||||
|
||||
export class SitesApi extends RepoApi {
|
||||
sitesApi = new AdfSiteApi(this.alfrescoJsApi);
|
||||
sitesApi = new AdfSiteApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async getSite(siteId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.getSite(siteId);
|
||||
} catch (error) {
|
||||
console.log('--- sites api getSite catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getSite(siteId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.getSite(siteId);
|
||||
async getSites() {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.listSiteMembershipsForPerson(this.getUsername());
|
||||
} catch (error) {
|
||||
console.log('--- sites api getSites catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getSites() {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.listSiteMembershipsForPerson(this.getUsername());
|
||||
async getDocLibId(siteId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return (await this.sitesApi.listSiteContainers(siteId)).list.entries[0].entry.id;
|
||||
} catch (error) {
|
||||
console.log('--- sites api getDocLibId catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getDocLibId(siteId: string) {
|
||||
await this.apiAuth();
|
||||
return (await this.sitesApi.listSiteContainers(siteId)).list.entries[0].entry.id;
|
||||
async getVisibility(siteId: string) {
|
||||
try {
|
||||
const site = await this.getSite(siteId);
|
||||
return site.entry.visibility;
|
||||
} catch (error) {
|
||||
console.log('--- sites api getVisibility catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getVisibility(siteId: string) {
|
||||
const site = await this.getSite(siteId);
|
||||
return site.entry.visibility;
|
||||
}
|
||||
|
||||
async getDescription(siteId: string) {
|
||||
async getDescription(siteId: string) {
|
||||
try {
|
||||
const site = await this.getSite(siteId);
|
||||
return site.entry.description;
|
||||
} catch (error) {
|
||||
console.log('--- sites api getDescription catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getTitle(siteId: string) {
|
||||
async getTitle(siteId: string) {
|
||||
try {
|
||||
const site = await this.getSite(siteId);
|
||||
return site.entry.title;
|
||||
} catch (error) {
|
||||
console.log('--- sites api getTitle catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async createSite(title: string, visibility?: string, description?: string, siteId?: string): Promise<SiteEntry|null> {
|
||||
const site = <SiteBody>{
|
||||
title,
|
||||
visibility: visibility || SITE_VISIBILITY.PUBLIC,
|
||||
description: description,
|
||||
id: siteId || title
|
||||
};
|
||||
async createSite(title: string, visibility?: string, description?: string, siteId?: string): Promise<SiteEntry|null> {
|
||||
const site = <SiteBody>{
|
||||
title,
|
||||
visibility: visibility || SITE_VISIBILITY.PUBLIC,
|
||||
description: description,
|
||||
id: siteId || title
|
||||
};
|
||||
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.createSite(site);
|
||||
} catch (error) {
|
||||
console.log('=== create site catch: ', error);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.createSite(site);
|
||||
} catch (error) {
|
||||
console.log('--- sites api createSite catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async createSites(titles: string[], visibility?: string) {
|
||||
return titles.reduce(async (previous: any, current: any) => {
|
||||
await previous;
|
||||
return await this.createSite(current, visibility);
|
||||
}, Promise.resolve());
|
||||
async createSites(titles: string[], visibility?: string) {
|
||||
try {
|
||||
return titles.reduce(async (previous: any, current: any) => {
|
||||
await previous;
|
||||
return await this.createSite(current, visibility);
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- sites api createSites catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteSite(siteId: string, permanent: boolean = true) {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.deleteSite(siteId, { permanent });
|
||||
async deleteSite(siteId: string, permanent: boolean = true) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.deleteSite(siteId, { permanent });
|
||||
} catch (error) {
|
||||
console.log('--- sites api deleteSite catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteSites(siteIds: string[], permanent: boolean = true) {
|
||||
return siteIds.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteSite(current, permanent);
|
||||
}, Promise.resolve());
|
||||
async deleteSites(siteIds: string[], permanent: boolean = true) {
|
||||
try {
|
||||
return siteIds.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteSite(current, permanent);
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- sites api deleteSites catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteAllUserSites(permanent: boolean = true) {
|
||||
async deleteAllUserSites(permanent: boolean = true) {
|
||||
try {
|
||||
const siteIds = (await this.getSites()).list.entries.map(entries => entries.entry.id);
|
||||
|
||||
return await siteIds.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteSite(current, permanent);
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- sites api deleteAllUserSites catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async updateSiteMember(siteId: string, userId: string, role: string) {
|
||||
const siteRole = <SiteMemberRoleBody>{
|
||||
role: role
|
||||
};
|
||||
async updateSiteMember(siteId: string, userId: string, role: string) {
|
||||
const siteRole = <SiteMemberRoleBody>{
|
||||
role: role
|
||||
};
|
||||
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.updateSiteMembership(siteId, userId, siteRole);
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.updateSiteMembership(siteId, userId, siteRole);
|
||||
} catch (error) {
|
||||
console.log('--- sites api updateSiteMember catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async addSiteMember(siteId: string, userId: string, role: string) {
|
||||
const memberBody = <SiteMemberBody>{
|
||||
id: userId,
|
||||
role: role
|
||||
};
|
||||
async addSiteMember(siteId: string, userId: string, role: string) {
|
||||
const memberBody = <SiteMemberBody>{
|
||||
id: userId,
|
||||
role: role
|
||||
};
|
||||
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.createSiteMembership(siteId, memberBody);
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.createSiteMembership(siteId, memberBody);
|
||||
} catch (error) {
|
||||
console.log('--- sites api addSiteMember catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async deleteSiteMember(siteId: string, userId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.deleteSiteMembership(siteId, userId);
|
||||
async deleteSiteMember(siteId: string, userId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.deleteSiteMembership(siteId, userId);
|
||||
} catch (error) {
|
||||
console.log('--- sites api deleteSiteMember catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async requestToJoin(siteId: string): Promise<SiteMembershipRequestEntry|null> {
|
||||
const body = {
|
||||
id: siteId
|
||||
};
|
||||
await this.apiAuth();
|
||||
try {
|
||||
return await this.sitesApi.createSiteMembershipRequestForPerson('-me-', body);
|
||||
} catch (error) {
|
||||
console.log('====== requestToJoin catch ', error);
|
||||
return null;
|
||||
};
|
||||
}
|
||||
async requestToJoin(siteId: string): Promise<SiteMembershipRequestEntry|null> {
|
||||
const body = {
|
||||
id: siteId
|
||||
};
|
||||
|
||||
async hasMembershipRequest(siteId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.createSiteMembershipRequestForPerson('-me-', body);
|
||||
} catch (error) {
|
||||
console.log('--- sites api requestToJoin catch error: ', error);
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
async hasMembershipRequest(siteId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
const requests = (await this.sitesApi.getSiteMembershipRequests('-me-')).list.entries.map(e => e.entry.id);
|
||||
return requests.includes(siteId);
|
||||
} catch (error) {
|
||||
console.log('--- sites api hasMembershipRequest catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async waitForApi(data) {
|
||||
try {
|
||||
const sites = async () => {
|
||||
const totalItems = (await this.getSites()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect ) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(sites);
|
||||
} catch (error) {
|
||||
console.log('-----> catch sites: ', error);
|
||||
async waitForApi(data: { expect: number }) {
|
||||
try {
|
||||
const sites = async () => {
|
||||
const totalItems = (await this.getSites()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect ) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(sites);
|
||||
} catch (error) {
|
||||
console.log('sites api waitForApi catch error: ', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,53 +28,71 @@ import { Utils } from '../../../../utilities/utils';
|
||||
import { TrashcanApi as AdfTrashcanApi} from '@alfresco/js-api';
|
||||
|
||||
export class TrashcanApi extends RepoApi {
|
||||
trashcanApi = new AdfTrashcanApi(this.alfrescoJsApi);
|
||||
trashcanApi = new AdfTrashcanApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async permanentlyDelete(id: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.trashcanApi.deleteDeletedNode(id);
|
||||
} catch (error) {
|
||||
console.log('--- trashcan api permanentlyDelete catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async permanentlyDelete(id: string) {
|
||||
await this.apiAuth();
|
||||
return await this.trashcanApi.deleteDeletedNode(id);
|
||||
async restore(id: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.trashcanApi.restoreDeletedNode(id);
|
||||
} catch (error) {
|
||||
console.log('--- trashcan api restore catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async restore(id: string) {
|
||||
await this.apiAuth();
|
||||
return await this.trashcanApi.restoreDeletedNode(id);
|
||||
async getDeletedNodes() {
|
||||
const opts = {
|
||||
maxItems: 1000
|
||||
};
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.trashcanApi.listDeletedNodes(opts);
|
||||
} catch (error) {
|
||||
console.log('--- trashcan api getDeletedNodes catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getDeletedNodes() {
|
||||
const opts = {
|
||||
maxItems: 1000
|
||||
};
|
||||
await this.apiAuth();
|
||||
return await this.trashcanApi.listDeletedNodes(opts);
|
||||
async emptyTrash() {
|
||||
try {
|
||||
const ids = (await this.getDeletedNodes()).list.entries.map(entries => entries.entry.id);
|
||||
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.permanentlyDelete(current);
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- trashcan api emptyTrash catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async emptyTrash() {
|
||||
const ids = (await this.getDeletedNodes()).list.entries.map(entries => entries.entry.id);
|
||||
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.permanentlyDelete(current);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
async waitForApi(data) {
|
||||
try {
|
||||
const deletedFiles = async () => {
|
||||
const totalItems = (await this.getDeletedNodes()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(deletedFiles);
|
||||
} catch (error) {
|
||||
console.log('-----> catch trash: ', error);
|
||||
async waitForApi(data: { expect: number }) {
|
||||
try {
|
||||
const deletedFiles = async () => {
|
||||
const totalItems = (await this.getDeletedNodes()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(deletedFiles);
|
||||
} catch (error) {
|
||||
console.log('--- trashcan api waitForApi catch error: ', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,39 +30,40 @@ import { UploadApi as AdfUploadApi } from '@alfresco/js-api';
|
||||
const fs = require('fs');
|
||||
|
||||
export class UploadApi extends RepoApi {
|
||||
upload = new AdfUploadApi(this.alfrescoJsApi);
|
||||
upload = new AdfUploadApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async uploadFile(fileName: string, parentFolderId: string = '-my-') {
|
||||
const file = fs.createReadStream(`${E2E_ROOT_PATH}/resources/test-files/${fileName}`);
|
||||
const opts = {
|
||||
name: file.name,
|
||||
nodeType: 'cm:content'
|
||||
};
|
||||
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.upload.uploadFile(file, '', parentFolderId, null, opts);
|
||||
} catch (error) {
|
||||
console.log('--- upload api uploadFile catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async uploadFile(fileName: string, parentFolderId: string = '-my-') {
|
||||
const file = fs.createReadStream(`${E2E_ROOT_PATH}/resources/test-files/${fileName}`);
|
||||
const opts = {
|
||||
name: file.name,
|
||||
nodeType: 'cm:content'
|
||||
};
|
||||
async uploadFileWithRename(fileName: string, parentFolderId: string = '-my-', newName: string) {
|
||||
const file = fs.createReadStream(`${E2E_ROOT_PATH}/resources/test-files/${fileName}`);
|
||||
const opts = {
|
||||
name: newName,
|
||||
nodeType: 'cm:content'
|
||||
};
|
||||
|
||||
await this.apiAuth();
|
||||
return await this.upload.uploadFile(file, '', parentFolderId, null, opts);
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.upload.uploadFile(file, '', parentFolderId, null, opts);
|
||||
} catch (error) {
|
||||
console.log('--- upload api uploadFileWithRename catch error: ', error);
|
||||
}
|
||||
|
||||
async uploadFileWithRename(fileName: string, parentFolderId: string = '-my-', newName: string) {
|
||||
const file = fs.createReadStream(`${E2E_ROOT_PATH}/resources/test-files/${fileName}`);
|
||||
const opts = {
|
||||
name: newName,
|
||||
nodeType: 'cm:content'
|
||||
};
|
||||
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.upload.uploadFile(file, '', parentFolderId, null, opts);
|
||||
} catch (error) {
|
||||
console.log('=== catch upload file with rename: ', error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user