[AAE-7338] Changed endpoint for process task list (#7522)

* [AAE-7338] Changed approach to use token injection

* [AAE-7338] moved model files up

* [AAE-7338] fixed imports

* [AAE-7338] changed class to interface

* [AAE-7338] fixed model imports

* * Fixed failing unit tests due recent changes

* [AAE-7338] fixed unit test

Co-authored-by: sivakumar414ram <sivakumar414ram@gmail.com>
This commit is contained in:
Tomasz Gnyp
2022-03-07 17:48:15 +01:00
committed by GitHub
parent a0c7631abb
commit e877cd822b
19 changed files with 172 additions and 21 deletions

View File

@@ -22,5 +22,6 @@ export * from './models/process-cloud-preset.model';
export * from './models/process-list-sorting.model'; export * from './models/process-list-sorting.model';
export * from './services/process-list-cloud.service'; export * from './services/process-list-cloud.service';
export * from './services/process-task-list-cloud.service';
export * from './process-list-cloud.module'; export * from './process-list-cloud.module';

View File

@@ -0,0 +1,100 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core';
import { Observable, throwError } from 'rxjs';
import { BaseCloudService } from '../../../services/base-cloud.service';
import { map } from 'rxjs/operators';
import { TaskListCloudServiceInterface } from '../../../services/task-list-cloud.service.interface';
import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model';
import { TaskCloudNodePaging } from '../../../models/task-cloud.model';
import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
@Injectable({ providedIn: 'root' })
export class ProcessTaskListCloudService extends BaseCloudService implements TaskListCloudServiceInterface {
constructor(apiService: AlfrescoApiService,
appConfigService: AppConfigService,
protected logService: LogService) {
super(apiService, appConfigService);
}
/**
* Finds a task using an object with optional query properties.
*
* @param requestNode Query object
* @param queryUrl Query url
* @returns Task information
*/
getTaskByRequest(requestNode: TaskQueryCloudRequestModel, queryUrl?: string): Observable<any> {
if (requestNode.appName || requestNode.appName === '') {
queryUrl = queryUrl || `${this.getBasePath(requestNode.appName)}/query/v1/process-instances/${requestNode.processInstanceId}/tasks`;
const queryParams = this.buildQueryParams(requestNode);
const sortingParams = this.buildSortingParam(requestNode.sorting);
if (sortingParams) {
queryParams['sort'] = sortingParams;
}
return this.get<TaskCloudNodePaging>(queryUrl, queryParams).pipe(
map((response: any) => {
const entries = response.list && response.list.entries;
if (entries) {
response.list.entries = entries.map((entryData: any) => entryData.entry);
}
return response;
})
);
} else {
this.logService.error('Appname is mandatory for querying task');
return throwError('Appname not configured');
}
}
protected buildQueryParams(requestNode: TaskQueryCloudRequestModel): any {
const queryParam: any = {};
for (const property in requestNode) {
if (requestNode.hasOwnProperty(property) &&
!this.isExcludedField(property) &&
this.isPropertyValueValid(requestNode, property)) {
queryParam[property] = requestNode[property];
}
}
return queryParam;
}
protected isExcludedField(property: string): boolean {
return property === 'appName' || property === 'sorting';
}
protected isPropertyValueValid(requestNode: any, property: string): boolean {
return requestNode[property] !== '' && requestNode[property] !== null && requestNode[property] !== undefined;
}
protected buildSortingParam(models: TaskListCloudSortingModel[]): string {
let finalSorting: string = '';
if (models) {
for (const sort of models) {
if (!finalSorting) {
finalSorting = `${sort.orderBy},${sort.direction}`;
} else {
finalSorting = `${finalSorting}&${sort.orderBy},${sort.direction}`;
}
}
}
return encodeURI(finalSorting);
}
}

View File

@@ -17,7 +17,10 @@
import { InjectionToken } from '@angular/core'; import { InjectionToken } from '@angular/core';
import { PreferenceCloudServiceInterface } from './preference-cloud.interface'; import { PreferenceCloudServiceInterface } from './preference-cloud.interface';
import { TaskListCloudServiceInterface } from './task-list-cloud.service.interface';
export const PROCESS_FILTERS_SERVICE_TOKEN = new InjectionToken<PreferenceCloudServiceInterface>('proccess-filters-cloud'); export const PROCESS_FILTERS_SERVICE_TOKEN = new InjectionToken<PreferenceCloudServiceInterface>('proccess-filters-cloud');
export const TASK_FILTERS_SERVICE_TOKEN = new InjectionToken<PreferenceCloudServiceInterface>('task-filters-cloud'); export const TASK_FILTERS_SERVICE_TOKEN = new InjectionToken<PreferenceCloudServiceInterface>('task-filters-cloud');
export const TASK_LIST_CLOUD_TOKEN = new InjectionToken<TaskListCloudServiceInterface>('task-list-cloud');

View File

@@ -0,0 +1,23 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Observable } from 'rxjs';
import { TaskQueryCloudRequestModel } from '../models/filter-cloud-model';
export interface TaskListCloudServiceInterface {
getTaskByRequest(requestNode: TaskQueryCloudRequestModel, queryUrl?: string): Observable<any>;
}

View File

@@ -23,7 +23,7 @@ import { switchMap, map } from 'rxjs/operators';
import { BaseCloudService } from '../../../services/base-cloud.service'; import { BaseCloudService } from '../../../services/base-cloud.service';
import { PreferenceCloudServiceInterface } from '../../../services/preference-cloud.interface'; import { PreferenceCloudServiceInterface } from '../../../services/preference-cloud.interface';
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
import { TaskCloudNodePaging } from '../../task-list/models/task-cloud.model'; import { TaskCloudNodePaging } from '../../../models/task-cloud.model';
import { NotificationCloudService } from '../../../services/notification-cloud.service'; import { NotificationCloudService } from '../../../services/notification-cloud.service';
import { TaskCloudEngineEvent } from '../../../models/engine-event-cloud.model'; import { TaskCloudEngineEvent } from '../../../models/engine-event-cloud.model';

View File

@@ -23,9 +23,9 @@ import {
DataRowEvent, CustomEmptyContentTemplateDirective, DataCellEvent, DataRowActionEvent, DataRow, DataColumn DataRowEvent, CustomEmptyContentTemplateDirective, DataCellEvent, DataRowActionEvent, DataRow, DataColumn
} from '@alfresco/adf-core'; } from '@alfresco/adf-core';
import { taskPresetsCloudDefaultModel } from '../models/task-preset-cloud.model'; import { taskPresetsCloudDefaultModel } from '../models/task-preset-cloud.model';
import { TaskQueryCloudRequestModel } from '../models/filter-cloud-model'; import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model';
import { BehaviorSubject, Subject } from 'rxjs'; import { BehaviorSubject, Subject } from 'rxjs';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { TaskCloudService } from '../../services/task-cloud.service'; import { TaskCloudService } from '../../services/task-cloud.service';

View File

@@ -24,7 +24,7 @@ import { fakeServiceTask, fakeCustomSchema } from '../mock/fake-task-response.mo
import { of } from 'rxjs'; import { of } from 'rxjs';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
import { skip } from 'rxjs/operators'; import { skip } from 'rxjs/operators';
import { ServiceTaskListCloudService } from '../services/service-task-list-cloud.service'; import { ServiceTaskListCloudService } from '../services/service-task-list-cloud.service';

View File

@@ -25,8 +25,10 @@ import { fakeGlobalTask, fakeCustomSchema } from '../mock/fake-task-response.moc
import { of } from 'rxjs'; import { of } from 'rxjs';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
import { skip } from 'rxjs/operators'; import { skip } from 'rxjs/operators';
import { TaskListCloudServiceInterface } from '../../../services/task-list-cloud.service.interface';
import { TASK_LIST_CLOUD_TOKEN } from '../../../services/cloud-token.service';
@Component({ @Component({
template: ` template: `
@@ -79,7 +81,7 @@ describe('TaskListCloudComponent', () => {
let component: TaskListCloudComponent; let component: TaskListCloudComponent;
let fixture: ComponentFixture<TaskListCloudComponent>; let fixture: ComponentFixture<TaskListCloudComponent>;
let appConfig: AppConfigService; let appConfig: AppConfigService;
let taskListCloudService: TaskListCloudService; let taskListCloudService: TaskListCloudServiceInterface;
setupTestBed({ setupTestBed({
imports: [ imports: [
@@ -88,14 +90,20 @@ describe('TaskListCloudComponent', () => {
], ],
declarations: [ declarations: [
EmptyTemplateComponent EmptyTemplateComponent
],
providers: [
{
provide: TASK_LIST_CLOUD_TOKEN,
useClass: TaskListCloudService
}
] ]
}); });
beforeEach(() => { beforeEach(() => {
appConfig = TestBed.inject(AppConfigService); appConfig = TestBed.inject(AppConfigService);
taskListCloudService = TestBed.inject(TaskListCloudService);
fixture = TestBed.createComponent(TaskListCloudComponent); fixture = TestBed.createComponent(TaskListCloudComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
taskListCloudService = TestBed.inject(TASK_LIST_CLOUD_TOKEN);
appConfig.config = Object.assign(appConfig.config, { appConfig.config = Object.assign(appConfig.config, {
'adf-cloud-task-list': { 'adf-cloud-task-list': {
presets: { presets: {
@@ -122,6 +130,12 @@ describe('TaskListCloudComponent', () => {
fixture.destroy(); fixture.destroy();
}); });
it('should be able to inject TaskListCloudService instance', () => {
fixture.detectChanges();
expect(component.taskListCloudService instanceof TaskListCloudService).toBeTruthy();
});
it('should use the default schemaColumn as default', () => { it('should use the default schemaColumn as default', () => {
component.ngAfterContentInit(); component.ngAfterContentInit();
expect(component.columns).toBeDefined(); expect(component.columns).toBeDefined();
@@ -495,7 +509,7 @@ describe('TaskListCloudComponent', () => {
beforeEach(() => { beforeEach(() => {
appConfig = TestBed.inject(AppConfigService); appConfig = TestBed.inject(AppConfigService);
taskListCloudService = TestBed.inject(TaskListCloudService); taskListCloudService = TestBed.inject(TASK_LIST_CLOUD_TOKEN);
appConfig.config = Object.assign(appConfig.config, { appConfig.config = Object.assign(appConfig.config, {
'adf-cloud-task-list': { 'adf-cloud-task-list': {
presets: { presets: {

View File

@@ -15,12 +15,13 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, ViewEncapsulation, Input } from '@angular/core'; import { Component, ViewEncapsulation, Input, Inject } from '@angular/core';
import { AppConfigService, UserPreferencesService } from '@alfresco/adf-core'; import { AppConfigService, UserPreferencesService } from '@alfresco/adf-core';
import { TaskQueryCloudRequestModel } from '../models/filter-cloud-model'; import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model';
import { TaskListCloudService } from '../services/task-list-cloud.service';
import { BaseTaskListCloudComponent } from './base-task-list-cloud.component'; import { BaseTaskListCloudComponent } from './base-task-list-cloud.component';
import { TaskCloudService } from '../../services/task-cloud.service'; import { TaskCloudService } from '../../services/task-cloud.service';
import { TASK_LIST_CLOUD_TOKEN } from '../../../services/cloud-token.service';
import { TaskListCloudServiceInterface } from '../../../services/task-list-cloud.service.interface';
const PRESET_KEY = 'adf-cloud-task-list.presets'; const PRESET_KEY = 'adf-cloud-task-list.presets';
@@ -131,7 +132,7 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent {
@Input() @Input()
candidateGroupId: string = ''; candidateGroupId: string = '';
constructor(private taskListCloudService: TaskListCloudService, constructor(@Inject(TASK_LIST_CLOUD_TOKEN) public taskListCloudService: TaskListCloudServiceInterface,
appConfigService: AppConfigService, appConfigService: AppConfigService,
taskCloudService: TaskCloudService, taskCloudService: TaskCloudService,
userPreferences: UserPreferencesService) { userPreferences: UserPreferencesService) {

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { TaskListCloudSortingModel } from './task-list-sorting.model'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
export interface ServiceTaskQueryCloudRequestModel { export interface ServiceTaskQueryCloudRequestModel {
appName: string; appName: string;

View File

@@ -18,9 +18,7 @@
export * from './components/task-list-cloud.component'; export * from './components/task-list-cloud.component';
export * from './components/service-task-list-cloud.component'; export * from './components/service-task-list-cloud.component';
export * from './models/filter-cloud-model';
export * from './models/service-task-cloud.model'; export * from './models/service-task-cloud.model';
export * from './models/task-list-sorting.model';
export * from './models/task-preset-cloud.model'; export * from './models/task-preset-cloud.model';
export * from './services/task-list-cloud.service'; export * from './services/task-list-cloud.service';

View File

@@ -19,7 +19,7 @@ import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core';
import { ServiceTaskQueryCloudRequestModel, ServiceTaskIntegrationContextCloudModel } from '../models/service-task-cloud.model'; import { ServiceTaskQueryCloudRequestModel, ServiceTaskIntegrationContextCloudModel } from '../models/service-task-cloud.model';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
import { BaseCloudService } from '../../../services/base-cloud.service'; import { BaseCloudService } from '../../../services/base-cloud.service';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';

View File

@@ -18,7 +18,7 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { setupTestBed, AlfrescoApiService } from '@alfresco/adf-core'; import { setupTestBed, AlfrescoApiService } from '@alfresco/adf-core';
import { TaskListCloudService } from './task-list-cloud.service'; import { TaskListCloudService } from './task-list-cloud.service';
import { TaskQueryCloudRequestModel } from '../models/filter-cloud-model'; import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';

View File

@@ -17,15 +17,16 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core'; import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core';
import { TaskQueryCloudRequestModel } from '../models/filter-cloud-model'; import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import { TaskListCloudSortingModel } from '../models/task-list-sorting.model'; import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
import { BaseCloudService } from '../../../services/base-cloud.service'; import { BaseCloudService } from '../../../services/base-cloud.service';
import { TaskCloudNodePaging } from '../models/task-cloud.model'; import { TaskCloudNodePaging } from '../../../models/task-cloud.model';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { TaskListCloudServiceInterface } from '../../../services/task-list-cloud.service.interface';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class TaskListCloudService extends BaseCloudService { export class TaskListCloudService extends BaseCloudService implements TaskListCloudServiceInterface {
constructor(apiService: AlfrescoApiService, constructor(apiService: AlfrescoApiService,
appConfigService: AppConfigService, appConfigService: AppConfigService,

View File

@@ -21,6 +21,8 @@ import { MaterialModule } from '../../material.module';
import { TaskListCloudComponent } from './components/task-list-cloud.component'; import { TaskListCloudComponent } from './components/task-list-cloud.component';
import { ServiceTaskListCloudComponent } from './components/service-task-list-cloud.component'; import { ServiceTaskListCloudComponent } from './components/service-task-list-cloud.component';
import { CoreModule } from '@alfresco/adf-core'; import { CoreModule } from '@alfresco/adf-core';
import { TASK_LIST_CLOUD_TOKEN } from '../../services/cloud-token.service';
import { TaskListCloudService } from './public-api';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -35,6 +37,12 @@ import { CoreModule } from '@alfresco/adf-core';
exports: [ exports: [
TaskListCloudComponent, TaskListCloudComponent,
ServiceTaskListCloudComponent ServiceTaskListCloudComponent
],
providers: [
{
provide: TASK_LIST_CLOUD_TOKEN,
useClass: TaskListCloudService
}
] ]
}) })
export class TaskListCloudModule { } export class TaskListCloudModule { }

View File

@@ -30,3 +30,5 @@ export * from './lib/models/process-definition-cloud.model';
export * from './lib/models/date-cloud-filter.model'; export * from './lib/models/date-cloud-filter.model';
export * from './lib/models/application-version.model'; export * from './lib/models/application-version.model';
export * from './lib/models/engine-event-cloud.model'; export * from './lib/models/engine-event-cloud.model';
export * from './lib/models/filter-cloud-model';
export * from './lib/models/task-list-sorting.model';