Fix create list input api call failure
[sdc.git] / catalog-ui / src / app / ng2 / services / component-services / topology-template.service.ts
1 /**
2  * Created by ob0695 on 6/26/2018.
3  */
4 /*-
5  * ============LICENSE_START=======================================================
6  * SDC
7  * ================================================================================
8  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 import * as _ from "lodash";
25 import {Injectable, Inject} from '@angular/core';
26 import {Observable} from 'rxjs/Observable';
27 import 'rxjs/add/operator/map';
28 import 'rxjs/add/operator/toPromise';
29 import {
30     Component,
31     InputBEModel,
32     InstancePropertiesAPIMap,
33     FilterPropertiesAssignmentData,
34     ArtifactModel,
35     PropertyModel,
36     IFileDownload,
37     AttributeModel,
38     IAttributeModel, Capability, Requirement
39 } from "app/models";
40 import {ArtifactGroupType, COMPONENT_FIELDS} from "app/utils";
41 import {ComponentGenericResponse} from "../responses/component-generic-response";
42 import {InstanceBePropertiesMap} from "../../../models/properties-inputs/property-fe-map";
43 import {API_QUERY_PARAMS} from "app/utils";
44 import {ComponentType, ServerTypeUrl, SERVICE_FIELDS} from "../../../utils/constants";
45 import {SdcConfigToken, ISdcConfig} from "../../config/sdc-config.config";
46 import {IDependenciesServerResponse} from "../responses/dependencies-server-response";
47 import {AutomatedUpgradeGenericResponse} from "../responses/automated-upgrade-response";
48 import {IAutomatedUpgradeRequestObj} from "../../pages/automated-upgrade/automated-upgrade.service";
49 import {ComponentInstance} from "../../../models/componentsInstances/componentInstance";
50 import {CommonUtils} from "../../../utils/common-utils";
51 import {RelationshipModel} from "../../../models/graph/relationship";
52 import {ServiceGenericResponse} from "../responses/service-generic-response";
53 import { HttpClient, HttpParams, HttpHeaders } from "@angular/common/http";
54 import { HttpHelperService } from "../http-hepler.service";
55 import {
56     Component as TopologyTemplate,
57     FullComponentInstance,
58     Service,
59     OperationModel,
60 } from 'app/models';
61 import { ConsumptionInput } from "../../components/logic/service-consumption/service-consumption.component";
62 import { ConstraintObject } from "../../components/logic/service-dependencies/service-dependencies.component";
63 import { ComponentMetadata } from "../../../models/component-metadata";
64 import { PolicyInstance } from "../../../models/graph/zones/policy-instance";
65 import { PropertyBEModel } from "../../../models/properties-inputs/property-be-model";
66 import {map} from "rxjs/operators";
67
68 /* we need to use this service from now, we will remove component.service when we finish remove the angular1.
69  The service is duplicated since we can not use downgrades service with NGXS*/
70
71 @Injectable()
72 export class TopologyTemplateService {
73
74     protected baseUrl;
75
76     constructor(protected http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
77         this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
78     }
79
80     getFullComponent(componentType: string, uniqueId: string): Observable<Component> {
81         return this.http.get<Component>(this.baseUrl + this.getServerTypeUrl(componentType) + uniqueId);
82     }
83
84     getComponentMetadata(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
85         return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_METADATA]);
86     }
87
88     getComponentInstanceAttributesAndProperties(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
89         return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
90     }
91
92     async getComponentAttributes(componentType: string, componentId: string): Promise<ComponentGenericResponse> {
93         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]).toPromise();
94     }
95
96     getComponentCompositionData(componentUniqueId: string, componentType: string): Observable<ComponentGenericResponse> {
97         const params: string[] = [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES,
98             COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS];
99         if (componentType === ComponentType.SERVICE) {
100             params.push(COMPONENT_FIELDS.FORWARDING_PATHS);
101         }
102         return this.getComponentDataByFieldsName(componentType, componentUniqueId, params);
103     }
104
105     getComponentResourcePropertiesData(component: Component): Observable<ComponentGenericResponse> {
106         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId,
107             [COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS]);
108     }
109
110     getComponentResourceInstances(component: Component): Observable<ComponentGenericResponse> {
111         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES]);
112     }
113
114     getComponentInputs(component: Component): Observable<ComponentGenericResponse> {
115         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
116     }
117
118     getComponentInputsWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
119         return this.getComponentDataByFieldsName(componentType, componentId,
120             [COMPONENT_FIELDS.COMPONENT_INPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
121     }
122
123     getComponentDeploymentArtifacts(component: Component): Observable<ComponentGenericResponse> {
124         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS]);
125     }
126
127     getComponentInformationalArtifacts(component: Component): Observable<ComponentGenericResponse> {
128         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS]);
129     }
130
131     getComponentInformationalArtifactsAndInstances(component: Component): Observable<ComponentGenericResponse> {
132         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
133     }
134
135     getComponentToscaArtifacts(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
136         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS]);
137     }
138
139     getComponentProperties(component: Component): Observable<ComponentGenericResponse> {
140         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
141     }
142
143     getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
144         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
145     }
146
147     getRequirementsAndCapabilitiesWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
148         return this.getComponentDataByFieldsName(componentType, componentId,
149             [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
150     }
151
152     getDeploymentGraphData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
153         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_GROUPS]);
154     }
155
156     createInput(component: Component, inputsToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
157         const inputs = isSelf ? { serviceProperties: inputsToCreate.componentInstanceProperties } : inputsToCreate;
158         return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/inputs', inputs);
159     }
160
161     restoreComponent(componentType: string, componentId: string) {
162         return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/restore', {});
163     }
164
165     archiveComponent(componentType: string, componentId: string) {
166         return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/archive', {});
167     }
168
169     deleteInput(component: Component, input: InputBEModel): Observable<InputBEModel> {
170         return this.http.delete<InputBEModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/delete/' + input.uniqueId + '/input')
171             .map((res) => {
172                 return new InputBEModel(res);
173             });
174     }
175
176     updateComponentInputs(component: Component, inputs: InputBEModel[]): Observable<InputBEModel[]> {
177         return this.http.post<InputBEModel[]>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/update/inputs', inputs)
178             .map((res) => {
179                 return res.map((input) => new InputBEModel(input));
180             });
181     }
182
183     filterComponentInstanceProperties(component: Component, filterData: FilterPropertiesAssignmentData): Observable<InstanceBePropertiesMap> {// instance-property-be-map
184         let params: HttpParams = new HttpParams();
185         _.forEach(filterData.selectedTypes, (type: string) => {
186             params = params.append('resourceType', type);
187         });
188
189         // tslint:disable-next-line:object-literal-shorthand
190         return this.http.get<InstanceBePropertiesMap>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {params: params});
191     }
192
193     createServiceProperty(componentId: string, propertyModel: PropertyBEModel): Observable<PropertyBEModel> {
194         const serverObject = {};
195         serverObject[propertyModel.name] = propertyModel;
196         return this.http.post<PropertyBEModel>(this.baseUrl + 'services/' + componentId + '/properties', serverObject)
197             .map((res) => {
198                 const property: PropertyBEModel = new PropertyBEModel(res);
199                 return property;
200             });
201     }
202
203     getServiceProperties(componentId: string): Observable<PropertyBEModel[]> {
204         return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/properties')
205             .map((res) => {
206                 if (!res) {
207                     return new Array<PropertyBEModel>();
208                 }
209                 return CommonUtils.initBeProperties(res);
210             });
211     }
212
213     updateServiceProperties(componentId: string, properties: PropertyBEModel[]) {
214         return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/properties', properties)
215             .map((res) => {
216                 const resJson = res;
217                 return _.map(resJson,
218                     (resValue: PropertyBEModel) => new PropertyBEModel(resValue));
219             });
220     }
221
222     deleteServiceProperty(componentId: string, property: PropertyBEModel): Observable<string> {
223         return this.http.delete(this.baseUrl + 'services/' + componentId + '/properties/' + property.uniqueId )
224             .map((res: Response) => {
225                 return property.uniqueId;
226             });
227     }
228
229     getDependencies(componentType: string, componentId: string): Observable<IDependenciesServerResponse[]> {
230         return this.http.get<IDependenciesServerResponse[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/dependencies');
231     }
232
233     automatedUpgrade(componentType: string, componentId: string, componentsIdsToUpgrade: IAutomatedUpgradeRequestObj[]): Observable<AutomatedUpgradeGenericResponse> {
234         return this.http.post<AutomatedUpgradeGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/automatedupgrade', componentsIdsToUpgrade);
235     }
236
237     updateComponentInstance(componentMetaDataId: string, componentType: string, componentInstance:ComponentInstance): Observable<ComponentInstance> {
238         return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstance/' + componentInstance.uniqueId, componentInstance);
239     }
240
241     updateMultipleComponentInstances(componentId: string, componentType: string, instances: ComponentInstance[]): Observable<ComponentInstance[]> {
242         return this.http.post<ComponentInstance[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/multipleComponentInstance', instances)
243             .map((res) => {
244                 return CommonUtils.initComponentInstances(res);
245             });
246     }
247
248     createRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
249         return this.http.post<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/associate', link)
250             .map((res) => {
251                 return new RelationshipModel(res);
252             });
253     }
254
255     deleteRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
256         return this.http.put<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/dissociate', link)
257             .map((res) => {
258                 return new RelationshipModel(res);
259             });
260     }
261
262     createComponentInstance(componentType: string, componentId: string, componentInstance: ComponentInstance): Observable<ComponentInstance> {
263         return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance', componentInstance)
264             .map((res) => {
265                 return new ComponentInstance(res);
266             });
267     }
268
269     deleteComponentInstance(componentType: string, componentId: string, componentInstanceId: string): Observable<ComponentInstance> {
270         return this.http.delete<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/' + componentInstanceId)
271             .map((res) => {
272                 return new ComponentInstance(res);
273             });
274     }
275
276     fetchRelation(componentType: string, componentId: string, linkId: string): Observable<RelationshipModel> {
277         return this.http.get<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/relationId/' + linkId)
278             .map((res) => {
279                 return new RelationshipModel(res);
280             });
281     }
282
283     addOrUpdateArtifact = (componentType: string, componentId: string, artifact: ArtifactModel): Observable<ArtifactModel> => {
284         let headerObj: HttpHeaders = new HttpHeaders();
285         if (artifact.payloadData) {
286             headerObj = headerObj.append('Content-MD5', HttpHelperService.getHeaderMd5(artifact));
287         }
288
289         let artifactID: string = '';
290         if (artifact.uniqueId) {
291             artifactID = '/' + artifact.uniqueId;
292         }
293         return this.http.post<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts' + artifactID, JSON.stringify(artifact), {headers: headerObj}).map(
294             (res) => new ArtifactModel(res)
295         );
296     }
297
298     deleteArtifact = (componentId: string, componentType: string, artifactId: string, artifactLabel: string): Observable<ArtifactModel> => {
299         return this.http.delete<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId + '?operation=' + artifactLabel)
300             .map((res) => new ArtifactModel(res));
301     }
302
303     downloadArtifact = (componentType: string, componentId: string, artifactId: string): Observable<IFileDownload> => {
304         return this.http.get<IFileDownload>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId);
305     }
306
307     // ------------------------------------------------ Properties API --------------------------------------------------//
308     addProperty = (componentType: string, componentId: string, property: PropertyModel):Observable<PropertyModel> => {
309         return this.http.post<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', property.convertToServerObject()).map((response) => {
310             return new PropertyModel(response[Object.keys(response)[0]]);
311         });
312     }
313
314     updateProperty = (componentType: string, componentId: string, property: PropertyModel): Observable<PropertyModel> => {
315         var propertiesList:PropertyBEModel[]  = [property];
316         return this.http.put<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', propertiesList)
317         .map((response) => {
318             return new PropertyModel(response[Object.keys(response)[0]]);
319         });
320     }
321
322     deleteProperty = (componentType: string, componentId: string, propertyId: string): Observable<PropertyModel> => {
323         return this.http.delete<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties/' + propertyId);
324     }
325
326     // ------------------------------------------------ Attributes API --------------------------------------------------//
327     addAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
328         return this.http.post<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes', attribute.convertToServerObject())
329             .map((response) => {
330                 return new AttributeModel(response);
331             });
332     }
333
334     updateAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
335         const payload = attribute.convertToServerObject();
336
337         return this.http.put<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, payload)
338             .map((response) => {
339                 return new AttributeModel(response);
340             });
341     }
342
343     // Async Methods
344     addAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
345         return this.addAttribute(componentType, componentId, attribute).toPromise();
346     }
347
348     updateAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
349         return this.updateAttribute(componentType, componentId, attribute).toPromise();
350     }
351
352     deleteAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<any> => {
353         return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, {}).toPromise();
354     }
355
356     getArtifactsByType(componentType: string, componentId: string, artifactsType: ArtifactGroupType) {
357         return this.getComponentDataByFieldsName(componentType, componentId, [this.convertArtifactTypeToUrl(artifactsType)]);
358     }
359
360     getServiceConsumptionData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
361         return this.getComponentDataByFieldsName(componentType, componentId, [
362             // COMPONENT_FIELDS.COMPONENT_INSTANCES_INTERFACES,
363             COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES,
364             // COMPONENT_FIELDS.COMPONENT_INSTANCES_INPUTS,
365             COMPONENT_FIELDS.COMPONENT_INPUTS,
366             COMPONENT_FIELDS.COMPONENT_INSTANCES,
367             COMPONENT_FIELDS.COMPONENT_CAPABILITIES
368         ]);
369     }
370
371     getServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, interfaceId: string, operation: OperationModel): Observable<ConsumptionInput[]> {
372         return this.http.get<ConsumptionInput[]>
373         (this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId + '/interfaces/' + interfaceId + '/operations/' + operation.uniqueId + '/inputs');
374     }
375
376     createOrUpdateServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, consumptionInputsList: Array<{[id: string]: ConsumptionInput[]}>): Observable<any> {
377         return this.http.post(this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId, consumptionInputsList);
378     }
379
380     getServiceFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
381         return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.NODE_FILTER]);
382     }
383
384     getSubstitutionFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
385         return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.SUBSTITUTION_FILTER]);
386     }
387
388     getComponentInstanceProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
389         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]);
390     }
391
392     createServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: ConstraintObject, componentType: string, constraintType: string): Observable<any> {
393         return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstances/' + componentInstanceId + '/nodeFilter/' + constraintType, constraint);
394     }
395
396     updateServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraints: ConstraintObject[], componentType: string, constraintType: string):Observable<any>{
397         return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstances/' + componentInstanceId + '/nodeFilter/' + constraintType, constraints)
398     }
399
400     deleteServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
401         return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstances/' + componentInstanceId + '/nodeFilter/' + constraintType + "/" + constraintIndex)
402     }
403
404     getComponentPropertiesSubstitutionFilter(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
405         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
406     }
407
408     createSubstitutionFilterConstraints(componentMetaDataId: string, constraint: ConstraintObject, componentType: string, constraintType: string): Observable<any> {
409         return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
410     }
411
412     updateSubstitutionFilterConstraints(componentMetaDataId: string, constraint: ConstraintObject[], componentType: string, constraintType: string): Observable<any>{
413         return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
414     }
415
416     deleteSubstitutionFilterConstraints(componentMetaDataId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
417         return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType + "/" + constraintIndex)
418     }
419
420     deletePolicy(component: Component, policy: PolicyInstance): Observable<PolicyInstance> {
421         return this.http.put<PolicyInstance>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policy.uniqueId + '/undeclare', policy)
422     }
423
424     createListInput(component: Component, input: any, isSelf: boolean): Observable<any> {
425         let inputs: any;
426         if (isSelf) {
427             // change componentInstanceProperties -> serviceProperties
428             inputs = {
429                 componentInstInputsMap: {
430                     serviceProperties: input.componentInstInputsMap.componentInstanceProperties
431                 },
432                 listInput: input.listInput
433             };
434         } else {
435             inputs = input;
436         }
437         return this.http.post<any>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/listInput', inputs);
438     }
439
440     createPolicy(component: Component, policiesToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
441         const policiesList =
442             isSelf ?
443                 // tslint:disable-next-line:object-literal-key-quotes
444                 {'componentPropertiesToPolicies': {
445                         ...policiesToCreate.componentInstanceProperties
446                     }
447                 } :
448                 // tslint:disable-next-line:object-literal-key-quotes
449                 {'componentInstancePropertiesToPolicies': {
450                         ...policiesToCreate.componentInstanceProperties
451                     }
452                 };
453         return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/policies', policiesList);
454     }
455
456     protected getComponentDataByFieldsName(componentType: string, componentId: string, fields: string[]): Observable<ComponentGenericResponse> {
457         let params: HttpParams = new HttpParams();
458         _.forEach(fields, (field: string): void => {
459             params = params.append(API_QUERY_PARAMS.INCLUDE, field);
460         });
461         // tslint:disable-next-line:object-literal-shorthand
462         return this.http.get<ComponentGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {params: params})
463             .map((res) => {
464                 return componentType === ComponentType.SERVICE ? new ServiceGenericResponse().deserialize(res) :
465                         new ComponentGenericResponse().deserialize(res);
466             });
467     }
468
469     private getServerTypeUrl = (componentType: string): string => {
470         switch (componentType) {
471             case ComponentType.SERVICE:
472             case ComponentType.SERVICE_PROXY:
473             case ComponentType.SERVICE_SUBSTITUTION:
474                 return ServerTypeUrl.SERVICES;
475             default:
476                 return ServerTypeUrl.RESOURCES;
477         }
478     }
479
480     private convertArtifactTypeToUrl = (artifactType: ArtifactGroupType): string => {
481         switch (artifactType) {
482             case ArtifactGroupType.TOSCA:
483                 return COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS;
484             case ArtifactGroupType.INFORMATION:
485                 return COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS;
486             case ArtifactGroupType.DEPLOYMENT:
487                 return COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS;
488             case ArtifactGroupType.SERVICE_API:
489                 return COMPONENT_FIELDS.SERVICE_API_ARTIFACT;
490         }
491     }
492
493     // createCapability(component: Component, capabilityData: Capability): Observable<Capability[]> {
494     createCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
495         let capBEObj = {
496             'capabilities': {
497                 [capabilityData.type]: [capabilityData]
498             }
499         };
500         return this.http.post<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
501     }
502
503     updateCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
504         let capBEObj = {
505             'capabilities': {
506                 [capabilityData.type]: [capabilityData]
507             }
508         };
509         return this.http.put<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
510     }
511
512     deleteCapability(component: Component, capId: string): Observable<Capability> {
513         return this.http.delete<Capability>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/capabilities/' + capId);
514     }
515
516     createRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
517         let reqBEObj = {
518             'requirements': {
519                 [requirementData.capability]: [requirementData]
520             }
521         };
522         return this.http.post(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
523     }
524
525     updateRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
526         let reqBEObj = {
527             'requirements': {
528                 [requirementData.capability]: [requirementData]
529             }
530         };
531         return this.http.put(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
532     }
533
534     deleteRequirement(component: Component, reqId: string): Observable<Requirement> {
535         return this.http.delete<Requirement>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/requirements/' + reqId);
536     }
537
538     getDirectiveList(): Observable<string[]> {
539         return this.http.get<ListDirectiveResponse>(this.baseUrl + "directives")
540         .pipe(map(response => response.directives));
541     }
542
543 }