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

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

View File

@@ -17,9 +17,8 @@
import { DownloadEntry, DownloadBodyCreate, DownloadsApi } from '@alfresco/js-api'; import { DownloadEntry, DownloadBodyCreate, DownloadsApi } from '@alfresco/js-api';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs'; import { Observable, from } from 'rxjs';
import { AlfrescoApiService, LogService } from '@alfresco/adf-core'; import { AlfrescoApiService } from '@alfresco/adf-core';
import { catchError } from 'rxjs/operators';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -32,8 +31,7 @@ export class DownloadZipService {
return this._downloadsApi; return this._downloadsApi;
} }
constructor(private apiService: AlfrescoApiService, constructor(private apiService: AlfrescoApiService) {
private logService: LogService) {
} }
/** /**
@@ -43,9 +41,7 @@ export class DownloadZipService {
* @returns Status object for the download * @returns Status object for the download
*/ */
createDownload(payload: DownloadBodyCreate): Observable<DownloadEntry> { createDownload(payload: DownloadBodyCreate): Observable<DownloadEntry> {
return from(this.downloadsApi.createDownload(payload)).pipe( return from(this.downloadsApi.createDownload(payload));
catchError((err) => this.handleError(err))
);
} }
/** /**
@@ -66,9 +62,4 @@ export class DownloadZipService {
cancelDownload(downloadId: string) { cancelDownload(downloadId: string) {
this.downloadsApi.cancelDownload(downloadId); 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. * limitations under the License.
*/ */
import { AlfrescoApiService, LogService, PaginationModel } from '@alfresco/adf-core'; import { AlfrescoApiService, PaginationModel } from '@alfresco/adf-core';
import { import {
NodePaging,
DeletedNodesPaging, DeletedNodesPaging,
SearchRequest, SearchRequest,
SharedLinkPaging, SharedLinkPaging,
@@ -30,11 +29,13 @@ import {
FavoritesApi, FavoritesApi,
SharedlinksApi, SharedlinksApi,
TrashcanApi, TrashcanApi,
NodesApi NodesApi,
SitePaging,
ResultSetPaging
} from '@alfresco/js-api'; } from '@alfresco/js-api';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, from, of, throwError } from 'rxjs'; import { Observable, from, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
const CREATE_PERMISSION: string = 'create'; const CREATE_PERMISSION: string = 'create';
@@ -83,7 +84,7 @@ export class CustomResourcesService {
return this._nodesApi; 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**) * @param filters Specifies additional filters to apply (joined with **AND**)
* @returns List of nodes for the recently used files * @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 = [ const defaultFilter = [
'TYPE:"content"', 'TYPE:"content"',
'-PNAME:"0/wiki"', '-PNAME:"0/wiki"',
@@ -165,7 +166,7 @@ export class CustomResourcesService {
observer.error(err); observer.error(err);
observer.complete(); 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 * @param where A string to restrict the returned objects by using a predicate
* @returns List of favorite files * @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 includeFieldsRequest = this.getIncludesFields(includeFields);
const defaultPredicate = '(EXISTS(target/file) OR EXISTS(target/folder))'; const defaultPredicate = '(EXISTS(target/file) OR EXISTS(target/folder))';
@@ -189,7 +190,7 @@ export class CustomResourcesService {
return new Observable((observer) => { return new Observable((observer) => {
this.favoritesApi.listFavorites('-me-', options) this.favoritesApi.listFavorites('-me-', options)
.then((result: FavoritePaging) => { .then((result) => {
const page: FavoritePaging = { const page: FavoritePaging = {
list: { list: {
entries: result.list.entries entries: result.list.entries
@@ -218,7 +219,7 @@ export class CustomResourcesService {
observer.error(err); observer.error(err);
observer.complete(); observer.complete();
}); });
}).pipe(catchError((err) => this.handleError(err))); });
} }
/** /**
@@ -260,7 +261,7 @@ export class CustomResourcesService {
observer.error(err); observer.error(err);
observer.complete(); 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 * @param where A string to restrict the returned objects by using a predicate
* @returns List of sites * @returns List of sites
*/ */
loadSites(pagination: PaginationModel, where?: string): Observable<NodePaging> { loadSites(pagination: PaginationModel, where?: string): Observable<SitePaging> {
const options = { const options = {
include: ['properties', 'aspectNames'], include: ['properties', 'aspectNames'],
maxItems: pagination.maxItems, maxItems: pagination.maxItems,
@@ -296,7 +297,7 @@ export class CustomResourcesService {
observer.error(err); observer.error(err);
observer.complete(); observer.complete();
}); });
}).pipe(catchError((err) => this.handleError(err))); });
} }
/** /**
@@ -315,9 +316,7 @@ export class CustomResourcesService {
skipCount: pagination.skipCount skipCount: pagination.skipCount
}; };
return from(this.trashcanApi.listDeletedNodes(options)) return from(this.trashcanApi.listDeletedNodes(options));
.pipe(catchError((err) => this.handleError(err)));
} }
/** /**
@@ -338,8 +337,7 @@ export class CustomResourcesService {
where where
}; };
return from(this.sharedLinksApi.listSharedLinks(options)) return from(this.sharedLinksApi.listSharedLinks(options));
.pipe(catchError((err) => this.handleError(err)));
} }
/** /**
@@ -458,9 +456,4 @@ export class CustomResourcesService {
return ['path', 'properties', 'allowableOperations', 'permissions', 'aspectNames', ...includeFields] return ['path', 'properties', 'allowableOperations', 'permissions', 'aspectNames', ...includeFields]
.filter((element, index, array) => index === array.indexOf(element)); .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. * 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 { NodesApiService } from '../../common/services/nodes-api.service';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Node, NodeEntry, NodePaging, NodesApi } from '@alfresco/js-api'; import { Node, NodeEntry, NodePaging, NodesApi } from '@alfresco/js-api';
import { DocumentLoaderNode } from '../models/document-folder.model'; import { DocumentLoaderNode } from '../models/document-folder.model';
import { Observable, from, throwError, forkJoin } from 'rxjs'; import { Observable, from, forkJoin } from 'rxjs';
import { catchError, map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { DocumentListLoader } from '../interfaces/document-list-loader.interface'; import { DocumentListLoader } from '../interfaces/document-list-loader.interface';
import { CustomResourcesService } from './custom-resources.service'; import { CustomResourcesService } from './custom-resources.service';
@@ -41,7 +40,6 @@ export class DocumentListService implements DocumentListLoader {
constructor( constructor(
private nodesApiService: NodesApiService, private nodesApiService: NodesApiService,
private apiService: AlfrescoApiService, private apiService: AlfrescoApiService,
private logService: LogService,
private customResourcesService: CustomResourcesService private customResourcesService: CustomResourcesService
) {} ) {}
@@ -63,7 +61,7 @@ export class DocumentListService implements DocumentListLoader {
* @returns NodeEntry for the copied node * @returns NodeEntry for the copied node
*/ */
copyNode(nodeId: string, targetParentId: string): Observable<NodeEntry> { 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 * @returns NodeEntry for the moved node
*/ */
moveNode(nodeId: string, targetParentId: string): Observable<NodeEntry> { 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 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); return this.customResourcesService.isCustomSource(nodeId);
} }
@@ -214,9 +212,4 @@ export class DocumentListService implements DocumentListLoader {
) )
]).pipe(map((results) => new DocumentLoaderNode(results[0], results[1]))); ]).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' providedIn: 'root'
}) })
export class NewVersionUploaderService { export class NewVersionUploaderService {
private _versionsApi: VersionsApi; private _versionsApi: VersionsApi;
get versionsApi(): VersionsApi { get versionsApi(): VersionsApi {
this._versionsApi = this._versionsApi ?? new VersionsApi(this.apiService.getInstance()); this._versionsApi = this._versionsApi ?? new VersionsApi(this.apiService.getInstance());
return this._versionsApi; return this._versionsApi;
} }
constructor( constructor(private apiService: AlfrescoApiService, private dialog: MatDialog, private overlayContainer: OverlayContainer) {}
private apiService: AlfrescoApiService,
private dialog: MatDialog,
private overlayContainer: OverlayContainer
) { }
/** /**
* Open a dialog NewVersionUploaderDialogComponent to display: * 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 * @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 * @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 { file, node, showVersionsOnly } = data;
const showComments = true; const showComments = true;
const allowDownload = true; const allowDownload = true;
@@ -66,11 +65,10 @@ export class NewVersionUploaderService {
width: '630px', width: '630px',
...(config && Object.keys(config).length > 0 && config) ...(config && Object.keys(config).length > 0 && config)
}); });
dialogRef.componentInstance.dialogAction.asObservable() dialogRef.componentInstance.dialogAction.asObservable().subscribe((newVersionUploaderData) => {
.subscribe((newVersionUploaderData: NewVersionUploaderData) => { observer.next(newVersionUploaderData);
observer.next(newVersionUploaderData); });
}); dialogRef.componentInstance.uploadError.asObservable().subscribe((error) => {
dialogRef.componentInstance.uploadError.asObservable().subscribe(error => {
observer.error(error); observer.error(error);
}); });
dialogRef.afterClosed().subscribe(() => { dialogRef.afterClosed().subscribe(() => {
@@ -80,7 +78,6 @@ export class NewVersionUploaderService {
this.overlayContainer.getContainerElement().setAttribute('role', 'main'); this.overlayContainer.getContainerElement().setAttribute('role', 'main');
}); });
}); });
} }
private composePanelClass(showVersionsOnly: boolean): string | string[] { private composePanelClass(showVersionsOnly: boolean): string | string[] {
@@ -90,7 +87,7 @@ export class NewVersionUploaderService {
private static focusOnClose(selectorAutoFocusedOnClose: string): void { private static focusOnClose(selectorAutoFocusedOnClose: string): void {
if (selectorAutoFocusedOnClose) { if (selectorAutoFocusedOnClose) {
document.querySelector<HTMLElement>(selectorAutoFocusedOnClose).focus(); document.querySelector<HTMLElement>(selectorAutoFocusedOnClose)?.focus();
} }
} }
} }

View File

@@ -15,100 +15,72 @@
* limitations under the License. * limitations under the License.
*/ */
import { import { AlfrescoApiService, CommentModel, CommentsService, User } from '@alfresco/adf-core';
AlfrescoApiService,
LogService,
CommentModel,
CommentsService,
User
} from '@alfresco/adf-core';
import { CommentEntry, CommentsApi, Comment } from '@alfresco/js-api'; import { CommentEntry, CommentsApi, Comment } from '@alfresco/js-api';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs'; import { Observable, from } from 'rxjs';
import { map, catchError } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ContentService } from '../../common/services/content.service'; import { ContentService } from '../../common/services/content.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class NodeCommentsService implements CommentsService { 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; constructor(private apiService: AlfrescoApiService, private contentService: ContentService) {}
get commentsApi(): CommentsApi {
this._commentsApi = this._commentsApi ?? new CommentsApi(this.apiService.getInstance());
return this._commentsApi;
}
constructor( /**
private apiService: AlfrescoApiService, * Gets all comments that have been added to a task.
private logService: LogService, *
private contentService: ContentService * @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) => {
* Gets all comments that have been added to a task. this.addToComments(comments, comment);
* });
* @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) => { return comments;
this.addToComments(comments, comment); })
}); );
}
return comments; /**
}), * Adds a comment to a task.
catchError( *
(err: any) => this.handleError(err) * @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)));
}
/** private addToComments(comments: CommentModel[], comment: CommentEntry): void {
* Adds a comment to a task. const newComment: Comment = comment.entry;
*
* @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 { comments.push(this.newCommentModel(newComment));
const newComment: Comment = comment.entry; }
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 { getUserImage(avatarId: string): string {
return new CommentModel({ return this.contentService.getContentUrl(avatarId);
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);
}
} }

View File

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

View File

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

View File

@@ -15,41 +15,26 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApiService, LogService } from '@alfresco/adf-core'; import { AlfrescoApiService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs'; import { Observable, from } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ModelJsonBpmnApi } from '@alfresco/js-api'; import { ModelJsonBpmnApi } from '@alfresco/js-api';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class DiagramsService { export class DiagramsService {
private _modelJsonBpmnApi: ModelJsonBpmnApi; private _modelJsonBpmnApi: ModelJsonBpmnApi;
get modelJsonBpmnApi(): ModelJsonBpmnApi { get modelJsonBpmnApi(): ModelJsonBpmnApi {
this._modelJsonBpmnApi = this._modelJsonBpmnApi ?? new ModelJsonBpmnApi(this.apiService.getInstance()); this._modelJsonBpmnApi = this._modelJsonBpmnApi ?? new ModelJsonBpmnApi(this.apiService.getInstance());
return this._modelJsonBpmnApi; return this._modelJsonBpmnApi;
} }
constructor(private apiService: AlfrescoApiService, constructor(private apiService: AlfrescoApiService) {}
private logService: LogService) {
}
getProcessDefinitionModel(processDefinitionId: string): Observable<any> { getProcessDefinitionModel(processDefinitionId: string): Observable<any> {
return from(this.modelJsonBpmnApi.getModelJSON(processDefinitionId)) return from(this.modelJsonBpmnApi.getModelJSON(processDefinitionId));
.pipe(
catchError((err) => this.handleError(err))
);
} }
getRunningProcessDefinitionModel(processInstanceId: string): Observable<any> { getRunningProcessDefinitionModel(processInstanceId: string): Observable<any> {
return from(this.modelJsonBpmnApi.getModelJSONForProcessDefinition(processInstanceId)) return from(this.modelJsonBpmnApi.getModelJSONForProcessDefinition(processInstanceId));
.pipe(
catchError((err) => this.handleError(err))
);
}
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
} }
} }

View File

@@ -16,9 +16,9 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, from, throwError, of } from 'rxjs'; import { Observable, from, of } from 'rxjs';
import { map, catchError } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { AppConfigService, LogService } from '@alfresco/adf-core'; import { AppConfigService } from '@alfresco/adf-core';
import { ApplicationInstanceModel } from '../models/application-instance.model'; import { ApplicationInstanceModel } from '../models/application-instance.model';
import { Environment } from '../../common/interface/environment.interface'; import { Environment } from '../../common/interface/environment.interface';
import { AdfHttpClient } from '@alfresco/adf-core/api'; import { AdfHttpClient } from '@alfresco/adf-core/api';
@@ -26,13 +26,9 @@ import { RequestOptions } from '@alfresco/js-api';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class AppsProcessCloudService { export class AppsProcessCloudService {
deployedApps: ApplicationInstanceModel[]; deployedApps: ApplicationInstanceModel[];
constructor( constructor(private adfHttpClient: AdfHttpClient, private appConfigService: AppConfigService) {
private adfHttpClient: AdfHttpClient,
private logService: LogService,
private appConfigService: AppConfigService) {
this.loadApps(); this.loadApps();
} }
@@ -76,7 +72,7 @@ export class AppsProcessCloudService {
} }
const path = this.getApplicationUrl(); const path = this.getApplicationUrl();
const pathParams = {}; const pathParams = {};
const queryParams = { status, roles : role, sort: 'name' }; const queryParams = { status, roles: role, sort: 'name' };
const httpMethod = 'GET'; const httpMethod = 'GET';
const headerParams = {}; const headerParams = {};
const formParams = {}; const formParams = {};
@@ -95,19 +91,12 @@ export class AppsProcessCloudService {
httpMethod httpMethod
}; };
return from(this.adfHttpClient.request(path, requestOptions)) return from(this.adfHttpClient.request(path, requestOptions)).pipe(
.pipe( map((applications) => applications.list.entries.map((application) => application.entry))
map((applications: any) => applications.list.entries.map((application) => application.entry)), );
catchError((err) => this.handleError(err))
);
} }
private getApplicationUrl(): string { private getApplicationUrl(): string {
return `${this.appConfigService.get('bpmHost')}/deployment-service/v1/applications`; return `${this.appConfigService.get('bpmHost')}/deployment-service/v1/applications`;
} }
private handleError(error?: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
} }

View File

@@ -877,7 +877,7 @@ describe('AttachFileCloudWidgetComponent', () => {
notificationService = TestBed.inject(NotificationService); notificationService = TestBed.inject(NotificationService);
newVersionUploaderService = TestBed.inject(NewVersionUploaderService); newVersionUploaderService = TestBed.inject(NewVersionUploaderService);
spyOnOpenUploadNewVersionDialog = spyOn(newVersionUploaderService, 'openUploadNewVersionDialog').and.returnValue( spyOnOpenUploadNewVersionDialog = spyOn(newVersionUploaderService, 'openUploadNewVersionDialog').and.returnValue(
of({ action: NewVersionUploaderDataAction.refresh }) of({ action: NewVersionUploaderDataAction.refresh } as any)
); );
spyOnReplaceOldFileVersionWithNew = spyOn(widget, 'replaceOldFileVersionWithNew'); spyOnReplaceOldFileVersionWithNew = spyOn(widget, 'replaceOldFileVersionWithNew');
spyOnShowError = spyOn(notificationService, 'showError'); spyOnShowError = spyOn(notificationService, 'showError');

View File

@@ -35,7 +35,7 @@ import { ContentCloudNodeSelectorService } from '../../../services/content-cloud
import { ProcessCloudContentService } from '../../../services/process-cloud-content.service'; import { ProcessCloudContentService } from '../../../services/process-cloud-content.service';
import { UploadCloudWidgetComponent } from './upload-cloud.widget'; import { UploadCloudWidgetComponent } from './upload-cloud.widget';
import { DestinationFolderPathModel, DestinationFolderPathType } from '../../../models/form-cloud-representation.model'; import { DestinationFolderPathModel, DestinationFolderPathType } from '../../../models/form-cloud-representation.model';
import { ContentNodeSelectorPanelService, NewVersionUploaderData, NewVersionUploaderDataAction, NewVersionUploaderDialogData, NewVersionUploaderService, VersionManagerUploadData } from '@alfresco/adf-content-services'; import { ContentNodeSelectorPanelService, NewVersionUploaderDataAction, NewVersionUploaderDialogData, NewVersionUploaderService, VersionManagerUploadData } from '@alfresco/adf-content-services';
export const RETRIEVE_METADATA_OPTION = 'retrieveMetadata'; export const RETRIEVE_METADATA_OPTION = 'retrieveMetadata';
export const ALIAS_ROOT_FOLDER = '-root-'; export const ALIAS_ROOT_FOLDER = '-root-';
@@ -65,7 +65,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
rootNodeId = ALIAS_USER_FOLDER; rootNodeId = ALIAS_USER_FOLDER;
selectedNode: Node; selectedNode: Node;
_nodesApi: NodesApi; private _nodesApi: NodesApi;
get nodesApi(): NodesApi { get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance()); this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
return this._nodesApi; return this._nodesApi;
@@ -214,7 +214,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
} }
onUploadNewFileVersion(node: NewVersionUploaderDialogData): void { onUploadNewFileVersion(node: NewVersionUploaderDialogData): void {
this.newVersionUploaderService.openUploadNewVersionDialog(node).subscribe((newVersionUploaderData: NewVersionUploaderData) => { this.newVersionUploaderService.openUploadNewVersionDialog(node).subscribe((newVersionUploaderData) => {
if (newVersionUploaderData.action === NewVersionUploaderDataAction.upload) { if (newVersionUploaderData.action === NewVersionUploaderDataAction.upload) {
this.replaceOldFileVersionWithNew(newVersionUploaderData as VersionManagerUploadData); this.replaceOldFileVersionWithNew(newVersionUploaderData as VersionManagerUploadData);
} }

View File

@@ -16,9 +16,9 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { throwError, Observable, from } from 'rxjs'; import { Observable, from } from 'rxjs';
import { catchError, map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { AlfrescoApiService, LogService, DownloadService } from '@alfresco/adf-core'; import { AlfrescoApiService, DownloadService } from '@alfresco/adf-core';
import { ContentService, NodesApiService } from '@alfresco/adf-content-services'; import { ContentService, NodesApiService } from '@alfresco/adf-content-services';
import { AuthenticationApi, Node, UploadApi } from '@alfresco/js-api'; import { AuthenticationApi, Node, UploadApi } from '@alfresco/js-api';
@@ -40,7 +40,6 @@ export class ProcessCloudContentService {
constructor( constructor(
private apiService: AlfrescoApiService, private apiService: AlfrescoApiService,
private logService: LogService,
private nodesApiService: NodesApiService, private nodesApiService: NodesApiService,
private contentService: ContentService, private contentService: ContentService,
private downloadService: DownloadService private downloadService: DownloadService
@@ -51,8 +50,7 @@ export class ProcessCloudContentService {
map((res: any) => ({ map((res: any) => ({
...res.entry, ...res.entry,
nodeId: res.entry.id nodeId: res.entry.id
})), }))
catchError((err) => this.handleError(err))
); );
} }
@@ -75,9 +73,4 @@ export class ProcessCloudContentService {
const ticket = await this.authenticationApi.getTicket(); const ticket = await this.authenticationApi.getTicket();
return ticket?.entry?.id || ''; return ticket?.entry?.id || '';
} }
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
} }

View File

@@ -17,8 +17,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AppConfigService, OAuth2Service } from '@alfresco/adf-core'; import { AppConfigService, OAuth2Service } from '@alfresco/adf-core';
import { EMPTY, Observable, throwError } from 'rxjs'; import { EMPTY, Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IdentityGroupServiceInterface } from './identity-group.service.interface'; import { IdentityGroupServiceInterface } from './identity-group.service.interface';
import { IdentityGroupFilterInterface } from './identity-group-filter.interface'; import { IdentityGroupFilterInterface } from './identity-group-filter.interface';
import { IdentityGroupModel } from '../models/identity-group.model'; import { IdentityGroupModel } from '../models/identity-group.model';
@@ -50,25 +49,19 @@ export class IdentityGroupService implements IdentityGroupServiceInterface {
private searchGroupsByName(name: string): Observable<IdentityGroupModel[]> { private searchGroupsByName(name: string): Observable<IdentityGroupModel[]> {
this.buildQueryParam(name); this.buildQueryParam(name);
return this.invokeIdentityGroupApi().pipe( return this.invokeIdentityGroupApi();
catchError((err) => this.handleError(err))
);
} }
private searchGroupsWithGlobalRoles(name: string, roles: string []): Observable<IdentityGroupModel[]> { private searchGroupsWithGlobalRoles(name: string, roles: string []): Observable<IdentityGroupModel[]> {
this.buildQueryParam(name, roles); this.buildQueryParam(name, roles);
return this.invokeIdentityGroupApi().pipe( return this.invokeIdentityGroupApi();
catchError((err) => this.handleError(err))
);
} }
private searchGroupsWithinApp(name: string, applicationName: string, roles?: string []): Observable<IdentityGroupModel[]> { private searchGroupsWithinApp(name: string, applicationName: string, roles?: string []): Observable<IdentityGroupModel[]> {
this.buildQueryParam(name, roles, applicationName); this.buildQueryParam(name, roles, applicationName);
return this.invokeIdentityGroupApi().pipe( return this.invokeIdentityGroupApi();
catchError((err) => this.handleError(err))
);
} }
private invokeIdentityGroupApi(): Observable<IdentityGroupModel[]> { private invokeIdentityGroupApi(): Observable<IdentityGroupModel[]> {
@@ -101,10 +94,6 @@ export class IdentityGroupService implements IdentityGroupServiceInterface {
return roles.filter( role => role.trim() ? true : false); return roles.filter( role => role.trim() ? true : false);
} }
private handleError(error: any) {
return throwError(error || 'Server error');
}
private get identityHost(): string { private get identityHost(): string {
return `${this.appConfigService.get('bpmHost')}`; return `${this.appConfigService.get('bpmHost')}`;
} }

View File

@@ -16,13 +16,8 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { import { AppConfigService, JwtHelperService, OAuth2Service } from '@alfresco/adf-core';
AppConfigService, import { EMPTY, Observable } from 'rxjs';
JwtHelperService,
OAuth2Service
} from '@alfresco/adf-core';
import { EMPTY, Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IdentityUserServiceInterface } from './identity-user.service.interface'; import { IdentityUserServiceInterface } from './identity-user.service.interface';
import { IdentityUserModel } from '../models/identity-user.model'; import { IdentityUserModel } from '../models/identity-user.model';
import { IdentityUserFilterInterface } from './identity-user-filter.interface'; import { IdentityUserFilterInterface } from './identity-user-filter.interface';
@@ -33,15 +28,9 @@ const IDENTITY_MICRO_SERVICE_INGRESS = 'identity-adapter-service';
providedIn: 'root' providedIn: 'root'
}) })
export class IdentityUserService implements IdentityUserServiceInterface { export class IdentityUserService implements IdentityUserServiceInterface {
queryParams: { search: string; application?: string; roles?: string[]; groups?: string[] }; queryParams: { search: string; application?: string; roles?: string[]; groups?: string[] };
constructor( constructor(private jwtHelperService: JwtHelperService, private oAuth2Service: OAuth2Service, private appConfigService: AppConfigService) {}
private jwtHelperService: JwtHelperService,
private oAuth2Service: OAuth2Service,
private appConfigService: AppConfigService) {
}
/** /**
* Gets the name and other basic details of the current user. * Gets the name and other basic details of the current user.
@@ -80,33 +69,25 @@ export class IdentityUserService implements IdentityUserServiceInterface {
private searchUsersByName(name: string): Observable<IdentityUserModel[]> { private searchUsersByName(name: string): Observable<IdentityUserModel[]> {
this.buildQueryParam(name); this.buildQueryParam(name);
return this.invokeIdentityUserApi().pipe( return this.invokeIdentityUserApi();
catchError((err) => this.handleError(err))
);
} }
private searchUsersWithGlobalRoles(name: string, roles: string []): Observable<IdentityUserModel[]> { private searchUsersWithGlobalRoles(name: string, roles: string[]): Observable<IdentityUserModel[]> {
this.buildQueryParam(name, {roles}); this.buildQueryParam(name, { roles });
return this.invokeIdentityUserApi().pipe( return this.invokeIdentityUserApi();
catchError((err) => this.handleError(err))
);
} }
private searchUsersWithinApp(name: string, withinApplication: string, roles?: string []): Observable<IdentityUserModel[]> { private searchUsersWithinApp(name: string, withinApplication: string, roles?: string[]): Observable<IdentityUserModel[]> {
this.buildQueryParam(name, {roles, withinApplication}); this.buildQueryParam(name, { roles, withinApplication });
return this.invokeIdentityUserApi().pipe( return this.invokeIdentityUserApi();
catchError((err) => this.handleError(err))
);
} }
private searchUsersWithGroups(name: string, filters: IdentityUserFilterInterface): Observable<IdentityUserModel[]> { private searchUsersWithGroups(name: string, filters: IdentityUserFilterInterface): Observable<IdentityUserModel[]> {
this.buildQueryParam(name, filters); this.buildQueryParam(name, filters);
return this.invokeIdentityUserApi().pipe( return this.invokeIdentityUserApi();
catchError((err) => this.handleError(err))
);
} }
private invokeIdentityUserApi(): Observable<any> { private invokeIdentityUserApi(): Observable<any> {
@@ -121,7 +102,7 @@ export class IdentityUserService implements IdentityUserServiceInterface {
this.addOptionalCommaValueToQueryParam('group', filters?.groups); this.addOptionalCommaValueToQueryParam('group', filters?.groups);
} }
private addOptionalCommaValueToQueryParam(key: string, values: string []) { private addOptionalCommaValueToQueryParam(key: string, values: string[]) {
if (values?.length > 0) { if (values?.length > 0) {
const valuesNotEmpty = this.filterOutEmptyValue(values); const valuesNotEmpty = this.filterOutEmptyValue(values);
if (valuesNotEmpty?.length > 0) { if (valuesNotEmpty?.length > 0) {
@@ -136,15 +117,11 @@ export class IdentityUserService implements IdentityUserServiceInterface {
} }
} }
private filterOutEmptyValue(values: string []): string [] { private filterOutEmptyValue(values: string[]): string[] {
return values.filter( value => value.trim() ? true : false); return values.filter((value) => value.trim());
} }
private get identityHost(): string { private get identityHost(): string {
return `${this.appConfigService.get('bpmHost')}`; return `${this.appConfigService.get('bpmHost')}`;
} }
private handleError(error: any) {
return throwError(error || 'Server error');
}
} }

View File

@@ -17,24 +17,21 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { RuntimeAppDefinitionsApi, AppDefinitionRepresentation } from '@alfresco/js-api'; import { RuntimeAppDefinitionsApi, AppDefinitionRepresentation } from '@alfresco/js-api';
import { Observable, from, throwError } from 'rxjs'; import { Observable, from } from 'rxjs';
import { AlfrescoApiService, LogService } from '@alfresco/adf-core'; import { AlfrescoApiService } from '@alfresco/adf-core';
import { map, catchError } from 'rxjs/operators'; import { map } from 'rxjs/operators';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class AppsProcessService { export class AppsProcessService {
private _appsApi: RuntimeAppDefinitionsApi; private _appsApi: RuntimeAppDefinitionsApi;
get appsApi(): RuntimeAppDefinitionsApi { get appsApi(): RuntimeAppDefinitionsApi {
this._appsApi = this._appsApi ?? new RuntimeAppDefinitionsApi(this.apiService.getInstance()); this._appsApi = this._appsApi ?? new RuntimeAppDefinitionsApi(this.apiService.getInstance());
return this._appsApi; return this._appsApi;
} }
constructor(private apiService: AlfrescoApiService, constructor(private apiService: AlfrescoApiService) {}
private logService: LogService) {
}
/** /**
* Gets a list of deployed apps for this user. * Gets a list of deployed apps for this user.
@@ -42,11 +39,7 @@ export class AppsProcessService {
* @returns The list of deployed apps * @returns The list of deployed apps
*/ */
getDeployedApplications(): Observable<AppDefinitionRepresentation[]> { getDeployedApplications(): Observable<AppDefinitionRepresentation[]> {
return from(this.appsApi.getAppDefinitions()) return from(this.appsApi.getAppDefinitions()).pipe(map((response) => response.data));
.pipe(
map((response: any) => response.data),
catchError((err) => this.handleError(err))
);
} }
/** /**
@@ -56,11 +49,7 @@ export class AppsProcessService {
* @returns The list of deployed apps * @returns The list of deployed apps
*/ */
getDeployedApplicationsByName(name: string): Observable<AppDefinitionRepresentation> { getDeployedApplicationsByName(name: string): Observable<AppDefinitionRepresentation> {
return from(this.appsApi.getAppDefinitions()) return from(this.appsApi.getAppDefinitions()).pipe(map((response) => response.data.find((app) => app.name === name)));
.pipe(
map((response: any) => response.data.find((app) => app.name === name)),
catchError((err) => this.handleError(err))
);
} }
/** /**
@@ -70,16 +59,6 @@ export class AppsProcessService {
* @returns Details of the app * @returns Details of the app
*/ */
getApplicationDetailsById(appId: number): Observable<AppDefinitionRepresentation> { getApplicationDetailsById(appId: number): Observable<AppDefinitionRepresentation> {
return from(this.appsApi.getAppDefinitions()) return from(this.appsApi.getAppDefinitions()).pipe(map((response) => response.data.find((app) => app.id === appId)));
.pipe(
map((response: any) => response.data.find((app) => app.id === appId)),
catchError((err) => this.handleError(err))
);
} }
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
} }

View File

@@ -16,9 +16,9 @@
*/ */
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs'; import { Observable, from } from 'rxjs';
import { CommentModel, AlfrescoApiService, LogService, CommentsService, User } from '@alfresco/adf-core'; import { CommentModel, AlfrescoApiService, CommentsService, User } from '@alfresco/adf-core';
import { map, catchError } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ActivitiCommentsApi } from '@alfresco/js-api'; import { ActivitiCommentsApi } from '@alfresco/js-api';
import { PeopleProcessService } from '../../common/services/people-process.service'; import { PeopleProcessService } from '../../common/services/people-process.service';
import { UserProcessModel } from '../../common/models/user-process.model'; import { UserProcessModel } from '../../common/models/user-process.model';
@@ -27,18 +27,13 @@ import { UserProcessModel } from '../../common/models/user-process.model';
providedIn: 'root' providedIn: 'root'
}) })
export class CommentProcessService implements CommentsService { export class CommentProcessService implements CommentsService {
private _commentsApi: ActivitiCommentsApi; private _commentsApi: ActivitiCommentsApi;
get commentsApi(): ActivitiCommentsApi { get commentsApi(): ActivitiCommentsApi {
this._commentsApi = this._commentsApi ?? new ActivitiCommentsApi(this.apiService.getInstance()); this._commentsApi = this._commentsApi ?? new ActivitiCommentsApi(this.apiService.getInstance());
return this._commentsApi; return this._commentsApi;
} }
constructor(private apiService: AlfrescoApiService, constructor(private apiService: AlfrescoApiService, private peopleProcessService: PeopleProcessService) {}
private logService: LogService,
private peopleProcessService: PeopleProcessService
) {
}
/** /**
* Gets all comments that have been added to a process instance. * Gets all comments that have been added to a process instance.
@@ -47,23 +42,23 @@ export class CommentProcessService implements CommentsService {
* @returns Details for each comment * @returns Details for each comment
*/ */
get(id: string): Observable<CommentModel[]> { get(id: string): Observable<CommentModel[]> {
return from(this.commentsApi.getProcessInstanceComments(id)) return from(this.commentsApi.getProcessInstanceComments(id)).pipe(
.pipe( map((response) => {
map((response) => { const comments: CommentModel[] = [];
const comments: CommentModel[] = []; response.data.forEach((comment) => {
response.data.forEach((comment) => { const user = new UserProcessModel(comment.createdBy);
const user = new UserProcessModel(comment.createdBy); comments.push(
comments.push(new CommentModel({ new CommentModel({
id: comment.id, id: comment.id,
message: comment.message, message: comment.message,
created: comment.created, created: comment.created,
createdBy: new User(user) createdBy: new User(user)
})); })
}); );
return comments; });
}), return comments;
catchError((err: any) => this.handleError(err)) })
); );
} }
/** /**
@@ -74,24 +69,19 @@ export class CommentProcessService implements CommentsService {
* @returns Details of the comment added * @returns Details of the comment added
*/ */
add(id: string, message: string): Observable<CommentModel> { add(id: string, message: string): Observable<CommentModel> {
return from( return from(this.commentsApi.addProcessInstanceComment({ message }, id)).pipe(
this.commentsApi.addProcessInstanceComment({ message }, id) map(
).pipe( (response) =>
map((response) => new CommentModel({ new CommentModel({
id: response.id, id: response.id,
message: response.message, message: response.message,
created: response.created, created: response.created,
createdBy: new User(response.createdBy) createdBy: new User(response.createdBy)
})), })
catchError((err: any) => this.handleError(err)) )
); );
} }
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
getUserImage(user: UserProcessModel): string { getUserImage(user: UserProcessModel): string {
return this.peopleProcessService.getUserImage(user); return this.peopleProcessService.getUserImage(user);
} }

View File

@@ -18,97 +18,77 @@
import { AlfrescoApiService, CommentModel, CommentsService, User } from '@alfresco/adf-core'; import { AlfrescoApiService, CommentModel, CommentsService, User } from '@alfresco/adf-core';
import { ActivitiCommentsApi, CommentRepresentation } from '@alfresco/js-api'; import { ActivitiCommentsApi, CommentRepresentation } from '@alfresco/js-api';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { from, Observable, throwError } from 'rxjs'; import { from, Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { UserProcessModel } from '../../common/models/user-process.model'; import { UserProcessModel } from '../../common/models/user-process.model';
import { PeopleProcessService } from '../../common/services/people-process.service'; import { PeopleProcessService } from '../../common/services/people-process.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class TaskCommentsService implements CommentsService { export class TaskCommentsService implements CommentsService {
private _commentsApi: ActivitiCommentsApi;
get commentsApi(): ActivitiCommentsApi {
this._commentsApi = this._commentsApi ?? new ActivitiCommentsApi(this.apiService.getInstance());
return this._commentsApi;
}
private _commentsApi: ActivitiCommentsApi; constructor(private apiService: AlfrescoApiService, private peopleProcessService: PeopleProcessService) {}
get commentsApi(): ActivitiCommentsApi {
this._commentsApi = this._commentsApi ?? new ActivitiCommentsApi(this.apiService.getInstance());
return this._commentsApi;
}
constructor( /**
private apiService: AlfrescoApiService, * Gets all comments that have been added to a task.
private peopleProcessService: PeopleProcessService *
) {} * @param id ID of the target task
* @returns Details for each comment
*/
get(id: string): Observable<CommentModel[]> {
return from(this.commentsApi.getTaskComments(id)).pipe(
map((response) => {
const comments: CommentModel[] = [];
/** response.data.forEach((comment) => {
* Gets all comments that have been added to a task. this.addToComments(comments, comment);
* });
* @param id ID of the target task
* @returns Details for each comment
*/
get(id: string): Observable<CommentModel[]> {
return from(this.commentsApi.getTaskComments(id))
.pipe(
map((response) => {
const comments: CommentModel[] = [];
response.data.forEach((comment: CommentRepresentation) => { return comments;
this.addToComments(comments, comment); })
}); );
}
return comments; /**
}), * Adds a comment to a task.
catchError( *
(err: any) => this.handleError(err) * @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.addTaskComment({ message }, id)).pipe(map((response) => this.newCommentModel(response)));
}
/** private addToComments(comments: CommentModel[], comment: CommentRepresentation): void {
* Adds a comment to a task. const user = new UserProcessModel(comment.createdBy);
*
* @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.addTaskComment({ message }, id))
.pipe(
map(
(response: CommentRepresentation) => this.newCommentModel(response)
),
catchError(
(err: any) => this.handleError(err)
)
);
}
private addToComments(comments: CommentModel[], comment: CommentRepresentation): void { const newComment: CommentRepresentation = {
const user = new UserProcessModel(comment.createdBy); id: comment.id,
message: comment.message,
created: comment.created,
createdBy: user
};
const newComment: CommentRepresentation = { comments.push(this.newCommentModel(newComment));
id: comment.id, }
message: comment.message,
created: comment.created,
createdBy: user
};
comments.push(this.newCommentModel(newComment)); private newCommentModel(representation: CommentRepresentation): CommentModel {
} return new CommentModel({
id: representation.id,
message: representation.message,
created: representation.created,
createdBy: new User(representation.createdBy)
});
}
private newCommentModel(representation: CommentRepresentation): CommentModel { getUserImage(user: UserProcessModel): string {
return new CommentModel({ return this.peopleProcessService.getUserImage(user);
id: representation.id, }
message: representation.message,
created: representation.created,
createdBy: new User(representation.createdBy)
});
}
private handleError(error: any) {
return throwError(error || 'Server error');
}
getUserImage(user: UserProcessModel): string {
return this.peopleProcessService.getUserImage(user);
}
} }

View File

@@ -15,17 +15,15 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApiService, AppConfigService} from '@alfresco/adf-core'; import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core';
import { DiscoveryApiService, UploadService } from '@alfresco/adf-content-services'; import { DiscoveryApiService, UploadService } from '@alfresco/adf-content-services';
import { ActivitiContentApi } from '@alfresco/js-api'; import { ActivitiContentApi, RelatedContentRepresentation } from '@alfresco/js-api';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { throwError } from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class ProcessUploadService extends UploadService { export class ProcessUploadService extends UploadService {
private _contentApi: ActivitiContentApi; private _contentApi: ActivitiContentApi;
get contentApi(): ActivitiContentApi { get contentApi(): ActivitiContentApi {
this._contentApi = this._contentApi ?? new ActivitiContentApi(this.apiService.getInstance()); this._contentApi = this._contentApi ?? new ActivitiContentApi(this.apiService.getInstance());
@@ -36,20 +34,11 @@ export class ProcessUploadService extends UploadService {
super(apiService, appConfigService, discoveryApiService); super(apiService, appConfigService, discoveryApiService);
} }
getUploadPromise(file: any): any { getUploadPromise(file: any): Promise<RelatedContentRepresentation> {
const opts = { const opts = {
isRelatedContent: true isRelatedContent: true
}; };
const processInstanceId = file.options.parentId; const processInstanceId = file.options.parentId;
const promise = this.contentApi.createRelatedContentOnProcessInstance(processInstanceId, file.file, opts); return this.contentApi.createRelatedContentOnProcessInstance(processInstanceId, file.file, opts);
promise.catch((err) => this.handleError(err));
return promise;
} }
private handleError(error: any) {
return throwError(error || 'Server error');
}
} }

View File

@@ -15,27 +15,24 @@
* limitations under the License. * limitations under the License.
*/ */
import { AlfrescoApiService, LogService } from '@alfresco/adf-core'; import { AlfrescoApiService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, forkJoin, from, throwError } from 'rxjs'; import { Observable, forkJoin, from } from 'rxjs';
import { FilterRepresentationModel } from '../models/filter.model'; import { FilterRepresentationModel } from '../models/filter.model';
import { map, catchError } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { UserFiltersApi } from '@alfresco/js-api'; import { UserFiltersApi } from '@alfresco/js-api';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class TaskFilterService { export class TaskFilterService {
private _userFiltersApi: UserFiltersApi; private _userFiltersApi: UserFiltersApi;
get userFiltersApi(): UserFiltersApi { get userFiltersApi(): UserFiltersApi {
this._userFiltersApi = this._userFiltersApi ?? new UserFiltersApi(this.apiService.getInstance()); this._userFiltersApi = this._userFiltersApi ?? new UserFiltersApi(this.apiService.getInstance());
return this._userFiltersApi; return this._userFiltersApi;
} }
constructor(private apiService: AlfrescoApiService, constructor(private apiService: AlfrescoApiService) {}
private logService: LogService) {
}
/** /**
* Creates and returns the default filters for a process app. * Creates and returns the default filters for a process app.
@@ -57,50 +54,48 @@ export class TaskFilterService {
const completeObservable = this.addFilter(completedTasksFilter); const completeObservable = this.addFilter(completedTasksFilter);
return new Observable((observer) => { return new Observable((observer) => {
forkJoin([ forkJoin([myTaskObservable, involvedObservable, queuedObservable, completeObservable]).subscribe((res) => {
myTaskObservable, const filters: FilterRepresentationModel[] = [];
involvedObservable, res.forEach((filter) => {
queuedObservable, if (!this.isFilterAlreadyExisting(filters, filter.name)) {
completeObservable if (filter.name === involvedTasksFilter.name) {
] filters.push(
).subscribe( new FilterRepresentationModel({
(res) => {
const filters: FilterRepresentationModel[] = [];
res.forEach((filter) => {
if (!this.isFilterAlreadyExisting(filters, filter.name)) {
if (filter.name === involvedTasksFilter.name) {
filters.push(new FilterRepresentationModel({
...filter, ...filter,
filter: involvedTasksFilter.filter, filter: involvedTasksFilter.filter,
appId appId
})); })
} else if (filter.name === myTasksFilter.name) { );
filters.push(new FilterRepresentationModel({ } else if (filter.name === myTasksFilter.name) {
filters.push(
new FilterRepresentationModel({
...filter, ...filter,
filter: myTasksFilter.filter, filter: myTasksFilter.filter,
appId appId
})); })
} else if (filter.name === queuedTasksFilter.name) { );
filters.push(new FilterRepresentationModel({ } else if (filter.name === queuedTasksFilter.name) {
filters.push(
new FilterRepresentationModel({
...filter, ...filter,
filter: queuedTasksFilter.filter, filter: queuedTasksFilter.filter,
appId appId
})); })
} else if (filter.name === completedTasksFilter.name) { );
filters.push(new FilterRepresentationModel({ } else if (filter.name === completedTasksFilter.name) {
filters.push(
new FilterRepresentationModel({
...filter, ...filter,
filter: completedTasksFilter.filter, filter: completedTasksFilter.filter,
appId appId
})); })
} );
} }
}); }
observer.next(filters);
observer.complete();
},
(err: any) => {
this.logService.error(err);
}); });
observer.next(filters);
observer.complete();
});
}); });
} }
@@ -111,20 +106,18 @@ export class TaskFilterService {
* @returns Array of task filter details * @returns Array of task filter details
*/ */
getTaskListFilters(appId?: number): Observable<FilterRepresentationModel[]> { getTaskListFilters(appId?: number): Observable<FilterRepresentationModel[]> {
return from(this.callApiTaskFilters(appId)) return from(this.callApiTaskFilters(appId)).pipe(
.pipe( map((response) => {
map((response: any) => { const filters: FilterRepresentationModel[] = [];
const filters: FilterRepresentationModel[] = []; response.data.forEach((filter: FilterRepresentationModel) => {
response.data.forEach((filter: FilterRepresentationModel) => { if (!this.isFilterAlreadyExisting(filters, filter.name)) {
if (!this.isFilterAlreadyExisting(filters, filter.name)) { const filterModel = new FilterRepresentationModel(filter);
const filterModel = new FilterRepresentationModel(filter); filters.push(filterModel);
filters.push(filterModel); }
} });
}); return filters;
return filters; })
}), );
catchError((err) => this.handleError(err))
);
} }
/** /**
@@ -146,10 +139,7 @@ export class TaskFilterService {
* @returns Details of task filter * @returns Details of task filter
*/ */
getTaskFilterById(filterId: number, appId?: number): Observable<FilterRepresentationModel> { getTaskFilterById(filterId: number, appId?: number): Observable<FilterRepresentationModel> {
return from(this.callApiTaskFilters(appId)).pipe( return from(this.callApiTaskFilters(appId)).pipe(map((response) => response.data.find((filter) => filter.id === filterId)));
map((response) => response.data.find((filter) => filter.id === filterId)),
catchError((err) => this.handleError(err))
);
} }
/** /**
@@ -160,10 +150,7 @@ export class TaskFilterService {
* @returns Details of task filter * @returns Details of task filter
*/ */
getTaskFilterByName(taskName: string, appId?: number): Observable<FilterRepresentationModel> { getTaskFilterByName(taskName: string, appId?: number): Observable<FilterRepresentationModel> {
return from(this.callApiTaskFilters(appId)).pipe( return from(this.callApiTaskFilters(appId)).pipe(map((response) => response.data.find((filter) => filter.name === taskName)));
map((response) => response.data.find((filter) => filter.name === taskName)),
catchError((err) => this.handleError(err))
);
} }
/** /**
@@ -173,11 +160,7 @@ export class TaskFilterService {
* @returns Details of task filter just added * @returns Details of task filter just added
*/ */
addFilter(filter: FilterRepresentationModel): Observable<FilterRepresentationModel> { addFilter(filter: FilterRepresentationModel): Observable<FilterRepresentationModel> {
return from(this.userFiltersApi.createUserTaskFilter(filter)) return from(this.userFiltersApi.createUserTaskFilter(filter)).pipe(map((response: FilterRepresentationModel) => response));
.pipe(
map((response: FilterRepresentationModel) => response),
catchError((err) => this.handleError(err))
);
} }
/** /**
@@ -270,9 +253,4 @@ export class TaskFilterService {
index index
}); });
} }
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
} }

View File

@@ -18,14 +18,12 @@
import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core'; import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core';
import { DiscoveryApiService, UploadService } from '@alfresco/adf-content-services'; import { DiscoveryApiService, UploadService } from '@alfresco/adf-content-services';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { throwError } from 'rxjs'; import { ActivitiContentApi, RelatedContentRepresentation } from '@alfresco/js-api';
import { ActivitiContentApi } from '@alfresco/js-api';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class TaskUploadService extends UploadService { export class TaskUploadService extends UploadService {
private _contentApi: ActivitiContentApi; private _contentApi: ActivitiContentApi;
get contentApi(): ActivitiContentApi { get contentApi(): ActivitiContentApi {
this._contentApi = this._contentApi ?? new ActivitiContentApi(this.apiService.getInstance()); this._contentApi = this._contentApi ?? new ActivitiContentApi(this.apiService.getInstance());
@@ -36,20 +34,11 @@ export class TaskUploadService extends UploadService {
super(apiService, appConfigService, discoveryApiService); super(apiService, appConfigService, discoveryApiService);
} }
getUploadPromise(file: any): any { getUploadPromise(file: any): Promise<RelatedContentRepresentation> {
const opts = { const opts = {
isRelatedContent: true isRelatedContent: true
}; };
const taskId = file.options.parentId; const taskId = file.options.parentId;
const promise = this.contentApi.createRelatedContentOnTask(taskId, file.file, opts); return this.contentApi.createRelatedContentOnTask(taskId, file.file, opts);
promise.catch((err) => this.handleError(err));
return promise;
} }
private handleError(error: any) {
return throwError(error || 'Server error');
}
} }