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 Capability, Requirement, BEOperationModel, InterfaceModel
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";
67 import {CapabilitiesConstraintObject} from "../../components/logic/capabilities-constraint/capabilities-constraint.component";
69 BEInterfaceOperationModel,
70 ComponentInstanceInterfaceModel,
71 InterfaceOperationModel
72 } from "../../../models/interfaceOperation";
73 import {AttributeBEModel} from "../../../models/attributes-outputs/attribute-be-model";
74 import {InstanceAttributesAPIMap} from "../../../models/attributes-outputs/attribute-fe-map";
76 /* we need to use this service from now, we will remove component.service when we finish remove the angular1.
77 The service is duplicated since we can not use downgrades service with NGXS*/
80 export class TopologyTemplateService {
84 constructor(protected http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
85 this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
88 getFullComponent(componentType: string, uniqueId: string): Observable<Component> {
89 return this.http.get<Component>(this.baseUrl + this.getServerTypeUrl(componentType) + uniqueId);
92 getComponentMetadata(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
93 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_METADATA]);
96 getComponentInstanceAttributesAndProperties(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
97 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
100 async getComponentAttributes(componentType: string, componentId: string): Promise<ComponentGenericResponse> {
101 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]).toPromise();
104 getComponentCompositionData(componentUniqueId: string, componentType: string): Observable<ComponentGenericResponse> {
105 const params: string[] = [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES,
106 COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS];
107 if (componentType === ComponentType.SERVICE) {
108 params.push(COMPONENT_FIELDS.FORWARDING_PATHS);
110 return this.getComponentDataByFieldsName(componentType, componentUniqueId, params);
113 getComponentResourcePropertiesData(component: Component): Observable<ComponentGenericResponse> {
114 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId,
115 [COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS]);
118 getComponentInstances(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
119 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES]);
122 getComponentInputs(component: Component): Observable<ComponentGenericResponse> {
123 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
126 getComponentInputsValues(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
127 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
130 getComponentInputsWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
131 return this.getComponentDataByFieldsName(componentType, componentId,
132 [COMPONENT_FIELDS.COMPONENT_INPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
135 getComponentOutputsWithAttributes(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
136 return this.getComponentDataByFieldsName(componentType, componentId,
137 [COMPONENT_FIELDS.COMPONENT_OUTPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_ATTRIBUTES,COMPONENT_FIELDS.COMPONENT_INSTANCES_OUTPUTS]);
140 getComponentDeploymentArtifacts(component: Component): Observable<ComponentGenericResponse> {
141 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS]);
144 getComponentInformationalArtifacts(component: Component): Observable<ComponentGenericResponse> {
145 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS]);
148 getComponentInformationalArtifactsAndInstances(component: Component): Observable<ComponentGenericResponse> {
149 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
152 getComponentToscaArtifacts(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
153 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS]);
156 getComponentProperties(component: Component): Observable<ComponentGenericResponse> {
157 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
160 getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
161 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
164 getRequirementsAndCapabilitiesWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
165 return this.getComponentDataByFieldsName(componentType, componentId,
166 [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
169 getDeploymentGraphData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
170 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_GROUPS]);
173 createInput(component: Component, inputsToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
174 const inputs = isSelf ? { serviceProperties: inputsToCreate.componentInstanceProperties } : inputsToCreate;
175 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/inputs', inputs);
178 createOutput(component: Component, outputsToCreate: InstanceAttributesAPIMap, isSelf: boolean): Observable<any> {
179 const outputs = isSelf ? { serviceProperties: outputsToCreate.componentInstanceAttributes } : outputsToCreate;
180 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/outputs', outputs);
183 restoreComponent(componentType: string, componentId: string) {
184 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/restore', {});
187 archiveComponent(componentType: string, componentId: string) {
188 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/archive', {});
191 deleteInput(component: Component, input: InputBEModel): Observable<InputBEModel> {
192 return this.http.delete<InputBEModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/delete/' + input.uniqueId + '/input')
194 return new InputBEModel(res);
198 updateComponentInputs(component: Component, inputs: InputBEModel[]): Observable<InputBEModel[]> {
199 return this.http.post<InputBEModel[]>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/update/inputs', inputs)
201 return res.map((input) => new InputBEModel(input));
205 filterComponentInstanceProperties(component: Component, filterData: FilterPropertiesAssignmentData): Observable<InstanceBePropertiesMap> {// instance-property-be-map
206 let params: HttpParams = new HttpParams();
207 _.forEach(filterData.selectedTypes, (type: string) => {
208 params = params.append('resourceType', type);
211 // tslint:disable-next-line:object-literal-shorthand
212 return this.http.get<InstanceBePropertiesMap>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {params: params});
215 createServiceProperty(componentId: string, propertyModel: PropertyBEModel): Observable<PropertyBEModel> {
216 const serverObject = {};
217 serverObject[propertyModel.name] = propertyModel;
218 return this.http.post<PropertyBEModel>(this.baseUrl + 'services/' + componentId + '/properties', serverObject)
220 const property: PropertyBEModel = new PropertyBEModel(res);
225 createServiceAttribute(componentId: string, attributeModel: AttributeBEModel): Observable<AttributeBEModel> {
226 const serverObject = {};
227 serverObject[attributeModel.name] = attributeModel;
228 return this.http.post<AttributeBEModel>(this.baseUrl + 'services/' + componentId + '/attributes', serverObject)
230 const attribute: AttributeBEModel = new AttributeBEModel(res);
235 getServiceProperties(componentId: string): Observable<PropertyBEModel[]> {
236 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/properties')
239 return new Array<PropertyBEModel>();
241 return CommonUtils.initBeProperties(res);
245 getServiceAttributes(componentId: string): Observable<AttributeBEModel[]> {
246 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/attributes')
249 return new Array<AttributeBEModel>();
251 return CommonUtils.initAttributes(res);
255 updateServiceProperties(componentId: string, properties: PropertyBEModel[]) {
256 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/properties', properties)
259 return _.map(resJson,
260 (resValue: PropertyBEModel) => new PropertyBEModel(resValue));
264 updateServiceAttributes(componentId: string, attributes: AttributeBEModel[]) {
265 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/attributes', attributes)
268 return _.map(resJson,
269 (resValue: AttributeBEModel) => new AttributeBEModel(resValue));
273 deleteServiceProperty(componentId: string, property: PropertyBEModel): Observable<string> {
274 return this.http.delete(this.baseUrl + 'services/' + componentId + '/properties/' + property.uniqueId )
275 .map((res: Response) => {
276 return property.uniqueId;
280 createServiceInput(componentId: string, inputModel: InputBEModel): Observable<InputBEModel> {
281 const serverObject = {};
282 serverObject[inputModel.name] = inputModel;
283 return this.http.post<InputBEModel>(this.baseUrl + 'services/' + componentId + '/create/input', serverObject)
285 const input: InputBEModel = new InputBEModel(res);
290 deleteServiceAttribute(componentId: string, attribute: AttributeBEModel): Observable<string> {
291 return this.http.delete(this.baseUrl + 'services/' + componentId + '/attributes/' + attribute.uniqueId )
292 .map((res: Response) => {
293 return attribute.uniqueId;
297 getDependencies(componentType: string, componentId: string): Observable<IDependenciesServerResponse[]> {
298 return this.http.get<IDependenciesServerResponse[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/dependencies');
301 automatedUpgrade(componentType: string, componentId: string, componentsIdsToUpgrade: IAutomatedUpgradeRequestObj[]): Observable<AutomatedUpgradeGenericResponse> {
302 return this.http.post<AutomatedUpgradeGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/automatedupgrade', componentsIdsToUpgrade);
305 updateComponentInstance(componentMetaDataId: string, componentType: string, componentInstance:ComponentInstance): Observable<ComponentInstance> {
306 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstance/' + componentInstance.uniqueId, componentInstance);
309 updateMultipleComponentInstances(componentId: string, componentType: string, instances: ComponentInstance[]): Observable<ComponentInstance[]> {
310 return this.http.post<ComponentInstance[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/multipleComponentInstance', instances)
312 return CommonUtils.initComponentInstances(res);
316 createRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
317 return this.http.post<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/associate', link)
319 return new RelationshipModel(res);
323 deleteRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
324 return this.http.put<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/dissociate', link)
326 return new RelationshipModel(res);
330 createComponentInstance(componentType: string, componentId: string, componentInstance: ComponentInstance): Observable<ComponentInstance> {
331 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance', componentInstance)
333 return new ComponentInstance(res);
337 deleteComponentInstance(componentType: string, componentId: string, componentInstanceId: string): Observable<ComponentInstance> {
338 return this.http.delete<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/' + componentInstanceId)
340 return new ComponentInstance(res);
344 fetchRelation(componentType: string, componentId: string, linkId: string): Observable<RelationshipModel> {
345 return this.http.get<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/relationId/' + linkId)
347 return new RelationshipModel(res);
351 addOrUpdateArtifact = (componentType: string, componentId: string, artifact: ArtifactModel): Observable<ArtifactModel> => {
352 let headerObj: HttpHeaders = new HttpHeaders();
353 if (artifact.payloadData) {
354 headerObj = headerObj.append('Content-MD5', HttpHelperService.getHeaderMd5(artifact));
357 let artifactID: string = '';
358 if (artifact.uniqueId) {
359 artifactID = '/' + artifact.uniqueId;
361 return this.http.post<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts' + artifactID, JSON.stringify(artifact), {headers: headerObj}).map(
362 (res) => new ArtifactModel(res)
366 deleteArtifact = (componentId: string, componentType: string, artifactId: string, artifactLabel: string): Observable<ArtifactModel> => {
367 return this.http.delete<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId + '?operation=' + artifactLabel)
368 .map((res) => new ArtifactModel(res));
371 downloadArtifact = (componentType: string, componentId: string, artifactId: string): Observable<IFileDownload> => {
372 return this.http.get<IFileDownload>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId);
375 // ------------------------------------------------ Properties API --------------------------------------------------//
376 addProperty = (componentType: string, componentId: string, property: PropertyModel):Observable<PropertyModel> => {
377 return this.http.post<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', property.convertToServerObject())
379 return new PropertyModel(response);
383 updateProperty = (componentType: string, componentId: string, property: PropertyModel): Observable<PropertyModel> => {
384 var propertiesList:PropertyBEModel[] = [property];
385 return this.http.put<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', propertiesList)
387 return new PropertyModel(response[Object.keys(response)[0]]);
391 deleteProperty = (componentType: string, componentId: string, propertyId: string): Observable<PropertyModel> => {
392 return this.http.delete<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties/' + propertyId);
395 // ------------------------------------------------ Attributes API --------------------------------------------------//
396 addAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
397 return this.http.post<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes', attribute.convertToServerObject())
399 return new AttributeModel(response);
403 updateAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
404 const payload = attribute.convertToServerObject();
406 return this.http.put<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, payload)
408 return new AttributeModel(response);
413 addAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
414 return this.addAttribute(componentType, componentId, attribute).toPromise();
417 updateAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
418 return this.updateAttribute(componentType, componentId, attribute).toPromise();
421 deleteAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<any> => {
422 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, {}).toPromise();
425 getArtifactsByType(componentType: string, componentId: string, artifactsType: ArtifactGroupType) {
426 return this.getComponentDataByFieldsName(componentType, componentId, [this.convertArtifactTypeToUrl(artifactsType)]);
429 getServiceConsumptionData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
430 return this.getComponentDataByFieldsName(componentType, componentId, [
431 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INTERFACES,
432 COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES,
433 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INPUTS,
434 COMPONENT_FIELDS.COMPONENT_INPUTS,
435 COMPONENT_FIELDS.COMPONENT_INSTANCES,
436 COMPONENT_FIELDS.COMPONENT_CAPABILITIES
440 getServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, interfaceId: string, operation: OperationModel): Observable<ConsumptionInput[]> {
441 return this.http.get<ConsumptionInput[]>
442 (this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId + '/interfaces/' + interfaceId + '/operations/' + operation.uniqueId + '/inputs');
445 createOrUpdateServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, consumptionInputsList: Array<{[id: string]: ConsumptionInput[]}>): Observable<any> {
446 return this.http.post(this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId, consumptionInputsList);
449 getServiceFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
450 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.NODE_FILTER]);
453 getSubstitutionFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
454 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.SUBSTITUTION_FILTER]);
457 getComponentInstanceProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
458 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]);
461 getComponentInstanceCapabilityProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
462 return this.getComponentDataByFieldsName(componentType, componentId,
463 [COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
466 createServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: ConstraintObject, componentType: string, constraintType: string): Observable<any> {
467 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
470 createServiceFilterCapabilitiesConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: CapabilitiesConstraintObject, componentType: string, constraintType: string): Observable<any> {
471 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
474 updateServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraints: ConstraintObject, componentType: string, constraintType: string, constraintIndex: number):Observable<any>{
475 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter', constraints)
478 updateServiceFilterCapabilitiesConstraint(componentMetaDataId: string, componentInstanceId: string, constraints: CapabilitiesConstraintObject, componentType: string, constraintType: string, constraintIndex: number):Observable<any>{
479 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter', constraints)
482 deleteServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
483 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter')
486 getComponentPropertiesAndInputsForSubstitutionFilter(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
487 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INPUTS]);
490 createSubstitutionFilterConstraints(componentMetaDataId: string, constraint: ConstraintObject, componentType: string, constraintType: string): Observable<any> {
491 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
494 updateSubstitutionFilterConstraints(componentMetaDataId: string, constraint: ConstraintObject[], componentType: string, constraintType: string): Observable<any>{
495 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
498 deleteSubstitutionFilterConstraints(componentMetaDataId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
499 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType + "/" + constraintIndex)
502 deletePolicy(component: Component, policy: PolicyInstance): Observable<PolicyInstance> {
503 return this.http.put<PolicyInstance>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policy.uniqueId + '/undeclare', policy)
506 createListInput(component: Component, input: any, isSelf: boolean): Observable<any> {
509 // change componentInstanceProperties -> serviceProperties
511 componentInstInputsMap: {
512 serviceProperties: input.componentInstInputsMap.componentInstanceProperties
514 listInput: input.listInput
519 return this.http.post<any>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/listInput', inputs);
522 createPolicy(component: Component, policiesToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
525 // tslint:disable-next-line:object-literal-key-quotes
526 {'componentPropertiesToPolicies': {
527 ...policiesToCreate.componentInstanceProperties
530 // tslint:disable-next-line:object-literal-key-quotes
531 {'componentInstancePropertiesToPolicies': {
532 ...policiesToCreate.componentInstanceProperties
535 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/policies', policiesList);
538 protected getComponentDataByFieldsName(componentType: string, componentId: string, fields: string[]): Observable<ComponentGenericResponse> {
539 let params: HttpParams = new HttpParams();
540 _.forEach(fields, (field: string): void => {
541 params = params.append(API_QUERY_PARAMS.INCLUDE, field);
543 // tslint:disable-next-line:object-literal-shorthand
544 return this.http.get<ComponentGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {params: params})
546 return componentType === ComponentType.SERVICE ? new ServiceGenericResponse().deserialize(res) :
547 new ComponentGenericResponse().deserialize(res);
551 private getServerTypeUrl = (componentType: string): string => {
552 switch (componentType) {
553 case ComponentType.SERVICE:
554 case ComponentType.SERVICE_PROXY:
555 case ComponentType.SERVICE_SUBSTITUTION:
556 return ServerTypeUrl.SERVICES;
558 return ServerTypeUrl.RESOURCES;
562 private convertArtifactTypeToUrl = (artifactType: ArtifactGroupType): string => {
563 switch (artifactType) {
564 case ArtifactGroupType.TOSCA:
565 return COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS;
566 case ArtifactGroupType.INFORMATION:
567 return COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS;
568 case ArtifactGroupType.DEPLOYMENT:
569 return COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS;
570 case ArtifactGroupType.SERVICE_API:
571 return COMPONENT_FIELDS.SERVICE_API_ARTIFACT;
575 // createCapability(component: Component, capabilityData: Capability): Observable<Capability[]> {
576 createCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
579 [capabilityData.type]: [capabilityData]
582 return this.http.post<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
585 updateCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
588 [capabilityData.type]: [capabilityData]
591 return this.http.put<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
594 deleteCapability(component: Component, capId: string): Observable<Capability> {
595 return this.http.delete<Capability>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/capabilities/' + capId);
598 createRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
601 [requirementData.capability]: [requirementData]
604 return this.http.post(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
607 updateRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
610 [requirementData.capability]: [requirementData]
613 return this.http.put(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
616 deleteRequirement(component: Component, reqId: string): Observable<Requirement> {
617 return this.http.delete<Requirement>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/requirements/' + reqId);
620 getDirectiveList(): Observable<string[]> {
621 return this.http.get<ListDirectiveResponse>(this.baseUrl + "directives")
622 .pipe(map(response => response.directives));
625 updateComponentInstanceInterfaceOperation(componentMetaDataId: string,
626 componentMetaDataType: string,
627 componentInstanceId: string,
628 operation: InterfaceOperationModel): Observable<ComponentInstance> {
629 const operationList = {
631 [operation.interfaceType]: {
632 type: operation.interfaceType,
634 [operation.name]: new BEInterfaceOperationModel(operation)
639 return this.http.put<ComponentInstance>(this.baseUrl + this
640 .getServerTypeUrl(componentMetaDataType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/interfaceOperation', operationList);