[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

@@ -17,24 +17,21 @@
import { Injectable } from '@angular/core';
import { RuntimeAppDefinitionsApi, AppDefinitionRepresentation } from '@alfresco/js-api';
import { Observable, from, throwError } from 'rxjs';
import { AlfrescoApiService, LogService } from '@alfresco/adf-core';
import { map, catchError } from 'rxjs/operators';
import { Observable, from } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class AppsProcessService {
private _appsApi: RuntimeAppDefinitionsApi;
get appsApi(): RuntimeAppDefinitionsApi {
this._appsApi = this._appsApi ?? new RuntimeAppDefinitionsApi(this.apiService.getInstance());
return this._appsApi;
}
constructor(private apiService: AlfrescoApiService,
private logService: LogService) {
}
constructor(private apiService: AlfrescoApiService) {}
/**
* Gets a list of deployed apps for this user.
@@ -42,11 +39,7 @@ export class AppsProcessService {
* @returns The list of deployed apps
*/
getDeployedApplications(): Observable<AppDefinitionRepresentation[]> {
return from(this.appsApi.getAppDefinitions())
.pipe(
map((response: any) => response.data),
catchError((err) => this.handleError(err))
);
return from(this.appsApi.getAppDefinitions()).pipe(map((response) => response.data));
}
/**
@@ -56,11 +49,7 @@ export class AppsProcessService {
* @returns The list of deployed apps
*/
getDeployedApplicationsByName(name: string): Observable<AppDefinitionRepresentation> {
return from(this.appsApi.getAppDefinitions())
.pipe(
map((response: any) => response.data.find((app) => app.name === name)),
catchError((err) => this.handleError(err))
);
return from(this.appsApi.getAppDefinitions()).pipe(map((response) => response.data.find((app) => app.name === name)));
}
/**
@@ -70,16 +59,6 @@ export class AppsProcessService {
* @returns Details of the app
*/
getApplicationDetailsById(appId: number): Observable<AppDefinitionRepresentation> {
return from(this.appsApi.getAppDefinitions())
.pipe(
map((response: any) => response.data.find((app) => app.id === appId)),
catchError((err) => this.handleError(err))
);
return from(this.appsApi.getAppDefinitions()).pipe(map((response) => response.data.find((app) => app.id === appId)));
}
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 { Observable, from, throwError } from 'rxjs';
import { CommentModel, AlfrescoApiService, LogService, CommentsService, User } from '@alfresco/adf-core';
import { map, catchError } from 'rxjs/operators';
import { Observable, from } from 'rxjs';
import { CommentModel, AlfrescoApiService, CommentsService, User } from '@alfresco/adf-core';
import { map } from 'rxjs/operators';
import { ActivitiCommentsApi } from '@alfresco/js-api';
import { PeopleProcessService } from '../../common/services/people-process.service';
import { UserProcessModel } from '../../common/models/user-process.model';
@@ -27,18 +27,13 @@ import { UserProcessModel } from '../../common/models/user-process.model';
providedIn: 'root'
})
export class CommentProcessService implements CommentsService {
private _commentsApi: ActivitiCommentsApi;
get commentsApi(): ActivitiCommentsApi {
this._commentsApi = this._commentsApi ?? new ActivitiCommentsApi(this.apiService.getInstance());
return this._commentsApi;
}
constructor(private apiService: AlfrescoApiService,
private logService: LogService,
private peopleProcessService: PeopleProcessService
) {
}
constructor(private apiService: AlfrescoApiService, private peopleProcessService: PeopleProcessService) {}
/**
* 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
*/
get(id: string): Observable<CommentModel[]> {
return from(this.commentsApi.getProcessInstanceComments(id))
.pipe(
map((response) => {
const comments: CommentModel[] = [];
response.data.forEach((comment) => {
const user = new UserProcessModel(comment.createdBy);
comments.push(new CommentModel({
return from(this.commentsApi.getProcessInstanceComments(id)).pipe(
map((response) => {
const comments: CommentModel[] = [];
response.data.forEach((comment) => {
const user = new UserProcessModel(comment.createdBy);
comments.push(
new CommentModel({
id: comment.id,
message: comment.message,
created: comment.created,
createdBy: new User(user)
}));
});
return comments;
}),
catchError((err: any) => this.handleError(err))
);
})
);
});
return comments;
})
);
}
/**
@@ -74,24 +69,19 @@ export class CommentProcessService implements CommentsService {
* @returns Details of the comment added
*/
add(id: string, message: string): Observable<CommentModel> {
return from(
this.commentsApi.addProcessInstanceComment({ message }, id)
).pipe(
map((response) => new CommentModel({
id: response.id,
message: response.message,
created: response.created,
createdBy: new User(response.createdBy)
})),
catchError((err: any) => this.handleError(err))
return from(this.commentsApi.addProcessInstanceComment({ message }, id)).pipe(
map(
(response) =>
new CommentModel({
id: response.id,
message: response.message,
created: response.created,
createdBy: new User(response.createdBy)
})
)
);
}
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
getUserImage(user: UserProcessModel): string {
return this.peopleProcessService.getUserImage(user);
}

View File

@@ -18,97 +18,77 @@
import { AlfrescoApiService, CommentModel, CommentsService, User } from '@alfresco/adf-core';
import { ActivitiCommentsApi, CommentRepresentation } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { from, Observable, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { from, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { UserProcessModel } from '../../common/models/user-process.model';
import { PeopleProcessService } from '../../common/services/people-process.service';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
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;
get commentsApi(): ActivitiCommentsApi {
this._commentsApi = this._commentsApi ?? new ActivitiCommentsApi(this.apiService.getInstance());
return this._commentsApi;
}
constructor(private apiService: AlfrescoApiService, private peopleProcessService: PeopleProcessService) {}
constructor(
private apiService: AlfrescoApiService,
private peopleProcessService: PeopleProcessService
) {}
/**
* 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.getTaskComments(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.getTaskComments(id))
.pipe(
map((response) => {
const comments: CommentModel[] = [];
response.data.forEach((comment) => {
this.addToComments(comments, comment);
});
response.data.forEach((comment: CommentRepresentation) => {
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.addTaskComment({ message }, id)).pipe(map((response) => this.newCommentModel(response)));
}
/**
* 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.addTaskComment({ message }, id))
.pipe(
map(
(response: CommentRepresentation) => this.newCommentModel(response)
),
catchError(
(err: any) => this.handleError(err)
)
);
}
private addToComments(comments: CommentModel[], comment: CommentRepresentation): void {
const user = new UserProcessModel(comment.createdBy);
private addToComments(comments: CommentModel[], comment: CommentRepresentation): void {
const user = new UserProcessModel(comment.createdBy);
const newComment: CommentRepresentation = {
id: comment.id,
message: comment.message,
created: comment.created,
createdBy: user
};
const newComment: CommentRepresentation = {
id: comment.id,
message: comment.message,
created: comment.created,
createdBy: user
};
comments.push(this.newCommentModel(newComment));
}
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 {
return new CommentModel({
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);
}
getUserImage(user: UserProcessModel): string {
return this.peopleProcessService.getUserImage(user);
}
}

View File

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

View File

@@ -15,27 +15,24 @@
* limitations under the License.
*/
import { AlfrescoApiService, LogService } from '@alfresco/adf-core';
import { AlfrescoApiService } from '@alfresco/adf-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 { map, catchError } from 'rxjs/operators';
import { map } from 'rxjs/operators';
import { UserFiltersApi } from '@alfresco/js-api';
@Injectable({
providedIn: 'root'
})
export class TaskFilterService {
private _userFiltersApi: UserFiltersApi;
get userFiltersApi(): UserFiltersApi {
this._userFiltersApi = this._userFiltersApi ?? new UserFiltersApi(this.apiService.getInstance());
return this._userFiltersApi;
}
constructor(private apiService: AlfrescoApiService,
private logService: LogService) {
}
constructor(private apiService: AlfrescoApiService) {}
/**
* Creates and returns the default filters for a process app.
@@ -57,50 +54,48 @@ export class TaskFilterService {
const completeObservable = this.addFilter(completedTasksFilter);
return new Observable((observer) => {
forkJoin([
myTaskObservable,
involvedObservable,
queuedObservable,
completeObservable
]
).subscribe(
(res) => {
const filters: FilterRepresentationModel[] = [];
res.forEach((filter) => {
if (!this.isFilterAlreadyExisting(filters, filter.name)) {
if (filter.name === involvedTasksFilter.name) {
filters.push(new FilterRepresentationModel({
forkJoin([myTaskObservable, involvedObservable, queuedObservable, completeObservable]).subscribe((res) => {
const filters: FilterRepresentationModel[] = [];
res.forEach((filter) => {
if (!this.isFilterAlreadyExisting(filters, filter.name)) {
if (filter.name === involvedTasksFilter.name) {
filters.push(
new FilterRepresentationModel({
...filter,
filter: involvedTasksFilter.filter,
appId
}));
} else if (filter.name === myTasksFilter.name) {
filters.push(new FilterRepresentationModel({
})
);
} else if (filter.name === myTasksFilter.name) {
filters.push(
new FilterRepresentationModel({
...filter,
filter: myTasksFilter.filter,
appId
}));
} else if (filter.name === queuedTasksFilter.name) {
filters.push(new FilterRepresentationModel({
})
);
} else if (filter.name === queuedTasksFilter.name) {
filters.push(
new FilterRepresentationModel({
...filter,
filter: queuedTasksFilter.filter,
appId
}));
} else if (filter.name === completedTasksFilter.name) {
filters.push(new FilterRepresentationModel({
})
);
} else if (filter.name === completedTasksFilter.name) {
filters.push(
new FilterRepresentationModel({
...filter,
filter: completedTasksFilter.filter,
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
*/
getTaskListFilters(appId?: number): Observable<FilterRepresentationModel[]> {
return from(this.callApiTaskFilters(appId))
.pipe(
map((response: any) => {
const filters: FilterRepresentationModel[] = [];
response.data.forEach((filter: FilterRepresentationModel) => {
if (!this.isFilterAlreadyExisting(filters, filter.name)) {
const filterModel = new FilterRepresentationModel(filter);
filters.push(filterModel);
}
});
return filters;
}),
catchError((err) => this.handleError(err))
);
return from(this.callApiTaskFilters(appId)).pipe(
map((response) => {
const filters: FilterRepresentationModel[] = [];
response.data.forEach((filter: FilterRepresentationModel) => {
if (!this.isFilterAlreadyExisting(filters, filter.name)) {
const filterModel = new FilterRepresentationModel(filter);
filters.push(filterModel);
}
});
return filters;
})
);
}
/**
@@ -146,10 +139,7 @@ export class TaskFilterService {
* @returns Details of task filter
*/
getTaskFilterById(filterId: number, appId?: number): Observable<FilterRepresentationModel> {
return from(this.callApiTaskFilters(appId)).pipe(
map((response) => response.data.find((filter) => filter.id === filterId)),
catchError((err) => this.handleError(err))
);
return from(this.callApiTaskFilters(appId)).pipe(map((response) => response.data.find((filter) => filter.id === filterId)));
}
/**
@@ -160,10 +150,7 @@ export class TaskFilterService {
* @returns Details of task filter
*/
getTaskFilterByName(taskName: string, appId?: number): Observable<FilterRepresentationModel> {
return from(this.callApiTaskFilters(appId)).pipe(
map((response) => response.data.find((filter) => filter.name === taskName)),
catchError((err) => this.handleError(err))
);
return from(this.callApiTaskFilters(appId)).pipe(map((response) => response.data.find((filter) => filter.name === taskName)));
}
/**
@@ -173,11 +160,7 @@ export class TaskFilterService {
* @returns Details of task filter just added
*/
addFilter(filter: FilterRepresentationModel): Observable<FilterRepresentationModel> {
return from(this.userFiltersApi.createUserTaskFilter(filter))
.pipe(
map((response: FilterRepresentationModel) => response),
catchError((err) => this.handleError(err))
);
return from(this.userFiltersApi.createUserTaskFilter(filter)).pipe(map((response: FilterRepresentationModel) => response));
}
/**
@@ -270,9 +253,4 @@ export class TaskFilterService {
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 { DiscoveryApiService, UploadService } from '@alfresco/adf-content-services';
import { Injectable } from '@angular/core';
import { throwError } from 'rxjs';
import { ActivitiContentApi } from '@alfresco/js-api';
import { ActivitiContentApi, RelatedContentRepresentation } from '@alfresco/js-api';
@Injectable({
providedIn: 'root'
})
export class TaskUploadService extends UploadService {
private _contentApi: ActivitiContentApi;
get contentApi(): ActivitiContentApi {
this._contentApi = this._contentApi ?? new ActivitiContentApi(this.apiService.getInstance());
@@ -36,20 +34,11 @@ export class TaskUploadService extends UploadService {
super(apiService, appConfigService, discoveryApiService);
}
getUploadPromise(file: any): any {
getUploadPromise(file: any): Promise<RelatedContentRepresentation> {
const opts = {
isRelatedContent: true
};
const taskId = file.options.parentId;
const promise = this.contentApi.createRelatedContentOnTask(taskId, file.file, opts);
promise.catch((err) => this.handleError(err));
return promise;
return this.contentApi.createRelatedContentOnTask(taskId, file.file, opts);
}
private handleError(error: any) {
return throwError(error || 'Server error');
}
}