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 getComponentInterfaceOperations(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
149 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INTERFACE_OPERATIONS]);
152 getComponentInformationalArtifactsAndInstances(component: Component): Observable<ComponentGenericResponse> {
153 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
156 getComponentToscaArtifacts(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
157 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS]);
160 getComponentProperties(component: Component): Observable<ComponentGenericResponse> {
161 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
164 getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
165 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
168 getRequirementsAndCapabilitiesWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
169 return this.getComponentDataByFieldsName(componentType, componentId,
170 [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
173 getDeploymentGraphData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
174 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_GROUPS]);
177 createInput(component: Component, inputsToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
178 const inputs = isSelf ? { serviceProperties: inputsToCreate.componentInstanceProperties } : inputsToCreate;
179 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/inputs', inputs);
182 createOutput(component: Component, outputsToCreate: InstanceAttributesAPIMap, isSelf: boolean): Observable<any> {
183 const outputs = isSelf ? { serviceProperties: outputsToCreate.componentInstanceAttributes } : outputsToCreate;
184 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/outputs', outputs);
187 restoreComponent(componentType: string, componentId: string) {
188 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/restore', {});
191 archiveComponent(componentType: string, componentId: string) {
192 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/archive', {});
195 deleteInput(component: Component, input: InputBEModel): Observable<InputBEModel> {
196 return this.http.delete<InputBEModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/delete/' + input.uniqueId + '/input')
198 return new InputBEModel(res);
202 updateComponentInputs(component: Component, inputs: InputBEModel[]): Observable<InputBEModel[]> {
203 return this.http.post<InputBEModel[]>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/update/inputs', inputs)
205 return res.map((input) => new InputBEModel(input));
209 filterComponentInstanceProperties(component: Component, filterData: FilterPropertiesAssignmentData): Observable<InstanceBePropertiesMap> {// instance-property-be-map
210 let params: HttpParams = new HttpParams();
211 _.forEach(filterData.selectedTypes, (type: string) => {
212 params = params.append('resourceType', type);
215 // tslint:disable-next-line:object-literal-shorthand
216 return this.http.get<InstanceBePropertiesMap>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {params: params});
219 createServiceProperty(componentId: string, propertyModel: PropertyBEModel): Observable<PropertyBEModel> {
220 const serverObject = {};
221 serverObject[propertyModel.name] = propertyModel;
222 return this.http.post<PropertyBEModel>(this.baseUrl + 'services/' + componentId + '/properties', serverObject)
224 const property: PropertyBEModel = new PropertyBEModel(res);
229 createServiceAttribute(componentId: string, attributeModel: AttributeBEModel): Observable<AttributeBEModel> {
230 const serverObject = {};
231 serverObject[attributeModel.name] = attributeModel;
232 return this.http.post<AttributeBEModel>(this.baseUrl + 'services/' + componentId + '/attributes', serverObject)
234 const attribute: AttributeBEModel = new AttributeBEModel(res);
239 getServiceProperties(componentId: string): Observable<PropertyBEModel[]> {
240 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/properties')
243 return new Array<PropertyBEModel>();
245 return CommonUtils.initBeProperties(res);
249 getServiceAttributes(componentId: string): Observable<AttributeBEModel[]> {
250 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/attributes')
253 return new Array<AttributeBEModel>();
255 return CommonUtils.initAttributes(res);
259 updateServiceProperties(componentId: string, properties: PropertyBEModel[]) {
260 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/properties', properties)
263 return _.map(resJson,
264 (resValue: PropertyBEModel) => new PropertyBEModel(resValue));
268 updateServiceAttributes(componentId: string, attributes: AttributeBEModel[]) {
269 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/attributes', attributes)
272 return _.map(resJson,
273 (resValue: AttributeBEModel) => new AttributeBEModel(resValue));
277 deleteServiceProperty(componentId: string, property: PropertyBEModel): Observable<string> {
278 return this.http.delete(this.baseUrl + 'services/' + componentId + '/properties/' + property.uniqueId )
279 .map((res: Response) => {
280 return property.uniqueId;
284 createServiceInput(componentId: string, inputModel: InputBEModel): Observable<InputBEModel> {
285 const serverObject = {};
286 serverObject[inputModel.name] = inputModel;
287 return this.http.post<InputBEModel>(this.baseUrl + 'services/' + componentId + '/create/input', serverObject)
289 const input: InputBEModel = new InputBEModel(res);
294 deleteServiceAttribute(componentId: string, attribute: AttributeBEModel): Observable<string> {
295 return this.http.delete(this.baseUrl + 'services/' + componentId + '/attributes/' + attribute.uniqueId )
296 .map((res: Response) => {
297 return attribute.uniqueId;
301 getDependencies(componentType: string, componentId: string): Observable<IDependenciesServerResponse[]> {
302 return this.http.get<IDependenciesServerResponse[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/dependencies');
305 automatedUpgrade(componentType: string, componentId: string, componentsIdsToUpgrade: IAutomatedUpgradeRequestObj[]): Observable<AutomatedUpgradeGenericResponse> {
306 return this.http.post<AutomatedUpgradeGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/automatedupgrade', componentsIdsToUpgrade);
309 updateComponentInstance(componentMetaDataId: string, componentType: string, componentInstance:ComponentInstance): Observable<ComponentInstance> {
310 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstance/' + componentInstance.uniqueId, componentInstance);
313 updateMultipleComponentInstances(componentId: string, componentType: string, instances: ComponentInstance[]): Observable<ComponentInstance[]> {
314 return this.http.post<ComponentInstance[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/multipleComponentInstance', instances)
316 return CommonUtils.initComponentInstances(res);
320 createRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
321 return this.http.post<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/associate', link)
323 return new RelationshipModel(res);
327 deleteRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
328 return this.http.put<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/dissociate', link)
330 return new RelationshipModel(res);
334 createComponentInstance(componentType: string, componentId: string, componentInstance: ComponentInstance): Observable<ComponentInstance> {
335 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance', componentInstance)
337 return new ComponentInstance(res);
341 deleteComponentInstance(componentType: string, componentId: string, componentInstanceId: string): Observable<ComponentInstance> {
342 return this.http.delete<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/' + componentInstanceId)
344 return new ComponentInstance(res);
348 fetchRelation(componentType: string, componentId: string, linkId: string): Observable<RelationshipModel> {
349 return this.http.get<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/relationId/' + linkId)
351 return new RelationshipModel(res);
355 addOrUpdateArtifact = (componentType: string, componentId: string, artifact: ArtifactModel): Observable<ArtifactModel> => {
356 let headerObj: HttpHeaders = new HttpHeaders();
357 if (artifact.payloadData) {
358 headerObj = headerObj.append('Content-MD5', HttpHelperService.getHeaderMd5(artifact));
361 let artifactID: string = '';
362 if (artifact.uniqueId) {
363 artifactID = '/' + artifact.uniqueId;
365 return this.http.post<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts' + artifactID, JSON.stringify(artifact), {headers: headerObj}).map(
366 (res) => new ArtifactModel(res)
370 deleteArtifact = (componentId: string, componentType: string, artifactId: string, artifactLabel: string): Observable<ArtifactModel> => {
371 return this.http.delete<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId + '?operation=' + artifactLabel)
372 .map((res) => new ArtifactModel(res));
375 downloadArtifact = (componentType: string, componentId: string, artifactId: string): Observable<IFileDownload> => {
376 return this.http.get<IFileDownload>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId);
379 // ------------------------------------------------ Properties API --------------------------------------------------//
380 addProperty = (componentType: string, componentId: string, property: PropertyModel):Observable<PropertyModel> => {
381 return this.http.post<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', property.convertToServerObject())
383 return new PropertyModel(response);
387 updateProperty = (componentType: string, componentId: string, property: PropertyModel): Observable<PropertyModel> => {
388 var propertiesList:PropertyBEModel[] = [property];
389 return this.http.put<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', propertiesList)
391 return new PropertyModel(response[Object.keys(response)[0]]);
395 deleteProperty = (componentType: string, componentId: string, propertyId: string): Observable<PropertyModel> => {
396 return this.http.delete<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties/' + propertyId);
399 // ------------------------------------------------ Attributes API --------------------------------------------------//
400 addAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
401 return this.http.post<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes', attribute.convertToServerObject())
403 return new AttributeModel(response);
407 updateAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
408 const payload = attribute.convertToServerObject();
410 return this.http.put<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, payload)
412 return new AttributeModel(response);
417 addAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
418 return this.addAttribute(componentType, componentId, attribute).toPromise();
421 updateAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
422 return this.updateAttribute(componentType, componentId, attribute).toPromise();
425 deleteAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<any> => {
426 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, {}).toPromise();
429 getArtifactsByType(componentType: string, componentId: string, artifactsType: ArtifactGroupType) {
430 return this.getComponentDataByFieldsName(componentType, componentId, [this.convertArtifactTypeToUrl(artifactsType)]);
433 getServiceConsumptionData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
434 return this.getComponentDataByFieldsName(componentType, componentId, [
435 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INTERFACES,
436 COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES,
437 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INPUTS,
438 COMPONENT_FIELDS.COMPONENT_INPUTS,
439 COMPONENT_FIELDS.COMPONENT_INSTANCES,
440 COMPONENT_FIELDS.COMPONENT_CAPABILITIES
444 getServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, interfaceId: string, operation: OperationModel): Observable<ConsumptionInput[]> {
445 return this.http.get<ConsumptionInput[]>
446 (this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId + '/interfaces/' + interfaceId + '/operations/' + operation.uniqueId + '/inputs');
449 createOrUpdateServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, consumptionInputsList: Array<{[id: string]: ConsumptionInput[]}>): Observable<any> {
450 return this.http.post(this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId, consumptionInputsList);
453 getServiceFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
454 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.NODE_FILTER]);
457 getSubstitutionFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
458 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.SUBSTITUTION_FILTER]);
461 getComponentInstanceProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
462 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]);
465 getComponentInstanceCapabilityProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
466 return this.getComponentDataByFieldsName(componentType, componentId,
467 [COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
470 createServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: ConstraintObject, componentType: string, constraintType: string): Observable<any> {
471 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
474 createServiceFilterCapabilitiesConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: CapabilitiesConstraintObject, componentType: string, constraintType: string): Observable<any> {
475 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
478 updateServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraints: ConstraintObject, 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 updateServiceFilterCapabilitiesConstraint(componentMetaDataId: string, componentInstanceId: string, constraints: CapabilitiesConstraintObject, componentType: string, constraintType: string, constraintIndex: number):Observable<any>{
483 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter', constraints)
486 deleteServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
487 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter')
490 getComponentPropertiesAndInputsForSubstitutionFilter(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
491 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INPUTS]);
494 createSubstitutionFilterConstraints(componentMetaDataId: string, constraint: ConstraintObject, componentType: string, constraintType: string): Observable<any> {
495 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
498 updateSubstitutionFilterConstraints(componentMetaDataId: string, constraint: ConstraintObject[], componentType: string, constraintType: string): Observable<any>{
499 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
502 deleteSubstitutionFilterConstraints(componentMetaDataId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
503 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType + "/" + constraintIndex)
506 deletePolicy(component: Component, policy: PolicyInstance): Observable<PolicyInstance> {
507 return this.http.put<PolicyInstance>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policy.uniqueId + '/undeclare', policy)
510 createListInput(component: Component, input: any, isSelf: boolean): Observable<any> {
513 // change componentInstanceProperties -> serviceProperties
515 componentInstInputsMap: {
516 serviceProperties: input.componentInstInputsMap.componentInstanceProperties
518 listInput: input.listInput
523 return this.http.post<any>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/listInput', inputs);
526 createPolicy(component: Component, policiesToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
529 // tslint:disable-next-line:object-literal-key-quotes
530 {'componentPropertiesToPolicies': {
531 ...policiesToCreate.componentInstanceProperties
534 // tslint:disable-next-line:object-literal-key-quotes
535 {'componentInstancePropertiesToPolicies': {
536 ...policiesToCreate.componentInstanceProperties
539 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/policies', policiesList);
542 protected getComponentDataByFieldsName(componentType: string, componentId: string, fields: string[]): Observable<ComponentGenericResponse> {
543 let params: HttpParams = new HttpParams();
544 _.forEach(fields, (field: string): void => {
545 params = params.append(API_QUERY_PARAMS.INCLUDE, field);
547 // tslint:disable-next-line:object-literal-shorthand
548 return this.http.get<ComponentGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {params: params})
550 return componentType === ComponentType.SERVICE ? new ServiceGenericResponse().deserialize(res) :
551 new ComponentGenericResponse().deserialize(res);
555 private getServerTypeUrl = (componentType: string): string => {
556 switch (componentType) {
557 case ComponentType.SERVICE:
558 case ComponentType.SERVICE_PROXY:
559 case ComponentType.SERVICE_SUBSTITUTION:
560 return ServerTypeUrl.SERVICES;
562 return ServerTypeUrl.RESOURCES;
566 private convertArtifactTypeToUrl = (artifactType: ArtifactGroupType): string => {
567 switch (artifactType) {
568 case ArtifactGroupType.TOSCA:
569 return COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS;
570 case ArtifactGroupType.INFORMATION:
571 return COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS;
572 case ArtifactGroupType.DEPLOYMENT:
573 return COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS;
574 case ArtifactGroupType.SERVICE_API:
575 return COMPONENT_FIELDS.SERVICE_API_ARTIFACT;
579 // createCapability(component: Component, capabilityData: Capability): Observable<Capability[]> {
580 createCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
583 [capabilityData.type]: [capabilityData]
586 return this.http.post<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
589 updateCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
592 [capabilityData.type]: [capabilityData]
595 return this.http.put<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
598 deleteCapability(component: Component, capId: string): Observable<Capability> {
599 return this.http.delete<Capability>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/capabilities/' + capId);
602 createRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
605 [requirementData.capability]: [requirementData]
608 return this.http.post(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
611 updateRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
614 [requirementData.capability]: [requirementData]
617 return this.http.put(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
620 deleteRequirement(component: Component, reqId: string): Observable<Requirement> {
621 return this.http.delete<Requirement>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/requirements/' + reqId);
624 getDirectiveList(): Observable<string[]> {
625 return this.http.get<ListDirectiveResponse>(this.baseUrl + "directives")
626 .pipe(map(response => response.directives));
629 updateComponentInstanceInterfaceOperation(componentMetaDataId: string,
630 componentMetaDataType: string,
631 componentInstanceId: string,
632 operation: InterfaceOperationModel): Observable<ComponentInstance> {
633 const operationList = {
635 [operation.interfaceType]: {
636 type: operation.interfaceType,
638 [operation.name]: new BEInterfaceOperationModel(operation)
643 return this.http.put<ComponentInstance>(this.baseUrl + this
644 .getServerTypeUrl(componentMetaDataType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/interfaceOperation', operationList);