mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
initial e2e integration (#329)
* e2e integration with ci * update travis config * try always build image * build the app in production mode * try to stop previous * stop default postgresql service * try upgrade selenium-webdriver * disable Gecko for webdriver-manager * use stable chrome and latest protractor
This commit is contained in:
committed by
Cilibiu Bogdan
parent
54a7f3679c
commit
09aeeff204
118
e2e/utilities/repo-client/apis/favorites/favorites-api.ts
Executable file
118
e2e/utilities/repo-client/apis/favorites/favorites-api.ts
Executable file
@@ -0,0 +1,118 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 { promise } from 'protractor';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { NodesApi } from '../nodes/nodes-api';
|
||||
import { RepoClient } from './../../repo-client';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class FavoritesApi extends RepoApi {
|
||||
|
||||
addFavorite(api: RepoClient, nodeType: string, name: string): Promise<any> {
|
||||
return api.nodes.getNodeByPath(name)
|
||||
.then((response) => {
|
||||
const { id } = response.data.entry;
|
||||
return ([{
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: id
|
||||
}
|
||||
}
|
||||
}]);
|
||||
})
|
||||
.then((data) => {
|
||||
return this.post(`/people/-me-/favorites`, { data });
|
||||
})
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
addFavoriteById(nodeType: 'file' | 'folder', id: string): Promise<any> {
|
||||
const data = [{
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: id
|
||||
}
|
||||
}
|
||||
}];
|
||||
return this
|
||||
.post(`/people/-me-/favorites`, { data })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
addFavoritesByIds(nodeType: 'file' | 'folder', ids: string[]): Promise<any[]> {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.addFavoriteById(nodeType, current))
|
||||
), Promise.resolve());
|
||||
}
|
||||
|
||||
getFavorites(): Promise<any> {
|
||||
return this
|
||||
.get('/people/-me-/favorites')
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getFavoriteById(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/people/-me-/favorites/${nodeId}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
isFavorite(nodeId: string) {
|
||||
return this.getFavorites()
|
||||
.then(resp => JSON.stringify(resp.data.list.entries).includes(nodeId))
|
||||
}
|
||||
|
||||
removeFavorite(api: RepoClient, nodeType: string, name: string): Promise<any> {
|
||||
return api.nodes.getNodeByPath(name)
|
||||
.then((response) => {
|
||||
const { id } = response.data.entry;
|
||||
return this.delete(`/people/-me-/favorites/${id}`);
|
||||
})
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
removeFavoriteById(nodeId: string) {
|
||||
return this
|
||||
.delete(`/people/-me-/favorites/${nodeId}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
waitForApi(data) {
|
||||
const favoriteFiles = () => {
|
||||
return this.getFavorites()
|
||||
.then(response => response.data.list.pagination.totalItems)
|
||||
.then(totalItems => {
|
||||
if ( totalItems < data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Utils.retryCall(favoriteFiles);
|
||||
}
|
||||
}
|
38
e2e/utilities/repo-client/apis/nodes/node-body-create.ts
Executable file
38
e2e/utilities/repo-client/apis/nodes/node-body-create.ts
Executable file
@@ -0,0 +1,38 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 properties?: any[]
|
||||
) {}
|
||||
}
|
85
e2e/utilities/repo-client/apis/nodes/node-content-tree.ts
Executable file
85
e2e/utilities/repo-client/apis/nodes/node-content-tree.ts
Executable file
@@ -0,0 +1,85 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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;
|
||||
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
|
||||
}));
|
||||
|
||||
data = data.concat(filesData);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
182
e2e/utilities/repo-client/apis/nodes/nodes-api.ts
Executable file
182
e2e/utilities/repo-client/apis/nodes/nodes-api.ts
Executable file
@@ -0,0 +1,182 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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, NODE_TYPE_FILE, NODE_TYPE_FOLDER } from './node-body-create';
|
||||
import { NodeContentTree, flattenNodeContentTree } from './node-content-tree';
|
||||
|
||||
export class NodesApi extends RepoApi {
|
||||
// nodes
|
||||
getNodeByPath(relativePath: string = '/'): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/-my-`, { parameters: { relativePath } })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getNodeById(id: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${id}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getNodeDescription(name: string, relativePath: string = '/') {
|
||||
relativePath = (relativePath === '/')
|
||||
? `${name}`
|
||||
: `${relativePath}/${name}`;
|
||||
|
||||
return this.getNodeByPath(`${relativePath}`)
|
||||
.then(response => response.data.entry.properties['cm:description']);
|
||||
}
|
||||
|
||||
deleteNodeById(id: string, permanent: boolean = true): Promise<any> {
|
||||
return this
|
||||
.delete(`/nodes/${id}?permanent=${permanent}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
deleteNodeByPath(path: string, permanent: boolean = true): Promise<any> {
|
||||
return this
|
||||
.getNodeByPath(path)
|
||||
.then((response: any): string => response.data.entry.id)
|
||||
.then((id: string): any => this.deleteNodeById(id, permanent))
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true): Promise<any[]> {
|
||||
return names.reduce((previous, current) => (
|
||||
previous.then(() => this.deleteNodeByPath(`${relativePath}/${current}`, permanent))
|
||||
), Promise.resolve());
|
||||
}
|
||||
|
||||
deleteNodesById(ids: string[], permanent: boolean = true): Promise<any[]> {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.deleteNodeById(current, permanent))
|
||||
), Promise.resolve());
|
||||
}
|
||||
|
||||
// children
|
||||
getNodeChildren(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}/children`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
const data = {
|
||||
name: name,
|
||||
nodeType: nodeType,
|
||||
properties: {
|
||||
'cm:title': title, 'cm:description': description
|
||||
}
|
||||
};
|
||||
|
||||
return this
|
||||
.post(`/nodes/${parentId}/children`, { data })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
createFile(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
return this.createNode('cm:content', name, parentId, title, description);
|
||||
}
|
||||
|
||||
createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
return this.createNode('cm:folder', name, parentId, title, description);
|
||||
}
|
||||
|
||||
createChildren(data: NodeBodyCreate[]): Promise<any> {
|
||||
return this
|
||||
.post(`/nodes/-my-/children`, { data })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
createContent(content: NodeContentTree, relativePath: string = '/'): Promise<any> {
|
||||
return this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
}
|
||||
|
||||
createFolders(names: string[], relativePath: string = '/'): Promise<any> {
|
||||
return this.createContent({ folders: names }, relativePath);
|
||||
}
|
||||
|
||||
createFiles(names: string[], relativePath: string = '/'): Promise<any> {
|
||||
return this.createContent({ files: names }, relativePath);
|
||||
}
|
||||
|
||||
// node content
|
||||
getNodeContent(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}/content`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
editNodeContent(nodeId: string, content: string): Promise<any> {
|
||||
return this
|
||||
.put(`/nodes/${nodeId}/content`, { data: content })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
renameNode(nodeId: string, newName: string): Promise<any> {
|
||||
return this
|
||||
.put(`/nodes/${nodeId}`, { data: { name: newName } })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
// node permissions
|
||||
setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string): Promise<any> {
|
||||
const data = {
|
||||
permissions: {
|
||||
isInheritanceEnabled: inheritPermissions,
|
||||
locallySet: [
|
||||
{
|
||||
authorityId: username,
|
||||
name: role
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
return this
|
||||
.put(`/nodes/${nodeId}`, { data })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getNodePermissions(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}?include=permissions`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
// lock node
|
||||
lockFile(nodeId: string, lockType: string = 'FULL') {
|
||||
return this
|
||||
.post(`/nodes/${nodeId}/lock?include=isLocked`, { data: { 'type': lockType } })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
unlockFile(nodeId: string) {
|
||||
return this
|
||||
.post(`/nodes/${nodeId}/unlock`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
}
|
43
e2e/utilities/repo-client/apis/people/people-api-models.ts
Executable file
43
e2e/utilities/repo-client/apis/people/people-api-models.ts
Executable file
@@ -0,0 +1,43 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 class Person {
|
||||
id?: string;
|
||||
password?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
properties?: any;
|
||||
|
||||
constructor(username: string, password: string, details: Person) {
|
||||
this.id = username;
|
||||
this.password = password || username;
|
||||
this.firstName = username;
|
||||
this.lastName = username;
|
||||
this.email = `${username}@alfresco.com`;
|
||||
|
||||
Object.assign(this, details);
|
||||
}
|
||||
}
|
70
e2e/utilities/repo-client/apis/people/people-api.ts
Executable file
70
e2e/utilities/repo-client/apis/people/people-api.ts
Executable file
@@ -0,0 +1,70 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 { Person } from './people-api-models';
|
||||
|
||||
export class PeopleApi extends RepoApi {
|
||||
getUser(username: string) {
|
||||
return this
|
||||
.get(`/people/${username}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
updateUser(username: string, details?: Person): Promise<any> {
|
||||
if (details.id) {
|
||||
delete details.id;
|
||||
}
|
||||
|
||||
return this
|
||||
.put(`/people/${username}`, { data: details })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
createUser(username: string, password?: string, details?: Person): Promise<any> {
|
||||
const person: Person = new Person(username, password, details);
|
||||
const onSuccess = (response) => response;
|
||||
const onError = (response) => {
|
||||
return (response.statusCode === 409)
|
||||
? Promise.resolve(this.updateUser(username, person))
|
||||
: Promise.reject(response);
|
||||
};
|
||||
|
||||
return this
|
||||
.post(`/people`, { data: person })
|
||||
.then(onSuccess, onError)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
disableUser(username: string): Promise<any> {
|
||||
return this.put(`/people/${username}`, { data: { enabled: false } })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
changePassword(username: string, newPassword: string) {
|
||||
return this.put(`/people/${username}`, { data: { password: newPassword } })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
}
|
71
e2e/utilities/repo-client/apis/repo-api.ts
Executable file
71
e2e/utilities/repo-client/apis/repo-api.ts
Executable file
@@ -0,0 +1,71 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 { RestClient, RestClientArgs, RestClientResponse } from '../../rest-client/rest-client';
|
||||
import { RepoClientAuth, RepoClientConfig } from '../repo-client-models';
|
||||
|
||||
export abstract class RepoApi {
|
||||
private client: RestClient;
|
||||
private defaults: RepoClientConfig = new RepoClientConfig();
|
||||
|
||||
constructor(
|
||||
auth: RepoClientAuth = new RepoClientAuth(),
|
||||
private config?: RepoClientConfig
|
||||
) {
|
||||
const { username, password } = auth;
|
||||
|
||||
this.client = new RestClient(username, password);
|
||||
}
|
||||
|
||||
private createEndpointUri(endpoint: string, apiDefinition: string = 'alfresco'): string {
|
||||
const { defaults, config } = this;
|
||||
const { host, tenant } = Object.assign(defaults, config);
|
||||
|
||||
return `${host}/alfresco/api/${tenant}/public/${apiDefinition}/versions/1${endpoint}`;
|
||||
}
|
||||
|
||||
protected handleError(response: RestClientResponse) {
|
||||
const { request: { method, path, data }, data: error } = response;
|
||||
|
||||
console.log(`ERROR on ${method}\n${path}\n${data}`);
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
protected get(endpoint: string, args: RestClientArgs = {}, apiDefinition: string = 'alfresco') {
|
||||
return this.client.get(this.createEndpointUri(endpoint, apiDefinition), args);
|
||||
}
|
||||
|
||||
protected post(endpoint: string, args: RestClientArgs = {}, apiDefinition: string = 'alfresco') {
|
||||
return this.client.post(this.createEndpointUri(endpoint, apiDefinition), args);
|
||||
}
|
||||
|
||||
protected put(endpoint: string, args: RestClientArgs = {}, apiDefinition: string = 'alfresco') {
|
||||
return this.client.put(this.createEndpointUri(endpoint, apiDefinition), args);
|
||||
}
|
||||
|
||||
protected delete(endpoint: string, args: RestClientArgs = {}, apiDefinition: string = 'alfresco') {
|
||||
return this.client.delete(this.createEndpointUri(endpoint, apiDefinition), args);
|
||||
}
|
||||
}
|
71
e2e/utilities/repo-client/apis/search/search-api.ts
Executable file
71
e2e/utilities/repo-client/apis/search/search-api.ts
Executable file
@@ -0,0 +1,71 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class SearchApi extends RepoApi {
|
||||
apiDefinition = 'search';
|
||||
|
||||
search(data: any[]): Promise<any> {
|
||||
return this
|
||||
.post(`/search`, { data }, this.apiDefinition)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
queryRecentFiles(username: string): Promise<any> {
|
||||
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"` }
|
||||
]
|
||||
};
|
||||
|
||||
return this
|
||||
.post(`/search`, { data }, this.apiDefinition)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
waitForApi(username, data) {
|
||||
const recentFiles = () => {
|
||||
return this.queryRecentFiles(username)
|
||||
.then(response => response.data.list.pagination.totalItems)
|
||||
.then(totalItems => {
|
||||
if ( totalItems < data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Utils.retryCall(recentFiles);
|
||||
}
|
||||
}
|
79
e2e/utilities/repo-client/apis/shared-links/shared-links-api.ts
Executable file
79
e2e/utilities/repo-client/apis/shared-links/shared-links-api.ts
Executable file
@@ -0,0 +1,79 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 { NodesApi } from '../nodes/nodes-api';
|
||||
import { RepoClient } from './../../repo-client';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class SharedLinksApi extends RepoApi {
|
||||
|
||||
shareFileById(id: string): Promise<any> {
|
||||
const data = [{ nodeId: id }];
|
||||
|
||||
return this.post(`/shared-links`, { data })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
shareFilesByIds(ids: string[]): Promise<any[]> {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.shareFileById(current))
|
||||
), Promise.resolve());
|
||||
}
|
||||
|
||||
getSharedIdOfNode(name: string) {
|
||||
return this.getSharedLinks()
|
||||
.then(resp => resp.data.list.entries.find(entries => entries.entry.name === name))
|
||||
.then(resp => resp.entry.id)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
unshareFile(name: string) {
|
||||
return this.getSharedIdOfNode(name)
|
||||
.then(id => this.delete(`/shared-links/${id}`))
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getSharedLinks(): Promise<any> {
|
||||
return this.get(`/shared-links`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
waitForApi(data) {
|
||||
const sharedFiles = () => {
|
||||
return this.getSharedLinks()
|
||||
.then(response => response.data.list.pagination.totalItems)
|
||||
.then(totalItems => {
|
||||
if ( totalItems < data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Utils.retryCall(sharedFiles);
|
||||
}
|
||||
}
|
42
e2e/utilities/repo-client/apis/sites/sites-api-models.ts
Executable file
42
e2e/utilities/repo-client/apis/sites/sites-api-models.ts
Executable file
@@ -0,0 +1,42 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 { SITE_VISIBILITY } from '../../../../configs';
|
||||
|
||||
export class Site {
|
||||
title?: string;
|
||||
visibility?: string = SITE_VISIBILITY.PUBLIC;
|
||||
id?: string;
|
||||
description?: string;
|
||||
|
||||
constructor(title: string, visibility: string, details: Site) {
|
||||
this.title = title;
|
||||
this.visibility = visibility;
|
||||
this.id = title;
|
||||
this.description = `${title} description`;
|
||||
|
||||
Object.assign(this, details);
|
||||
}
|
||||
}
|
124
e2e/utilities/repo-client/apis/sites/sites-api.ts
Executable file
124
e2e/utilities/repo-client/apis/sites/sites-api.ts
Executable file
@@ -0,0 +1,124 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 { Site } from './sites-api-models';
|
||||
|
||||
export class SitesApi extends RepoApi {
|
||||
getSite(id: string): Promise<any> {
|
||||
return this
|
||||
.get(`/sites/${id}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getSiteContainers(siteId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/sites/${siteId}/containers`)
|
||||
.then(resp => resp.data.list.entries)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getDocLibId(siteId: string) {
|
||||
return this.getSiteContainers(siteId)
|
||||
.then(resp => resp[0].entry.id)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
updateSite(id: string, details?: Site): Promise<any> {
|
||||
if (details.id) {
|
||||
delete details.id;
|
||||
}
|
||||
|
||||
return this
|
||||
.put(`/sites/${id}`, { data: details })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
createOrUpdateSite(title: string, visibility: string, details?: Site): Promise<any> {
|
||||
const site: Site = new Site(title, visibility, details);
|
||||
const onSuccess = (response) => response;
|
||||
const onError = (response) => {
|
||||
return (response.statusCode === 409)
|
||||
? Promise.resolve(this.updateSite(site.id, site))
|
||||
: Promise.reject(response);
|
||||
};
|
||||
|
||||
return this
|
||||
.post(`/sites`, { data: site })
|
||||
.then(onSuccess, onError)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
createSite(title: string, visibility: string, details?: Site): Promise<any> {
|
||||
const site: Site = new Site(title, visibility, details);
|
||||
return this
|
||||
.post(`/sites`, { data: site })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
createSites(titles: string[], visibility: string): Promise<any[]> {
|
||||
return titles.reduce((previous, current) => (
|
||||
previous.then(() => this.createSite(current, visibility))
|
||||
), Promise.resolve());
|
||||
}
|
||||
|
||||
deleteSite(id: string, permanent: boolean = true): Promise<any> {
|
||||
return this
|
||||
.delete(`/sites/${id}?permanent=${permanent}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
deleteSites(ids: string[], permanent: boolean = true): Promise<any[]> {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.deleteSite(current))
|
||||
), Promise.resolve());
|
||||
}
|
||||
|
||||
updateSiteMember(siteId: string, userId: string, role: string): Promise<any> {
|
||||
return this
|
||||
.put(`/sites/${siteId}/members/${userId}`, { data: { role } })
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
addSiteMember(siteId: string, userId: string, role: string): Promise<any> {
|
||||
const onSuccess = (response) => response;
|
||||
const onError = (response) => {
|
||||
return (response.statusCode === 409)
|
||||
? Promise.resolve(this.updateSiteMember(siteId, userId, role))
|
||||
: Promise.reject(response);
|
||||
};
|
||||
|
||||
return this
|
||||
.post(`/sites/${siteId}/members`, { data: { role, id: userId } })
|
||||
.then(onSuccess, onError)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
deleteSiteMember(siteId: string, userId: string): Promise<any> {
|
||||
return this
|
||||
.delete(`/sites/${siteId}/members/${userId}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
}
|
76
e2e/utilities/repo-client/apis/trashcan/trashcan-api.ts
Executable file
76
e2e/utilities/repo-client/apis/trashcan/trashcan-api.ts
Executable file
@@ -0,0 +1,76 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 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 { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class TrashcanApi extends RepoApi {
|
||||
permanentlyDelete(id: string): Promise<any> {
|
||||
return this
|
||||
.delete(`/deleted-nodes/${id}`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
restore(id: string) {
|
||||
return this
|
||||
.post(`/deleted-nodes/${id}/restore`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getDeletedNodes(): Promise<any> {
|
||||
return this
|
||||
.get(`/deleted-nodes?maxItems=1000`)
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
emptyTrash(): Promise<any> {
|
||||
return this.getDeletedNodes()
|
||||
.then(resp => {
|
||||
return resp.data.list.entries.map(entries => entries.entry.id);
|
||||
})
|
||||
.then(ids => {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.permanentlyDelete(current))
|
||||
), Promise.resolve());
|
||||
})
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
waitForApi(data) {
|
||||
const deletedFiles = () => {
|
||||
return this.getDeletedNodes()
|
||||
.then(response => response.data.list.pagination.totalItems)
|
||||
.then(totalItems => {
|
||||
if ( totalItems < data.expect) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Utils.retryCall(deletedFiles);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user