Skip to content

Commit

Permalink
[MNT-22865] fix get all task variables (#7508)
Browse files Browse the repository at this point in the history
* fix get all task variables

* Update lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts

Co-authored-by: Andrea Ligios <11974750+andrea-ligios@users.noreply.github.com>

* Update lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts

Co-authored-by: Andrea Ligios <11974750+andrea-ligios@users.noreply.github.com>

* Update form-cloud.service.ts

Co-authored-by: Andrea Ligios <11974750+andrea-ligios@users.noreply.github.com>
  • Loading branch information
eromano and andrea-ligios committed Feb 18, 2022
1 parent 9f72e30 commit 7c171ea
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
FormModel,
FormFieldOption
} from '@alfresco/adf-core';
import { Observable, from } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { Observable, from, EMPTY } from 'rxjs';
import { expand, map, reduce, switchMap } from 'rxjs/operators';
import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model';
import { CompleteFormRepresentation, UploadApi } from '@alfresco/js-api';
import { TaskVariableCloud } from '../models/task-variable-cloud.model';
Expand Down Expand Up @@ -171,9 +171,21 @@ export class FormCloudService extends BaseCloudService implements FormCloudServi
*/
getTaskVariables(appName: string, taskId: string): Observable<TaskVariableCloud[]> {
const apiUrl = `${this.getBasePath(appName)}/query/v1/tasks/${taskId}/variables`;

return this.get(apiUrl).pipe(
map((res: any) => res.list.entries.map((variable) => new TaskVariableCloud(variable.entry)))
let skipCount = 0;
const maxItems = 1000;

return this.get(apiUrl, { maxItems, skipCount }).pipe(
expand((res: any) => {
skipCount += maxItems;
return res.list.pagination.hasMoreItems ? this.get(apiUrl, {
maxItems,
skipCount
}) : EMPTY;
}),
map((res: any) => {
return res.list.entries.map((variable) => new TaskVariableCloud(variable.entry));
}),
reduce((acc, res) => acc.concat(res), [])
);
}

Expand Down

0 comments on commit 7c171ea

Please sign in to comment.