Drawing Board RECREATE will use a new route that retrieves a template
[vid.git] / vid-webpack-master / src / app / shared / services / templateService / instantiationTemplates.service.ts
1 import {Injectable} from "@angular/core";
2 import {HttpClient} from "@angular/common/http";
3 import {NgRedux} from "@angular-redux/store";
4 import {AppState} from "../../store/reducers";
5 import {Observable} from "rxjs";
6 import {ServiceInstance} from "../../models/serviceInstance";
7 import {Constants} from "../../utils/constants";
8 import {createServiceInstance} from "../../storeUtil/utils/service/service.actions";
9
10 @Injectable()
11 export class InstantiationTemplatesService {
12   constructor(private http: HttpClient, private store: NgRedux<AppState>) {
13   }
14
15   retrieveInstantiationTemplateTopology(jobId: string): Observable<ServiceInstance> {
16     let pathQuery: string = `${Constants.Path.INSTANTIATION_TEMPLATE_TOPOLOGY}/${jobId}`;
17     return this.http.get<ServiceInstance>(pathQuery)
18   }
19
20   public retrieveAndStoreInstantiationTemplateTopology(jobId: string, serviceModelId: string): Observable<ServiceInstance> {
21     return this.retrieveInstantiationTemplateTopology(jobId).do((instantiationTemplate: ServiceInstance) => {
22       this.store.dispatch(createServiceInstance(instantiationTemplate, serviceModelId));
23     });
24   };
25
26 }