[ADF-5426] Remove compatibility layer from Lib (#7110)

* remove compatibility step 1

* remove compatibility step 2

* remove compatibility step 3

* remove compatibility step 4

* remove compatibility step 5
This commit is contained in:
Eugenio Romano
2021-08-04 17:31:35 +02:00
committed by GitHub
parent 5d5b582e32
commit f30b20cc46
113 changed files with 1375 additions and 2348 deletions

View File

@@ -29,7 +29,6 @@ import {
FormService,
DownloadService,
AppConfigService,
AlfrescoApiService,
UploadWidgetContentLinkModel
} from '@alfresco/adf-core';
import {
@@ -79,7 +78,6 @@ describe('AttachFileCloudWidgetComponent', () => {
let processCloudContentService: ProcessCloudContentService;
let formService: FormService;
let downloadService: DownloadService;
let alfrescoApiService: AlfrescoApiService;
let contentNodeSelectorPanelService: ContentNodeSelectorPanelService;
let apiServiceSpy: jasmine.Spy;
let contentModelFormFileHandlerSpy: jasmine.Spy;
@@ -127,7 +125,6 @@ describe('AttachFileCloudWidgetComponent', () => {
AppConfigService
);
formService = TestBed.inject(FormService);
alfrescoApiService = TestBed.inject(AlfrescoApiService);
contentNodeSelectorPanelService = TestBed.inject(ContentNodeSelectorPanelService);
openUploadFileDialogSpy = spyOn(contentCloudNodeSelectorService, 'openUploadFileDialog').and.returnValue(of([fakeMinimalNode]));
});
@@ -533,7 +530,7 @@ describe('AttachFileCloudWidgetComponent', () => {
describe('when a file is uploaded', () => {
beforeEach(async () => {
apiServiceSpy = spyOn(alfrescoApiService.getInstance().node, 'getNode').and.returnValue(new Promise(resolve => resolve({entry: fakeNodeWithProperties})));
apiServiceSpy = spyOn(widget['nodesApi'], 'getNode').and.returnValue(new Promise(resolve => resolve({entry: fakeNodeWithProperties})));
spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(new Promise(resolve => resolve('fake-properties')));
openUploadFileDialogSpy.and.returnValue(of([fakeNodeWithProperties]));
widget.field = new FormFieldModel(new FormModel(), {
@@ -700,7 +697,7 @@ describe('AttachFileCloudWidgetComponent', () => {
describe('contentModelFormFileHandler', () => {
beforeEach(async () => {
apiServiceSpy = spyOn(alfrescoApiService.getInstance().node, 'getNode').and.returnValue(new Promise(resolve => resolve({ entry: fakeNodeWithProperties })));
apiServiceSpy = spyOn(widget['nodesApi'], 'getNode').and.returnValue(new Promise(resolve => resolve({ entry: fakeNodeWithProperties })));
contentModelFormFileHandlerSpy = spyOn(widget, 'contentModelFormFileHandler').and.callThrough();
updateFormSpy = spyOn(formService.updateFormValuesRequested, 'next');
contentClickedSpy = spyOn(formService.formContentClicked, 'next');

View File

@@ -29,7 +29,7 @@ import {
AlfrescoApiService,
UploadWidgetContentLinkModel
} from '@alfresco/adf-core';
import { Node, RelatedContentRepresentation } from '@alfresco/js-api';
import { Node, NodesApi, RelatedContentRepresentation } from '@alfresco/js-api';
import { ContentCloudNodeSelectorService } from '../../../services/content-cloud-node-selector.service';
import { ProcessCloudContentService } from '../../../services/process-cloud-content.service';
import { UploadCloudWidgetComponent } from './upload-cloud.widget';
@@ -67,6 +67,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
rootNodeId = AttachFileCloudWidgetComponent.ALIAS_USER_FOLDER;
selectedNode: Node;
private nodesApi: NodesApi;
constructor(
formService: FormService,
logger: LogService,
@@ -79,6 +81,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
private contentNodeSelectorPanelService: ContentNodeSelectorPanelService
) {
super(formService, thumbnails, processCloudContentService, notificationService, logger);
this.nodesApi = new NodesApi(this.apiService.getInstance());
}
ngOnInit() {
@@ -222,7 +225,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
contentModelFormFileHandler(file?: any) {
if (file?.id && this.isRetrieveMetadataOptionEnabled()) {
const values: FormValues = {};
this.apiService.getInstance().node.getNode(file.id).then(acsNode => {
this.nodesApi.getNode(file.id).then(acsNode => {
const metadata = acsNode?.entry?.properties;
if (metadata) {
const keys = Object.keys(metadata);

View File

@@ -1,143 +0,0 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { TestBed } from '@angular/core/testing';
import { AlfrescoApiService, NotificationService, setupTestBed } from '@alfresco/adf-core';
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { ContentCloudNodeSelectorService } from 'process-services-cloud';
import { MatDialog } from '@angular/material/dialog';
import { of, Subject } from 'rxjs';
import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData } from '@alfresco/adf-content-services';
describe('ContentCloudNodeSelectorService', () => {
let service: ContentCloudNodeSelectorService;
let apiService: AlfrescoApiService;
let notificationService: NotificationService;
let getNodeSpy: jasmine.Spy;
let dialog: MatDialog;
let openDialogSpy: jasmine.Spy;
let showWarningSpy: jasmine.Spy;
const relativePathNodeResponseBody = {
entry: {
id: 'mock-relative-path-node-id'
}
};
const aliasNodeResponseBody = {
entry: {
id: 'mock-alias-node-id'
}
};
setupTestBed({
imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule]
});
beforeEach(() => {
service = TestBed.inject(ContentCloudNodeSelectorService);
notificationService = TestBed.inject(NotificationService);
apiService = TestBed.inject(AlfrescoApiService);
dialog = TestBed.inject(MatDialog);
showWarningSpy = spyOn(notificationService, 'showWarning');
openDialogSpy = spyOn(dialog, 'open').and.callFake(() => ({
afterOpened: () => of({}),
afterClosed: () => of({}),
componentInstance: {
body: '',
error: new Subject<any>()
}
}));
getNodeSpy = spyOn(apiService.nodesApi, 'getNode');
});
it('should be able to open the content node select panel dialog', () => {
const mockData = <ContentNodeSelectorComponentData> {
title: 'Select a file',
actionName: 'ATTACH',
currentFolderId: 'nodeId',
selectionMode: 'single'
};
service.openUploadFileDialog('nodeId', 'single', true, true);
const args = openDialogSpy.calls.allArgs()[0];
expect(openDialogSpy).toHaveBeenCalled();
expect(args[0]).toEqual(ContentNodeSelectorComponent);
expect(args[1].data.title).toEqual(mockData.title);
expect(args[1].data.actionName).toEqual(mockData.actionName);
expect(args[1].panelClass).toEqual('adf-content-node-selector-dialog');
expect(args[1].data.selectionMode).toEqual(mockData.selectionMode);
expect(args[1].data.currentFolderId).toEqual('nodeId');
});
it('should be able to set sourceNodeNotFound value to true if the relative path is invalid/deleted', async () => {
expect(service.sourceNodeNotFound).toBe(false);
getNodeSpy.and.returnValue(Promise.reject('Not exists'));
await service.fetchNodeIdFromRelativePath('mock-alias', { relativePath: 'mock-wrong-relativePath' });
expect(getNodeSpy).toHaveBeenCalledWith('mock-alias', {
relativePath: 'mock-wrong-relativePath'
});
expect(service.sourceNodeNotFound).toBe(true);
});
it('should be able to set sourceNodeNotFound value to false after the dialog close', async () => {
service.sourceNodeNotFound = true;
service.openUploadFileDialog('nodeId', 'single', true, true);
service.close();
expect(service.sourceNodeNotFound).toBe(false);
});
it('should be able to show a notification if the relative path is invalid/deleted', () => {
service.sourceNodeNotFound = true;
service.openUploadFileDialog('nodeId', 'single', true, true);
expect(showWarningSpy).toHaveBeenCalledWith('ADF_CLOUD_TASK_FORM.ERROR.DESTINATION_FOLDER_PATH_ERROR');
});
it('should not show a notification if the relative path is valid', () => {
service.sourceNodeNotFound = false;
service.openUploadFileDialog('nodeId', 'single', true, true);
expect(showWarningSpy).not.toHaveBeenCalled();
});
it('should be able to fetch given relative path node id', async () => {
getNodeSpy.and.returnValue(Promise.resolve(relativePathNodeResponseBody));
await service.fetchNodeIdFromRelativePath('mock-alias', { relativePath: 'mock-relativePath' });
expect(getNodeSpy).toHaveBeenCalledWith('mock-alias', {
relativePath: 'mock-relativePath'
});
expect(service.sourceNodeNotFound).toBe(false);
});
it('should be able to fetch given alias node id', async () => {
getNodeSpy.and.returnValue(Promise.resolve(aliasNodeResponseBody));
await service.fetchAliasNodeId('mock-alias');
expect(getNodeSpy).toHaveBeenCalledWith('mock-alias');
});
});

View File

@@ -18,21 +18,27 @@
import { Injectable } from '@angular/core';
import { AlfrescoApiService, NotificationService } from '@alfresco/adf-core';
import { MatDialog } from '@angular/material/dialog';
import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, NodeAction } from '@alfresco/adf-content-services';
import { Node } from '@alfresco/js-api';
import {
ContentNodeSelectorComponent,
ContentNodeSelectorComponentData,
NodeAction
} from '@alfresco/adf-content-services';
import { Node, NodesApi } from '@alfresco/js-api';
import { Observable, Subject, throwError } from 'rxjs';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class ContentCloudNodeSelectorService {
nodesApi: NodesApi;
sourceNodeNotFound = false;
constructor(
private apiService: AlfrescoApiService,
private notificationService: NotificationService,
private dialog: MatDialog) {
this.nodesApi = new NodesApi(this.apiService.getInstance());
}
openUploadFileDialog(currentFolderId?: string, selectionMode?: string, isAllFileSources?: boolean, restrictRootToCurrentFolderId?: boolean): Observable<Node[]> {
@@ -55,7 +61,7 @@ export class ContentCloudNodeSelectorService {
}
async fetchNodeIdFromRelativePath(alias: string, opts: { relativePath: string }): Promise<string> {
const relativePathNodeEntry: any = await this.apiService.nodesApi
const relativePathNodeEntry: any = await this.nodesApi
.getNode(alias, opts)
.catch((err) => {
this.sourceNodeNotFound = true;
@@ -65,9 +71,9 @@ export class ContentCloudNodeSelectorService {
}
async fetchAliasNodeId(alias: string): Promise<string> {
const aliasNodeEntry: any = await this.apiService.nodesApi
.getNode(alias)
.catch((err) => this.handleError(err));
const aliasNodeEntry: any = await this.nodesApi
.getNode(alias)
.catch((err) => this.handleError(err));
return aliasNodeEntry?.entry?.id;
}

View File

@@ -26,7 +26,7 @@ import {
import { Observable, from } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model';
import { CompleteFormRepresentation } from '@alfresco/js-api';
import { CompleteFormRepresentation, UploadApi } from '@alfresco/js-api';
import { TaskVariableCloud } from '../models/task-variable-cloud.model';
import { BaseCloudService } from '../../services/base-cloud.service';
import { FormContent } from '../../services/form-fields.interfaces';
@@ -36,11 +36,14 @@ import { FormContent } from '../../services/form-fields.interfaces';
})
export class FormCloudService extends BaseCloudService {
uploadApi: UploadApi;
constructor(
apiService: AlfrescoApiService,
appConfigService: AppConfigService
) {
super(apiService, appConfigService);
this.uploadApi = new UploadApi(apiService.getInstance());
}
/**
@@ -99,7 +102,7 @@ export class FormCloudService extends BaseCloudService {
changedConfig.provider = 'ALL';
changedConfig.hostEcm = contentHost.replace('/alfresco', '');
this.apiService.getInstance().setConfig(changedConfig);
return from(this.apiService.getInstance().upload.uploadFile(
return from(this.uploadApi.uploadFile(
file,
'',
nodeId,

View File

@@ -24,18 +24,25 @@ import {
ContentService,
DownloadService
} from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api';
import { AuthenticationApi, Node, UploadApi } from '@alfresco/js-api';
@Injectable({
providedIn: 'root'
})
export class ProcessCloudContentService {
uploadApi: UploadApi;
authenticationApi: AuthenticationApi;
constructor(
private apiService: AlfrescoApiService,
private logService: LogService,
public contentService: ContentService,
private downloadService: DownloadService
) {}
) {
this.uploadApi = new UploadApi(this.apiService.getInstance());
this.authenticationApi = new AuthenticationApi(this.apiService.getInstance());
}
createTemporaryRawRelatedContent(
file: File,
@@ -43,9 +50,7 @@ export class ProcessCloudContentService {
): Observable<Node> {
return from(
this.apiService
.getInstance()
.upload.uploadFile(file, '', nodeId, '', { overwrite: true })
this.uploadApi.uploadFile(file, '', nodeId, '', { overwrite: true })
).pipe(
map((res: any) => {
return {
@@ -74,8 +79,7 @@ export class ProcessCloudContentService {
}
async getAuthTicket(): Promise<string> {
const { auth } = this.apiService.getInstance();
const ticket = await auth.authenticationApi.getTicket();
const ticket = await this.authenticationApi.getTicket();
if (ticket && ticket.entry) {
return ticket.entry.id || '';