src.app.core.services.scenario-execution.service.ts Maven / Gradle / Ivy
The newest version!
/*
* SPDX-FileCopyrightText: 2017-2024 Enedis
*
* SPDX-License-Identifier: Apache-2.0
*
*/
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { environment } from '@env/environment';
import { Dataset, Execution, KeyValue, ScenarioExecutionReport } from '@model';
import { HttpClient } from '@angular/common/http';
import { ExecutionDataset } from "@core/model/scenario/execution.dataset";
@Injectable({
providedIn: "root"
})
export class ScenarioExecutionService {
resourceUrl = '/api/ui/scenario';
constructor(private http: HttpClient) {
}
findScenarioExecutions(scenarioId: string): Observable {
return this.http.get(environment.backend + `${this.resourceUrl}/${scenarioId}/execution/v1`)
.pipe(
map((res: Execution[]) => {
return res.map((execution) => Execution.deserialize(execution));
}));
}
findScenarioExecutionSummary(executionId: number): Observable {
return this.http.get(environment.backend + `${this.resourceUrl}/execution/${executionId}/summary/v1`)
.pipe(
map((res: Execution) => Execution.deserialize(res)));
}
executeScenarioAsync(scenarioId: string, env: string, dataset: Dataset = null): Observable {
const envPathParam = !!env ? `/${env}` : '';
return this.http.post(environment.backend + `${this.resourceUrl}/executionasync/v1/${scenarioId}${envPathParam}`, dataset ? dataset : {});
}
observeScenarioExecution(scenarioId: string, executionId: number): Observable {
return this.createScenarioExecutionObservable(environment.backend +
`${this.resourceUrl}/executionasync/v1/${scenarioId}/execution/${executionId}`);
}
findExecutionReport(scenarioId: string, executionId: number): Observable {
return this.http.get(environment.backend + `${this.resourceUrl}/${scenarioId}/execution/${executionId}/v1`)
.pipe(map((res: Object) => {
if (res != null && res !== '') {
return this.buildExecutionReport(res);
}
return null
}));
}
stopScenario(scenarioId: string, executionId: number): Observable {
return this.http.post(environment.backend +
`${this.resourceUrl}/executionasync/v1/${scenarioId}/execution/${executionId}/stop`, {}).pipe(map((res: Response) => {
}));
}
pauseScenario(scenarioId: string, executionId: number): Observable {
return this.http.post(environment.backend +
`${this.resourceUrl}/executionasync/v1/${scenarioId}/execution/${executionId}/pause`, {}).pipe(map((res: Response) => {
}));
}
resumeScenario(scenarioId: string, executionId: number): Observable {
return this.http.post(environment.backend +
`${this.resourceUrl}/executionasync/v1/${scenarioId}/execution/${executionId}/resume`, {}).pipe(map((res: Response) => {
}));
}
deleteExecution(executionId: number): Observable
© 2015 - 2024 Weber Informatics LLC | Privacy Policy