Skip to content

Commit

Permalink
Revert mistakenly deleted file (#10367)
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaRobert authored Nov 5, 2024
1 parent 3bcaeef commit 558ff71
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ export * from './models/process-list-sorting.model';
export * from './models/process-cloud-preferences';

export * from './services/process-list-cloud.service';
export * from './services/process-task-list-cloud.service';

export * from './process-list-cloud.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* 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 { Observable, throwError } from 'rxjs';
import { BaseCloudService } from '../../../services/base-cloud.service';
import { map } from 'rxjs/operators';
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 {
/**
* 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) => {
const entries = response.list?.entries;
if (entries) {
// TODO: this is a hack of the model and should be revisited
response.list.entries = entries.map((entryData: any) => entryData.entry);
}
return response;
})
);
} else {
return throwError('Appname not configured');
}
}

protected buildQueryParams(requestNode: TaskQueryCloudRequestModel): any {
const queryParam: any = {};
for (const property in requestNode) {
if (
Object.prototype.hasOwnProperty.call(requestNode, 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: TaskQueryCloudRequestModel, 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);
}
}

0 comments on commit 558ff71

Please sign in to comment.