2 * Created by ob0695 on 6/26/2018.
5 * ============LICENSE_START=======================================================
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
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';
32 InstancePropertiesAPIMap,
33 FilterPropertiesAssignmentData,
38 IAttributeModel, Capability, Requirement
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";
56 Component as TopologyTemplate,
57 FullComponentInstance,
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";
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*/
72 export class TopologyTemplateService {
76 constructor(protected http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
77 this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
80 getFullComponent(componentType: string, uniqueId: string): Observable<Component> {
81 return this.http.get<Component>(this.baseUrl + this.getServerTypeUrl(componentType) + uniqueId);
84 getComponentMetadata(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
85 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_METADATA]);
88 getComponentInstanceAttributesAndProperties(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
89 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
92 async getComponentAttributes(componentType: string, componentId: string): Promise<ComponentGenericResponse> {
93 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]).toPromise();
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);
102 return this.getComponentDataByFieldsName(componentType, componentUniqueId, params);
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]);
110 getComponentResourceInstances(component: Component): Observable<ComponentGenericResponse> {
111 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES]);
114 getComponentInputs(component: Component): Observable<ComponentGenericResponse> {
115 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
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]);
123 getComponentDeploymentArtifacts(component: Component): Observable<ComponentGenericResponse> {
124 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS]);
127 getComponentInformationalArtifacts(component: Component): Observable<ComponentGenericResponse> {
128 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS]);
131 getComponentInformationalArtifactsAndInstances(component: Component): Observable<ComponentGenericResponse> {
132 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
135 getComponentToscaArtifacts(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
136 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS]);
139 getComponentProperties(component: Component): Observable<ComponentGenericResponse> {
140 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
143 getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
144 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
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]);
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]);
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);
161 restoreComponent(componentType: string, componentId: string) {
162 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/restore', {});
165 archiveComponent(componentType: string, componentId: string) {
166 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/archive', {});
169 deleteInput(component: Component, input: InputBEModel): Observable<InputBEModel> {
170 return this.http.delete<InputBEModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/delete/' + input.uniqueId + '/input')
172 return new InputBEModel(res);
176 updateComponentInputs(component: Component, inputs: InputBEModel[]): Observable<InputBEModel[]> {
177 return this.http.post<InputBEModel[]>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/update/inputs', inputs)
179 return res.map((input) => new InputBEModel(input));
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);
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});
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)
198 const property: PropertyBEModel = new PropertyBEModel(res);
203 getServiceProperties(componentId: string): Observable<PropertyBEModel[]> {
204 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/properties')
207 return new Array<PropertyBEModel>();
209 return CommonUtils.initBeProperties(res);
213 updateServiceProperties(componentId: string, properties: PropertyBEModel[]) {
214 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/properties', properties)
217 return _.map(resJson,
218 (resValue: PropertyBEModel) => new PropertyBEModel(resValue));
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;
229 getDependencies(componentType: string, componentId: string): Observable<IDependenciesServerResponse[]> {
230 return this.http.get<IDependenciesServerResponse[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/dependencies');
233 automatedUpgrade(componentType: string, componentId: string, componentsIdsToUpgrade: IAutomatedUpgradeRequestObj[]): Observable<AutomatedUpgradeGenericResponse> {
234 return this.http.post<AutomatedUpgradeGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/automatedupgrade', componentsIdsToUpgrade);
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);
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)
244 return CommonUtils.initComponentInstances(res);
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)
251 return new RelationshipModel(res);
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)
258 return new RelationshipModel(res);
262 createComponentInstance(componentType: string, componentId: string, componentInstance: ComponentInstance): Observable<ComponentInstance> {
263 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance', componentInstance)
265 return new ComponentInstance(res);
269 deleteComponentInstance(componentType: string, componentId: string, componentInstanceId: string): Observable<ComponentInstance> {
270 return this.http.delete<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/' + componentInstanceId)
272 return new ComponentInstance(res);
276 fetchRelation(componentType: string, componentId: string, linkId: string): Observable<RelationshipModel> {
277 return this.http.get<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/relationId/' + linkId)
279 return new RelationshipModel(res);
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));
289 let artifactID: string = '';
290 if (artifact.uniqueId) {
291 artifactID = '/' + artifact.uniqueId;
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)
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));
303 downloadArtifact = (componentType: string, componentId: string, artifactId: string): Observable<IFileDownload> => {
304 return this.http.get<IFileDownload>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId);
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]]);
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)
318 return new PropertyModel(response[Object.keys(response)[0]]);
322 deleteProperty = (componentType: string, componentId: string, propertyId: string): Observable<PropertyModel> => {
323 return this.http.delete<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties/' + propertyId);
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())
330 return new AttributeModel(response);
334 updateAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
335 const payload = attribute.convertToServerObject();
337 return this.http.put<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, payload)
339 return new AttributeModel(response);
344 addAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
345 return this.addAttribute(componentType, componentId, attribute).toPromise();
348 updateAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
349 return this.updateAttribute(componentType, componentId, attribute).toPromise();
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();
356 getArtifactsByType(componentType: string, componentId: string, artifactsType: ArtifactGroupType) {
357 return this.getComponentDataByFieldsName(componentType, componentId, [this.convertArtifactTypeToUrl(artifactsType)]);
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
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');
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);
380 getServiceFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
381 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.NODE_FILTER]);
384 getSubstitutionFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
385 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.SUBSTITUTION_FILTER]);
388 getComponentInstanceProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
389 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]);
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);
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)
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)
404 createSubstitutionFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: ConstraintObject, componentType: string): Observable<any> {
405 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstances/' + componentInstanceId + '/substitutionFilter', constraint);
408 updateSubstitutionFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: ConstraintObject, componentType: string): Observable<any> {
409 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstances/' + componentInstanceId + '/substitutionFilter', constraint);
412 deleteSubstitutionFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraintIndex: number, componentType: string): Observable<any>{
413 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstances/' + componentInstanceId + '/substitutionFilter/' + constraintIndex)
416 deletePolicy(component: Component, policy: PolicyInstance): Observable<PolicyInstance> {
417 return this.http.put<PolicyInstance>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policy.uniqueId + '/undeclare', policy)
420 createListInput(componentId: string, input: any, isSelf: boolean): Observable<any> {
423 // change componentInstanceProperties -> serviceProperties
425 componentInstInputsMap: {
426 serviceProperties: input.componentInstInputsMap.componentInstanceProperties
428 listInput: input.listInput
433 return this.http.post<any>(this.baseUrl + 'services/' + componentId + '/create/listInput', inputs);
436 createPolicy(component: Component, policiesToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
439 // tslint:disable-next-line:object-literal-key-quotes
440 {'componentPropertiesToPolicies': {
441 ...policiesToCreate.componentInstanceProperties
444 // tslint:disable-next-line:object-literal-key-quotes
445 {'componentInstancePropertiesToPolicies': {
446 ...policiesToCreate.componentInstanceProperties
449 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/policies', policiesList);
452 protected getComponentDataByFieldsName(componentType: string, componentId: string, fields: string[]): Observable<ComponentGenericResponse> {
453 let params: HttpParams = new HttpParams();
454 _.forEach(fields, (field: string): void => {
455 params = params.append(API_QUERY_PARAMS.INCLUDE, field);
457 // tslint:disable-next-line:object-literal-shorthand
458 return this.http.get<ComponentGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {params: params})
460 return componentType === ComponentType.SERVICE ? new ServiceGenericResponse().deserialize(res) :
461 new ComponentGenericResponse().deserialize(res);
465 private getServerTypeUrl = (componentType: string): string => {
466 switch (componentType) {
467 case ComponentType.SERVICE:
468 case ComponentType.SERVICE_PROXY:
469 case ComponentType.SERVICE_SUBSTITUTION:
470 return ServerTypeUrl.SERVICES;
472 return ServerTypeUrl.RESOURCES;
476 private convertArtifactTypeToUrl = (artifactType: ArtifactGroupType): string => {
477 switch (artifactType) {
478 case ArtifactGroupType.TOSCA:
479 return COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS;
480 case ArtifactGroupType.INFORMATION:
481 return COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS;
482 case ArtifactGroupType.DEPLOYMENT:
483 return COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS;
484 case ArtifactGroupType.SERVICE_API:
485 return COMPONENT_FIELDS.SERVICE_API_ARTIFACT;
489 // createCapability(component: Component, capabilityData: Capability): Observable<Capability[]> {
490 createCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
493 [capabilityData.type]: [capabilityData]
496 return this.http.post<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
499 updateCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
502 [capabilityData.type]: [capabilityData]
505 return this.http.put<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
508 deleteCapability(component: Component, capId: string): Observable<Capability> {
509 return this.http.delete<Capability>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/capabilities/' + capId);
512 createRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
515 [requirementData.capability]: [requirementData]
518 return this.http.post(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
521 updateRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
524 [requirementData.capability]: [requirementData]
527 return this.http.put(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
530 deleteRequirement(component: Component, reqId: string): Observable<Requirement> {
531 return this.http.delete<Requirement>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/requirements/' + reqId);
534 getDirectiveList(): Observable<string[]> {
535 return this.http.get<ListDirectiveResponse>(this.baseUrl + "directives")
536 .pipe(map(response => response.directives));