095c8d6e76f298474ce9c11d94ad8fe6ae2924ed
[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
67 /* we need to use this service from now, we will remove component.service when we finish remove the angular1.
68  The service is duplicated since we can not use downgrades service with NGXS*/
69
70 @Injectable()
71 export class TopologyTemplateService {
72
73     protected baseUrl;
74
75     constructor(protected http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
76         this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
77     }
78
79     getFullComponent(componentType: string, uniqueId: string): Observable<Component> {
80         return this.http.get<Component>(this.baseUrl + this.getServerTypeUrl(componentType) + uniqueId);
81     }
82
83     getComponentMetadata(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
84         return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_METADATA]);
85     }
86
87     getComponentInstanceAttributesAndProperties(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
88         return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
89     }
90
91     async getComponentAttributes(componentType: string, componentId: string): Promise<ComponentGenericResponse> {
92         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]).toPromise();
93     }
94
95     getComponentCompositionData(componentUniqueId: string, componentType: string): Observable<ComponentGenericResponse> {
96         const params: string[] = [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES,
97             COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS];
98         if (componentType === ComponentType.SERVICE) {
99             params.push(COMPONENT_FIELDS.FORWARDING_PATHS);
100         }
101         return this.getComponentDataByFieldsName(componentType, componentUniqueId, params);
102     }
103
104     getComponentResourcePropertiesData(component: Component): Observable<ComponentGenericResponse> {
105         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId,
106             [COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS]);
107     }
108
109     getComponentResourceInstances(component: Component): Observable<ComponentGenericResponse> {
110         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES]);
111     }
112
113     getComponentInputs(component: Component): Observable<ComponentGenericResponse> {
114         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
115     }
116
117     getComponentInputsWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
118         return this.getComponentDataByFieldsName(componentType, componentId,
119             [COMPONENT_FIELDS.COMPONENT_INPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
120     }
121
122     getComponentDeploymentArtifacts(component: Component): Observable<ComponentGenericResponse> {
123         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS]);
124     }
125
126     getComponentInformationalArtifacts(component: Component): Observable<ComponentGenericResponse> {
127         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS]);
128     }
129
130     getComponentInformationalArtifactsAndInstances(component: Component): Observable<ComponentGenericResponse> {
131         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
132     }
133
134     getComponentToscaArtifacts(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
135         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS]);
136     }
137
138     getComponentProperties(component: Component): Observable<ComponentGenericResponse> {
139         return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
140     }
141
142     getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
143         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
144     }
145
146     getRequirementsAndCapabilitiesWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
147         return this.getComponentDataByFieldsName(componentType, componentId,
148             [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
149     }
150
151     getDeploymentGraphData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
152         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_GROUPS]);
153     }
154
155     createInput(component: Component, inputsToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
156         const inputs = isSelf ? { serviceProperties: inputsToCreate.componentInstanceProperties } : inputsToCreate;
157         return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/inputs', inputs);
158     }
159
160     restoreComponent(componentType: string, componentId: string) {
161         return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/restore', {});
162     }
163
164     archiveComponent(componentType: string, componentId: string) {
165         return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/archive', {});
166     }
167
168     deleteInput(component: Component, input: InputBEModel): Observable<InputBEModel> {
169         return this.http.delete<InputBEModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/delete/' + input.uniqueId + '/input')
170             .map((res) => {
171                 return new InputBEModel(res);
172             });
173     }
174
175     updateComponentInputs(component: Component, inputs: InputBEModel[]): Observable<InputBEModel[]> {
176         return this.http.post<InputBEModel[]>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/update/inputs', inputs)
177             .map((res) => {
178                 return res.map((input) => new InputBEModel(input));
179             });
180     }
181
182     filterComponentInstanceProperties(component: Component, filterData: FilterPropertiesAssignmentData): Observable<InstanceBePropertiesMap> {// instance-property-be-map
183         let params: HttpParams = new HttpParams();
184         _.forEach(filterData.selectedTypes, (type: string) => {
185             params = params.append('resourceType', type);
186         });
187
188         // tslint:disable-next-line:object-literal-shorthand
189         return this.http.get<InstanceBePropertiesMap>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {params: params});
190     }
191
192     createServiceProperty(componentId: string, propertyModel: PropertyBEModel): Observable<PropertyBEModel> {
193         const serverObject = {};
194         serverObject[propertyModel.name] = propertyModel;
195         return this.http.post<PropertyBEModel>(this.baseUrl + 'services/' + componentId + '/properties', serverObject)
196             .map((res) => {
197                 const property: PropertyBEModel = new PropertyBEModel(res);
198                 return property;
199             });
200     }
201
202     getServiceProperties(componentId: string): Observable<PropertyBEModel[]> {
203         return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/properties')
204             .map((res) => {
205                 if (!res) {
206                     return new Array<PropertyBEModel>();
207                 }
208                 return CommonUtils.initBeProperties(res);
209             });
210     }
211
212     updateServiceProperties(componentId: string, properties: PropertyBEModel[]) {
213         return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/properties', properties)
214             .map((res) => {
215                 const resJson = res;
216                 return _.map(resJson,
217                     (resValue: PropertyBEModel) => new PropertyBEModel(resValue));
218             });
219     }
220
221     deleteServiceProperty(componentId: string, property: PropertyBEModel): Observable<string> {
222         return this.http.delete(this.baseUrl + 'services/' + componentId + '/properties/' + property.uniqueId )
223             .map((res: Response) => {
224                 return property.uniqueId;
225             });
226     }
227
228     getDependencies(componentType: string, componentId: string): Observable<IDependenciesServerResponse[]> {
229         return this.http.get<IDependenciesServerResponse[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/dependencies');
230     }
231
232     automatedUpgrade(componentType: string, componentId: string, componentsIdsToUpgrade: IAutomatedUpgradeRequestObj[]): Observable<AutomatedUpgradeGenericResponse> {
233         return this.http.post<AutomatedUpgradeGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/automatedupgrade', componentsIdsToUpgrade);
234     }
235
236     updateComponentInstance(componentMetaDataId: string, componentType: string, componentInstance:ComponentInstance): Observable<ComponentInstance> {
237         return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstance/' + componentInstance.uniqueId, componentInstance);
238     }
239
240     updateMultipleComponentInstances(componentId: string, componentType: string, instances: ComponentInstance[]): Observable<ComponentInstance[]> {
241         return this.http.post<ComponentInstance[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/multipleComponentInstance', instances)
242             .map((res) => {
243                 return CommonUtils.initComponentInstances(res);
244             });
245     }
246
247     createRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
248         return this.http.post<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/associate', link)
249             .map((res) => {
250                 return new RelationshipModel(res);
251             });
252     }
253
254     deleteRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
255         return this.http.put<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/dissociate', link)
256             .map((res) => {
257                 return new RelationshipModel(res);
258             });
259     }
260
261     createComponentInstance(componentType: string, componentId: string, componentInstance: ComponentInstance): Observable<ComponentInstance> {
262         return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance', componentInstance)
263             .map((res) => {
264                 return new ComponentInstance(res);
265             });
266     }
267
268     deleteComponentInstance(componentType: string, componentId: string, componentInstanceId: string): Observable<ComponentInstance> {
269         return this.http.delete<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/' + componentInstanceId)
270             .map((res) => {
271                 return new ComponentInstance(res);
272             });
273     }
274
275     fetchRelation(componentType: string, componentId: string, linkId: string): Observable<RelationshipModel> {
276         return this.http.get<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/relationId/' + linkId)
277             .map((res) => {
278                 return new RelationshipModel(res);
279             });
280     }
281
282     addOrUpdateArtifact = (componentType: string, componentId: string, artifact: ArtifactModel): Observable<ArtifactModel> => {
283         let headerObj: HttpHeaders = new HttpHeaders();
284         if (artifact.payloadData) {
285             headerObj = headerObj.append('Content-MD5', HttpHelperService.getHeaderMd5(artifact));
286         }
287
288         let artifactID: string = '';
289         if (artifact.uniqueId) {
290             artifactID = '/' + artifact.uniqueId;
291         }
292         return this.http.post<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts' + artifactID, JSON.stringify(artifact), {headers: headerObj}).map(
293             (res) => new ArtifactModel(res)
294         );
295     }
296
297     deleteArtifact = (componentId: string, componentType: string, artifactId: string, artifactLabel: string): Observable<ArtifactModel> => {
298         return this.http.delete<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId + '?operation=' + artifactLabel)
299             .map((res) => new ArtifactModel(res));
300     }
301
302     downloadArtifact = (componentType: string, componentId: string, artifactId: string): Observable<IFileDownload> => {
303         return this.http.get<IFileDownload>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId);
304     }
305
306     // ------------------------------------------------ Properties API --------------------------------------------------//
307     addProperty = (componentType: string, componentId: string, property: PropertyModel):Observable<PropertyModel> => {
308         return this.http.post<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', property.convertToServerObject()).map((response) => {
309             return new PropertyModel(response[Object.keys(response)[0]]);
310         });
311     }
312
313     updateProperty = (componentType: string, componentId: string, property: PropertyModel): Observable<PropertyModel> => {
314         var propertiesList:PropertyBEModel[]  = [property];
315         return this.http.put<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', propertiesList)
316         .map((response) => {
317             return new PropertyModel(response[Object.keys(response)[0]]);
318         });
319     }
320
321     deleteProperty = (componentType: string, componentId: string, propertyId: string): Observable<PropertyModel> => {
322         return this.http.delete<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties/' + propertyId);
323     }
324
325     // ------------------------------------------------ Attributes API --------------------------------------------------//
326     addAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
327         return this.http.post<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes', attribute.convertToServerObject())
328             .map((response) => {
329                 return new AttributeModel(response);
330             });
331     }
332
333     updateAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
334         const payload = attribute.convertToServerObject();
335
336         return this.http.put<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, payload)
337             .map((response) => {
338                 return new AttributeModel(response);
339             });
340     }
341
342     // Async Methods
343     addAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
344         return this.addAttribute(componentType, componentId, attribute).toPromise();
345     }
346
347     updateAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
348         return this.updateAttribute(componentType, componentId, attribute).toPromise();
349     }
350
351     deleteAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<any> => {
352         return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, {}).toPromise();
353     }
354
355     getArtifactsByType(componentType: string, componentId: string, artifactsType: ArtifactGroupType) {
356         return this.getComponentDataByFieldsName(componentType, componentId, [this.convertArtifactTypeToUrl(artifactsType)]);
357     }
358
359     getServiceConsumptionData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
360         return this.getComponentDataByFieldsName(componentType, componentId, [
361             // COMPONENT_FIELDS.COMPONENT_INSTANCES_INTERFACES,
362             COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES,
363             // COMPONENT_FIELDS.COMPONENT_INSTANCES_INPUTS,
364             COMPONENT_FIELDS.COMPONENT_INPUTS,
365             COMPONENT_FIELDS.COMPONENT_INSTANCES,
366             COMPONENT_FIELDS.COMPONENT_CAPABILITIES
367         ]);
368     }
369
370     getServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, interfaceId: string, operation: OperationModel): Observable<ConsumptionInput[]> {
371         return this.http.get<ConsumptionInput[]>
372         (this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId + '/interfaces/' + interfaceId + '/operations/' + operation.uniqueId + '/inputs');
373     }
374
375     createOrUpdateServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, consumptionInputsList: Array<{[id: string]: ConsumptionInput[]}>): Observable<any> {
376         return this.http.post(this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId, consumptionInputsList);
377     }
378
379     getServiceFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
380         return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.NODE_FILTER]);
381     }
382
383     getComponentInstanceProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
384         return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]);
385     }
386
387     createServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: ConstraintObject, componentType: string): Observable<any> {
388         return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstances/' + componentInstanceId + '/nodeFilter', constraint);
389     }
390
391     updateServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraints: ConstraintObject[], componentType: string):Observable<any>{
392         return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstances/' + componentInstanceId + '/nodeFilter', constraints)
393     }
394
395     deleteServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraintIndex: number, componentType: string): Observable<any>{
396         return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstances/' + componentInstanceId + '/nodeFilter/' + constraintIndex)
397     }
398
399     deletePolicy(component: Component, policy: PolicyInstance): Observable<PolicyInstance> {
400         return this.http.put<PolicyInstance>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policy.uniqueId + '/undeclare', policy)
401     }
402
403     createListInput(componentId: string, input: any, isSelf: boolean): Observable<any> {
404         let inputs: any;
405         if (isSelf) {
406             // change componentInstanceProperties -> serviceProperties
407             inputs = {
408                 componentInstInputsMap: {
409                     serviceProperties: input.componentInstInputsMap.componentInstanceProperties
410                 },
411                 listInput: input.listInput
412             };
413         } else {
414             inputs = input;
415         }
416         return this.http.post<any>(this.baseUrl + 'services/' + componentId + '/create/listInput', inputs);
417     }
418
419     createPolicy(component: Component, policiesToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
420         const policiesList =
421             isSelf ?
422                 // tslint:disable-next-line:object-literal-key-quotes
423                 {'componentPropertiesToPolicies': {
424                         ...policiesToCreate.componentInstanceProperties
425                     }
426                 } :
427                 // tslint:disable-next-line:object-literal-key-quotes
428                 {'componentInstancePropertiesToPolicies': {
429                         ...policiesToCreate.componentInstanceProperties
430                     }
431                 };
432         return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/policies', policiesList);
433     }
434
435     protected getComponentDataByFieldsName(componentType: string, componentId: string, fields: string[]): Observable<ComponentGenericResponse> {
436         let params: HttpParams = new HttpParams();
437         _.forEach(fields, (field: string): void => {
438             params = params.append(API_QUERY_PARAMS.INCLUDE, field);
439         });
440         // tslint:disable-next-line:object-literal-shorthand
441         return this.http.get<ComponentGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {params: params})
442             .map((res) => {
443                 return componentType === ComponentType.SERVICE ? new ServiceGenericResponse().deserialize(res) :
444                         new ComponentGenericResponse().deserialize(res);
445             });
446     }
447
448     private getServerTypeUrl = (componentType: string): string => {
449         switch (componentType) {
450             case ComponentType.SERVICE:
451             case ComponentType.SERVICE_PROXY:
452                 return ServerTypeUrl.SERVICES;
453             default:
454                 return ServerTypeUrl.RESOURCES;
455         }
456     }
457
458     private convertArtifactTypeToUrl = (artifactType: ArtifactGroupType): string => {
459         switch (artifactType) {
460             case ArtifactGroupType.TOSCA:
461                 return COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS;
462             case ArtifactGroupType.INFORMATION:
463                 return COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS;
464             case ArtifactGroupType.DEPLOYMENT:
465                 return COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS;
466             case ArtifactGroupType.SERVICE_API:
467                 return COMPONENT_FIELDS.SERVICE_API_ARTIFACT;
468         }
469     }
470
471     // createCapability(component: Component, capabilityData: Capability): Observable<Capability[]> {
472     createCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
473         let capBEObj = {
474             'capabilities': {
475                 [capabilityData.type]: [capabilityData]
476             }
477         };
478         return this.http.post<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
479     }
480
481     updateCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
482         let capBEObj = {
483             'capabilities': {
484                 [capabilityData.type]: [capabilityData]
485             }
486         };
487         return this.http.put<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
488     }
489
490     deleteCapability(component: Component, capId: string): Observable<Capability> {
491         return this.http.delete<Capability>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/capabilities/' + capId);
492     }
493
494     createRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
495         let reqBEObj = {
496             'requirements': {
497                 [requirementData.capability]: [requirementData]
498             }
499         };
500         return this.http.post(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
501     }
502
503     updateRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
504         let reqBEObj = {
505             'requirements': {
506                 [requirementData.capability]: [requirementData]
507             }
508         };
509         return this.http.put(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
510     }
511
512     deleteRequirement(component: Component, reqId: string): Observable<Requirement> {
513         return this.http.delete<Requirement>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/requirements/' + reqId);
514     }
515 }