Provide UI page for interface assignment in service for VFC instances
[sdc.git] / catalog-ui / src / app / ng2 / services / component-services / component.service.ts
index 8d91eed..eca70be 100644 (file)
@@ -44,15 +44,13 @@ import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http";
 import {BEOperationModel, InterfaceModel} from "../../../models/operation";
 import {PropertyBEModel} from "../../../models/properties-inputs/property-be-model";
 import {PolicyInstance} from "../../../models/graph/zones/policy-instance";
-import {
-    ConstraintObject
-} from "../../components/logic/service-dependencies/service-dependencies.component";
 import {OutputBEModel} from "app/models/attributes-outputs/output-be-model";
 import {HttpHelperService} from '../http-hepler.service';
 import {
     BEInterfaceOperationModel,
     InterfaceOperationModel
 } from "../../../models/interfaceOperation";
+import {FilterConstraint} from "../../../models/filter-constraint";
 
 /*
 PLEASE DO NOT USE THIS SERVICE IN ANGULAR2! Use the topology-template.service instead
@@ -116,7 +114,7 @@ export class ComponentServiceNg2 {
     }
 
     getComponentResourcePropertiesData(component: Component): Observable<ComponentGenericResponse> {
-        return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS]);
+        return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INTERFACE_OPERATIONS, COMPONENT_FIELDS.COMPONENT_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS]);
     }
 
     getComponentResourceAttributesData(component: Component): Observable<ComponentGenericResponse> {
@@ -159,6 +157,8 @@ export class ComponentServiceNg2 {
         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INTERFACE_OPERATIONS]);
     }
 
+    
+
     getInterfaceOperation(component: Component, operation: OperationModel): Observable<OperationModel> {
         return this.http.get<OperationModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/interfaceOperations/' + operation.uniqueId);
     }
@@ -238,12 +238,44 @@ export class ComponentServiceNg2 {
         });
     }
 
+    createComponentInterfaceOperation(componentMetaDataId: string,
+                                      componentMetaDataType: string,
+                                      operation: InterfaceOperationModel): Observable<InterfaceOperationModel> {
+        const operationList = {
+            interfaces: {
+                [operation.interfaceType]: {
+                    type: operation.interfaceType,
+                    operations: {
+                        [operation.name]: new BEInterfaceOperationModel(operation)
+                    }
+                }
+            }
+        };
+        console.log(operationList);
+        console.log(this.baseUrl + componentMetaDataType + componentMetaDataId + '/resource/interfaceOperation')
+        return this.http.post<any>(this.baseUrl + componentMetaDataType + componentMetaDataId + '/resource/interfaceOperation', operationList)
+        .map((res: any) => {
+            const interf: InterfaceModel = _.find(res.interfaces, interf => interf.type === operation.interfaceType);
+            const newOperation: OperationModel = _.find(interf.operations, op => op.name === operation.name);
+
+            return new InterfaceOperationModel({
+                ...newOperation,
+                interfaceType: interf.type,
+                interfaceId: interf.uniqueId,
+            });
+        });
+    }
+
     deleteInterfaceOperation(component: Component, operation: OperationModel): Observable<OperationModel> {
         return this.http.delete<OperationModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/interfaces/' + operation.interfaceId + '/operations/' + operation.uniqueId);
     }
 
     getInterfaceTypes(component: Component): Observable<{ [id: string]: Array<string> }> {
-        return this.http.get<any>(this.baseUrl + 'interfaceLifecycleTypes' + ((component && component.model) ? '?model=' + component.model : ''))
+        return this.getInterfaceTypesByModel(component && component.model);
+    }
+
+    getInterfaceTypesByModel(model: string): Observable<{ [id: string]: Array<string> }> {
+        return this.http.get<any>(this.baseUrl + 'interfaceLifecycleTypes' + ((model) ? '?model=' + model : ''))
         .map((res: any) => {
             const interfaceMap = {};
             if (!res) {
@@ -386,6 +418,10 @@ export class ComponentServiceNg2 {
         return this.http.get<InstanceBePropertiesMap>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {params: params});
     }
 
+    deleteComponent(componentType: string, componentId: string) {
+        return this.http.delete(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + "?deleteAction=DELETE", {});
+    }
+
     createServiceProperty(component: Component, propertyModel: PropertyBEModel): Observable<PropertyBEModel> {
         let serverObject = {};
         serverObject[propertyModel.name] = propertyModel;
@@ -438,11 +474,11 @@ export class ComponentServiceNg2 {
         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [SERVICE_FIELDS.NODE_FILTER]);
     }
 
-    createServiceFilterConstraints(component: Component, componentInstance: ComponentInstance, constraint: ConstraintObject): Observable<any> {
+    createServiceFilterConstraints(component: Component, componentInstance: ComponentInstance, constraint: FilterConstraint): Observable<any> {
         return this.http.post<any>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstances/' + componentInstance.uniqueId + '/nodeFilter', constraint);
     }
 
-    updateServiceFilterConstraints(component: Component, componentInstance: ComponentInstance, constraints: ConstraintObject[]): Observable<any> {
+    updateServiceFilterConstraints(component: Component, componentInstance: ComponentInstance, constraints: FilterConstraint[]): Observable<any> {
         return this.http.put<any>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstances/' + componentInstance.uniqueId + '/nodeFilter/', constraints);
     }