[ACS-7688] Reduce the usage of LogService and TranslateModule (tests) (#9567)

This commit is contained in:
Denys Vuika
2024-04-19 12:14:33 -04:00
committed by GitHub
parent caa2166151
commit 54c3e12ad8
275 changed files with 4090 additions and 5551 deletions

View File

@@ -16,7 +16,7 @@
*/
import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core';
import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core';
import { from, Observable, of, zip } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { AspectEntry, AspectPaging, AspectsApi } from '@alfresco/js-api';
@@ -25,17 +25,13 @@ import { AspectEntry, AspectPaging, AspectsApi } from '@alfresco/js-api';
providedIn: 'root'
})
export class AspectListService {
private _aspectsApi: AspectsApi;
get aspectsApi(): AspectsApi {
this._aspectsApi = this._aspectsApi ?? new AspectsApi(this.alfrescoApiService.getInstance());
return this._aspectsApi;
}
constructor(private alfrescoApiService: AlfrescoApiService,
private appConfigService: AppConfigService,
private logService: LogService) {
}
constructor(private alfrescoApiService: AlfrescoApiService, private appConfigService: AppConfigService) {}
getAspects(): Observable<AspectEntry[]> {
const visibleAspectList = this.getVisibleAspects();
@@ -52,14 +48,11 @@ export class AspectListService {
where,
include: ['properties']
};
return from(this.aspectsApi.listAspects(opts))
.pipe(
map((result: AspectPaging) => this.filterAspectByConfig(whiteList, result?.list?.entries)),
catchError((error) => {
this.logService.error(error);
return of([]);
})
);
return from(this.aspectsApi.listAspects(opts)).pipe(
map((result: AspectPaging) => this.filterAspectByConfig(whiteList, result?.list?.entries)),
catchError(() => of([]))
);
}
getCustomAspects(whiteList?: string[]): Observable<AspectEntry[]> {
@@ -68,14 +61,10 @@ export class AspectListService {
where,
include: ['properties']
};
return from(this.aspectsApi.listAspects(opts))
.pipe(
map((result: AspectPaging) => this.filterAspectByConfig(whiteList, result?.list?.entries)),
catchError((error) => {
this.logService.error(error);
return of([]);
})
);
return from(this.aspectsApi.listAspects(opts)).pipe(
map((result: AspectPaging) => this.filterAspectByConfig(whiteList, result?.list?.entries)),
catchError(() => of([]))
);
}
private filterAspectByConfig(visibleAspectList: string[], aspectEntries: AspectEntry[]): AspectEntry[] {
@@ -96,5 +85,4 @@ export class AspectListService {
}
return visibleAspectList;
}
}

View File

@@ -17,13 +17,12 @@
import { Injectable } from '@angular/core';
import { ContentApi, RenditionEntry, RenditionPaging, RenditionsApi, VersionsApi } from '@alfresco/js-api';
import { AlfrescoApiService , LogService, Track,TranslationService, ViewUtilService } from '@alfresco/adf-core';
import { AlfrescoApiService, Track, TranslationService, ViewUtilService } from '@alfresco/adf-core';
@Injectable({
providedIn: 'root'
})
export class RenditionService {
static TARGET = '_new';
/**
@@ -53,7 +52,6 @@ export class RenditionService {
*/
private TRY_TIMEOUT: number = 10000;
_renditionsApi: RenditionsApi;
get renditionsApi(): RenditionsApi {
this._renditionsApi = this._renditionsApi ?? new RenditionsApi(this.apiService.getInstance());
@@ -74,17 +72,12 @@ export class RenditionService {
return this._versionsApi;
}
constructor(private apiService: AlfrescoApiService,
private logService: LogService,
private translateService: TranslationService,
private viewUtilsService: ViewUtilService) {
}
constructor(private apiService: AlfrescoApiService, private translateService: TranslationService, private viewUtilsService: ViewUtilService) {}
getRenditionUrl(nodeId: string, type: string, renditionExists: boolean): string {
return (renditionExists && type !== RenditionService.ContentGroup.IMAGE) ?
this.contentApi.getRenditionUrl(nodeId, RenditionService.ContentGroup.PDF) :
this.contentApi.getContentUrl(nodeId, false);
return renditionExists && type !== RenditionService.ContentGroup.IMAGE
? this.contentApi.getRenditionUrl(nodeId, RenditionService.ContentGroup.PDF)
: this.contentApi.getContentUrl(nodeId, false);
}
private async waitRendition(nodeId: string, renditionId: string, retries: number): Promise<RenditionEntry> {
@@ -110,18 +103,18 @@ export class RenditionService {
async getRendition(nodeId: string, renditionId: string): Promise<RenditionEntry> {
const renditionPaging: RenditionPaging = await this.renditionsApi.listRenditions(nodeId);
let rendition: RenditionEntry = renditionPaging.list.entries.find((renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId);
let rendition: RenditionEntry = renditionPaging.list.entries.find(
(renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId
);
if (rendition) {
const status = rendition.entry.status.toString();
if (status === 'NOT_CREATED') {
try {
await this.renditionsApi.createRendition(nodeId, {id: renditionId});
await this.renditionsApi.createRendition(nodeId, { id: renditionId });
rendition = await this.waitRendition(nodeId, renditionId, 0);
} catch (err) {
this.logService.error(err);
}
} catch {}
}
}
return new Promise<RenditionEntry>((resolve) => resolve(rendition));
@@ -129,10 +122,8 @@ export class RenditionService {
async getNodeRendition(nodeId: string, versionId?: string): Promise<{ url: string; mimeType: string }> {
try {
return versionId ? await this.resolveNodeRendition(nodeId, 'pdf', versionId) :
await this.resolveNodeRendition(nodeId, 'pdf');
} catch (err) {
this.logService.error(err);
return versionId ? await this.resolveNodeRendition(nodeId, 'pdf', versionId) : await this.resolveNodeRendition(nodeId, 'pdf');
} catch {
return null;
}
}
@@ -140,8 +131,9 @@ export class RenditionService {
private async resolveNodeRendition(nodeId: string, renditionId: string, versionId?: string): Promise<{ url: string; mimeType: string }> {
renditionId = renditionId.toLowerCase();
const supportedRendition: RenditionPaging = versionId ? await this.versionsApi.listVersionRenditions(nodeId, versionId) :
await this.renditionsApi.listRenditions(nodeId);
const supportedRendition: RenditionPaging = versionId
? await this.versionsApi.listVersionRenditions(nodeId, versionId)
: await this.renditionsApi.listRenditions(nodeId);
let rendition = this.findRenditionById(supportedRendition, renditionId);
if (!rendition) {
@@ -154,9 +146,9 @@ export class RenditionService {
const mimeType: string = rendition.entry.content.mimeType;
if (status === 'NOT_CREATED') {
return {url: await this.requestCreateRendition(nodeId, renditionId, versionId), mimeType};
return { url: await this.requestCreateRendition(nodeId, renditionId, versionId), mimeType };
} else {
return {url: await this.handleNodeRendition(nodeId, renditionId, versionId), mimeType};
return { url: await this.handleNodeRendition(nodeId, renditionId, versionId), mimeType };
}
}
@@ -166,25 +158,22 @@ export class RenditionService {
private async requestCreateRendition(nodeId: string, renditionId: string, versionId: string): Promise<string> {
try {
if (versionId) {
await this.versionsApi.createVersionRendition(nodeId, versionId, {id: renditionId});
await this.versionsApi.createVersionRendition(nodeId, versionId, { id: renditionId });
} else {
await this.renditionsApi.createRendition(nodeId, {id: renditionId});
await this.renditionsApi.createRendition(nodeId, { id: renditionId });
}
try {
return versionId ? await this.waitNodeRendition(nodeId, renditionId, versionId) : await this.waitNodeRendition(nodeId, renditionId);
} catch (e) {
return null;
}
} catch (err) {
this.logService.error(err);
} catch {
return null;
}
}
private findRenditionById(supportedRendition: RenditionPaging, renditionId: string) {
const rendition: RenditionEntry = supportedRendition.list.entries.find((renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId);
return rendition;
return supportedRendition.list.entries.find((renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId);
}
private async waitNodeRendition(nodeId: string, renditionId: string, versionId?: string): Promise<string> {
@@ -194,23 +183,29 @@ export class RenditionService {
currentRetry++;
if (this.maxRetries >= currentRetry) {
if (versionId) {
this.versionsApi.getVersionRendition(nodeId, versionId, renditionId).then((rendition: RenditionEntry) => {
const status: string = rendition.entry.status.toString();
this.versionsApi.getVersionRendition(nodeId, versionId, renditionId).then(
(rendition: RenditionEntry) => {
const status: string = rendition.entry.status.toString();
if (status === 'CREATED') {
clearInterval(intervalId);
return resolve(this.handleNodeRendition(nodeId, rendition.entry.content.mimeType, versionId));
}
}, () => reject(new Error('Error geting version rendition')));
if (status === 'CREATED') {
clearInterval(intervalId);
return resolve(this.handleNodeRendition(nodeId, rendition.entry.content.mimeType, versionId));
}
},
() => reject(new Error('Error geting version rendition'))
);
} else {
this.renditionsApi.getRendition(nodeId, renditionId).then((rendition: RenditionEntry) => {
const status: string = rendition.entry.status.toString();
this.renditionsApi.getRendition(nodeId, renditionId).then(
(rendition: RenditionEntry) => {
const status: string = rendition.entry.status.toString();
if (status === 'CREATED') {
clearInterval(intervalId);
return resolve(this.handleNodeRendition(nodeId, renditionId, versionId));
}
}, () => reject(new Error('Error getting rendition')));
if (status === 'CREATED') {
clearInterval(intervalId);
return resolve(this.handleNodeRendition(nodeId, renditionId, versionId));
}
},
() => reject(new Error('Error getting rendition'))
);
}
} else {
clearInterval(intervalId);
@@ -221,11 +216,9 @@ export class RenditionService {
}
private async handleNodeRendition(nodeId: string, renditionId: string, versionId?: string): Promise<string> {
const url = versionId ? this.contentApi.getVersionRenditionUrl(nodeId, versionId, renditionId) :
this.contentApi.getRenditionUrl(nodeId, renditionId);
return url;
return versionId
? this.contentApi.getVersionRenditionUrl(nodeId, versionId, renditionId)
: this.contentApi.getRenditionUrl(nodeId, renditionId);
}
async generateMediaTracksRendition(nodeId: string): Promise<Track[]> {
@@ -241,16 +234,14 @@ export class RenditionService {
}
return tracks;
})
.catch((err) => {
this.logService.error('Error while retrieving ' + RenditionService.SUBTITLES_RENDITION_NAME + ' rendition');
this.logService.error(err);
return [];
});
.catch(() => []);
}
private async isRenditionAvailable(nodeId: string, renditionId: string): Promise<boolean> {
const renditionPaging: RenditionPaging = await this.renditionsApi.listRenditions(nodeId);
const rendition: RenditionEntry = renditionPaging.list.entries.find((renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId);
const rendition: RenditionEntry = renditionPaging.list.entries.find(
(renditionEntry: RenditionEntry) => renditionEntry.entry.id.toLowerCase() === renditionId
);
return rendition?.entry?.status?.toString() === 'CREATED' || false;
}
@@ -297,15 +288,13 @@ export class RenditionService {
this.getRendition(nodeId, RenditionService.ContentGroup.PDF)
.then((value) => {
const url: string = this.getRenditionUrl(nodeId, type, (!!value));
const printType = (type === RenditionService.ContentGroup.PDF
|| type === RenditionService.ContentGroup.TEXT)
? RenditionService.ContentGroup.PDF : type;
const url: string = this.getRenditionUrl(nodeId, type, !!value);
const printType =
type === RenditionService.ContentGroup.PDF || type === RenditionService.ContentGroup.TEXT
? RenditionService.ContentGroup.PDF
: type;
this.printFile(url, printType);
})
.catch((err) => {
this.logService.error('Error with Printing');
this.logService.error(err);
});
.catch(() => {});
}
}

View File

@@ -16,7 +16,7 @@
*/
import { TestBed } from '@angular/core/testing';
import { AlfrescoApiService, LogService, TranslationService, ViewUtilService } from '@alfresco/adf-core';
import { AlfrescoApiService, TranslationService, ViewUtilService } from '@alfresco/adf-core';
import { Rendition, RenditionEntry, RenditionPaging, RenditionsApi } from '@alfresco/js-api';
import { RenditionService } from '@alfresco/adf-content-services';
@@ -28,7 +28,7 @@ const getRenditionEntry = (status: Rendition.StatusEnum): RenditionEntry => ({
}
});
const getRenditionPaging = (status: Rendition.StatusEnum): RenditionPaging => ({
const getRenditionPaging = (status: Rendition.StatusEnum): RenditionPaging => ({
list: {
entries: [getRenditionEntry(status)]
}
@@ -43,14 +43,16 @@ describe('RenditionService', () => {
providers: [
RenditionService,
{ provide: AlfrescoApiService, useValue: {} },
{ provide: LogService, useValue: { error: jasmine.createSpy('error') } },
{ provide: TranslationService, useValue: {} },
{ provide: ViewUtilService, useValue: {} },
{ provide: RenditionsApi, useValue: {
{
provide: RenditionsApi,
useValue: {
listRenditions: jasmine.createSpy('listRenditions'),
getRendition: jasmine.createSpy('getRendition'),
createRendition: jasmine.createSpy('createRendition')
} }
}
}
]
});
renditionService = TestBed.inject(RenditionService);
@@ -77,9 +79,9 @@ describe('RenditionService', () => {
renditionsApi.listRenditions.and.returnValue(Promise.resolve(mockRenditionPaging));
renditionsApi.getRendition.and.returnValues(
Promise.resolve(getRenditionEntry(Rendition.StatusEnum.NOTCREATED)),
Promise.resolve(getRenditionEntry(Rendition.StatusEnum.NOTCREATED)),
Promise.resolve(mockRenditionEntry)
Promise.resolve(getRenditionEntry(Rendition.StatusEnum.NOTCREATED)),
Promise.resolve(getRenditionEntry(Rendition.StatusEnum.NOTCREATED)),
Promise.resolve(mockRenditionEntry)
);
const result = await renditionService.getRendition('nodeId', 'pdf');
@@ -98,5 +100,4 @@ describe('RenditionService', () => {
expect(result).toEqual(mockRenditionPaging.list.entries[0]);
expect(renditionsApi.getRendition).not.toHaveBeenCalled();
});
});

View File

@@ -16,7 +16,7 @@
*/
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { LogService, InfiniteSelectScrollDirective, AuthenticationService } from '@alfresco/adf-core';
import { InfiniteSelectScrollDirective, AuthenticationService } from '@alfresco/adf-core';
import { SitePaging, SiteEntry, Site } from '@alfresco/js-api';
import { MatSelectChange } from '@angular/material/select';
import { LiveAnnouncer } from '@angular/cdk/a11y';
@@ -77,6 +77,9 @@ export class DropdownSitesComponent implements OnInit {
@Output()
change: EventEmitter<SiteEntry> = new EventEmitter();
@Output()
error = new EventEmitter<any>();
private loading = true;
private skipCount = 0;
@@ -86,7 +89,6 @@ export class DropdownSitesComponent implements OnInit {
constructor(
private authService: AuthenticationService,
private sitesService: SitesService,
private logService: LogService,
private liveAnnouncer: LiveAnnouncer,
private translateService: TranslateService
) {}
@@ -158,7 +160,7 @@ export class DropdownSitesComponent implements OnInit {
this.loading = false;
},
(error) => {
this.logService.error(error);
this.error.emit(error);
}
);
}

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { EXTENDIBLE_COMPONENT, FileUtils, LogService } from '@alfresco/adf-core';
import { EXTENDIBLE_COMPONENT, FileUtils } from '@alfresco/adf-core';
import { Component, EventEmitter, forwardRef, Input, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, inject } from '@angular/core';
import { NodesApiService } from '../../common/services/nodes-api.service';
import { ContentService } from '../../common/services/content.service';
@@ -36,7 +36,6 @@ import { NodeAllowableOperationSubject } from '../../interfaces/node-allowable-o
export class UploadButtonComponent extends UploadBase implements OnInit, OnChanges, NodeAllowableOperationSubject {
private contentService = inject(ContentService);
private nodesApiService = inject(NodesApiService);
protected logService = inject(LogService);
/** Allows/disallows upload folders (only for Chrome). */
@Input()

View File

@@ -32,7 +32,6 @@ import {
import {
AlfrescoApiService,
CloseButtonPosition,
LogService,
Track,
ViewerComponent,
ViewerMoreActionsComponent,
@@ -241,7 +240,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
private nodesApiService: NodesApiService,
private renditionService: RenditionService,
private viewUtilService: ViewUtilService,
private logService: LogService,
private contentService: ContentService,
private uploadService: UploadService,
public dialog: MatDialog,
@@ -256,9 +254,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
.pipe(
filter(
(node) =>
node &&
node.id === this.nodeId &&
this.getNodeVersionProperty(this.nodeEntry.entry) !== this.getNodeVersionProperty(node)
node && node.id === this.nodeId && this.getNodeVersionProperty(this.nodeEntry.entry) !== this.getNodeVersionProperty(node)
),
takeUntil(this.onDestroy$)
)
@@ -284,7 +280,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
const sharedLinkEntry = await this.sharedLinksApi.getSharedLink(this.sharedLinkId);
await this.setUpSharedLinkFile(sharedLinkEntry);
} catch (error) {
this.logService.error('This sharedLink does not exist');
this.invalidSharedLink.next(undefined);
this.mimeType = 'invalid-link';
this.urlFileContent = 'invalid-file';
@@ -303,7 +298,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
}
} catch (error) {
this.urlFileContent = 'invalid-node';
this.logService.error('This node does not exist');
}
}
@@ -373,7 +367,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
return { url: urlFileContent, mimeType: 'application/pdf' };
}
} catch (error) {
this.logService.error(error);
try {
const rendition: RenditionEntry = await this.sharedLinksApi.getSharedLinkRendition(sharedId, 'imgpreview');
if (rendition.entry.status.toString() === 'CREATED') {
@@ -381,7 +374,6 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
return { url: urlFileContent, mimeType: 'image/png' };
}
} catch (renditionError) {
this.logService.error(renditionError);
return null;
}
}