From a5445100050e49e83f73424198d73cd72d672a4d Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Sun, 4 Mar 2018 14:53:33 +0200 Subject: Sync Integ to Master Change-Id: I71e3acc26fa612127756ac04073a522b9cc6cd74 Issue-ID: SDC-977 Signed-off-by: Gitelman, Tal (tg851x) --- .../component-instance.service.ts | 49 +++++++++++----------- 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'catalog-ui/src/app/ng2/services/component-instance-services') diff --git a/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts b/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts index b852539edd..0947b2aa7f 100644 --- a/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts +++ b/catalog-ui/src/app/ng2/services/component-instance-services/component-instance.service.ts @@ -23,10 +23,9 @@ import {Response, RequestOptions, Headers} from '@angular/http'; import { Observable } from 'rxjs/Observable'; import {PropertyFEModel, PropertyBEModel} from "app/models"; import {CommonUtils} from "app/utils"; -import {Component, ComponentInstance, InputModel} from "app/models"; +import {Component, ComponentInstance, Capability, PropertyModel} from "app/models"; import { HttpService } from '../http.service'; import {SdcConfigToken, ISdcConfig} from "../../config/sdc-config.config"; -import {isEqual} from "lodash"; @Injectable() export class ComponentInstanceServiceNg2 { @@ -52,43 +51,45 @@ export class ComponentInstanceServiceNg2 { }) } - updateInstanceProperty(component: Component, componentInstanceId: string, property: PropertyBEModel): Observable { + updateInstanceProperties(component: Component, componentInstanceId: string, properties: PropertyBEModel[]) { - return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/property', property) + return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/properties', properties) .map((res: Response) => { - return new PropertyBEModel(res.json()); - }) + return res.json().map((resProperty) => new PropertyBEModel(resProperty)); + }); } - getInstanceCapabilityProperties(component: Component, componentInstanceId: string, capabilityType: string, capabilityName: string): Observable> { + getInstanceCapabilityProperties(component: Component, componentInstanceId: string, capability: Capability): Observable> { - return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstanceId + '/capability/' + capabilityType + - '/capabilityName/' + capabilityName + '/properties') + return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstanceId + '/capability/' + capability.type + + '/capabilityName/' + capability.name + '/ownerId/' + capability.ownerId + '/properties') .map((res: Response) => { - return CommonUtils.initBeProperties(res.json()); + capability.properties = res.json().map((capProp) => new PropertyModel(capProp)); // update capability properties + return capability.properties; }) } - updateInstanceCapabilityProperties(component: Component, componentInstanceId: string, capabilityType: string, capabilityName: string, properties: PropertyBEModel[]): Observable { + updateInstanceCapabilityProperties(component: Component, componentInstanceId: string, capability: Capability, properties: PropertyBEModel[]): Observable> { - return this.http.put(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstanceId + '/capability/' + capabilityType + - '/capabilityName/' + capabilityName +'/properties', properties) + return this.http.put(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstanceId + '/capability/' + capability.type + + '/capabilityName/' + capability.name + '/ownerId/' + capability.ownerId + '/properties', properties) .map((res: Response) => { - return res.json().map((resProperty) => new PropertyBEModel(resProperty)); + const savedProperties: PropertyModel[] = res.json().map((resProperty) => new PropertyModel(resProperty)); + savedProperties.forEach((savedProperty) => { + const propIdx = capability.properties.findIndex((p) => p.uniqueId === savedProperty.uniqueId); + if (propIdx !== -1) { + capability.properties.splice(propIdx, 1, savedProperty); + } + }); + return savedProperties; }) } - updateInstanceInput(component: Component, componentInstanceId: string, input: PropertyBEModel): Observable { + updateInstanceInputs(component: Component, componentInstanceId: string, inputs: PropertyBEModel[]): Observable { - return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/input', input) + return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/inputs', inputs) .map((res: Response) => { - return new PropertyBEModel(res.json()); - }) - } - - hasPropertyChanged(property: PropertyFEModel) { - let oldValue: any = property.value; - const newValue = property.getJSONValue(); - return ((oldValue || newValue) && !isEqual(oldValue, newValue)); + return res.json().map((resInput) => new PropertyBEModel(resInput)); + }); } } -- cgit 1.2.3-korg