mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -22,5 +22,6 @@ export * from './models/process-cloud-preset.model';
|
||||
export * from './models/process-list-sorting.model';
|
||||
|
||||
export * from './services/process-list-cloud.service';
|
||||
export * from './services/process-task-list-cloud.service';
|
||||
|
||||
export * from './process-list-cloud.module';
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -17,7 +17,10 @@
|
||||
|
||||
import { InjectionToken } from '@angular/core';
|
||||
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 TASK_FILTERS_SERVICE_TOKEN = new InjectionToken<PreferenceCloudServiceInterface>('task-filters-cloud');
|
||||
|
||||
export const TASK_LIST_CLOUD_TOKEN = new InjectionToken<TaskListCloudServiceInterface>('task-list-cloud');
|
||||
|
@@ -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>;
|
||||
}
|
@@ -23,7 +23,7 @@ import { switchMap, map } from 'rxjs/operators';
|
||||
import { BaseCloudService } from '../../../services/base-cloud.service';
|
||||
import { PreferenceCloudServiceInterface } from '../../../services/preference-cloud.interface';
|
||||
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 { TaskCloudEngineEvent } from '../../../models/engine-event-cloud.model';
|
||||
|
||||
|
@@ -23,9 +23,9 @@ import {
|
||||
DataRowEvent, CustomEmptyContentTemplateDirective, DataCellEvent, DataRowActionEvent, DataRow, DataColumn
|
||||
} from '@alfresco/adf-core';
|
||||
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 { TaskListCloudSortingModel } from '../models/task-list-sorting.model';
|
||||
import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
import { TaskCloudService } from '../../services/task-cloud.service';
|
||||
|
||||
|
@@ -24,7 +24,7 @@ import { fakeServiceTask, fakeCustomSchema } from '../mock/fake-task-response.mo
|
||||
import { of } from 'rxjs';
|
||||
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
|
||||
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 { ServiceTaskListCloudService } from '../services/service-task-list-cloud.service';
|
||||
|
||||
|
@@ -25,8 +25,10 @@ import { fakeGlobalTask, fakeCustomSchema } from '../mock/fake-task-response.moc
|
||||
import { of } from 'rxjs';
|
||||
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
|
||||
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 { TaskListCloudServiceInterface } from '../../../services/task-list-cloud.service.interface';
|
||||
import { TASK_LIST_CLOUD_TOKEN } from '../../../services/cloud-token.service';
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
@@ -79,7 +81,7 @@ describe('TaskListCloudComponent', () => {
|
||||
let component: TaskListCloudComponent;
|
||||
let fixture: ComponentFixture<TaskListCloudComponent>;
|
||||
let appConfig: AppConfigService;
|
||||
let taskListCloudService: TaskListCloudService;
|
||||
let taskListCloudService: TaskListCloudServiceInterface;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
@@ -88,14 +90,20 @@ describe('TaskListCloudComponent', () => {
|
||||
],
|
||||
declarations: [
|
||||
EmptyTemplateComponent
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: TASK_LIST_CLOUD_TOKEN,
|
||||
useClass: TaskListCloudService
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
taskListCloudService = TestBed.inject(TaskListCloudService);
|
||||
fixture = TestBed.createComponent(TaskListCloudComponent);
|
||||
component = fixture.componentInstance;
|
||||
taskListCloudService = TestBed.inject(TASK_LIST_CLOUD_TOKEN);
|
||||
appConfig.config = Object.assign(appConfig.config, {
|
||||
'adf-cloud-task-list': {
|
||||
presets: {
|
||||
@@ -122,6 +130,12 @@ describe('TaskListCloudComponent', () => {
|
||||
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', () => {
|
||||
component.ngAfterContentInit();
|
||||
expect(component.columns).toBeDefined();
|
||||
@@ -495,7 +509,7 @@ describe('TaskListCloudComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
taskListCloudService = TestBed.inject(TaskListCloudService);
|
||||
taskListCloudService = TestBed.inject(TASK_LIST_CLOUD_TOKEN);
|
||||
appConfig.config = Object.assign(appConfig.config, {
|
||||
'adf-cloud-task-list': {
|
||||
presets: {
|
||||
|
@@ -15,12 +15,13 @@
|
||||
* 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 { TaskQueryCloudRequestModel } from '../models/filter-cloud-model';
|
||||
import { TaskListCloudService } from '../services/task-list-cloud.service';
|
||||
import { TaskQueryCloudRequestModel } from '../../../models/filter-cloud-model';
|
||||
import { BaseTaskListCloudComponent } from './base-task-list-cloud.component';
|
||||
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';
|
||||
|
||||
@@ -131,7 +132,7 @@ export class TaskListCloudComponent extends BaseTaskListCloudComponent {
|
||||
@Input()
|
||||
candidateGroupId: string = '';
|
||||
|
||||
constructor(private taskListCloudService: TaskListCloudService,
|
||||
constructor(@Inject(TASK_LIST_CLOUD_TOKEN) public taskListCloudService: TaskListCloudServiceInterface,
|
||||
appConfigService: AppConfigService,
|
||||
taskCloudService: TaskCloudService,
|
||||
userPreferences: UserPreferencesService) {
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TaskListCloudSortingModel } from './task-list-sorting.model';
|
||||
import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
|
||||
|
||||
export interface ServiceTaskQueryCloudRequestModel {
|
||||
appName: string;
|
||||
|
@@ -18,9 +18,7 @@
|
||||
export * from './components/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/task-list-sorting.model';
|
||||
export * from './models/task-preset-cloud.model';
|
||||
|
||||
export * from './services/task-list-cloud.service';
|
||||
|
@@ -19,7 +19,7 @@ import { Injectable } from '@angular/core';
|
||||
import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf-core';
|
||||
import { ServiceTaskQueryCloudRequestModel, ServiceTaskIntegrationContextCloudModel } from '../models/service-task-cloud.model';
|
||||
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 { map } from 'rxjs/operators';
|
||||
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { setupTestBed, AlfrescoApiService } from '@alfresco/adf-core';
|
||||
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 { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
|
@@ -17,15 +17,16 @@
|
||||
|
||||
import { Injectable } from '@angular/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 { TaskListCloudSortingModel } from '../models/task-list-sorting.model';
|
||||
import { TaskListCloudSortingModel } from '../../../models/task-list-sorting.model';
|
||||
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 { TaskListCloudServiceInterface } from '../../../services/task-list-cloud.service.interface';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class TaskListCloudService extends BaseCloudService {
|
||||
export class TaskListCloudService extends BaseCloudService implements TaskListCloudServiceInterface {
|
||||
|
||||
constructor(apiService: AlfrescoApiService,
|
||||
appConfigService: AppConfigService,
|
||||
|
@@ -21,6 +21,8 @@ import { MaterialModule } from '../../material.module';
|
||||
import { TaskListCloudComponent } from './components/task-list-cloud.component';
|
||||
import { ServiceTaskListCloudComponent } from './components/service-task-list-cloud.component';
|
||||
import { CoreModule } from '@alfresco/adf-core';
|
||||
import { TASK_LIST_CLOUD_TOKEN } from '../../services/cloud-token.service';
|
||||
import { TaskListCloudService } from './public-api';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -35,6 +37,12 @@ import { CoreModule } from '@alfresco/adf-core';
|
||||
exports: [
|
||||
TaskListCloudComponent,
|
||||
ServiceTaskListCloudComponent
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: TASK_LIST_CLOUD_TOKEN,
|
||||
useClass: TaskListCloudService
|
||||
}
|
||||
]
|
||||
})
|
||||
export class TaskListCloudModule { }
|
||||
|
@@ -30,3 +30,5 @@ export * from './lib/models/process-definition-cloud.model';
|
||||
export * from './lib/models/date-cloud-filter.model';
|
||||
export * from './lib/models/application-version.model';
|
||||
export * from './lib/models/engine-event-cloud.model';
|
||||
export * from './lib/models/filter-cloud-model';
|
||||
export * from './lib/models/task-list-sorting.model';
|
||||
|
Reference in New Issue
Block a user