mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[ACA-1635][ACA-1636] update favoritesApi and nodesApi to use alfresco-js-api-node (#564)
* refactor favoritesApi and nodesApi to use alfresco-js-api-node * remove node-rest-client
This commit is contained in:
committed by
Cilibiu Bogdan
parent
213c2deedc
commit
86a90d33e2
@@ -23,96 +23,82 @@
|
||||
* 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);
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
addFavoriteById(nodeType: 'file' | 'folder', id: string): Promise<any> {
|
||||
const data = [{
|
||||
async addFavorite(api: RepoClient, nodeType: string, name: string) {
|
||||
const nodeId = (await api.nodes.getNodeByPath(name)).entry.id;
|
||||
const data = {
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: nodeId
|
||||
}
|
||||
}
|
||||
};
|
||||
return await this.alfrescoJsApi.core.favoritesApi.addFavorite('-me-', data);
|
||||
}
|
||||
|
||||
async addFavoriteById(nodeType: 'file' | 'folder', id: string) {
|
||||
const data = {
|
||||
target: {
|
||||
[nodeType]: {
|
||||
guid: id
|
||||
}
|
||||
}
|
||||
}];
|
||||
return this
|
||||
.post(`/people/-me-/favorites`, { data })
|
||||
.catch(this.handleError);
|
||||
};
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.favoritesApi.addFavorite('-me-', data);
|
||||
}
|
||||
|
||||
addFavoritesByIds(nodeType: 'file' | 'folder', ids: string[]): Promise<any[]> {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.addFavoriteById(nodeType, current))
|
||||
), Promise.resolve());
|
||||
async addFavoritesByIds(nodeType: 'file' | 'folder', ids: string[]) {
|
||||
await this.apiAuth();
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
await this.addFavoriteById(nodeType, current);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
getFavorites(): Promise<any> {
|
||||
return this
|
||||
.get('/people/-me-/favorites')
|
||||
.catch(this.handleError);
|
||||
async getFavorites() {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.favoritesApi.getFavorites(this.getUsername());
|
||||
}
|
||||
|
||||
getFavoriteById(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/people/-me-/favorites/${nodeId}`)
|
||||
.catch(this.handleError);
|
||||
async getFavoriteById(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.favoritesApi.getFavorite('-me', nodeId);
|
||||
}
|
||||
|
||||
isFavorite(nodeId: string) {
|
||||
return this.getFavorites()
|
||||
.then(resp => JSON.stringify(resp.data.list.entries).includes(nodeId));
|
||||
async isFavorite(nodeId: string) {
|
||||
return JSON.stringify((await this.getFavorites()).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);
|
||||
async removeFavoriteById(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.peopleApi.removeFavoriteSite('-me-', nodeId);
|
||||
}
|
||||
|
||||
removeFavoriteById(nodeId: string) {
|
||||
return this
|
||||
.delete(`/people/-me-/favorites/${nodeId}`)
|
||||
.catch(this.handleError);
|
||||
async removeFavorite(api: RepoClient, name: string) {
|
||||
const nodeId = (await api.nodes.getNodeByPath(name)).entry.id;
|
||||
return await this.removeFavoriteById(nodeId);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
async waitForApi(data) {
|
||||
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 Utils.retryCall(favoriteFiles);
|
||||
return await Utils.retryCall(favoriteFiles);
|
||||
}
|
||||
}
|
||||
|
@@ -23,127 +23,125 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { NodeBodyLock } from 'alfresco-js-api-node';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { NodeBodyCreate, NODE_TYPE_FILE, NODE_TYPE_FOLDER } from './node-body-create';
|
||||
import { NodeBodyCreate } from './node-body-create';
|
||||
import { NodeContentTree, flattenNodeContentTree } from './node-content-tree';
|
||||
|
||||
export class NodesApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
// nodes
|
||||
getNodeByPath(relativePath: string = '/'): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/-my-`, { parameters: { relativePath } })
|
||||
.catch(this.handleError);
|
||||
|
||||
async getNodeByPath(relativePath: string = '/') {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNode('-my-', { relativePath });
|
||||
}
|
||||
|
||||
getNodeById(id: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${id}`)
|
||||
.catch(this.handleError);
|
||||
async getNodeById(id: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNode(id);
|
||||
}
|
||||
|
||||
getNodeDescription(name: string, relativePath: string = '/') {
|
||||
async getNodeDescription(name: string, relativePath: string = '/') {
|
||||
relativePath = (relativePath === '/')
|
||||
? `${name}`
|
||||
: `${relativePath}/${name}`;
|
||||
|
||||
return this.getNodeByPath(`${relativePath}`)
|
||||
.then(response => response.data.entry.properties['cm:description']);
|
||||
return (await this.getNodeByPath(`${relativePath}`)).entry.properties['cm:description'];
|
||||
}
|
||||
|
||||
deleteNodeById(id: string, permanent: boolean = true): Promise<any> {
|
||||
return this
|
||||
.delete(`/nodes/${id}?permanent=${permanent}`)
|
||||
.catch(this.handleError);
|
||||
async deleteNodeById(id: string, permanent: boolean = true) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.deleteNode(id, { permanent });
|
||||
}
|
||||
|
||||
deleteNodeByPath(path: string, permanent: boolean = true): Promise<any> {
|
||||
return this
|
||||
.getNodeByPath(path)
|
||||
.then((response: any): string => response.data.entry.id)
|
||||
.then((id: string): any => this.deleteNodeById(id, permanent))
|
||||
.catch(this.handleError);
|
||||
async deleteNodeByPath(path: string, permanent: boolean = true) {
|
||||
const id = (await this.getNodeByPath(path)).entry.id;
|
||||
return await this.deleteNodeById(id, permanent);
|
||||
}
|
||||
|
||||
deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true): Promise<any[]> {
|
||||
return names.reduce((previous, current) => (
|
||||
previous.then(() => this.deleteNodeByPath(`${relativePath}/${current}`, permanent))
|
||||
), Promise.resolve());
|
||||
async deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true) {
|
||||
return await names.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteNodeByPath(`${relativePath}/${current}`, permanent);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
deleteNodesById(ids: string[], permanent: boolean = true): Promise<any[]> {
|
||||
return ids.reduce((previous, current) => (
|
||||
previous.then(() => this.deleteNodeById(current, permanent))
|
||||
), Promise.resolve());
|
||||
async deleteNodesById(ids: string[], permanent: boolean = true) {
|
||||
return await ids.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
return await this.deleteNodeById(current, permanent);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
// children
|
||||
getNodeChildren(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}/children`)
|
||||
.catch(this.handleError);
|
||||
|
||||
async getNodeChildren(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNodeChildren(nodeId);
|
||||
}
|
||||
|
||||
createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
const data = {
|
||||
name: name,
|
||||
nodeType: nodeType,
|
||||
async createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
const nodeBody = {
|
||||
name,
|
||||
nodeType,
|
||||
properties: {
|
||||
'cm:title': title, 'cm:description': description
|
||||
'cm:title': title,
|
||||
'cm:description': description
|
||||
}
|
||||
};
|
||||
|
||||
return this
|
||||
.post(`/nodes/${parentId}/children`, { data })
|
||||
.catch(this.handleError);
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.addNode(parentId, nodeBody);
|
||||
}
|
||||
|
||||
createFile(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
return this.createNode('cm:content', name, parentId, title, description);
|
||||
async createFile(name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
return await this.createNode('cm:content', name, parentId, title, description);
|
||||
}
|
||||
|
||||
createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
|
||||
return this.createNode('cm:folder', name, parentId, title, description);
|
||||
async createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = '') {
|
||||
return await this.createNode('cm:folder', name, parentId, title, description);
|
||||
}
|
||||
|
||||
createChildren(data: NodeBodyCreate[]): Promise<any> {
|
||||
return this
|
||||
.post(`/nodes/-my-/children`, { data })
|
||||
.catch(this.handleError);
|
||||
async createChildren(data: NodeBodyCreate[]) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.addNode('-my-', data);
|
||||
}
|
||||
|
||||
createContent(content: NodeContentTree, relativePath: string = '/'): Promise<any> {
|
||||
return this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
async createContent(content: NodeContentTree, relativePath: string = '/') {
|
||||
return await this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
}
|
||||
|
||||
createFolders(names: string[], relativePath: string = '/'): Promise<any> {
|
||||
return this.createContent({ folders: names }, relativePath);
|
||||
async createFolders(names: string[], relativePath: string = '/') {
|
||||
return await this.createContent({ folders: names }, relativePath);
|
||||
}
|
||||
|
||||
createFiles(names: string[], relativePath: string = '/'): Promise<any> {
|
||||
return this.createContent({ files: names }, relativePath);
|
||||
async createFiles(names: string[], relativePath: string = '/') {
|
||||
return await this.createContent({ files: names }, relativePath);
|
||||
}
|
||||
|
||||
// node content
|
||||
getNodeContent(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}/content`)
|
||||
.catch(this.handleError);
|
||||
async getNodeContent(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNodeContent(nodeId);
|
||||
}
|
||||
|
||||
editNodeContent(nodeId: string, content: string): Promise<any> {
|
||||
return this
|
||||
.put(`/nodes/${nodeId}/content`, { data: content })
|
||||
.catch(this.handleError);
|
||||
async editNodeContent(nodeId: string, content: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.updateNodeContent(nodeId, content);
|
||||
}
|
||||
|
||||
renameNode(nodeId: string, newName: string): Promise<any> {
|
||||
return this
|
||||
.put(`/nodes/${nodeId}`, { data: { name: newName } })
|
||||
.catch(this.handleError);
|
||||
async renameNode(nodeId: string, newName: string) {
|
||||
await this.apiAuth();
|
||||
return this.alfrescoJsApi.core.nodesApi.updateNode(nodeId, { name: newName });
|
||||
}
|
||||
|
||||
// node permissions
|
||||
setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string): Promise<any> {
|
||||
async setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string) {
|
||||
const data = {
|
||||
permissions: {
|
||||
isInheritanceEnabled: inheritPermissions,
|
||||
@@ -156,27 +154,26 @@ export class NodesApi extends RepoApi {
|
||||
}
|
||||
};
|
||||
|
||||
return this
|
||||
.put(`/nodes/${nodeId}`, { data })
|
||||
.catch(this.handleError);
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.updateNode(nodeId, data);
|
||||
}
|
||||
|
||||
getNodePermissions(nodeId: string): Promise<any> {
|
||||
return this
|
||||
.get(`/nodes/${nodeId}?include=permissions`)
|
||||
.catch(this.handleError);
|
||||
async getNodePermissions(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.getNode(nodeId, { include: ['permissions'] });
|
||||
}
|
||||
|
||||
// lock node
|
||||
lockFile(nodeId: string, lockType: string = 'FULL') {
|
||||
return this
|
||||
.post(`/nodes/${nodeId}/lock?include=isLocked`, { data: { 'type': lockType } })
|
||||
.catch(this.handleError);
|
||||
async lockFile(nodeId: string, lockType: string = 'FULL') {
|
||||
const data = <NodeBodyLock>{
|
||||
type: lockType
|
||||
};
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.lockNode(nodeId, data );
|
||||
}
|
||||
|
||||
unlockFile(nodeId: string) {
|
||||
return this
|
||||
.post(`/nodes/${nodeId}/unlock`)
|
||||
.catch(this.handleError);
|
||||
async unlockFile(nodeId: string) {
|
||||
await this.apiAuth();
|
||||
return await this.alfrescoJsApi.core.nodesApi.unlockNode(nodeId);
|
||||
}
|
||||
}
|
||||
|
@@ -24,9 +24,9 @@
|
||||
*/
|
||||
|
||||
import { PersonModel, Person } from './people-api-models';
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
|
||||
export class PeopleApi extends RepoApiNew {
|
||||
export class PeopleApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@@ -1,46 +0,0 @@
|
||||
/*!
|
||||
* @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 * as AlfrescoApi from 'alfresco-js-api-node';
|
||||
import { REPO_API_HOST } from '../../../configs';
|
||||
import { RepoClientAuth } from '../repo-client-models';
|
||||
|
||||
export abstract class RepoApiNew {
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
provider: 'ECM',
|
||||
hostEcm: REPO_API_HOST
|
||||
});
|
||||
|
||||
constructor(
|
||||
private username: string = RepoClientAuth.DEFAULT_USERNAME,
|
||||
private password: string = RepoClientAuth.DEFAULT_PASSWORD
|
||||
) {}
|
||||
|
||||
apiAuth() {
|
||||
return this.alfrescoJsApi.login(this.username, this.password);
|
||||
}
|
||||
|
||||
}
|
51
e2e/utilities/repo-client/apis/repo-api.ts
Executable file → Normal file
51
e2e/utilities/repo-client/apis/repo-api.ts
Executable file → Normal file
@@ -23,49 +23,28 @@
|
||||
* 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';
|
||||
import * as AlfrescoApi from 'alfresco-js-api-node';
|
||||
import { REPO_API_HOST } from '../../../configs';
|
||||
import { RepoClientAuth } from '../repo-client-models';
|
||||
|
||||
export abstract class RepoApi {
|
||||
private client: RestClient;
|
||||
private defaults: RepoClientConfig = new RepoClientConfig();
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
provider: 'ECM',
|
||||
hostEcm: REPO_API_HOST
|
||||
});
|
||||
|
||||
constructor(
|
||||
auth: RepoClientAuth = new RepoClientAuth(),
|
||||
private config?: RepoClientConfig
|
||||
) {
|
||||
const { username, password } = auth;
|
||||
private username: string = RepoClientAuth.DEFAULT_USERNAME,
|
||||
private password: string = RepoClientAuth.DEFAULT_PASSWORD
|
||||
) {}
|
||||
|
||||
this.client = new RestClient(username, password);
|
||||
apiAuth() {
|
||||
return this.alfrescoJsApi.login(this.username, this.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}`;
|
||||
getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -23,10 +23,10 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class SearchApi extends RepoApiNew {
|
||||
export class SearchApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@@ -23,10 +23,10 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class SharedLinksApi extends RepoApiNew {
|
||||
export class SharedLinksApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@@ -23,11 +23,11 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { SiteBody, SiteMemberRoleBody, SiteMemberBody } from 'alfresco-js-api-node';
|
||||
import { SITE_VISIBILITY } from '../../../../configs';
|
||||
|
||||
export class SitesApi extends RepoApiNew {
|
||||
export class SitesApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@@ -23,10 +23,10 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoApiNew } from '../repo-api-new';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class TrashcanApi extends RepoApiNew {
|
||||
export class TrashcanApi extends RepoApi {
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
|
@@ -25,9 +25,7 @@
|
||||
|
||||
import {
|
||||
ADMIN_USERNAME,
|
||||
ADMIN_PASSWORD,
|
||||
REPO_API_HOST,
|
||||
REPO_API_TENANT
|
||||
ADMIN_PASSWORD
|
||||
} from '../../configs';
|
||||
|
||||
export class RepoClientAuth {
|
||||
@@ -39,8 +37,3 @@ export class RepoClientAuth {
|
||||
public password: string = RepoClientAuth.DEFAULT_PASSWORD
|
||||
) {}
|
||||
}
|
||||
|
||||
export class RepoClientConfig {
|
||||
host?: string = REPO_API_HOST;
|
||||
tenant?: string = REPO_API_TENANT;
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoClientAuth, RepoClientConfig } from './repo-client-models';
|
||||
import { RepoClientAuth } from './repo-client-models';
|
||||
|
||||
import { PeopleApi } from './apis/people/people-api';
|
||||
import { NodesApi } from './apis/nodes/nodes-api';
|
||||
@@ -36,8 +36,7 @@ import { SearchApi } from './apis/search/search-api';
|
||||
export class RepoClient {
|
||||
constructor(
|
||||
private username: string = RepoClientAuth.DEFAULT_USERNAME,
|
||||
private password: string = RepoClientAuth.DEFAULT_PASSWORD,
|
||||
private config?: RepoClientConfig
|
||||
private password: string = RepoClientAuth.DEFAULT_PASSWORD
|
||||
) {}
|
||||
|
||||
private get auth(): RepoClientAuth {
|
||||
@@ -50,7 +49,7 @@ export class RepoClient {
|
||||
}
|
||||
|
||||
get nodes() {
|
||||
return new NodesApi(this.auth, this.config);
|
||||
return new NodesApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get sites() {
|
||||
@@ -58,7 +57,7 @@ export class RepoClient {
|
||||
}
|
||||
|
||||
get favorites() {
|
||||
return new FavoritesApi(this.auth, this.config);
|
||||
return new FavoritesApi(this.auth.username, this.auth.password);
|
||||
}
|
||||
|
||||
get shared() {
|
||||
|
@@ -1,63 +0,0 @@
|
||||
/*!
|
||||
* @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/>.
|
||||
*/
|
||||
|
||||
interface RequestConfig {
|
||||
timeout?: number;
|
||||
noDelay?: boolean;
|
||||
keepAlive?: boolean;
|
||||
keepAliveDelay?: number;
|
||||
}
|
||||
|
||||
interface ResponseConfig {
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
interface ResponseRequest {
|
||||
method: string;
|
||||
path: string;
|
||||
data: string;
|
||||
}
|
||||
|
||||
export interface NodeRestClient {
|
||||
get(uri: string, callback: Function): Function;
|
||||
post(uri: string, callback: Function): Function;
|
||||
put(uri: string, callback: Function): Function;
|
||||
delete(uri: string, callback: Function): Function;
|
||||
}
|
||||
|
||||
export interface RestClientArgs {
|
||||
data?: any;
|
||||
parameters?: any;
|
||||
headers?: any;
|
||||
requestConfig?: RequestConfig;
|
||||
responseConfig?: ResponseConfig;
|
||||
}
|
||||
|
||||
export interface RestClientResponse {
|
||||
request: ResponseRequest;
|
||||
data: any;
|
||||
statusMessage: string;
|
||||
statusCode: number;
|
||||
}
|
@@ -1,89 +0,0 @@
|
||||
/*!
|
||||
* @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 { Client } from 'node-rest-client';
|
||||
import { NodeRestClient, RestClientArgs, RestClientResponse } from './rest-client-models';
|
||||
|
||||
export * from './rest-client-models';
|
||||
|
||||
export class RestClient {
|
||||
private static DEFAULT_HEADERS = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
};
|
||||
|
||||
private client: NodeRestClient;
|
||||
|
||||
constructor(user: string, password: string) {
|
||||
this.client = <NodeRestClient>(new Client({ user, password }));
|
||||
}
|
||||
|
||||
get(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
|
||||
return this.promisify('get', uri, args);
|
||||
}
|
||||
|
||||
post(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
|
||||
return this.promisify('post', uri, args);
|
||||
}
|
||||
|
||||
put(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
|
||||
return this.promisify('put', uri, args);
|
||||
}
|
||||
|
||||
delete(uri: string, args: RestClientArgs = {}): Promise<RestClientResponse> {
|
||||
return this.promisify('delete', uri, args);
|
||||
}
|
||||
|
||||
private createArgs(args: RestClientArgs = {}): RestClientArgs {
|
||||
const data = JSON.stringify(args.data);
|
||||
|
||||
return Object.assign({}, RestClient.DEFAULT_HEADERS, args, { data });
|
||||
}
|
||||
|
||||
private promisify(fnName: string, uri: string, args: RestClientArgs): Promise<RestClientResponse> {
|
||||
const fn: Function = this.client[fnName];
|
||||
const fnArgs = [ encodeURI(uri), this.createArgs(args) ];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const fnCallback = (data, rawResponse) => {
|
||||
const {
|
||||
statusCode, statusMessage,
|
||||
req: { method, path }
|
||||
} = rawResponse;
|
||||
|
||||
const response: RestClientResponse = {
|
||||
data, statusCode, statusMessage,
|
||||
request: { method, path, data: args.data }
|
||||
};
|
||||
|
||||
(response.statusCode >= 400)
|
||||
? reject(response)
|
||||
: resolve(response);
|
||||
};
|
||||
|
||||
fn(...fnArgs, fnCallback);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user