mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[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:
215
projects/aca-testing-shared/src/utilities/admin-actions.ts
Executable file
215
projects/aca-testing-shared/src/utilities/admin-actions.ts
Executable file
@@ -0,0 +1,215 @@
|
||||
/*!
|
||||
* @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 { RepoClient, NodeContentTree } from './repo-client/repo-client';
|
||||
import { PersonEntry, NodeEntry } from '@alfresco/js-api';
|
||||
import { PersonModel } from './repo-client/apis/people/people-api-models';
|
||||
|
||||
import { SitesApi } from './repo-client/apis/sites/sites-api';
|
||||
import { UploadApi } from './repo-client/apis/upload/upload-api';
|
||||
import { NodesApi } from './repo-client/apis/nodes/nodes-api';
|
||||
import { FavoritesApi } from './repo-client/apis/favorites/favorites-api';
|
||||
import { SearchApi } from './repo-client/apis/search/search-api';
|
||||
|
||||
export class AdminActions {
|
||||
private adminApi: RepoClient;
|
||||
|
||||
constructor() {
|
||||
this.adminApi = new RepoClient();
|
||||
}
|
||||
|
||||
sites: SitesApi = new SitesApi();
|
||||
upload: UploadApi = new UploadApi();
|
||||
nodes: NodesApi = new NodesApi();
|
||||
favorites: FavoritesApi = new FavoritesApi();
|
||||
search: SearchApi = new SearchApi();
|
||||
|
||||
async getDataDictionaryId(): Promise<string> {
|
||||
return this.adminApi.nodes.getNodeIdFromParent('Data Dictionary', '-root-');
|
||||
}
|
||||
|
||||
async getNodeTemplatesFolderId(): Promise<string> {
|
||||
return this.adminApi.nodes.getNodeIdFromParent(
|
||||
'Node Templates',
|
||||
await this.getDataDictionaryId()
|
||||
);
|
||||
}
|
||||
|
||||
async getSpaceTemplatesFolderId(): Promise<string> {
|
||||
return this.adminApi.nodes.getNodeIdFromParent(
|
||||
'Space Templates',
|
||||
await this.getDataDictionaryId()
|
||||
);
|
||||
}
|
||||
|
||||
async createUser(user: PersonModel): Promise<PersonEntry> {
|
||||
return this.adminApi.people.createUser(user);
|
||||
}
|
||||
|
||||
async createNodeTemplate(
|
||||
name: string,
|
||||
title: string = '',
|
||||
description: string = '',
|
||||
author: string = ''
|
||||
): Promise<NodeEntry> {
|
||||
const templatesRootFolderId: string = await this.getNodeTemplatesFolderId();
|
||||
|
||||
return this.adminApi.nodes.createFile(
|
||||
name,
|
||||
templatesRootFolderId,
|
||||
title,
|
||||
description,
|
||||
author
|
||||
);
|
||||
}
|
||||
|
||||
async createNodeTemplatesHierarchy(hierarchy: NodeContentTree): Promise<any> {
|
||||
return this.adminApi.nodes.createContent(
|
||||
hierarchy,
|
||||
`Data Dictionary/Node Templates`
|
||||
);
|
||||
}
|
||||
|
||||
async createSpaceTemplate(
|
||||
name: string,
|
||||
title: string = '',
|
||||
description: string = ''
|
||||
): Promise<NodeEntry> {
|
||||
const templatesRootFolderId: string = await this.getSpaceTemplatesFolderId();
|
||||
|
||||
return this.adminApi.nodes.createFolder(
|
||||
name,
|
||||
templatesRootFolderId,
|
||||
title,
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
async createSpaceTemplatesHierarchy(
|
||||
hierarchy: NodeContentTree
|
||||
): Promise<any> {
|
||||
return this.adminApi.nodes.createContent(
|
||||
hierarchy,
|
||||
`Data Dictionary/Space Templates`
|
||||
);
|
||||
}
|
||||
|
||||
async removeUserAccessOnNodeTemplate(nodeName: string): Promise<NodeEntry> {
|
||||
const templatesRootFolderId = await this.getNodeTemplatesFolderId();
|
||||
const nodeId: string = await this.adminApi.nodes.getNodeIdFromParent(
|
||||
nodeName,
|
||||
templatesRootFolderId
|
||||
);
|
||||
|
||||
return this.adminApi.nodes.setInheritPermissions(nodeId, false);
|
||||
}
|
||||
|
||||
async removeUserAccessOnSpaceTemplate(nodeName: string): Promise<NodeEntry> {
|
||||
const templatesRootFolderId = await this.getSpaceTemplatesFolderId();
|
||||
const nodeId: string = await this.adminApi.nodes.getNodeIdFromParent(
|
||||
nodeName,
|
||||
templatesRootFolderId
|
||||
);
|
||||
|
||||
return this.adminApi.nodes.setInheritPermissions(nodeId, false);
|
||||
}
|
||||
|
||||
async cleanupNodeTemplatesFolder(): Promise<void> {
|
||||
return this.adminApi.nodes.deleteNodeChildren(
|
||||
await this.getNodeTemplatesFolderId()
|
||||
);
|
||||
}
|
||||
|
||||
async cleanupSpaceTemplatesFolder(): Promise<void> {
|
||||
const spaceTemplatesNodeId = await this.getSpaceTemplatesFolderId();
|
||||
|
||||
// folder links are deleted automatically when original folder is deleted
|
||||
// Software Engineering Project is the default folder template coming from ACS, should not be deleted
|
||||
const nodesToDelete = (await this.adminApi.nodes.getNodeChildren(
|
||||
spaceTemplatesNodeId
|
||||
)).list.entries
|
||||
.filter(
|
||||
node =>
|
||||
node.entry.nodeType !== 'app:folderlink' &&
|
||||
node.entry.name !== 'Software Engineering Project'
|
||||
)
|
||||
.map(node => node.entry.id);
|
||||
return this.adminApi.nodes.deleteNodesById(nodesToDelete);
|
||||
}
|
||||
|
||||
async createLinkToFileId(
|
||||
originalFileId: string,
|
||||
destinationParentId: string
|
||||
): Promise<NodeEntry> {
|
||||
return this.adminApi.nodes.createFileLink(
|
||||
originalFileId,
|
||||
destinationParentId
|
||||
);
|
||||
}
|
||||
|
||||
async createLinkToFileName(
|
||||
originalFileName: string,
|
||||
originalFileParentId: string,
|
||||
destinationParentId?: string
|
||||
): Promise<NodeEntry> {
|
||||
if (!destinationParentId) {
|
||||
destinationParentId = originalFileParentId;
|
||||
}
|
||||
|
||||
const nodeId = await this.adminApi.nodes.getNodeIdFromParent(
|
||||
originalFileName,
|
||||
originalFileParentId
|
||||
);
|
||||
|
||||
return this.createLinkToFileId(nodeId, destinationParentId);
|
||||
}
|
||||
|
||||
async createLinkToFolderId(
|
||||
originalFolderId: string,
|
||||
destinationParentId: string
|
||||
): Promise<NodeEntry> {
|
||||
return this.adminApi.nodes.createFolderLink(
|
||||
originalFolderId,
|
||||
destinationParentId
|
||||
);
|
||||
}
|
||||
|
||||
async createLinkToFolderName(
|
||||
originalFolderName: string,
|
||||
originalFolderParentId: string,
|
||||
destinationParentId?: string
|
||||
): Promise<NodeEntry> {
|
||||
if (!destinationParentId) {
|
||||
destinationParentId = originalFolderParentId;
|
||||
}
|
||||
|
||||
const nodeId = await this.adminApi.nodes.getNodeIdFromParent(
|
||||
originalFolderName,
|
||||
originalFolderParentId
|
||||
);
|
||||
|
||||
return this.createLinkToFolderId(nodeId, destinationParentId);
|
||||
}
|
||||
}
|
39
projects/aca-testing-shared/src/utilities/browser-utils.ts
Normal file
39
projects/aca-testing-shared/src/utilities/browser-utils.ts
Normal 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/>.
|
||||
*/
|
||||
|
||||
import { browser } from 'protractor';
|
||||
import { USE_HASH_STRATEGY } from '../configs';
|
||||
|
||||
export async function navigate(relativePath: string) {
|
||||
const path = [
|
||||
browser.baseUrl,
|
||||
browser.baseUrl.endsWith('/') ? '' : '/',
|
||||
USE_HASH_STRATEGY ? '#' : '',
|
||||
relativePath.startsWith('/') ? '' : '/',
|
||||
relativePath
|
||||
].join('');
|
||||
|
||||
return browser.get(path);
|
||||
}
|
30
projects/aca-testing-shared/src/utilities/index.ts
Normal file
30
projects/aca-testing-shared/src/utilities/index.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/*!
|
||||
* @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 './repo-client/apis';
|
||||
export * from './repo-client/repo-client';
|
||||
export * from './admin-actions';
|
||||
export * from './browser-utils';
|
||||
export * from './utils';
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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}`);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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';
|
@@ -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[]
|
||||
) {}
|
||||
}
|
@@ -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;
|
||||
}
|
784
projects/aca-testing-shared/src/utilities/repo-client/apis/nodes/nodes-api.ts
Executable file
784
projects/aca-testing-shared/src/utilities/repo-client/apis/nodes/nodes-api.ts
Executable 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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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}`);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
144
projects/aca-testing-shared/src/utilities/repo-client/apis/search/search-api.ts
Executable file
144
projects/aca-testing-shared/src/utilities/repo-client/apis/search/search-api.ts
Executable 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}`);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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}`);
|
||||
}
|
||||
}
|
||||
}
|
361
projects/aca-testing-shared/src/utilities/repo-client/apis/sites/sites-api.ts
Executable file
361
projects/aca-testing-shared/src/utilities/repo-client/apis/sites/sites-api.ts
Executable 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}`);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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}`);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
97
projects/aca-testing-shared/src/utilities/repo-client/repo-client.ts
Executable file
97
projects/aca-testing-shared/src/utilities/repo-client/repo-client.ts
Executable 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 { browser } from 'protractor';
|
||||
import { PeopleApi } from './apis/people/people-api';
|
||||
import { NodesApi } from './apis/nodes/nodes-api';
|
||||
import { CommentsApi } from './apis/comments/comments-api';
|
||||
import { SitesApi } from './apis/sites/sites-api';
|
||||
import { FavoritesApi } from './apis/favorites/favorites-api';
|
||||
import { QueriesApi } from './apis/queries/queries-api';
|
||||
import { SharedLinksApi } from './apis/shared-links/shared-links-api';
|
||||
import { TrashcanApi } from './apis/trashcan/trashcan-api';
|
||||
import { SearchApi } from './apis/search/search-api';
|
||||
import { UploadApi } from './apis/upload/upload-api';
|
||||
import { AuthenticationApi } from './apis/authentication/authentication-api';
|
||||
|
||||
export class RepoClient {
|
||||
constructor(
|
||||
private username: string = browser.params.ADMIN_USERNAME,
|
||||
private password: string = browser.params.ADMIN_PASSWORD
|
||||
) {}
|
||||
|
||||
private get auth() {
|
||||
const { username, password } = this;
|
||||
return { username, password };
|
||||
}
|
||||
|
||||
get people() {
|
||||
return new PeopleApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get nodes() {
|
||||
return new NodesApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get comments() {
|
||||
return new CommentsApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get sites() {
|
||||
return new SitesApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get favorites() {
|
||||
return new FavoritesApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get shared() {
|
||||
return new SharedLinksApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get trashcan() {
|
||||
return new TrashcanApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get search() {
|
||||
return new SearchApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get queries() {
|
||||
return new QueriesApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get upload() {
|
||||
return new UploadApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get authentication() {
|
||||
return new AuthenticationApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
}
|
||||
|
||||
export * from './apis/nodes/node-body-create';
|
||||
export * from './apis/nodes/node-content-tree';
|
||||
export * from './apis/nodes/nodes-api';
|
344
projects/aca-testing-shared/src/utilities/utils.ts
Normal file
344
projects/aca-testing-shared/src/utilities/utils.ts
Normal file
@@ -0,0 +1,344 @@
|
||||
/*!
|
||||
* @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,
|
||||
protractor,
|
||||
ElementFinder,
|
||||
ExpectedConditions as EC,
|
||||
by,
|
||||
logging,
|
||||
until,
|
||||
WebElement
|
||||
} from 'protractor';
|
||||
import { Logger } from '@alfresco/adf-testing';
|
||||
import { BROWSER_WAIT_TIMEOUT } from '../configs';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const StreamZip = require('node-stream-zip');
|
||||
|
||||
export async function typeText(
|
||||
element: ElementFinder,
|
||||
text: string
|
||||
): Promise<void> {
|
||||
await element.clear();
|
||||
await element.sendKeys(text);
|
||||
}
|
||||
|
||||
export async function clearTextWithBackspace(
|
||||
element: ElementFinder
|
||||
): Promise<void> {
|
||||
await element.clear();
|
||||
await element.sendKeys(
|
||||
' ',
|
||||
protractor.Key.CONTROL,
|
||||
'a',
|
||||
protractor.Key.NULL,
|
||||
protractor.Key.BACK_SPACE
|
||||
);
|
||||
}
|
||||
|
||||
export async function waitElement(
|
||||
css: string,
|
||||
errorMessage?: string
|
||||
): Promise<WebElement> {
|
||||
return browser.wait(
|
||||
until.elementLocated(by.css(css)),
|
||||
BROWSER_WAIT_TIMEOUT,
|
||||
errorMessage || `Timeout waiting for element: ${css}`
|
||||
);
|
||||
}
|
||||
|
||||
export async function waitForClickable(
|
||||
element: ElementFinder,
|
||||
errorMessage?: string
|
||||
): Promise<void> {
|
||||
await browser.wait(
|
||||
EC.elementToBeClickable(element),
|
||||
BROWSER_WAIT_TIMEOUT,
|
||||
errorMessage ||
|
||||
`Timeout waiting for element to be clickable: ${element.locator()}`
|
||||
);
|
||||
}
|
||||
|
||||
export async function waitForVisibility(
|
||||
element: ElementFinder,
|
||||
errorMessage?: string
|
||||
): Promise<void> {
|
||||
await browser.wait(
|
||||
EC.visibilityOf(element),
|
||||
BROWSER_WAIT_TIMEOUT,
|
||||
errorMessage ||
|
||||
`Timeout waiting for element visibility: ${element.locator()}`
|
||||
);
|
||||
}
|
||||
|
||||
export async function waitForInvisibility(
|
||||
element: ElementFinder,
|
||||
errorMessage?: string
|
||||
): Promise<void> {
|
||||
await browser.wait(
|
||||
EC.invisibilityOf(element),
|
||||
BROWSER_WAIT_TIMEOUT,
|
||||
errorMessage ||
|
||||
`Timeout waiting for element visibility: ${element.locator()}`
|
||||
);
|
||||
}
|
||||
|
||||
export async function waitForPresence(
|
||||
element: ElementFinder,
|
||||
errorMessage?: string
|
||||
): Promise<void> {
|
||||
await browser.wait(
|
||||
EC.presenceOf(element),
|
||||
BROWSER_WAIT_TIMEOUT,
|
||||
errorMessage || `Timeout waiting for element presence: ${element.locator()}`
|
||||
);
|
||||
}
|
||||
|
||||
export async function waitForStaleness(
|
||||
element: ElementFinder,
|
||||
errorMessage?: string
|
||||
): Promise<void> {
|
||||
await browser.wait(
|
||||
EC.stalenessOf(element),
|
||||
BROWSER_WAIT_TIMEOUT,
|
||||
errorMessage || `Timeout waiting element staleness: ${element.locator()}`
|
||||
);
|
||||
}
|
||||
|
||||
export const isPresentAndEnabled = async (
|
||||
element: ElementFinder
|
||||
): Promise<boolean> => {
|
||||
const isPresent = await element.isPresent();
|
||||
|
||||
if (isPresent) {
|
||||
return element.isEnabled();
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
export const isPresentAndDisplayed = async (
|
||||
element: ElementFinder
|
||||
): Promise<boolean> => {
|
||||
const isPresent = await element.isPresent();
|
||||
|
||||
if (isPresent) {
|
||||
return element.isDisplayed();
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
export class Utils {
|
||||
static string257 =
|
||||
'assembly doctor offender limit clearance inspiration baker fraud active apples trait brainstorm concept breaks down presidential \
|
||||
reluctance summary communication patience books opponent banana economist head develop project swear unanimous read conservation';
|
||||
|
||||
static string513 =
|
||||
'great indirect brain tune other expectation fun silver drain tumble rhythm harmful wander picture distribute opera complication copyright \
|
||||
explosion snack ride pool machinery pair frog joint wrestle video referee drive window cage falsify happen tablet horror thank conception \
|
||||
extension decay dismiss platform respect ceremony applaud absorption presentation dominate race courtship soprano body \
|
||||
lighter track cinema tread tick climate lend summit singer radical flower visual negotiation promises cooperative live';
|
||||
|
||||
static random(): string {
|
||||
return Math.random()
|
||||
.toString(36)
|
||||
.substring(5, 10)
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
static async clearLocalStorage(): Promise<void> {
|
||||
await browser.executeScript('window.localStorage.clear();');
|
||||
}
|
||||
|
||||
static async setSessionStorageFromConfig(
|
||||
configFileName: string
|
||||
): Promise<void> {
|
||||
const configFile = `${
|
||||
browser.params.e2eRootPath
|
||||
}/resources/extensibility-configs/${configFileName}`;
|
||||
const fileContent = JSON.stringify(
|
||||
fs.readFileSync(configFile, { encoding: 'utf8' })
|
||||
);
|
||||
|
||||
await browser.executeScript(
|
||||
`window.sessionStorage.setItem('app.extension.config', ${fileContent});`
|
||||
);
|
||||
}
|
||||
|
||||
static retryCall(
|
||||
fn: () => Promise<any>,
|
||||
retry: number = 30,
|
||||
delay: number = 1000
|
||||
): Promise<any> {
|
||||
const pause = duration => new Promise(res => setTimeout(res, duration));
|
||||
|
||||
const run = retries => {
|
||||
return fn().catch(err =>
|
||||
retries > 1
|
||||
? pause(delay).then(() => run(retries - 1))
|
||||
: Promise.reject(err)
|
||||
);
|
||||
};
|
||||
|
||||
return run(retry);
|
||||
}
|
||||
|
||||
static async clearFieldWithBackspace(elem: ElementFinder): Promise<void> {
|
||||
const text = await elem.getAttribute('value');
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
await elem.sendKeys(protractor.Key.BACK_SPACE);
|
||||
}
|
||||
}
|
||||
|
||||
static async fileExistsOnOS(
|
||||
fileName: string,
|
||||
folderName: string = '',
|
||||
subFolderName: string = ''
|
||||
): Promise<any> {
|
||||
const config = await browser.getProcessedConfig();
|
||||
const filePath = path.join(
|
||||
config.params.downloadFolder,
|
||||
folderName,
|
||||
subFolderName,
|
||||
fileName
|
||||
);
|
||||
|
||||
let tries = 15;
|
||||
|
||||
return new Promise(function(resolve) {
|
||||
const checkExist = setInterval(() => {
|
||||
fs.access(filePath, function(error) {
|
||||
tries--;
|
||||
|
||||
if (error && tries === 0) {
|
||||
clearInterval(checkExist);
|
||||
resolve(false);
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
clearInterval(checkExist);
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
|
||||
static async renameFile(oldName: string, newName: string): Promise<void> {
|
||||
const config = await browser.getProcessedConfig();
|
||||
const oldFilePath = path.join(config.params.downloadFolder, oldName);
|
||||
const newFilePath = path.join(config.params.downloadFolder, newName);
|
||||
|
||||
const fileExists = await this.fileExistsOnOS(oldName);
|
||||
|
||||
if (fileExists) {
|
||||
fs.rename(oldFilePath, newFilePath, function(err) {
|
||||
if (err) {
|
||||
Logger.error('==== rename err: ', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static async unzip(
|
||||
filename: string,
|
||||
unzippedName: string = ''
|
||||
): Promise<void> {
|
||||
const config = await browser.getProcessedConfig();
|
||||
const filePath = path.join(config.params.downloadFolder, filename);
|
||||
const output = path.join(
|
||||
config.params.downloadFolder,
|
||||
unzippedName ? unzippedName : ''
|
||||
);
|
||||
|
||||
const zip = new StreamZip({
|
||||
file: filePath,
|
||||
storeEntries: true
|
||||
});
|
||||
|
||||
await zip.on('error', err => {
|
||||
Logger.error('=== unzip err: ', err);
|
||||
});
|
||||
|
||||
await zip.on('ready', async () => {
|
||||
if (unzippedName) {
|
||||
await fs.mkdirSync(output);
|
||||
}
|
||||
await zip.extract(null, output, async () => {
|
||||
await zip.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async pressEscape(): Promise<void> {
|
||||
await browser
|
||||
.actions()
|
||||
.sendKeys(protractor.Key.ESCAPE)
|
||||
.perform();
|
||||
}
|
||||
|
||||
static async pressTab(): Promise<void> {
|
||||
await browser
|
||||
.actions()
|
||||
.sendKeys(protractor.Key.TAB)
|
||||
.perform();
|
||||
}
|
||||
|
||||
static async pressCmd(): Promise<void> {
|
||||
await browser
|
||||
.actions()
|
||||
.sendKeys(protractor.Key.COMMAND)
|
||||
.perform();
|
||||
}
|
||||
|
||||
static async releaseKeyPressed(): Promise<void> {
|
||||
await browser
|
||||
.actions()
|
||||
.sendKeys(protractor.Key.NULL)
|
||||
.perform();
|
||||
}
|
||||
|
||||
static async getBrowserLog(): Promise<logging.Entry[]> {
|
||||
return browser
|
||||
.manage()
|
||||
.logs()
|
||||
.get('browser');
|
||||
}
|
||||
|
||||
static formatDate(date: string): string {
|
||||
return new Date(date).toLocaleDateString('en-US');
|
||||
}
|
||||
|
||||
static async uploadFileNewVersion(fileFromOS: string): Promise<void> {
|
||||
const el = browser.element(by.id('app-upload-file-version'));
|
||||
await el.sendKeys(
|
||||
`${browser.params.e2eRootPath}/resources/test-files/${fileFromOS}`
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user