1 import {Injectable, Query} from '@angular/core';
2 import {Observable} from 'rxjs/Observable';
3 import 'rxjs/add/operator/map';
4 import 'rxjs/add/operator/toPromise';
5 import {Response, URLSearchParams} from '@angular/http';
6 import { Component, PropertyBEModel, InstancePropertiesAPIMap, FilterPropertiesAssignmentData} from "app/models";
7 import {downgradeInjectable} from '@angular/upgrade/static';
8 import {HttpService} from "../http.service";
9 import {COMPONENT_FIELDS} from "app/utils";
10 import {ComponentGenericResponse} from "../responses/component-generic-response";
11 import {sdc2Config} from "../../../../main";
12 import {InstanceBePropertiesMap} from "../../../models/properties-inputs/property-fe-map";
13 import {API_QUERY_PARAMS} from "app/utils";
14 import {ComponentType, ServerTypeUrl} from "../../../utils/constants";
16 declare var angular:angular.IAngularStatic;
19 export class ComponentServiceNg2 {
23 constructor(private http:HttpService) {
24 this.baseUrl = sdc2Config.api.root + sdc2Config.api.component_api_root;
27 private getComponentDataByFieldsName(componentType:string, componentId: string, fields:Array<string>):Observable<ComponentGenericResponse> {
29 let params:URLSearchParams = new URLSearchParams();
30 _.forEach(fields, (field:string):void => {
31 params.append(API_QUERY_PARAMS.INCLUDE, field);
34 return this.http.get(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {search: params})
35 .map((res:Response) => {
36 return new ComponentGenericResponse().deserialize(res.json());
37 }).do(error => console.log('server data:', error));
40 private getServerTypeUrl = (componentType:string):string => {
41 switch (componentType) {
42 case ComponentType.PRODUCT:
43 return ServerTypeUrl.PRODUCTS;
44 case ComponentType.SERVICE:
45 return ServerTypeUrl.SERVICES;
47 return ServerTypeUrl.RESOURCES;
51 getComponentMetadata(component:Component):Observable<ComponentGenericResponse> {
52 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_METADATA]);
55 getComponentInstanceAttributesAndProperties(component:Component):Observable<ComponentGenericResponse> {
56 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
59 getComponentAttributes(component:Component):Observable<ComponentGenericResponse> {
60 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]);
63 getComponentInstancesAndRelation(component:Component):Observable<ComponentGenericResponse> {
64 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
67 getComponentResourceInstances(component:Component):Observable<ComponentGenericResponse> {
68 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES]);
71 getComponentInputs(component:Component):Observable<ComponentGenericResponse> {
72 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
75 getComponentDeploymentArtifacts(component:Component):Observable<ComponentGenericResponse> {
76 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS]);
79 getComponentInformationalArtifacts(component:Component):Observable<ComponentGenericResponse> {
80 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS]);
83 getComponentInformationalArtifactsAndInstances(component:Component):Observable<ComponentGenericResponse> {
84 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
87 getComponentToscaArtifacts(component:Component):Observable<ComponentGenericResponse> {
88 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS]);
91 getComponentProperties(component:Component):Observable<ComponentGenericResponse> {
92 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
95 getCapabilitiesAndRequirements(componentType: string, componentId:string):Observable<ComponentGenericResponse> {
96 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
99 getDeploymentGraphData(component:Component):Observable<ComponentGenericResponse> {
100 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_GROUPS]);
103 createInput(component:Component, inputsToCreate:InstancePropertiesAPIMap):Observable<any> {
104 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/inputs', inputsToCreate)
110 deleteInput(component:Component, input:PropertyBEModel):Observable<PropertyBEModel> {
112 return this.http.delete(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/delete/' + input.uniqueId + '/input')
113 .map((res:Response) => {
114 return new PropertyBEModel(res.json());
118 updateComponentInput(component:Component, input:PropertyBEModel):Observable<PropertyBEModel> {
120 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/update/inputs', input)
121 .map((res:Response) => {
122 return new PropertyBEModel(res.json())
126 filterComponentInstanceProperties(component: Component, filterData:FilterPropertiesAssignmentData): Observable<InstanceBePropertiesMap> {//instance-property-be-map
127 let params: URLSearchParams = new URLSearchParams();
128 _.forEach(filterData.selectedTypes, (type:string) => {
129 params.append('resourceType', type);
132 return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {search: params})
133 .map((res: Response) => {
137 // return {'ExtVL 0':[{definition: false,name:"network_assignments",password:false,required:true,type:"org.openecomp.datatypes.network.NetworkAssignments",uniqueId:"623cca1c-d605-4c9c-9f2b-935ec85ebcf8.network_assignments"},
138 // {definition: false,name: "exVL_naming",password: false,required: true,type: "org.openecomp.datatypes.Naming",uniqueId: "623cca1c-d605-4c9c-9f2b-935ec85ebcf8.exVL_naming"},
139 // {definition: false,name: "network_flows",password: false,required: false,type: "org.openecomp.datatypes.network.NetworkFlows",uniqueId: "623cca1c-d605-4c9c-9f2b-935ec85ebcf8.network_flows"},
140 // {definition: false,name: "provider_network",password: false,required: true,type: "org.openecomp.datatypes.network.ProviderNetwork",uniqueId: "623cca1c-d605-4c9c-9f2b-935ec85ebcf8.provider_network"},
141 // {definition: false,name: "network_homing",password: false,required: true,type: "org.openecomp.datatypes.EcompHoming",uniqueId: "623cca1c-d605-4c9c-9f2b-935ec85ebcf8.network_homing"}],
142 // 'NetworkCP 0':[{definition: false,description: "identifies MAC address assignments to the CP",name: "mac_requirements",password: false,required: false,type: "org.openecomp.datatypes.network.MacRequirements",uniqueId: "26ec2bfd-b904-46c7-87ed-b32775120f2c.mac_requirements"}],
143 // 'NetworkCP 1':[{definition: false,description: "identifies MAC address assignments to the CP",name: "mac_requirements",password: false,required: false,type: "org.openecomp.datatypes.network.MacRequirements",uniqueId: "26ec2bfd-b904-46c7-87ed-b32775120f2c.mac_requirements"}]};
149 angular.module('Sdc.Services').factory('ComponentServiceNg2', downgradeInjectable(ComponentServiceNg2)); // This is in order to use the service in angular1 till we finish remove all angular1 code