[SDC] rebase code
[sdc.git] / catalog-ui / src / app / ng2 / services / component-instance-services / component-instance.service.ts
1 import {Injectable} from '@angular/core';
2 import {Response, RequestOptions, Headers} from '@angular/http';
3 import { Observable } from 'rxjs/Observable';
4 import {sdc2Config} from "../../../../main";
5 import {PropertyBEModel} from "app/models";
6 import {CommonUtils} from "app/utils";
7 import {Component, ComponentInstance, InputModel} from "app/models";
8 import {InterceptorService} from "ng2-interceptors/index";
9
10 @Injectable()
11 export class ComponentInstanceServiceNg2 {
12
13     protected baseUrl;
14
15     constructor(private http: InterceptorService) {
16         this.baseUrl = sdc2Config.api.root + sdc2Config.api.component_api_root;
17     }
18
19     getComponentInstanceProperties(component: Component, componentInstanceId: string): Observable<Array<PropertyBEModel>> {
20
21         return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstanceId + '/properties')
22             .map((res: Response) => {
23                 return CommonUtils.initBeProperties(res.json());
24         })
25     }
26
27     getComponentInstanceInputs(component: Component, componentInstance: ComponentInstance): Observable<Array<PropertyBEModel>> {
28         return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstance.uniqueId + '/' + componentInstance.componentUid + '/inputs')
29             .map((res: Response) => {
30                 return CommonUtils.initInputs(res.json());
31             })
32     }
33
34     updateInstanceProperty(component: Component, componentInstanceId: string, property: PropertyBEModel): Observable<PropertyBEModel> {
35
36         return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/property', property)
37             .map((res: Response) => {
38                 return new PropertyBEModel(res.json());
39         })
40     }
41
42     updateInstanceInput(component: Component, componentInstanceId: string, input: PropertyBEModel): Observable<PropertyBEModel> {
43
44         return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/input', input)
45             .map((res: Response) => {
46                 return new PropertyBEModel(res.json());
47             })
48     }
49
50
51 }