mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
* [ADF-4409] PorcessServicesCloud - add community page * [ADF-4409] - add process and task details page * [ADF-4409] fix lint and reset package-lock * [ADF-4409] - PR changes * [ADF-4409] - PR changes * [ADF-4409] - fix start task/process redirection * [ADF-4409] - fix unit tests
79 lines
2.9 KiB
TypeScript
79 lines
2.9 KiB
TypeScript
/*!
|
|
* @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 { from, Observable, throwError } from 'rxjs';
|
|
import { StartTaskCloudRequestModel } from '../models/start-task-cloud-request.model';
|
|
import { TaskDetailsCloudModel, StartTaskCloudResponseModel } from '../models/task-details-cloud.model';
|
|
import { map, catchError } from 'rxjs/operators';
|
|
import { BaseCloudService } from '../../../services/base-cloud.service';
|
|
|
|
@Injectable()
|
|
export class StartTaskCloudService extends BaseCloudService {
|
|
|
|
constructor(
|
|
private apiService: AlfrescoApiService,
|
|
private appConfigService: AppConfigService,
|
|
private logService: LogService
|
|
) { super(); }
|
|
|
|
/**
|
|
* Creates a new standalone task.
|
|
* @param taskDetails Details of the task to create
|
|
* @returns Details of the newly created task
|
|
*/
|
|
createNewTask(taskDetails: TaskDetailsCloudModel): Observable<TaskDetailsCloudModel> {
|
|
const queryUrl = this.buildCreateTaskUrl(taskDetails.appName);
|
|
const bodyParam = JSON.stringify(this.buildRequestBody(taskDetails));
|
|
const pathParams = {}, queryParams = {}, headerParams = {},
|
|
formParams = {}, contentTypes = ['application/json'], accepts = ['application/json'];
|
|
|
|
return from(
|
|
this.apiService
|
|
.getInstance()
|
|
.oauth2Auth.callCustomApi(
|
|
queryUrl, 'POST', pathParams, queryParams,
|
|
headerParams, formParams, bodyParam,
|
|
contentTypes, accepts, null, null)
|
|
).pipe(
|
|
map((response: StartTaskCloudResponseModel) => {
|
|
return new TaskDetailsCloudModel(response.entry);
|
|
}),
|
|
catchError((err) => this.handleError(err))
|
|
);
|
|
}
|
|
|
|
private buildCreateTaskUrl(appName: string): any {
|
|
this.contextRoot = this.appConfigService.get('bpmHost');
|
|
return `${this.getBasePath(appName)}/rb/v1/tasks`;
|
|
}
|
|
|
|
private buildRequestBody(taskDetails: any) {
|
|
return new StartTaskCloudRequestModel(taskDetails);
|
|
}
|
|
|
|
private handleError(error: any) {
|
|
this.logService.error(error);
|
|
return throwError(error || 'Server error');
|
|
}
|
|
}
|