Skip to content

Commit

Permalink
ACS-5975 change getting tasks in tasklist component and service (#8987)
Browse files Browse the repository at this point in the history
Co-authored-by: Grzegorz Jaskowski <[email protected]>
  • Loading branch information
dominikiwanekhyland and g-jaskowski authored Jan 25, 2024
1 parent a7e7934 commit d61c20c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 228 deletions.
10 changes: 3 additions & 7 deletions docs/process-services/services/tasklist.service.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,15 @@ Manages Task Instances.
Fetches the Task Audit information in PDF format.
- _taskId:_ `string` - ID of the target task
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)`>` - Binary PDF data
- **findAllTaskByState**(requestNode: [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts), state?: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>`<br/>
- **findAllTasksByState**(requestNode: [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts), state?: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>`<br/>
Gets all tasks matching a query and state value.
- _requestNode:_ [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts) - Query to search for tasks.
- _state:_ `string` - (Optional) Task state. Can be "open" or "completed".
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>` - List of tasks
- **findAllTasksWithoutState**(requestNode: [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>`<br/>
Gets all tasks matching the supplied query but ignoring the task state.
- _requestNode:_ [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts) - Query to search for tasks
- _state:_ `string` - (Optional) Task state. Can be "open" or "completed". State "all" applies to both "active" and "completed" tasks.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>` - List of tasks
- **findTasksByState**(requestNode: [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts), state?: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>`<br/>
Gets tasks matching a query and state value.
- _requestNode:_ [`TaskQueryRequestRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts) - Query to search for tasks
- _state:_ `string` - (Optional) Task state. Can be "open" or "completed".
- _state:_ `string` - (Optional) Task state. Can be "open" or "completed". State "all" applies to both "active" and "completed" tasks.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskListModel`](../../../lib/process-services/src/lib/task-list/models/task-list.model.ts)`>` - List of tasks
- **getFilterForTaskById**(taskId: `string`, filterList: [`FilterRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts)`[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`FilterRepresentationModel`](../../../lib/process-services/src/lib/task-list/models/filter.model.ts)`>`<br/>
Gets all the filters in the list that belong to a task.
Expand Down
6 changes: 6 additions & 0 deletions lib/process-services/src/lib/mock/task/task-filters.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ export const fakeFilter: TaskQueryRequestRepresentationModel = {
assignment: 'fake-assignee'
};

export const mockFilterNoState: TaskQueryRequestRepresentationModel = {
sort: 'created-desc',
text: '',
assignment: 'fake-assignee'
};

export const fakeRepresentationFilter1: FilterRepresentationModel = new FilterRepresentationModel({
appId: 1,
name: 'CONTAIN FILTER',
Expand Down
149 changes: 0 additions & 149 deletions lib/process-services/src/lib/mock/task/tasklist-service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { fakeAppFilter } from './task-filters.mock';

export const fakeUser1 = { id: 1, email: '[email protected]', firstName: 'firstName', lastName: 'lastName' };

export const fakeUser2 = { id: 1001, email: '[email protected]', firstName: 'some', lastName: 'one' };

export const fakeTaskList = new TaskListModel({
size: 1,
total: 1,
Expand All @@ -37,151 +35,4 @@ export const fakeTaskList = new TaskListModel({
}
]
});

export const secondFakeTaskList = {
size: 1,
total: 1,
start: 0,
data: [
{
id: '200',
name: 'FakeNameTask',
description: null,
category: null,
assignee: fakeUser1,
created: '2016-07-15T11:19:17.440+0000'
}
]
};

export const fakeTaskDetails = { id: '999', name: 'fake-task-name', formKey: '99', assignee: fakeUser1 };

export const fakeTasksChecklist = {
size: 1,
total: 1,
start: 0,
data: [
{
id: 1,
name: 'FakeCheckTask1',
description: null,
category: null,
assignee: fakeUser1,
created: '2016-07-15T11:19:17.440+0000'
},
{
id: 2,
name: 'FakeCheckTask2',
description: null,
category: null,
assignee: fakeUser1,
created: '2016-07-15T11:19:17.440+0000'
}
]
};

export const fakeAppPromise = Promise.resolve(fakeAppFilter);

export const fakeFormList = {
size: 2,
total: 2,
start: 0,
data: [
{
id: 1,
name: 'form with all widgets',
description: '',
createdBy: 2,
createdByFullName: 'Admin Admin',
lastUpdatedBy: 2,
lastUpdatedByFullName: 'Admin Admin',
lastUpdated: 1491400951205,
latestVersion: true,
version: 4,
comment: null,
stencilSet: null,
referenceId: null,
modelType: 2,
favorite: null,
permission: 'write',
tenantId: null
},
{
id: 2,
name: 'uppy',
description: '',
createdBy: 2,
createdByFullName: 'Admin Admin',
lastUpdatedBy: 2,
lastUpdatedByFullName: 'Admin Admin',
lastUpdated: 1490951054477,
latestVersion: true,
version: 2,
comment: null,
stencilSet: null,
referenceId: null,
modelType: 2,
favorite: null,
permission: 'write',
tenantId: null
}
]
};

export const fakeTaskOpen1 = {
id: '1',
name: 'FakeOpenTask1',
description: null,
category: null,
assignee: fakeUser1,
created: '2017-07-15T11:19:17.440+0000',
dueDate: null,
endDate: null
};

export const fakeTaskOpen2 = {
id: '1',
name: 'FakeOpenTask2',
description: null,
category: null,
assignee: { id: 1, email: '[email protected]', firstName: 'firstName', lastName: 'lastName' },
created: '2017-07-15T11:19:17.440+0000',
dueDate: null,
endDate: null
};

export const fakeTaskCompleted1 = {
id: '1',
name: 'FakeCompletedTaskName1',
description: null,
category: null,
assignee: { id: 1, email: '[email protected]', firstName: 'firstName', lastName: 'lastName' },
created: '2016-07-15T11:19:17.440+0000',
dueDate: null,
endDate: '2016-11-03T15:25:42.749+0000'
};

export const fakeTaskCompleted2 = {
id: '1',
name: 'FakeCompletedTaskName2',
description: null,
category: null,
assignee: fakeUser1,
created: null,
dueDate: null,
endDate: '2016-11-03T15:25:42.749+0000'
};

export const fakeOpenTaskList = new TaskListModel({
size: 2,
total: 2,
start: 0,
data: [fakeTaskOpen1, fakeTaskOpen2]
});

export const fakeCompletedTaskList = new TaskListModel({
size: 2,
total: 2,
start: 0,
data: [fakeTaskCompleted1, fakeTaskCompleted2]
});
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,7 @@ export class TaskListComponent extends DataTableSchema implements OnChanges, Aft
}

private loadTasksByState(): Observable<TaskListModel> {
return this.requestNode.state === 'all'
? this.taskListService.findAllTasksWithoutState(this.requestNode)
: this.taskListService.findTasksByState(this.requestNode);
return this.taskListService.findTasksByState(this.requestNode);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import { TestBed } from '@angular/core/testing';
import { CoreModule } from '@alfresco/adf-core';
import { of } from 'rxjs';
import { fakeCompletedTaskList, fakeOpenTaskList, fakeTaskList } from '../../mock';
import { fakeFilter } from '../../mock/task/task-filters.mock';
import { fakeFilter, mockFilterNoState } from '../../mock/task/task-filters.mock';
import { TaskListService } from './tasklist.service';
import { ProcessTestingModule } from '../../testing/process.testing.module';
import { fakeTaskList } from '../../mock';

describe('Activiti TaskList Service', () => {
let service: TaskListService;
Expand All @@ -38,7 +38,7 @@ describe('Activiti TaskList Service', () => {
spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList));
spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList));

service.findAllTaskByState(fakeFilter, 'open').subscribe((res) => {
service.findAllTasksByState(fakeFilter, 'open').subscribe((res) => {
expect(res).toBeDefined();
expect(res.size).toEqual(1);
expect(res.start).toEqual(0);
Expand All @@ -56,7 +56,7 @@ describe('Activiti TaskList Service', () => {
spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList));
spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList));

service.findAllTaskByState(fakeFilter).subscribe((res) => {
service.findAllTasksByState(fakeFilter).subscribe((res) => {
expect(res).toBeDefined();
expect(res.size).toEqual(1);
expect(res.start).toEqual(0);
Expand All @@ -74,51 +74,11 @@ describe('Activiti TaskList Service', () => {
spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList));
spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList));

service.findAllTasksWithoutState(fakeFilter).subscribe((res) => {
service.findAllTasksByState(mockFilterNoState).subscribe((res) => {
expect(res).toBeDefined();
expect(res.data).toBeDefined();
expect(res.data.length).toEqual(2);
expect(res.data[0].name).toEqual('FakeNameTask');
expect(res.data[0].assignee.email).toEqual('[email protected]');
expect(res.data[0].assignee.firstName).toEqual('firstName');
expect(res.data[0].assignee.lastName).toEqual('lastName');

expect(res.data[1].name).toEqual('FakeNameTask');
expect(res.data[1].assignee.email).toEqual('[email protected]');
expect(res.data[1].assignee.firstName).toEqual('firstName');
expect(res.data[1].assignee.lastName).toEqual('lastName');
done();
});
});

it('Should return both open and completed task', (done) => {
spyOn(service, 'findTasksByState').and.returnValue(of(fakeOpenTaskList));
spyOn(service, 'findAllTaskByState').and.returnValue(of(fakeCompletedTaskList));
service.findAllTasksWithoutState(fakeFilter).subscribe((res) => {
expect(res).toBeDefined();
expect(res.data).toBeDefined();
expect(res.data.length).toEqual(4);
expect(res.data[0].name).toEqual('FakeOpenTask1');
expect(res.data[1].assignee.email).toEqual('[email protected]');
expect(res.data[2].name).toEqual('FakeCompletedTaskName1');
expect(res.data[2].assignee.email).toEqual('[email protected]');
expect(res.data[3].name).toEqual('FakeCompletedTaskName2');
done();
});
});

it('should add the task list to the tasklistSubject with all tasks filtered without state', (done) => {
spyOn(service, 'getTasks').and.returnValue(of(fakeTaskList));
spyOn(service, 'getTotalTasks').and.returnValue(of(fakeTaskList));

service.findAllTasksWithoutState(fakeFilter).subscribe((res) => {
expect(res).toBeDefined();
expect(res.data).toBeDefined();
expect(res.data.length).toEqual(2);
expect(res.data.length).toEqual(1);
expect(res.data[0].name).toEqual('FakeNameTask');
expect(res.data[0].assignee.email).toEqual('[email protected]');
expect(res.data[1].name).toEqual('FakeNameTask');
expect(res.data[1].assignee.email).toEqual('[email protected]');
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { AlfrescoApiService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { Observable, from, forkJoin, of } from 'rxjs';
import { Observable, from, of } from 'rxjs';
import { map, catchError, switchMap, flatMap, filter } from 'rxjs/operators';
import { FilterRepresentationModel, TaskQueryRequestRepresentationModel } from '../models/filter.model';
import { Form } from '../models/form.model';
Expand Down Expand Up @@ -104,7 +104,7 @@ export class TaskListService {
* Gets tasks matching a query and state value.
*
* @param requestNode Query to search for tasks
* @param state Task state. Can be "open" or "completed".
* @param state Task state. Can be "open" or "completed". State "all" applies to both "open" and "completed" tasks.
* @returns List of tasks
*/
findTasksByState(requestNode: TaskQueryRequestRepresentationModel, state?: string): Observable<TaskListModel> {
Expand All @@ -119,10 +119,10 @@ export class TaskListService {
* Gets all tasks matching a query and state value.
*
* @param requestNode Query to search for tasks.
* @param state Task state. Can be "open" or "completed".
* @param state Task state. Can be "open" or "completed". State "all" applies to both "open" and "completed" tasks.
* @returns List of tasks
*/
findAllTaskByState(requestNode: TaskQueryRequestRepresentationModel, state?: string): Observable<TaskListModel> {
findAllTasksByState(requestNode: TaskQueryRequestRepresentationModel, state?: string): Observable<TaskListModel> {
if (state) {
requestNode.state = state;
}
Expand All @@ -135,25 +135,6 @@ export class TaskListService {
);
}

/**
* Gets all tasks matching the supplied query but ignoring the task state.
*
* @param requestNode Query to search for tasks
* @returns List of tasks
*/
findAllTasksWithoutState(requestNode: TaskQueryRequestRepresentationModel): Observable<TaskListModel> {
return forkJoin(
this.findTasksByState(requestNode, 'open'),
this.findAllTaskByState(requestNode, 'completed'),
(activeTasks: TaskListModel, completedTasks: TaskListModel) => {
const tasks = Object.assign({}, activeTasks);
tasks.total += completedTasks.total;
tasks.data = tasks.data.concat(completedTasks.data);
return tasks;
}
);
}

/**
* Gets details for a task.
*
Expand Down

0 comments on commit d61c20c

Please sign in to comment.