2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import {Injectable, Inject} from '@angular/core';
22 import {Response, RequestOptions, Headers} from '@angular/http';
23 import { Observable } from 'rxjs/Observable';
24 import {PropertyFEModel, PropertyBEModel} from "app/models";
25 import {CommonUtils} from "app/utils";
26 import {Component, ComponentInstance, Capability, PropertyModel} from "app/models";
27 import { HttpService } from '../http.service';
28 import {SdcConfigToken, ISdcConfig} from "../../config/sdc-config.config";
31 export class ComponentInstanceServiceNg2 {
35 constructor(private http: HttpService, @Inject(SdcConfigToken) sdcConfig:ISdcConfig) {
36 this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
39 getComponentInstanceProperties(component: Component, componentInstanceId: string): Observable<Array<PropertyBEModel>> {
41 return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstanceId + '/properties')
42 .map((res: Response) => {
43 return CommonUtils.initBeProperties(res.json());
47 getComponentInstanceInputs(component: Component, componentInstance: ComponentInstance): Observable<Array<PropertyBEModel>> {
48 return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstance.uniqueId + '/' + componentInstance.componentUid + '/inputs')
49 .map((res: Response) => {
50 return CommonUtils.initInputs(res.json());
54 updateInstanceProperties(component: Component, componentInstanceId: string, properties: PropertyBEModel[]) {
56 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/properties', properties)
57 .map((res: Response) => {
58 return res.json().map((resProperty) => new PropertyBEModel(resProperty));
62 getInstanceCapabilityProperties(component: Component, componentInstanceId: string, capability: Capability): Observable<Array<PropertyModel>> {
64 return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstanceId + '/capability/' + capability.type +
65 '/capabilityName/' + capability.name + '/ownerId/' + capability.ownerId + '/properties')
66 .map((res: Response) => {
67 capability.properties = res.json().map((capProp) => new PropertyModel(capProp)); // update capability properties
68 return capability.properties;
72 updateInstanceCapabilityProperties(component: Component, componentInstanceId: string, capability: Capability, properties: PropertyBEModel[]): Observable<Array<PropertyModel>> {
74 return this.http.put(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstanceId + '/capability/' + capability.type +
75 '/capabilityName/' + capability.name + '/ownerId/' + capability.ownerId + '/properties', properties)
76 .map((res: Response) => {
77 const savedProperties: PropertyModel[] = res.json().map((resProperty) => new PropertyModel(resProperty));
78 savedProperties.forEach((savedProperty) => {
79 const propIdx = capability.properties.findIndex((p) => p.uniqueId === savedProperty.uniqueId);
81 capability.properties.splice(propIdx, 1, savedProperty);
84 return savedProperties;
88 updateInstanceInputs(component: Component, componentInstanceId: string, inputs: PropertyBEModel[]): Observable<PropertyBEModel[]> {
90 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/inputs', inputs)
91 .map((res: Response) => {
92 return res.json().map((resInput) => new PropertyBEModel(resInput));
96 getComponentGroupInstanceProperties(component: Component, groupInstanceId: string): Observable<Array<PropertyBEModel>> {
97 return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/groups/' + groupInstanceId + '/properties')
98 .map((res: Response) => {
99 return CommonUtils.initBeProperties(res.json());
103 updateComponentGroupInstanceProperties(component: Component, groupInstanceId: string, properties: PropertyBEModel[]): Observable<Array<PropertyBEModel>> {
104 return this.http.put(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/groups/' + groupInstanceId + '/properties', properties)
105 .map((res: Response) => {
106 return res.json().map((resProperty) => new PropertyBEModel(resProperty));
110 getComponentPolicyInstanceProperties(component: Component, policyInstanceId: string): Observable<Array<PropertyBEModel>> {
111 return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policyInstanceId + '/properties')
112 .map((res: Response) => {
113 return CommonUtils.initBeProperties(res.json());
117 updateComponentPolicyInstanceProperties(component: Component, policyInstanceId: string, properties: PropertyBEModel[]): Observable<Array<PropertyBEModel>> {
118 return this.http.put(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policyInstanceId + '/properties', properties)
119 .map((res: Response) => {
120 return res.json().map((resProperty) => new PropertyBEModel(resProperty));