[ACA-3392] Create aca-testing-shared project to be reused in ADW (#1480)

* Move e2e framework to aca-shared/testing

* * Update e2e suites imports from @alfresco/aca-shared/testing
* Remove testing framework from 'e2e' directory

* Move e2e testing framework to `aca-testing-shared` project
This commit is contained in:
Roxana Diacenco
2020-06-04 23:40:07 +03:00
committed by GitHub
parent 33327bb505
commit 6e17405787
166 changed files with 2745 additions and 1128 deletions

View File

@@ -0,0 +1,41 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
export class AuthenticationApi extends RepoApi {
constructor(username?, password?) {
super(username, password);
}
async logout() {
try {
await this.apiAuth();
await this.alfrescoJsApi.logout();
} catch (error) {
this.handleError(`${this.constructor.name} ${this.logout.name}`, error);
}
}
}

View File

@@ -0,0 +1,74 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { CommentsApi as AdfCommentsApi } from '@alfresco/js-api';
export class CommentsApi extends RepoApi {
commentsApi = new AdfCommentsApi(this.alfrescoJsApi);
constructor(username?, password?) {
super(username, password);
}
async getNodeComments(nodeId: string) {
try {
await this.apiAuth();
return await this.commentsApi.listComments(nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeComments.name}`,
error
);
return null;
}
}
async addComment(nodeId: string, comment: string) {
try {
await this.apiAuth();
return await this.commentsApi.createComment(nodeId, { content: comment });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addComment.name}`,
error
);
return null;
}
}
async addComments(nodeId: string, comment: any) {
try {
await this.apiAuth();
return await this.commentsApi.createComment(nodeId, comment);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addComments.name}`,
error
);
return null;
}
}
}

View File

@@ -0,0 +1,208 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { Logger } from '@alfresco/adf-testing';
import { RepoClient } from './../../repo-client';
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);
constructor(username?, password?) {
super(username, password);
}
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 this.favoritesApi.createFavorite('-me-', data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addFavorite.name}`,
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) {
this.handleError(
`${this.constructor.name} ${this.addFavoriteById.name}`,
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) {
this.handleError(
`${this.constructor.name} ${this.addFavoritesByIds.name}`,
error
);
}
}
async getFavorites() {
try {
await this.apiAuth();
return await this.favoritesApi.listFavorites(this.getUsername());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getFavorites.name}`,
error
);
return null;
}
}
async getFavoriteById(nodeId: string) {
try {
await this.apiAuth();
return await this.favoritesApi.getFavorite('-me-', nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getFavoriteById.name}`,
error
);
return null;
}
}
async isFavorite(nodeId: string) {
try {
return JSON.stringify((await this.getFavorites()).list.entries).includes(
nodeId
);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.isFavorite.name}`,
error
);
return null;
}
}
async isFavoriteWithRetry(nodeId: string, data: { expect: boolean }) {
let isFavorite: boolean;
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) {
// this.handleError(`${this.constructor.name} ${this.isFavoriteWithRetry.name}`, error);
}
return isFavorite;
}
async removeFavoriteById(nodeId: string) {
try {
await this.apiAuth();
return await this.favoritesApi.deleteFavorite('-me-', nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.removeFavoriteById.name}`,
error
);
}
}
async removeFavoritesByIds(ids: string[]) {
try {
return await ids.reduce(async (previous, current) => {
await previous;
await this.removeFavoriteById(current);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.removeFavoritesByIds.name}`,
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) {
Logger.error(`${this.constructor.name} ${this.waitForApi.name} catch: `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}

View File

@@ -0,0 +1,40 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
export * from './authentication/authentication-api';
export * from './comments/comments-api';
export * from './favorites/favorites-api';
export * from './nodes/node-body-create';
export * from './nodes/node-content-tree';
export * from './nodes/nodes-api';
export * from './people/people-api-models';
export * from './people/people-api';
export * from './queries/queries-api';
export * from './search/search-api';
export * from './shared-links/shared-links-api';
export * from './sites/sites-api';
export * from './trashcan/trashcan-api';
export * from './upload/upload-api';
export * from './repo-api';

View File

@@ -0,0 +1,39 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
export const NODE_TYPE_FILE = 'cm:content';
export const NODE_TYPE_FOLDER = 'cm:folder';
export const NODE_TITLE = 'cm:title';
export const NODE_DESCRIPTION = 'cm:description';
export class NodeBodyCreate {
constructor(
public name: string,
public nodeType: string,
public relativePath: string = '/',
public aspectNames?: string[],
public properties?: any[]
) {}
}

View File

@@ -0,0 +1,103 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import {
NodeBodyCreate,
NODE_TYPE_FILE,
NODE_TYPE_FOLDER,
NODE_TITLE,
NODE_DESCRIPTION
} from './node-body-create';
export interface NodeContentTree {
name?: string;
files?: string[];
folders?: (string | NodeContentTree)[];
title?: string;
description?: string;
}
export function flattenNodeContentTree(
content: NodeContentTree,
relativePath: string = '/'
): NodeBodyCreate[] {
const { name, files, folders, title, description } = content;
const aspectNames: string[] = ['cm:versionable'];
let data: NodeBodyCreate[] = [];
let properties: any;
properties = {
[NODE_TITLE]: title,
[NODE_DESCRIPTION]: description
};
if (name) {
data = data.concat([
{
nodeType: NODE_TYPE_FOLDER,
name,
relativePath,
properties
}
]);
relativePath =
relativePath === '/' ? `/${name}` : `${relativePath}/${name}`;
}
if (folders) {
const foldersData: NodeBodyCreate[] = folders
.map(
(folder: string | NodeContentTree): NodeBodyCreate[] => {
const folderData: NodeContentTree =
typeof folder === 'string' ? { name: folder } : folder;
return flattenNodeContentTree(folderData, relativePath);
}
)
.reduce(
(nodesData: NodeBodyCreate[], folderData: NodeBodyCreate[]) =>
nodesData.concat(folderData),
[]
);
data = data.concat(foldersData);
}
if (files) {
const filesData: NodeBodyCreate[] = files.map(
(filename: string): NodeBodyCreate => ({
nodeType: NODE_TYPE_FILE,
name: filename,
relativePath,
aspectNames
})
);
data = data.concat(filesData);
}
return data;
}

View File

@@ -0,0 +1,784 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { NodeBodyCreate } from './node-body-create';
import { NodeContentTree, flattenNodeContentTree } from './node-content-tree';
import {
NodesApi as AdfNodeApi,
NodeBodyLock,
NodeEntry,
NodeChildAssociationPaging
} from '@alfresco/js-api';
import { Utils } from '../../../../utilities/utils';
export class NodesApi extends RepoApi {
nodesApi = new AdfNodeApi(this.alfrescoJsApi);
constructor(username?, password?) {
super(username, password);
}
async getNodeByPath(relativePath: string = '/'): Promise<NodeEntry | null> {
try {
await this.apiAuth();
return await this.nodesApi.getNode('-my-', { relativePath });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeByPath.name}`,
error
);
return null;
}
}
async getNodeById(id: string): Promise<NodeEntry | null> {
try {
await this.apiAuth();
const node = await this.nodesApi.getNode(id);
return node;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeById.name}`,
error
);
return null;
}
}
async getNodeIdFromParent(name: string, parentId: string): Promise<string> {
try {
const children = (await this.getNodeChildren(parentId)).list.entries;
return children.find(elem => elem.entry.name === name).entry.id || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeIdFromParent.name}`,
error
);
return '';
}
}
async getNodeDescription(name: string, parentId: string): Promise<string> {
try {
const children = (await this.getNodeChildren(parentId)).list.entries;
return (
children.find(elem => elem.entry.name === name).entry.properties[
'cm:description'
] || ''
);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeDescription.name}`,
error
);
return '';
}
}
async getNodeTitle(name: string, parentId: string): Promise<string> {
try {
const children = (await this.getNodeChildren(parentId)).list.entries;
return (
children.find(elem => elem.entry.name === name).entry.properties[
'cm:title'
] || ''
);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeTitle.name}`,
error
);
return '';
}
}
async getNodeProperty(nodeId: string, property: string): Promise<string> {
try {
const node = await this.getNodeById(nodeId);
return (node.entry.properties && node.entry.properties[property]) || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeProperty.name}`,
error
);
return '';
}
}
async getFileVersionType(nodeId: string): Promise<string> {
try {
const prop = await this.getNodeProperty(nodeId, 'cm:versionType');
return prop || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getFileVersionType.name}`,
error
);
return '';
}
}
async getFileVersionLabel(nodeId: string): Promise<string> {
try {
const prop = await this.getNodeProperty(nodeId, 'cm:versionLabel');
return prop || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getFileVersionLabel.name}`,
error
);
return '';
}
}
async getSharedId(nodeId: string): Promise<string> {
try {
const sharedId = await this.getNodeProperty(nodeId, 'qshare:sharedId');
return sharedId || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getSharedId.name}`,
error
);
return '';
}
}
async getSharedExpiryDate(nodeId: string): Promise<string> {
try {
const expiryDate = await this.getNodeProperty(
nodeId,
'qshare:expiryDate'
);
return expiryDate || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getSharedExpiryDate.name}`,
error
);
return '';
}
}
async isFileShared(nodeId: string): Promise<boolean> {
try {
const sharedId = await this.getSharedId(nodeId);
return sharedId !== '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.isFileShared.name}`,
error
);
return null;
}
}
async deleteNodeById(id: string, permanent: boolean = true): Promise<void> {
try {
await this.apiAuth();
await this.nodesApi.deleteNode(id, { permanent });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodeById.name}`,
error
);
}
}
async deleteNodeByPath(
path: string,
permanent: boolean = true
): Promise<void> {
try {
const id = (await this.getNodeByPath(path)).entry.id;
await this.deleteNodeById(id, permanent);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodeByPath.name}`,
error
);
}
}
async deleteNodes(
names: string[],
relativePath: string = '',
permanent: boolean = true
): Promise<void> {
try {
await names.reduce(async (previous, current) => {
await previous;
const req = await this.deleteNodeByPath(
`${relativePath}/${current}`,
permanent
);
return req;
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodes.name}`,
error
);
}
}
async deleteNodesById(
ids: string[],
permanent: boolean = true
): Promise<void> {
try {
for (const id of ids) {
await this.deleteNodeById(id, permanent);
}
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodesById.name}`,
error
);
}
}
async getNodeChildren(
nodeId: string
): Promise<NodeChildAssociationPaging | null> {
try {
const opts = {
include: ['properties']
};
await this.apiAuth();
return await this.nodesApi.listNodeChildren(nodeId, opts);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeChildren.name}`,
error
);
return null;
}
}
async deleteNodeChildren(
parentId: string,
exceptNodesNamed?: string[]
): Promise<void> {
try {
const listEntries = (await this.getNodeChildren(parentId)).list.entries;
let nodeIds: string[];
if (exceptNodesNamed) {
nodeIds = listEntries
.filter(entries => !exceptNodesNamed.includes(entries.entry.name))
.map(entries => entries.entry.id);
} else {
nodeIds = listEntries.map(entries => entries.entry.id);
}
await this.deleteNodesById(nodeIds);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteNodeChildren.name}`,
error
);
}
}
async createImageNode(
name: string,
parentId: string = '-my-',
title: string = '',
description: string = ''
): Promise<NodeEntry | null> {
const imageProps = {
'exif:pixelXDimension': 1000,
'exif:pixelYDimension': 1200
};
try {
return await this.createNode(
'cm:content',
name,
parentId,
title,
description,
imageProps
);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createImageNode.name}`,
error
);
return null;
}
}
async createNode(
nodeType: string,
name: string,
parentId: string = '-my-',
title: string = '',
description: string = '',
imageProps: any = null,
author: string = '',
majorVersion: boolean = true,
aspectNames: string[] = null
): Promise<NodeEntry | null> {
if (!aspectNames) {
aspectNames = ['cm:versionable']; // workaround for REPO-4772
}
const nodeBody = {
name,
nodeType,
properties: {
'cm:title': title,
'cm:description': description,
'cm:author': author
},
aspectNames
};
if (imageProps) {
nodeBody.properties = Object.assign(nodeBody.properties, imageProps);
}
try {
await this.apiAuth();
return await this.nodesApi.createNode(parentId, nodeBody, {
majorVersion
});
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createNode.name}`,
error
);
return null;
}
}
async createFile(
name: string,
parentId: string = '-my-',
title: string = '',
description: string = '',
author: string = '',
majorVersion: boolean = true,
aspectNames: string[] = null
): Promise<NodeEntry> {
try {
return await this.createNode(
'cm:content',
name,
parentId,
title,
description,
null,
author,
majorVersion,
aspectNames
);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFile.name}`,
error
);
return null;
}
}
async createImage(
name: string,
parentId: string = '-my-',
title: string = '',
description: string = ''
): Promise<NodeEntry | null> {
try {
return await this.createImageNode(name, parentId, title, description);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createImage.name}`,
error
);
return null;
}
}
async createFolder(
name: string,
parentId: string = '-my-',
title: string = '',
description: string = '',
author: string = '',
aspectNames: string[] = null
): Promise<NodeEntry | null> {
try {
return await this.createNode(
'cm:folder',
name,
parentId,
title,
description,
null,
author,
null,
aspectNames
);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFolder.name}`,
error
);
return null;
}
}
async createChildren(data: NodeBodyCreate[]): Promise<NodeEntry | any> {
try {
await this.apiAuth();
return await this.nodesApi.createNode('-my-', data as any);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createChildren.name}`,
error
);
}
}
async createContent(
content: NodeContentTree,
relativePath: string = '/'
): Promise<NodeEntry | any> {
try {
return await this.createChildren(
flattenNodeContentTree(content, relativePath)
);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createContent.name}`,
error
);
}
}
async createFolders(
names: string[],
relativePath: string = '/'
): Promise<NodeEntry | any> {
try {
return await this.createContent({ folders: names }, relativePath);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFolders.name}`,
error
);
}
}
async createFiles(
names: string[],
relativePath: string = '/'
): Promise<NodeEntry | any> {
try {
return await this.createContent({ files: names }, relativePath);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFiles.name}`,
error
);
}
}
async addAspects(nodeId: string, aspectNames: string[]): Promise<NodeEntry> {
try {
await this.apiAuth();
return this.nodesApi.updateNode(nodeId, { aspectNames });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addAspects.name}`,
error
);
return null;
}
}
async createFileLink(
originalNodeId: string,
destinationId: string
): Promise<NodeEntry | null> {
const name = (await this.getNodeById(originalNodeId)).entry.name;
const nodeBody = {
name: `Link to ${name}.url`,
nodeType: 'app:filelink',
properties: {
'cm:destination': originalNodeId
}
};
try {
await this.apiAuth();
const link = await this.nodesApi.createNode(destinationId, nodeBody);
await this.addAspects(originalNodeId, ['app:linked']);
return link;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFileLink.name}`,
error
);
return null;
}
}
async createFolderLink(
originalNodeId: string,
destinationId: string
): Promise<NodeEntry | null> {
const name = (await this.getNodeById(originalNodeId)).entry.name;
const nodeBody = {
name: `Link to ${name}.url`,
nodeType: 'app:folderlink',
properties: {
'cm:title': `Link to ${name}.url`,
'cm:destination': originalNodeId,
'cm:description': `Link to ${name}.url`,
'app:icon': 'space-icon-link'
}
};
try {
await this.apiAuth();
const link = await this.nodesApi.createNode(destinationId, nodeBody);
await this.addAspects(originalNodeId, ['app:linked']);
return link;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createFolderLink.name}`,
error
);
return null;
}
}
// node content
async getNodeContent(nodeId: string): Promise<any> {
try {
await this.apiAuth();
return await this.nodesApi.getNodeContent(nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getNodeContent.name}`,
error
);
}
}
async editNodeContent(
nodeId: string,
content: string
): Promise<NodeEntry | null> {
try {
await this.apiAuth();
return await this.nodesApi.updateNodeContent(nodeId, content);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.editNodeContent.name}`,
error
);
return null;
}
}
async renameNode(nodeId: string, newName: string): Promise<NodeEntry | null> {
try {
await this.apiAuth();
return this.nodesApi.updateNode(nodeId, { name: newName });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.renameNode.name}`,
error
);
return null;
}
}
// node permissions
async setInheritPermissions(
nodeId: string,
inheritPermissions: boolean
): Promise<NodeEntry | null> {
const data = {
permissions: {
isInheritanceEnabled: inheritPermissions
}
};
try {
await this.apiAuth();
return await this.nodesApi.updateNode(nodeId, data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.setGranularPermission.name}`,
error
);
return null;
}
}
async setGranularPermission(
nodeId: string,
inheritPermissions: boolean = false,
username: string,
role: string
): Promise<NodeEntry | null> {
const data = {
permissions: {
isInheritanceEnabled: inheritPermissions,
locallySet: [
{
authorityId: username,
name: role
}
]
}
};
try {
await this.apiAuth();
return await this.nodesApi.updateNode(nodeId, data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.setGranularPermission.name}`,
error
);
return null;
}
}
// lock node
async lockFile(
nodeId: string,
lockType: string = 'ALLOW_OWNER_CHANGES'
): Promise<NodeEntry | null> {
const data = {
type: lockType
} as NodeBodyLock;
try {
await this.apiAuth();
return await this.nodesApi.lockNode(nodeId, data);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.lockFile.name}`, error);
return null;
}
}
async unlockFile(nodeId: string): Promise<NodeEntry | null> {
try {
await this.apiAuth();
return await this.nodesApi.unlockNode(nodeId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.unlockFile.name}`,
error
);
return null;
}
}
async getLockType(nodeId: string): Promise<string> {
try {
const lockType = await this.getNodeProperty(nodeId, 'cm:lockType');
return lockType || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getLockType.name}`,
error
);
return '';
}
}
async getLockOwner(nodeId: string): Promise<string> {
try {
const lockOwner = await this.getNodeProperty(nodeId, 'cm:lockOwner');
return lockOwner || '';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getLockOwner.name}`,
error
);
return '';
}
}
async isFileLockedWrite(nodeId: string): Promise<boolean> {
try {
return (await this.getLockType(nodeId)) === 'WRITE_LOCK';
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.isFileLockedWrite.name}`,
error
);
return null;
}
}
async isFileLockedWriteWithRetry(
nodeId: string,
expect: boolean
): Promise<boolean> {
const data = {
expect: expect,
retry: 5
};
let isLocked: boolean;
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) {
this.handleError(
`${this.constructor.name} ${this.isFileLockedWriteWithRetry.name}`,
error
);
}
return isLocked;
}
async isFileLockedByName(
fileName: string,
parentId: string
): Promise<boolean> {
try {
const id = await this.getNodeIdFromParent(fileName, parentId);
return await this.isFileLockedWrite(id);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.isFileLockedByName.name}`,
error
);
return null;
}
}
}

View File

@@ -0,0 +1,53 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
export interface PersonModel {
username?: string;
password?: string;
firstName?: string;
lastName?: string;
email?: string;
enabled?: boolean;
properties?: any;
}
export class Person {
id: string;
password: string;
firstName: string;
lastName: string;
email: string;
enabled: boolean;
properties: any;
constructor(user: PersonModel) {
this.id = user.username;
this.password = user.password || user.username;
this.firstName = user.firstName || user.username;
this.lastName = user.lastName || user.username;
this.email = user.email || `${user.username}@alfresco.com`;
this.enabled = user.enabled || true;
}
}

View File

@@ -0,0 +1,97 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { PersonModel, Person } from './people-api-models';
import { RepoApi } from '../repo-api';
import { PeopleApi as AdfPeopleApi } from '@alfresco/js-api';
export class PeopleApi extends RepoApi {
peopleApi = new AdfPeopleApi(this.alfrescoJsApi);
constructor(username?: string, password?: string) {
super(username, password);
}
async createUser(user: PersonModel) {
try {
const person = new Person(user);
await this.apiAuth();
return await this.peopleApi.createPerson(person);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createUser.name}`,
error
);
return null;
}
}
async getUser(username: string) {
try {
await this.apiAuth();
return await this.peopleApi.getPerson(username);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.getUser.name}`, error);
return null;
}
}
async updateUser(username: string, userDetails?: PersonModel) {
try {
await this.apiAuth();
return this.peopleApi.updatePerson(username, userDetails);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.updateUser.name}`,
error
);
return null;
}
}
async disableUser(username: string) {
try {
return await this.updateUser(username, { enabled: false });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.disableUser.name}`,
error
);
return null;
}
}
async changePassword(username: string, newPassword: string) {
try {
return await this.updateUser(username, { password: newPassword });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.changePassword.name}`,
error
);
return null;
}
}
}

View File

@@ -0,0 +1,115 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { Logger } from '@alfresco/adf-testing';
import { Utils } from '../../../../utilities/utils';
import { QueriesApi as AdfQueriesApi } from '@alfresco/js-api';
export class QueriesApi extends RepoApi {
queriesApi = new AdfQueriesApi(this.alfrescoJsApi);
constructor(username?: string, password?: string) {
super(username, password);
}
async findSites(searchTerm: string) {
const data = {
term: searchTerm,
fields: ['title']
};
try {
await this.apiAuth();
return this.queriesApi.findSites(searchTerm, data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.findSites.name}`,
error
);
return null;
}
}
async findNodes(searchTerm: string) {
const data = {
term: searchTerm,
fields: ['name']
};
try {
await this.apiAuth();
return this.queriesApi.findNodes(searchTerm, data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.findNodes.name}`,
error
);
return null;
}
}
async waitForSites(searchTerm: string, data: { expect: number }) {
try {
const sites = async () => {
const totalItems = (await this.findSites(searchTerm)).list.pagination
.totalItems;
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {
return Promise.resolve(totalItems);
}
};
return await Utils.retryCall(sites);
} catch (error) {
Logger.error(
`${this.constructor.name} ${this.waitForSites.name} catch: `
);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
async waitForFilesAndFolders(searchTerm: string, data: { expect: number }) {
try {
const nodes = async () => {
const totalItems = (await this.findNodes(searchTerm)).list.pagination
.totalItems;
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {
return Promise.resolve(totalItems);
}
};
return await Utils.retryCall(nodes);
} catch (error) {
Logger.error(
`${this.constructor.name} ${this.waitForFilesAndFolders.name} catch: `
);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}

View File

@@ -0,0 +1,63 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { browser } from 'protractor';
import { AlfrescoApi } from '@alfresco/js-api';
import { Logger } from '@alfresco/adf-testing';
export abstract class RepoApi {
alfrescoJsApi = new AlfrescoApi();
constructor(
private username: string = browser.params.ADMIN_USERNAME,
private password: string = browser.params.ADMIN_PASSWORD
) {
this.alfrescoJsApi.setConfig(browser.params.config);
}
apiAuth(): Promise<any> {
return this.alfrescoJsApi.login(this.username, this.password);
}
getUsername(): string {
return this.username;
}
protected handleError(message: string, response: any) {
Logger.error(`\n--- ${message} error :`);
Logger.error('\t>>> username: ', this.username);
Logger.error('\t>>> JSON: ', JSON.stringify(browser.params.config));
if (response.status && response.response) {
try {
Logger.error('\t>>> Status: ', response.status);
Logger.error('\t>>> Text: ', response.response.text);
Logger.error('\t>>> Method: ', response.response.error.method);
Logger.error('\t>>> Path: ', response.response.error.path);
} catch {
Logger.error('\t>>> ', response);
}
} else Logger.error('\t>>> ', response);
}
}

View File

@@ -0,0 +1,144 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { Logger } from '@alfresco/adf-testing';
import { Utils } from '../../../../utilities/utils';
import { SearchApi as AdfSearchApi } from '@alfresco/js-api';
export class SearchApi extends RepoApi {
searchApi = new AdfSearchApi(this.alfrescoJsApi);
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"` }
]
};
try {
await this.apiAuth();
return this.searchApi.search(data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.queryRecentFiles.name}`,
error
);
return null;
}
}
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) {
this.handleError(
`${this.constructor.name} ${this.queryNodesNames.name}`,
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'` }]
};
try {
await this.apiAuth();
return this.searchApi.search(data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.queryNodesExactNames.name}`,
error
);
return null;
}
}
async waitForApi(username: string, data: { expect: number }) {
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) {
Logger.error(`${this.constructor.name} ${this.waitForApi.name} catch: `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
async waitForNodes(searchTerm: string, data: { expect: number }) {
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) {
Logger.error(
`${this.constructor.name} ${this.waitForNodes.name} catch: `
);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}

View File

@@ -0,0 +1,134 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { Logger } from '@alfresco/adf-testing';
import { Utils } from '../../../../utilities/utils';
import {
SharedlinksApi as AdfSharedlinksApi,
SharedLinkEntry
} from '@alfresco/js-api';
export class SharedLinksApi extends RepoApi {
sharedlinksApi = new AdfSharedlinksApi(this.alfrescoJsApi);
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
};
return await this.sharedlinksApi.createSharedLink(data);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.shareFileById.name}`,
error
);
return null;
}
}
async shareFilesByIds(ids: string[]) {
try {
return await ids.reduce(async (previous: any, current: any) => {
await previous;
return this.shareFileById(current);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.shareFilesByIds.name}`,
error
);
}
}
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) {
this.handleError(
`${this.constructor.name} ${this.getSharedIdOfNode.name}`,
error
);
return null;
}
}
async unshareFile(name: string) {
try {
const id = await this.getSharedIdOfNode(name);
return await this.sharedlinksApi.deleteSharedLink(id);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.unshareFile.name}`,
error
);
}
}
async getSharedLinks() {
try {
await this.apiAuth();
return await this.sharedlinksApi.listSharedLinks();
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getSharedLinks.name}`,
error
);
return null;
}
}
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) {
Logger.error(`${this.constructor.name} ${this.waitForApi.name} catch: `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}

View File

@@ -0,0 +1,361 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { Logger } from '@alfresco/adf-testing';
import {
SiteBody,
SiteMemberRoleBody,
SiteMemberBody,
SiteEntry,
SiteMembershipRequestEntry,
SitesApi as AdfSiteApi,
SiteMemberEntry
} from '@alfresco/js-api';
import { SITE_VISIBILITY, SITE_ROLES } from '../../../../configs';
import { Utils } from '../../../../utilities/utils';
export class SitesApi extends RepoApi {
sitesApi = new AdfSiteApi(this.alfrescoJsApi);
constructor(username?, password?) {
super(username, password);
}
async getSite(siteId: string) {
try {
await this.apiAuth();
return await this.sitesApi.getSite(siteId);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.getSite.name}`, error);
return null;
}
}
async getSites() {
try {
await this.apiAuth();
return await this.sitesApi.listSiteMembershipsForPerson(
this.getUsername()
);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.getSites.name}`, error);
return null;
}
}
async getDocLibId(siteId: string) {
try {
await this.apiAuth();
return (await this.sitesApi.listSiteContainers(siteId)).list.entries[0]
.entry.id;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getDocLibId.name}`,
error
);
return null;
}
}
async getVisibility(siteId: string) {
try {
const site = await this.getSite(siteId);
return site.entry.visibility;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getVisibility.name}`,
error
);
return null;
}
}
async getDescription(siteId: string) {
try {
const site = await this.getSite(siteId);
return site.entry.description;
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getDescription.name}`,
error
);
return null;
}
}
async getTitle(siteId: string) {
try {
const site = await this.getSite(siteId);
return site.entry.title;
} catch (error) {
this.handleError(`${this.constructor.name} ${this.getTitle.name}`, error);
return null;
}
}
async createSite(
title: string,
visibility?: string,
description?: string,
siteId?: string
): Promise<SiteEntry | null> {
const site = {
title,
visibility: visibility || SITE_VISIBILITY.PUBLIC,
description: description,
id: siteId || title
} as SiteBody;
try {
await this.apiAuth();
return await this.sitesApi.createSite(site);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createSite.name}`,
error
);
return null;
}
}
async createSitePrivate(
title: string,
description?: string,
siteId?: string
): Promise<SiteEntry> {
return this.createSite(title, SITE_VISIBILITY.PRIVATE, description, siteId);
}
async createSiteModerated(
title: string,
description?: string,
siteId?: string
): Promise<SiteEntry> {
return this.createSite(
title,
SITE_VISIBILITY.MODERATED,
description,
siteId
);
}
async createSites(titles: string[], visibility?: string): Promise<any> {
try {
return titles.reduce(async (previous: any, current: any) => {
await previous;
return this.createSite(current, visibility);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.createSites.name}`,
error
);
}
}
async createSitesPrivate(siteNames: string[]): Promise<any> {
return this.createSites(siteNames, SITE_VISIBILITY.PRIVATE);
}
async deleteSite(siteId: string, permanent: boolean = true) {
try {
await this.apiAuth();
return await this.sitesApi.deleteSite(siteId, { permanent });
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteSite.name}`,
error
);
}
}
async deleteSites(siteIds: string[], permanent: boolean = true) {
try {
return siteIds.reduce(async (previous, current) => {
await previous;
return this.deleteSite(current, permanent);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteSites.name}`,
error
);
}
}
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 this.deleteSite(current, permanent);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteAllUserSites.name}`,
error
);
}
}
async updateSiteMember(siteId: string, userId: string, role: string) {
const siteRole = {
role: role
} as SiteMemberRoleBody;
try {
await this.apiAuth();
return await this.sitesApi.updateSiteMembership(siteId, userId, siteRole);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.updateSiteMember.name}`,
error
);
return null;
}
}
async addSiteMember(siteId: string, userId: string, role: string) {
const memberBody = {
id: userId,
role: role
} as SiteMemberBody;
try {
await this.apiAuth();
return await this.sitesApi.createSiteMembership(siteId, memberBody);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.addSiteMember.name}`,
error
);
return null;
}
}
async addSiteConsumer(
siteId: string,
userId: string
): Promise<SiteMemberEntry> {
return this.addSiteMember(siteId, userId, SITE_ROLES.SITE_CONSUMER.ROLE);
}
async addSiteContributor(
siteId: string,
userId: string
): Promise<SiteMemberEntry> {
return this.addSiteMember(siteId, userId, SITE_ROLES.SITE_CONTRIBUTOR.ROLE);
}
async addSiteCollaborator(
siteId: string,
userId: string
): Promise<SiteMemberEntry> {
return this.addSiteMember(
siteId,
userId,
SITE_ROLES.SITE_COLLABORATOR.ROLE
);
}
async addSiteManager(
siteId: string,
userId: string
): Promise<SiteMemberEntry> {
return this.addSiteMember(siteId, userId, SITE_ROLES.SITE_MANAGER.ROLE);
}
async deleteSiteMember(siteId: string, userId: string) {
try {
await this.apiAuth();
return await this.sitesApi.deleteSiteMembership(siteId, userId);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.deleteSiteMember.name}`,
error
);
}
}
async requestToJoin(
siteId: string
): Promise<SiteMembershipRequestEntry | null> {
const body = {
id: siteId
};
try {
await this.apiAuth();
return await this.sitesApi.createSiteMembershipRequestForPerson(
'-me-',
body
);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.requestToJoin.name}`,
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) {
this.handleError(
`${this.constructor.name} ${this.hasMembershipRequest.name}`,
error
);
return null;
}
}
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) {
Logger.error(`${this.constructor.name} ${this.waitForApi.name} catch: `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}

View File

@@ -0,0 +1,112 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { Logger } from '@alfresco/adf-testing';
import { Utils } from '../../../../utilities/utils';
import { TrashcanApi as AdfTrashcanApi } from '@alfresco/js-api';
export class TrashcanApi extends RepoApi {
trashcanApi = new AdfTrashcanApi(this.alfrescoJsApi);
constructor(username?: string, password?: string) {
super(username, password);
}
async permanentlyDelete(id: string) {
try {
await this.apiAuth();
return await this.trashcanApi.deleteDeletedNode(id);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.permanentlyDelete.name}`,
error
);
}
}
async restore(id: string) {
try {
await this.apiAuth();
return await this.trashcanApi.restoreDeletedNode(id);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.restore.name}`, error);
return null;
}
}
async getDeletedNodes() {
const opts = {
maxItems: 1000
};
try {
await this.apiAuth();
return await this.trashcanApi.listDeletedNodes(opts);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.getDeletedNodes.name}`,
error
);
return null;
}
}
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 this.permanentlyDelete(current);
}, Promise.resolve());
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.emptyTrash.name}`,
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) {
Logger.error(`${this.constructor.name} ${this.waitForApi.name} catch: `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}

View File

@@ -0,0 +1,92 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { UploadApi as AdfUploadApi } from '@alfresco/js-api';
import { browser } from 'protractor';
const fs = require('fs');
export class UploadApi extends RepoApi {
upload = new AdfUploadApi(this.alfrescoJsApi);
e2eRootPath = browser.params.e2eRootPath;
constructor(username?, password?) {
super(username, password);
}
async uploadFile(fileName: string, parentFolderId: string = '-my-') {
const file = fs.createReadStream(
`${this.e2eRootPath}/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) {
this.handleError(
`${this.constructor.name} ${this.uploadFile.name}`,
error
);
}
}
async uploadFileWithRename(
fileName: string,
parentId: string = '-my-',
newName: string,
title: string = '',
description: string = ''
) {
const file = fs.createReadStream(
`${this.e2eRootPath}/resources/test-files/${fileName}`
);
const nodeProps = {
properties: {
'cm:title': title,
'cm:description': description
}
};
const opts = {
name: newName,
nodeType: 'cm:content'
};
try {
await this.apiAuth();
return await this.upload.uploadFile(file, '', parentId, nodeProps, opts);
} catch (error) {
this.handleError(
`${this.constructor.name} ${this.uploadFileWithRename.name}`,
error
);
}
}
}