[ACS-6227] cleanup error handling and fix typing issues (#9035)

* cleanup audit service, remove useless ajax tests

* cleanup sites service and remove useless ajax tests

* cleanup services

* cleanup services

* fix typings

* code cleanup
This commit is contained in:
Denys Vuika
2023-10-27 13:51:28 +01:00
committed by GitHub
parent 53ad9f729b
commit 2d3175ef4a
24 changed files with 319 additions and 937 deletions

View File

@@ -1,202 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* 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 { AuditService } from './audit.service';
import { AppConfigService } from '@alfresco/adf-core';
import { TranslateModule } from '@ngx-translate/core';
import { ContentTestingModule } from '../testing/content.testing.module';
import { TestBed } from '@angular/core/testing';
declare let jasmine: any;
describe('AuditService', () => {
let service: AuditService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
ContentTestingModule
]
});
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
appConfig.config = {
ecmHost: 'http://localhost:9876/ecm',
files: {
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git']
}
};
service = TestBed.inject(AuditService);
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('Should get Audit Applications', (done) => {
service.getAuditApps().subscribe((data) => {
expect(data.list.pagination.count).toBe(3);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
list: {
pagination: {
count: 3,
hasMoreItems: false,
totalItems: 3,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
isEnabled: true,
name: 'Alfresco Tagging Service',
id: 'tagging'
}
},
{
entry: {
isEnabled: true,
name: 'ShareSiteAccess',
id: 'share-site-access'
}
},
{
entry: {
isEnabled: true,
name: 'alfresco-access',
id: 'alfresco-access'
}
}
]
}
}
});
});
it('Should get an Audit Application', (done) => {
service.getAuditApp('alfresco-access').subscribe((data) => {
expect(data.entry.id).toBe('alfresco-access');
expect(data.entry.name).toBe('alfresco-access');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
entry: {
id: 'alfresco-access',
name: 'alfresco-access',
isEnabled: true
}
}
});
});
it('Should get Audit Entries', (done) => {
service.getAuditEntries('alfresco-access').subscribe((data) => {
expect(data.list.pagination.count).toBe(3);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
list: {
pagination: {
count: 3,
hasMoreItems: false,
totalItems: 3,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
id: '1',
auditApplicationId: 'alfresco-access',
createdByUser: {
displayName: 'admin',
id: 'admin'
},
createdAt: '2020-08-11T13:11:59.141Z',
values: {}
}
},
{
entry: {
id: '2',
auditApplicationId: 'alfresco-access',
createdByUser: {
displayName: 'admin',
id: 'admin'
},
createdAt: '2020-08-11T13:11:59.141Z',
values: {}
}
},
{
entry: {
id: '3',
auditApplicationId: 'alfresco-access',
createdByUser: {
displayName: 'admin',
id: 'admin'
},
createdAt: '2020-08-11T13:11:59.141Z',
values: {}
}
}
]
}
}
});
});
it('Should get an Audit Entry', (done) => {
service.getAuditEntry('alfresco-access', '1').subscribe((data) => {
expect(data.entry.id).toBe('1');
expect(data.entry.auditApplicationId).toBe('alfresco-access');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
entry: {
id: '1',
auditApplicationId: 'alfresco-access',
createdByUser: {
displayName: 'admin',
id: 'admin'
},
createdAt: '2020-08-11T13:11:59.148Z',
values: {}
}
}
});
});
});

View File

@@ -16,10 +16,9 @@
*/
import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs';
import { AlfrescoApiService, LogService } from '@alfresco/adf-core';
import { AuditApi, AuditAppPaging, AuditAppEntry, AuditApp, AuditBodyUpdate, AuditEntryPaging, AuditEntryEntry } from '@alfresco/js-api';
import { catchError } from 'rxjs/operators';
import { Observable, from } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { AuditApi, AuditAppPaging, AuditApp, AuditBodyUpdate, AuditEntryPaging, AuditEntryEntry } from '@alfresco/js-api';
@Injectable({
providedIn: 'root'
@@ -31,7 +30,7 @@ export class AuditService {
return this._auditApi;
}
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
constructor(private apiService: AlfrescoApiService) {}
/**
* Gets a list of audit applications.
@@ -44,7 +43,7 @@ export class AuditService {
skipCount: 0
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.listAuditApps(queryOptions)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.auditApi.listAuditApps(queryOptions));
}
/**
@@ -54,12 +53,12 @@ export class AuditService {
* @param opts Options.
* @returns status of an audit application.
*/
getAuditApp(auditApplicationId: string, opts?: any): Observable<AuditAppEntry> {
getAuditApp(auditApplicationId: string, opts?: any): Observable<AuditApp> {
const defaultOptions = {
auditApplicationId
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.getAuditApp(queryOptions)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.auditApi.getAuditApp(queryOptions));
}
/**
@@ -73,9 +72,7 @@ export class AuditService {
updateAuditApp(auditApplicationId: string, auditAppBodyUpdate: boolean, opts?: any): Observable<AuditApp | any> {
const defaultOptions = {};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.updateAuditApp(auditApplicationId, new AuditBodyUpdate({ isEnabled: auditAppBodyUpdate }), queryOptions)).pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.updateAuditApp(auditApplicationId, new AuditBodyUpdate({ isEnabled: auditAppBodyUpdate }), queryOptions));
}
/**
@@ -91,9 +88,7 @@ export class AuditService {
maxItems: 100
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.listAuditEntriesForAuditApp(auditApplicationId, queryOptions)).pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.listAuditEntriesForAuditApp(auditApplicationId, queryOptions));
}
/**
@@ -107,9 +102,7 @@ export class AuditService {
getAuditEntry(auditApplicationId: string, auditEntryId: string, opts?: any): Observable<AuditEntryEntry> {
const defaultOptions = {};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.getAuditEntry(auditApplicationId, auditEntryId, queryOptions)).pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.getAuditEntry(auditApplicationId, auditEntryId, queryOptions));
}
/**
@@ -124,7 +117,7 @@ export class AuditService {
nodeId
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.listAuditEntriesForNode(queryOptions)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.auditApi.listAuditEntriesForNode(queryOptions));
}
/**
@@ -135,7 +128,7 @@ export class AuditService {
* @returns void operation
*/
deleteAuditEntries(auditApplicationId: string, where: string): Observable<any> {
return from(this.auditApi.deleteAuditEntriesForAuditApp(auditApplicationId, where)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.auditApi.deleteAuditEntriesForAuditApp(auditApplicationId, where));
}
/**
@@ -146,11 +139,6 @@ export class AuditService {
* @returns void operation
*/
deleteAuditEntry(auditApplicationId: string, auditEntryId: string): Observable<any> {
return from(this.auditApi.deleteAuditEntry(auditApplicationId, auditEntryId)).pipe(catchError((err: any) => this.handleError(err)));
}
private handleError(error: any): any {
this.logService.error(error);
return throwError(error || 'Server error');
return from(this.auditApi.deleteAuditEntry(auditApplicationId, auditEntryId));
}
}

View File

@@ -1,156 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* 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 { AppConfigService, CoreTestingModule } from '@alfresco/adf-core';
import { SitesService } from './sites.service';
import { TranslateModule } from '@ngx-translate/core';
declare let jasmine: any;
describe('Sites service', () => {
let service: SitesService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CoreTestingModule
]
});
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
appConfig.config = {
ecmHost: 'http://localhost:9876/ecm',
files: {
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git']
}
};
service = TestBed.inject(SitesService);
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('Should get a list of users sites', (done) => {
service.getSites().subscribe((data) => {
expect(data.list.entries[0].entry.title).toBe('FAKE');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
list: {
pagination: {
count: 1,
hasMoreItems: false,
totalItems: 1,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
role: 'SiteManager',
visibility: 'PUBLIC',
guid: 'b4cff62a-664d-4d45-9302-98723eac1319',
description: 'This is a Sample Alfresco Team site.',
id: 'swsdp',
title: 'FAKE'
}
}
]
}
}
});
});
it('Should get single sites via siteId', (done) => {
service.getSite('fake-site-id').subscribe((data) => {
expect(data.entry.title).toBe('FAKE-SINGLE-TITLE');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
entry: {
role: 'SiteManager',
visibility: 'PUBLIC',
guid: 'b4cff62a-664d-4d45-9302-98723eac1319',
description: 'This is a Sample Alfresco Team site.',
id: 'swsdp',
preset: 'site-dashboard',
title: 'FAKE-SINGLE-TITLE'
}
}
});
});
it('should get a list of membership requests', (done) => {
service.getSiteMembershipRequests().subscribe((data) => {
expect(data.list.entries[0].entry.site.id).toBe('site-id');
expect(data.list.entries[0].entry.person.id).toBe('user-id');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
list: {
pagination: {
count: 1,
hasMoreItems: false,
totalItems: 1,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
id: 'site-id',
createdAt: '2020-05-13T07:46:36.180Z',
site: {
id: 'site-id',
guid: 'b4cff62a-664d-4d45-9302-98723eac1319',
title: 'Sample Site',
description: '',
visibility: 'MODERATED',
preset: 'preset',
role: 'Manager'
},
person: {
id: 'user-id',
firstName: 'string',
lastName: 'string',
displayName: 'string'
},
message: 'message'
}
}
]
}
}
});
});
});

View File

@@ -16,8 +16,8 @@
*/
import { Injectable } from '@angular/core';
import { from, Observable, throwError } from 'rxjs';
import { AlfrescoApiService, LogService } from '@alfresco/adf-core';
import { from, Observable } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import {
Node,
SiteBodyCreate,
@@ -32,7 +32,6 @@ import {
SitePaging,
SitesApi
} from '@alfresco/js-api';
import { catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
@@ -44,7 +43,7 @@ export class SitesService {
return this._sitesApi;
}
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
constructor(private apiService: AlfrescoApiService) {}
/**
* Create a site
@@ -53,7 +52,7 @@ export class SitesService {
* @returns site SiteEntry
*/
createSite(siteBody: SiteBodyCreate): Observable<SiteEntry> {
return from(this.sitesApi.createSite(siteBody)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.createSite(siteBody));
}
/**
@@ -68,7 +67,7 @@ export class SitesService {
include: ['properties']
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.sitesApi.listSites(queryOptions)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.listSites(queryOptions));
}
/**
@@ -79,7 +78,7 @@ export class SitesService {
* @returns Information about the site
*/
getSite(siteId: string, opts?: any): Observable<SiteEntry | any> {
return from(this.sitesApi.getSite(siteId, opts)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.getSite(siteId, opts));
}
/**
@@ -92,7 +91,7 @@ export class SitesService {
deleteSite(siteId: string, permanentFlag: boolean = true): Observable<any> {
const options: any = {};
options.permanent = permanentFlag;
return from(this.sitesApi.deleteSite(siteId, options)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.deleteSite(siteId, options));
}
/**
@@ -149,7 +148,7 @@ export class SitesService {
* @returns Site membership requests
*/
getSiteMembershipRequests(opts?: any): Observable<SiteMembershipRequestWithPersonPaging> {
return from(this.sitesApi.getSiteMembershipRequests(opts)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.getSiteMembershipRequests(opts));
}
/**
@@ -161,7 +160,7 @@ export class SitesService {
* @returns Observable<SiteMemberEntry>
*/
createSiteMembership(siteId: string, siteMembershipBodyCreate: SiteMembershipBodyCreate, opts?: any): Observable<SiteMemberEntry> {
return from(this.sitesApi.createSiteMembership(siteId, siteMembershipBodyCreate, opts)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.createSiteMembership(siteId, siteMembershipBodyCreate, opts));
}
/**
@@ -179,9 +178,7 @@ export class SitesService {
siteMembershipBodyUpdate: SiteMembershipBodyUpdate,
opts?: any
): Observable<SiteMemberEntry> {
return from(this.sitesApi.updateSiteMembership(siteId, personId, siteMembershipBodyUpdate, opts)).pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.sitesApi.updateSiteMembership(siteId, personId, siteMembershipBodyUpdate, opts));
}
/**
@@ -192,7 +189,7 @@ export class SitesService {
* @returns Null response notifying when the operation is complete
*/
deleteSiteMembership(siteId: string, personId: string): Observable<void> {
return from(this.sitesApi.deleteSiteMembership(siteId, personId)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.deleteSiteMembership(siteId, personId));
}
/**
@@ -204,7 +201,7 @@ export class SitesService {
* @returns Null response notifying when the operation is complete
*/
approveSiteMembershipRequest(siteId: string, inviteeId: string, opts?: any): Observable<SiteMembershipRequestWithPersonPaging> {
return from(this.sitesApi.approveSiteMembershipRequest(siteId, inviteeId, opts)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.approveSiteMembershipRequest(siteId, inviteeId, opts));
}
/**
@@ -216,7 +213,7 @@ export class SitesService {
* @returns Null response notifying when the operation is complete
*/
rejectSiteMembershipRequest(siteId: string, inviteeId: string, opts?: any): Observable<SiteMembershipRequestWithPersonPaging> {
return from(this.sitesApi.rejectSiteMembershipRequest(siteId, inviteeId, opts)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.rejectSiteMembershipRequest(siteId, inviteeId, opts));
}
/**
@@ -227,7 +224,7 @@ export class SitesService {
* @returns Observable<SiteGroupPaging>
*/
listSiteGroups(siteId: string, opts?: any): Observable<SiteGroupPaging> {
return from(this.sitesApi.listSiteGroups(siteId, opts)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.listSiteGroups(siteId, opts));
}
/**
@@ -238,7 +235,7 @@ export class SitesService {
* @returns Observable<SiteGroupEntry>
*/
createSiteGroupMembership(siteId: string, siteMembershipBodyCreate: SiteMembershipBodyCreate): Observable<SiteGroupEntry> {
return from(this.sitesApi.createSiteGroupMembership(siteId, siteMembershipBodyCreate)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.createSiteGroupMembership(siteId, siteMembershipBodyCreate));
}
/**
@@ -249,7 +246,7 @@ export class SitesService {
* @returns Observable<SiteGroupEntry>
*/
getSiteGroupMembership(siteId: string, groupId: string): Observable<SiteGroupEntry> {
return from(this.sitesApi.getSiteGroupMembership(siteId, groupId)).pipe(catchError((err: any) => this.handleError(err)));
return from(this.sitesApi.getSiteGroupMembership(siteId, groupId));
}
/**
@@ -261,9 +258,7 @@ export class SitesService {
* @returns Observable<SiteGroupEntry>
*/
updateSiteGroupMembership(siteId: string, groupId: string, siteMembershipBodyUpdate: SiteMembershipBodyUpdate): Observable<SiteGroupEntry> {
return from(this.sitesApi.updateSiteGroupMembership(siteId, groupId, siteMembershipBodyUpdate)).pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.sitesApi.updateSiteGroupMembership(siteId, groupId, siteMembershipBodyUpdate));
}
/**
@@ -274,11 +269,6 @@ export class SitesService {
* @returns Observable<void>
*/
deleteSiteGroupMembership(siteId: string, groupId: string): Observable<void> {
return from(this.sitesApi.deleteSiteGroupMembership(siteId, groupId)).pipe(catchError((err: any) => this.handleError(err)));
}
private handleError(error: any): Observable<never> {
this.logService.error(error);
return throwError(error || 'Server error');
return from(this.sitesApi.deleteSiteGroupMembership(siteId, groupId));
}
}

View File

@@ -17,9 +17,8 @@
import { DownloadEntry, DownloadBodyCreate, DownloadsApi } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs';
import { AlfrescoApiService, LogService } from '@alfresco/adf-core';
import { catchError } from 'rxjs/operators';
import { Observable, from } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
@Injectable({
providedIn: 'root'
@@ -32,8 +31,7 @@ export class DownloadZipService {
return this._downloadsApi;
}
constructor(private apiService: AlfrescoApiService,
private logService: LogService) {
constructor(private apiService: AlfrescoApiService) {
}
/**
@@ -43,9 +41,7 @@ export class DownloadZipService {
* @returns Status object for the download
*/
createDownload(payload: DownloadBodyCreate): Observable<DownloadEntry> {
return from(this.downloadsApi.createDownload(payload)).pipe(
catchError((err) => this.handleError(err))
);
return from(this.downloadsApi.createDownload(payload));
}
/**
@@ -66,9 +62,4 @@ export class DownloadZipService {
cancelDownload(downloadId: string) {
this.downloadsApi.cancelDownload(downloadId);
}
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
}

View File

@@ -15,9 +15,8 @@
* limitations under the License.
*/
import { AlfrescoApiService, LogService, PaginationModel } from '@alfresco/adf-core';
import { AlfrescoApiService, PaginationModel } from '@alfresco/adf-core';
import {
NodePaging,
DeletedNodesPaging,
SearchRequest,
SharedLinkPaging,
@@ -30,11 +29,13 @@ import {
FavoritesApi,
SharedlinksApi,
TrashcanApi,
NodesApi
NodesApi,
SitePaging,
ResultSetPaging
} from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { Observable, from, of, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { Observable, from, of } from 'rxjs';
import { map } from 'rxjs/operators';
const CREATE_PERMISSION: string = 'create';
@@ -83,7 +84,7 @@ export class CustomResourcesService {
return this._nodesApi;
}
constructor(private apiService: AlfrescoApiService, private logService: LogService) {
constructor(private apiService: AlfrescoApiService) {
}
/**
@@ -94,7 +95,7 @@ export class CustomResourcesService {
* @param filters Specifies additional filters to apply (joined with **AND**)
* @returns List of nodes for the recently used files
*/
getRecentFiles(personId: string, pagination: PaginationModel, filters?: string[]): Observable<NodePaging> {
getRecentFiles(personId: string, pagination: PaginationModel, filters?: string[]): Observable<ResultSetPaging> {
const defaultFilter = [
'TYPE:"content"',
'-PNAME:"0/wiki"',
@@ -165,7 +166,7 @@ export class CustomResourcesService {
observer.error(err);
observer.complete();
});
}).pipe(catchError((err) => this.handleError(err)));
});
}
/**
@@ -176,7 +177,7 @@ export class CustomResourcesService {
* @param where A string to restrict the returned objects by using a predicate
* @returns List of favorite files
*/
loadFavorites(pagination: PaginationModel, includeFields: string[] = [], where?: string): Observable<NodePaging> {
loadFavorites(pagination: PaginationModel, includeFields: string[] = [], where?: string): Observable<FavoritePaging> {
const includeFieldsRequest = this.getIncludesFields(includeFields);
const defaultPredicate = '(EXISTS(target/file) OR EXISTS(target/folder))';
@@ -189,7 +190,7 @@ export class CustomResourcesService {
return new Observable((observer) => {
this.favoritesApi.listFavorites('-me-', options)
.then((result: FavoritePaging) => {
.then((result) => {
const page: FavoritePaging = {
list: {
entries: result.list.entries
@@ -218,7 +219,7 @@ export class CustomResourcesService {
observer.error(err);
observer.complete();
});
}).pipe(catchError((err) => this.handleError(err)));
});
}
/**
@@ -260,7 +261,7 @@ export class CustomResourcesService {
observer.error(err);
observer.complete();
});
}).pipe(catchError((err) => this.handleError(err)));
});
}
/**
@@ -270,7 +271,7 @@ export class CustomResourcesService {
* @param where A string to restrict the returned objects by using a predicate
* @returns List of sites
*/
loadSites(pagination: PaginationModel, where?: string): Observable<NodePaging> {
loadSites(pagination: PaginationModel, where?: string): Observable<SitePaging> {
const options = {
include: ['properties', 'aspectNames'],
maxItems: pagination.maxItems,
@@ -296,7 +297,7 @@ export class CustomResourcesService {
observer.error(err);
observer.complete();
});
}).pipe(catchError((err) => this.handleError(err)));
});
}
/**
@@ -315,9 +316,7 @@ export class CustomResourcesService {
skipCount: pagination.skipCount
};
return from(this.trashcanApi.listDeletedNodes(options))
.pipe(catchError((err) => this.handleError(err)));
return from(this.trashcanApi.listDeletedNodes(options));
}
/**
@@ -338,8 +337,7 @@ export class CustomResourcesService {
where
};
return from(this.sharedLinksApi.listSharedLinks(options))
.pipe(catchError((err) => this.handleError(err)));
return from(this.sharedLinksApi.listSharedLinks(options));
}
/**
@@ -458,9 +456,4 @@ export class CustomResourcesService {
return ['path', 'properties', 'allowableOperations', 'permissions', 'aspectNames', ...includeFields]
.filter((element, index, array) => index === array.indexOf(element));
}
private handleError(error: Response) {
this.logService.error(error);
return throwError(error || 'Server error');
}
}

View File

@@ -15,14 +15,13 @@
* limitations under the License.
*/
import { AlfrescoApiService, LogService, PaginationModel } from '@alfresco/adf-core';
import { AlfrescoApiService, PaginationModel } from '@alfresco/adf-core';
import { NodesApiService } from '../../common/services/nodes-api.service';
import { Injectable } from '@angular/core';
import { Node, NodeEntry, NodePaging, NodesApi } from '@alfresco/js-api';
import { DocumentLoaderNode } from '../models/document-folder.model';
import { Observable, from, throwError, forkJoin } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { Observable, from, forkJoin } from 'rxjs';
import { map } from 'rxjs/operators';
import { DocumentListLoader } from '../interfaces/document-list-loader.interface';
import { CustomResourcesService } from './custom-resources.service';
@@ -41,7 +40,6 @@ export class DocumentListService implements DocumentListLoader {
constructor(
private nodesApiService: NodesApiService,
private apiService: AlfrescoApiService,
private logService: LogService,
private customResourcesService: CustomResourcesService
) {}
@@ -63,7 +61,7 @@ export class DocumentListService implements DocumentListLoader {
* @returns NodeEntry for the copied node
*/
copyNode(nodeId: string, targetParentId: string): Observable<NodeEntry> {
return from(this.nodes.copyNode(nodeId, { targetParentId })).pipe(catchError((err) => this.handleError(err)));
return from(this.nodes.copyNode(nodeId, { targetParentId }));
}
/**
@@ -74,7 +72,7 @@ export class DocumentListService implements DocumentListLoader {
* @returns NodeEntry for the moved node
*/
moveNode(nodeId: string, targetParentId: string): Observable<NodeEntry> {
return from(this.nodes.moveNode(nodeId, { targetParentId })).pipe(catchError((err) => this.handleError(err)));
return from(this.nodes.moveNode(nodeId, { targetParentId }));
}
/**
@@ -119,7 +117,7 @@ export class DocumentListService implements DocumentListLoader {
}
}
return from(this.nodes.listNodeChildren(rootNodeId, params)).pipe(catchError((err) => this.handleError(err)));
return from(this.nodes.listNodeChildren(rootNodeId, params));
}
/**
@@ -159,10 +157,10 @@ export class DocumentListService implements DocumentListLoader {
include: includeFieldsRequest
};
return from(this.nodes.getNode(nodeId, opts)).pipe(catchError((err) => this.handleError(err)));
return from(this.nodes.getNode(nodeId, opts));
}
isCustomSourceService(nodeId): boolean {
isCustomSourceService(nodeId: string): boolean {
return this.customResourcesService.isCustomSource(nodeId);
}
@@ -214,9 +212,4 @@ export class DocumentListService implements DocumentListLoader {
)
]).pipe(map((results) => new DocumentLoaderNode(results[0], results[1])));
}
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
}

View File

@@ -29,18 +29,13 @@ import { OverlayContainer } from '@angular/cdk/overlay';
providedIn: 'root'
})
export class NewVersionUploaderService {
private _versionsApi: VersionsApi;
get versionsApi(): VersionsApi {
this._versionsApi = this._versionsApi ?? new VersionsApi(this.apiService.getInstance());
return this._versionsApi;
}
constructor(
private apiService: AlfrescoApiService,
private dialog: MatDialog,
private overlayContainer: OverlayContainer
) { }
constructor(private apiService: AlfrescoApiService, private dialog: MatDialog, private overlayContainer: OverlayContainer) {}
/**
* Open a dialog NewVersionUploaderDialogComponent to display:
@@ -53,7 +48,11 @@ export class NewVersionUploaderService {
* @param selectorAutoFocusedOnClose element's selector which should be autofocused after closing modal
* @returns an Observable represents the triggered dialog action or an error in case of an error condition
*/
openUploadNewVersionDialog(data: NewVersionUploaderDialogData, config?: MatDialogConfig, selectorAutoFocusedOnClose?: string) {
openUploadNewVersionDialog(
data: NewVersionUploaderDialogData,
config?: MatDialogConfig,
selectorAutoFocusedOnClose?: string
): Observable<NewVersionUploaderData> {
const { file, node, showVersionsOnly } = data;
const showComments = true;
const allowDownload = true;
@@ -66,11 +65,10 @@ export class NewVersionUploaderService {
width: '630px',
...(config && Object.keys(config).length > 0 && config)
});
dialogRef.componentInstance.dialogAction.asObservable()
.subscribe((newVersionUploaderData: NewVersionUploaderData) => {
observer.next(newVersionUploaderData);
});
dialogRef.componentInstance.uploadError.asObservable().subscribe(error => {
dialogRef.componentInstance.dialogAction.asObservable().subscribe((newVersionUploaderData) => {
observer.next(newVersionUploaderData);
});
dialogRef.componentInstance.uploadError.asObservable().subscribe((error) => {
observer.error(error);
});
dialogRef.afterClosed().subscribe(() => {
@@ -80,7 +78,6 @@ export class NewVersionUploaderService {
this.overlayContainer.getContainerElement().setAttribute('role', 'main');
});
});
}
private composePanelClass(showVersionsOnly: boolean): string | string[] {
@@ -90,7 +87,7 @@ export class NewVersionUploaderService {
private static focusOnClose(selectorAutoFocusedOnClose: string): void {
if (selectorAutoFocusedOnClose) {
document.querySelector<HTMLElement>(selectorAutoFocusedOnClose).focus();
document.querySelector<HTMLElement>(selectorAutoFocusedOnClose)?.focus();
}
}
}

View File

@@ -15,100 +15,72 @@
* limitations under the License.
*/
import {
AlfrescoApiService,
LogService,
CommentModel,
CommentsService,
User
} from '@alfresco/adf-core';
import { AlfrescoApiService, CommentModel, CommentsService, User } from '@alfresco/adf-core';
import { CommentEntry, CommentsApi, Comment } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { ContentService } from '../../common/services/content.service';
import { Observable, from } from 'rxjs';
import { map } from 'rxjs/operators';
import { ContentService } from '../../common/services/content.service';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class NodeCommentsService implements CommentsService {
private _commentsApi: CommentsApi;
get commentsApi(): CommentsApi {
this._commentsApi = this._commentsApi ?? new CommentsApi(this.apiService.getInstance());
return this._commentsApi;
}
private _commentsApi: CommentsApi;
get commentsApi(): CommentsApi {
this._commentsApi = this._commentsApi ?? new CommentsApi(this.apiService.getInstance());
return this._commentsApi;
}
constructor(private apiService: AlfrescoApiService, private contentService: ContentService) {}
constructor(
private apiService: AlfrescoApiService,
private logService: LogService,
private contentService: ContentService
) {}
/**
* Gets all comments that have been added to a task.
*
* @param id ID of the target task
* @returns Details for each comment
*/
get(id: string): Observable<CommentModel[]> {
return from(this.commentsApi.listComments(id)).pipe(
map((response) => {
const comments: CommentModel[] = [];
/**
* Gets all comments that have been added to a task.
*
* @param id ID of the target task
* @returns Details for each comment
*/
get(id: string): Observable<CommentModel[]> {
return from(this.commentsApi.listComments(id))
.pipe(
map((response) => {
const comments: CommentModel[] = [];
response.list.entries.forEach((comment: CommentEntry) => {
this.addToComments(comments, comment);
});
response.list.entries.forEach((comment: CommentEntry) => {
this.addToComments(comments, comment);
});
return comments;
})
);
}
return comments;
}),
catchError(
(err: any) => this.handleError(err)
)
);
}
/**
* Adds a comment to a task.
*
* @param id ID of the target task
* @param message Text for the comment
* @returns Details about the comment
*/
add(id: string, message: string): Observable<CommentModel> {
return from(this.commentsApi.createComment(id, { content: message })).pipe(map((response) => this.newCommentModel(response.entry)));
}
/**
* Adds a comment to a task.
*
* @param id ID of the target task
* @param message Text for the comment
* @returns Details about the comment
*/
add(id: string, message: string): Observable<CommentModel> {
return from(this.commentsApi.createComment(id, { content: message }))
.pipe(
map(
(response: CommentEntry) => this.newCommentModel(response.entry)
),
catchError(
(err: any) => this.handleError(err)
)
);
}
private addToComments(comments: CommentModel[], comment: CommentEntry): void {
const newComment: Comment = comment.entry;
private addToComments(comments: CommentModel[], comment: CommentEntry): void {
const newComment: Comment = comment.entry;
comments.push(this.newCommentModel(newComment));
}
comments.push(this.newCommentModel(newComment));
}
private newCommentModel(comment: Comment): CommentModel {
return new CommentModel({
id: comment.id,
message: comment.content,
created: comment.createdAt,
createdBy: new User(comment.createdBy)
});
}
private newCommentModel(comment: Comment): CommentModel {
return new CommentModel({
id: comment.id,
message: comment.content,
created: comment.createdAt,
createdBy: new User(comment.createdBy)
});
}
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
getUserImage(avatarId: string): string {
return this.contentService.getContentUrl(avatarId);
}
getUserImage(avatarId: string): string {
return this.contentService.getContentUrl(avatarId);
}
}

View File

@@ -17,7 +17,7 @@
import { Injectable } from '@angular/core';
import { NodePaging, QueriesApi, SearchRequest, ResultSetPaging, SearchApi } from '@alfresco/js-api';
import { Observable, Subject, from, throwError } from 'rxjs';
import { Observable, Subject, from } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { SearchConfigurationService } from './search-configuration.service';
@@ -25,7 +25,7 @@ import { SearchConfigurationService } from './search-configuration.service';
providedIn: 'root'
})
export class SearchService {
dataLoaded: Subject<ResultSetPaging> = new Subject();
dataLoaded = new Subject<ResultSetPaging>();
private _queriesApi: QueriesApi;
get queriesApi(): QueriesApi {
@@ -54,8 +54,7 @@ export class SearchService {
promise
.then((nodePaging) => {
this.dataLoaded.next(nodePaging);
})
.catch((err) => this.handleError(err));
});
return from(promise);
}
@@ -75,8 +74,7 @@ export class SearchService {
promise
.then((nodePaging) => {
this.dataLoaded.next(nodePaging);
})
.catch((err) => this.handleError(err));
});
return from(promise);
}
@@ -93,15 +91,10 @@ export class SearchService {
promise
.then((nodePaging) => {
this.dataLoaded.next(nodePaging);
})
.catch((err) => this.handleError(err));
});
return from(promise);
}
private handleError(error: any): Observable<any> {
return throwError(error || 'Server error');
}
}
export interface SearchOptions {

View File

@@ -15,11 +15,10 @@
* limitations under the License.
*/
import { AlfrescoApiService, LogService } from '@alfresco/adf-core';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { RatingEntry, RatingBody, RatingsApi } from '@alfresco/js-api';
import { from, throwError, Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { from, Observable } from 'rxjs';
import { RatingServiceInterface } from './rating.service.interface';
@Injectable({
@@ -33,7 +32,7 @@ export class RatingService implements RatingServiceInterface {
return this._ratingsApi;
}
constructor(private apiService: AlfrescoApiService, private logService: LogService) {
constructor(private apiService: AlfrescoApiService) {
}
/**
@@ -44,10 +43,7 @@ export class RatingService implements RatingServiceInterface {
* @returns The rating value
*/
getRating(nodeId: string, ratingType: any): Observable<RatingEntry | any> {
return from(this.ratingsApi.getRating(nodeId, ratingType))
.pipe(
catchError(this.handleError)
);
return from(this.ratingsApi.getRating(nodeId, ratingType));
}
/**
@@ -63,10 +59,7 @@ export class RatingService implements RatingServiceInterface {
id: ratingType,
myRating: vote
});
return from(this.ratingsApi.createRating(nodeId, ratingBody))
.pipe(
catchError(this.handleError)
);
return from(this.ratingsApi.createRating(nodeId, ratingBody));
}
/**
@@ -77,14 +70,6 @@ export class RatingService implements RatingServiceInterface {
* @returns Null response indicating that the operation is complete
*/
deleteRating(nodeId: string, ratingType: any): Observable<any> {
return from(this.ratingsApi.deleteRating(nodeId, ratingType))
.pipe(
catchError(this.handleError)
);
}
private handleError(error: any): any {
this.logService.error(error);
return throwError(error || 'Server error');
return from(this.ratingsApi.deleteRating(nodeId, ratingType));
}
}