2 * Created by ob0695 on 6/26/2018.
5 * ============LICENSE_START=======================================================
7 * ================================================================================
8 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
9 * Modification Copyright (C) 2022 Nordix Foundation.
10 * ================================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 * ============LICENSE_END=========================================================
25 import * as _ from "lodash";
26 import {Inject, Injectable} from '@angular/core';
27 import {Observable} from 'rxjs/Observable';
28 import 'rxjs/add/operator/map';
29 import 'rxjs/add/operator/toPromise';
35 FilterPropertiesAssignmentData,
38 InstancePropertiesAPIMap,
44 import {API_QUERY_PARAMS, ArtifactGroupType, COMPONENT_FIELDS} from "app/utils";
45 import {ComponentGenericResponse} from "../responses/component-generic-response";
46 import {InstanceBePropertiesMap} from "../../../models/properties-inputs/property-fe-map";
47 import {ComponentType, ServerTypeUrl, SERVICE_FIELDS} from "../../../utils/constants";
48 import {ISdcConfig, SdcConfigToken} from "../../config/sdc-config.config";
49 import {IDependenciesServerResponse} from "../responses/dependencies-server-response";
50 import {AutomatedUpgradeGenericResponse} from "../responses/automated-upgrade-response";
51 import {IAutomatedUpgradeRequestObj} from "../../pages/automated-upgrade/automated-upgrade.service";
52 import {ComponentInstance} from "../../../models/componentsInstances/componentInstance";
53 import {CommonUtils} from "../../../utils/common-utils";
54 import {RelationshipModel} from "../../../models/graph/relationship";
55 import {ServiceGenericResponse} from "../responses/service-generic-response";
56 import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http";
57 import {HttpHelperService} from "../http-hepler.service";
58 import {ConsumptionInput} from "../../components/logic/service-consumption/service-consumption.component";
59 import {PolicyInstance} from "../../../models/graph/zones/policy-instance";
60 import {PropertyBEModel} from "../../../models/properties-inputs/property-be-model";
61 import {map} from "rxjs/operators";
62 import {BEInterfaceOperationModel, InterfaceOperationModel} from "../../../models/interfaceOperation";
63 import {AttributeBEModel} from "../../../models/attributes-outputs/attribute-be-model";
64 import {InstanceAttributesAPIMap} from "../../../models/attributes-outputs/attribute-fe-map";
65 import {FilterConstraint} from "../../../models/filter-constraint";
66 import {CustomToscaFunction, DefaultCustomFunctions} from "../../../models/default-custom-functions";
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 putServiceToscaTemplate(componentId: string, componentType: string, file) {
81 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/toscaTemplate', file)
84 putServiceToscaModel(componentId: string, componentType: string, file) {
85 let uploadData:FormData = new FormData();
86 uploadData.append('upload', file);
87 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/toscaModel', uploadData);
90 getFullComponent(componentType: string, uniqueId: string): Observable<Component> {
91 return this.http.get<Component>(this.baseUrl + this.getServerTypeUrl(componentType) + uniqueId);
94 getComponentMetadata(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
95 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_METADATA]);
98 getComponentInstanceAttributesAndProperties(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
99 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
102 getComponentInstanceAttributesAndPropertiesAndInputs(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
103 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_INPUTS]);
106 async getComponentAttributes(componentType: string, componentId: string): Promise<ComponentGenericResponse> {
107 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]).toPromise();
110 getComponentCompositionData(componentUniqueId: string, componentType: string): Observable<ComponentGenericResponse> {
111 const params: string[] = [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES,
112 COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS];
113 if (componentType === ComponentType.SERVICE) {
114 params.push(COMPONENT_FIELDS.FORWARDING_PATHS);
116 return this.getComponentDataByFieldsName(componentType, componentUniqueId, params);
119 getComponentResourcePropertiesData(component: Component): Observable<ComponentGenericResponse> {
120 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId,
121 [COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS]);
124 getComponentInstances(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
125 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES]);
128 getComponentInputs(component: Component): Observable<ComponentGenericResponse> {
129 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
132 getComponentInputsValues(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
133 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
136 getComponentInputsWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
137 return this.getComponentDataByFieldsName(componentType, componentId,
138 [COMPONENT_FIELDS.COMPONENT_INPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
141 getComponentOutputsWithAttributes(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
142 return this.getComponentDataByFieldsName(componentType, componentId,
143 [COMPONENT_FIELDS.COMPONENT_OUTPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_ATTRIBUTES,COMPONENT_FIELDS.COMPONENT_INSTANCES_OUTPUTS]);
146 getComponentDeploymentArtifacts(component: Component): Observable<ComponentGenericResponse> {
147 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS]);
150 getComponentInformationalArtifacts(component: Component): Observable<ComponentGenericResponse> {
151 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS]);
154 getComponentInterfaceOperations(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
155 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INTERFACE_OPERATIONS]);
158 getComponentInformationalArtifactsAndInstances(component: Component): Observable<ComponentGenericResponse> {
159 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
162 getComponentToscaArtifacts(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
163 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS]);
166 getComponentProperties(component: Component): Observable<ComponentGenericResponse> {
167 return this.findAllComponentProperties(component.componentType, component.uniqueId);
170 findAllComponentProperties(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> {
171 return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
174 findAllComponentAttributes(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> {
175 return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]);
178 findAllComponentAttributesAndProperties(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> {
179 return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
182 getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
183 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
186 getRequirementsAndCapabilitiesWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
187 return this.getComponentDataByFieldsName(componentType, componentId,
188 [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
191 getDeploymentGraphData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
192 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_GROUPS]);
195 createInput(component: Component, inputsToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
196 const inputs = isSelf ? { serviceProperties: inputsToCreate.componentInstanceProperties } : inputsToCreate;
197 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/inputs', inputs);
200 createOutput(component: Component, outputsToCreate: InstanceAttributesAPIMap, isSelf: boolean): Observable<any> {
201 const outputs = isSelf ? { serviceProperties: outputsToCreate.componentInstanceAttributes } : outputsToCreate;
202 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/outputs', outputs);
205 restoreComponent(componentType: string, componentId: string) {
206 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/restore', {});
209 archiveComponent(componentType: string, componentId: string) {
210 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/archive', {});
213 deleteInput(component: Component, input: InputBEModel): Observable<InputBEModel> {
214 return this.http.delete<InputBEModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/delete/' + input.uniqueId + '/input')
216 return new InputBEModel(res);
220 updateComponentInputs(component: Component, inputs: InputBEModel[]): Observable<InputBEModel[]> {
221 return this.http.post<InputBEModel[]>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/update/inputs', inputs)
223 return res.map((input) => new InputBEModel(input));
227 filterComponentInstanceProperties(component: Component, filterData: FilterPropertiesAssignmentData): Observable<InstanceBePropertiesMap> {// instance-property-be-map
228 let params: HttpParams = new HttpParams();
229 _.forEach(filterData.selectedTypes, (type: string) => {
230 params = params.append('resourceType', type);
233 // tslint:disable-next-line:object-literal-shorthand
234 return this.http.get<InstanceBePropertiesMap>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {params: params});
237 createServiceProperty(componentId: string, propertyModel: PropertyBEModel): Observable<PropertyBEModel> {
238 const serverObject = {};
239 serverObject[propertyModel.name] = propertyModel;
240 return this.http.post<PropertyBEModel>(this.baseUrl + 'services/' + componentId + '/properties', serverObject)
242 const property: PropertyBEModel = new PropertyBEModel(res);
247 createServiceAttribute(componentId: string, attributeModel: AttributeBEModel): Observable<AttributeBEModel> {
248 const serverObject = {};
249 serverObject[attributeModel.name] = attributeModel;
250 return this.http.post<AttributeBEModel>(this.baseUrl + 'services/' + componentId + '/attributes', serverObject)
252 const attribute: AttributeBEModel = new AttributeBEModel(res);
257 getServiceProperties(componentId: string): Observable<PropertyBEModel[]> {
258 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/properties')
261 return new Array<PropertyBEModel>();
263 return CommonUtils.initBeProperties(res);
267 getServiceAttributes(componentId: string): Observable<AttributeBEModel[]> {
268 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/attributes')
271 return new Array<AttributeBEModel>();
273 return CommonUtils.initAttributes(res);
277 updateServiceProperties(componentId: string, properties: PropertyBEModel[]) {
278 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/properties', properties)
281 return _.map(resJson,
282 (resValue: PropertyBEModel) => new PropertyBEModel(resValue));
286 updateServiceAttributes(componentId: string, attributes: AttributeBEModel[]) {
287 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/attributes', attributes)
290 return _.map(resJson,
291 (resValue: AttributeBEModel) => new AttributeBEModel(resValue));
295 deleteServiceProperty(componentId: string, property: PropertyBEModel): Observable<string> {
296 return this.http.delete(this.baseUrl + 'services/' + componentId + '/properties/' + property.uniqueId )
297 .map((res: Response) => {
298 return property.uniqueId;
302 createServiceInput(componentId: string, inputModel: InputBEModel): Observable<InputBEModel> {
303 const serverObject = {};
304 serverObject[inputModel.name] = inputModel;
305 return this.http.post<InputBEModel>(this.baseUrl + 'services/' + componentId + '/create/input', serverObject)
307 const input: InputBEModel = new InputBEModel(res);
312 deleteServiceAttribute(componentId: string, attribute: AttributeBEModel): Observable<string> {
313 return this.http.delete(this.baseUrl + 'services/' + componentId + '/attributes/' + attribute.uniqueId )
314 .map((res: Response) => {
315 return attribute.uniqueId;
319 getDependencies(componentType: string, componentId: string): Observable<IDependenciesServerResponse[]> {
320 return this.http.get<IDependenciesServerResponse[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/dependencies');
323 automatedUpgrade(componentType: string, componentId: string, componentsIdsToUpgrade: IAutomatedUpgradeRequestObj[]): Observable<AutomatedUpgradeGenericResponse> {
324 return this.http.post<AutomatedUpgradeGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/automatedupgrade', componentsIdsToUpgrade);
327 updateComponentInstance(componentMetaDataId: string, componentType: string, componentInstance:ComponentInstance): Observable<ComponentInstance> {
328 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstance/' + componentInstance.uniqueId, componentInstance);
331 updateMultipleComponentInstances(componentId: string, componentType: string, instances: ComponentInstance[]): Observable<ComponentInstance[]> {
332 return this.http.post<ComponentInstance[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/multipleComponentInstance', instances)
334 return CommonUtils.initComponentInstances(res);
338 createRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
339 return this.http.post<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/associate', link)
341 return new RelationshipModel(res);
345 deleteRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
346 return this.http.put<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/dissociate', link)
348 return new RelationshipModel(res);
352 createComponentInstance(componentType: string, componentId: string, componentInstance: ComponentInstance): Observable<ComponentInstance> {
353 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance', componentInstance)
355 return new ComponentInstance(res);
359 deleteComponentInstance(componentType: string, componentId: string, componentInstanceId: string): Observable<ComponentInstance> {
360 return this.http.delete<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/' + componentInstanceId)
362 return new ComponentInstance(res);
366 fetchRelation(componentType: string, componentId: string, linkId: string): Observable<RelationshipModel> {
367 return this.http.get<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/relationId/' + linkId)
369 return new RelationshipModel(res);
373 addOrUpdateArtifact = (componentType: string, componentId: string, artifact: ArtifactModel): Observable<ArtifactModel> => {
374 let headerObj: HttpHeaders = new HttpHeaders();
375 if (artifact.payloadData) {
376 headerObj = headerObj.append('Content-MD5', HttpHelperService.getHeaderMd5(artifact));
379 let artifactID: string = '';
380 if (artifact.uniqueId) {
381 artifactID = '/' + artifact.uniqueId;
383 return this.http.post<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts' + artifactID, JSON.stringify(artifact), {headers: headerObj}).map(
384 (res) => new ArtifactModel(res)
388 deleteArtifact = (componentId: string, componentType: string, artifactId: string, artifactLabel: string): Observable<ArtifactModel> => {
389 return this.http.delete<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId + '?operation=' + artifactLabel)
390 .map((res) => new ArtifactModel(res));
393 downloadArtifact = (componentType: string, componentId: string, artifactId: string): Observable<IFileDownload> => {
394 return this.http.get<IFileDownload>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId);
397 // ------------------------------------------------ Properties API --------------------------------------------------//
398 addProperty = (componentType: string, componentId: string, property: PropertyModel):Observable<PropertyModel> => {
399 return this.http.post<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', property.convertToServerObject())
401 return new PropertyModel(response);
405 updateProperty = (componentType: string, componentId: string, property: PropertyModel): Observable<PropertyModel> => {
406 const propertiesList: PropertyBEModel[] = [property];
407 return this.http.put<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', propertiesList)
409 return new PropertyModel(response[Object.keys(response)[0]]);
413 deleteProperty = (componentType: string, componentId: string, propertyId: string): Observable<PropertyModel> => {
414 return this.http.delete<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties/' + propertyId);
417 // ------------------------------------------------ Attributes API --------------------------------------------------//
418 addAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
419 return this.http.post<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes', attribute.convertToServerObject())
421 return new AttributeModel(response);
425 updateAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
426 const payload = attribute.convertToServerObject();
428 return this.http.put<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, payload)
430 return new AttributeModel(response);
435 addAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
436 return this.addAttribute(componentType, componentId, attribute).toPromise();
439 updateAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
440 return this.updateAttribute(componentType, componentId, attribute).toPromise();
443 deleteAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<any> => {
444 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, {}).toPromise();
447 getArtifactsByType(componentType: string, componentId: string, artifactsType: ArtifactGroupType) {
448 return this.getComponentDataByFieldsName(componentType, componentId, [this.convertArtifactTypeToUrl(artifactsType)]);
451 getServiceConsumptionData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
452 return this.getComponentDataByFieldsName(componentType, componentId, [
453 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INTERFACES,
454 COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES,
455 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INPUTS,
456 COMPONENT_FIELDS.COMPONENT_INPUTS,
457 COMPONENT_FIELDS.COMPONENT_INSTANCES,
458 COMPONENT_FIELDS.COMPONENT_CAPABILITIES
462 getServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, interfaceId: string, operation: OperationModel): Observable<ConsumptionInput[]> {
463 return this.http.get<ConsumptionInput[]>
464 (this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId + '/interfaces/' + interfaceId + '/operations/' + operation.uniqueId + '/inputs');
467 createOrUpdateServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, consumptionInputsList: Array<{[id: string]: ConsumptionInput[]}>): Observable<any> {
468 return this.http.post(this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId, consumptionInputsList);
471 getServiceFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
472 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.NODE_FILTER]);
475 getSubstitutionFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
476 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.SUBSTITUTION_FILTER]);
479 getComponentInstanceProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
480 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]);
483 getComponentInstancesAndInputsAndProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
484 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES ,COMPONENT_FIELDS.COMPONENT_INSTANCES_INPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]);
487 findAllComponentInstanceAttributes(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
488 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
491 getComponentInstanceCapabilityProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
492 return this.getComponentDataByFieldsName(componentType, componentId,
493 [COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
496 createServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: FilterConstraint, componentType: string, constraintType: string): Observable<any> {
497 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
500 createServiceFilterCapabilitiesConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: FilterConstraint, componentType: string, constraintType: string): Observable<any> {
501 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
504 updateServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: FilterConstraint, componentType: string, constraintType: string, constraintIndex: number):Observable<any>{
505 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter', constraint)
508 updateServiceFilterCapabilitiesConstraint(componentMetaDataId: string, componentInstanceId: string, constraints: FilterConstraint, componentType: string, constraintType: string, constraintIndex: number):Observable<any>{
509 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter', constraints)
512 deleteServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
513 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter')
516 getComponentPropertiesAndInputsForSubstitutionFilter(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
517 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INPUTS]);
520 createSubstitutionFilterConstraints(componentMetaDataId: string, constraint: FilterConstraint, componentType: string, constraintType: string): Observable<any> {
521 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
524 updateSubstitutionFilterConstraint(componentId: string, constraint: FilterConstraint, componentType: string, constraintType: string,
525 index: number): Observable<any> {
526 const url = `${this.baseUrl}${this.getServerTypeUrl(componentType)}${componentId}/substitutionFilter/${constraintType}/${index}`;
527 return this.http.put<any>(url, constraint);
530 deleteSubstitutionFilterConstraints(componentMetaDataId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
531 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType + "/" + constraintIndex)
534 deletePolicy(component: Component, policy: PolicyInstance): Observable<PolicyInstance> {
535 return this.http.put<PolicyInstance>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policy.uniqueId + '/undeclare', policy)
538 createListInput(component: Component, input: any, isSelf: boolean): Observable<any> {
541 // change componentInstanceProperties -> serviceProperties
543 componentInstInputsMap: {
544 serviceProperties: input.componentInstInputsMap.componentInstanceProperties
546 listInput: input.listInput
551 return this.http.post<any>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/listInput', inputs);
554 createPolicy(component: Component, policiesToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
557 // tslint:disable-next-line:object-literal-key-quotes
558 {'componentPropertiesToPolicies': {
559 ...policiesToCreate.componentInstanceProperties
562 // tslint:disable-next-line:object-literal-key-quotes
563 {'componentInstancePropertiesToPolicies': {
564 ...policiesToCreate.componentInstanceProperties
567 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/policies', policiesList);
570 protected getComponentDataByFieldsName(componentType: string, componentId: string, fields: string[]): Observable<ComponentGenericResponse> {
571 let params: HttpParams = new HttpParams();
572 _.forEach(fields, (field: string): void => {
573 params = params.append(API_QUERY_PARAMS.INCLUDE, field);
575 // tslint:disable-next-line:object-literal-shorthand
576 return this.http.get<ComponentGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {params: params})
578 return componentType === ComponentType.SERVICE ? new ServiceGenericResponse().deserialize(res) :
579 new ComponentGenericResponse().deserialize(res);
583 private getServerTypeUrl = (componentType: string): string => {
584 switch (componentType) {
585 case ComponentType.SERVICE:
586 case ComponentType.SERVICE_PROXY:
587 case ComponentType.SERVICE_SUBSTITUTION:
588 return ServerTypeUrl.SERVICES;
590 return ServerTypeUrl.RESOURCES;
594 private convertArtifactTypeToUrl = (artifactType: ArtifactGroupType): string => {
595 switch (artifactType) {
596 case ArtifactGroupType.TOSCA:
597 return COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS;
598 case ArtifactGroupType.INFORMATION:
599 return COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS;
600 case ArtifactGroupType.DEPLOYMENT:
601 return COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS;
602 case ArtifactGroupType.SERVICE_API:
603 return COMPONENT_FIELDS.SERVICE_API_ARTIFACT;
607 // createCapability(component: Component, capabilityData: Capability): Observable<Capability[]> {
608 createCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
611 [capabilityData.type]: [capabilityData]
614 return this.http.post<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
617 updateCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
620 [capabilityData.type]: [capabilityData]
623 return this.http.put<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
626 deleteCapability(component: Component, capId: string): Observable<Capability> {
627 return this.http.delete<Capability>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/capabilities/' + capId);
630 createRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
633 [requirementData.capability]: [requirementData]
636 return this.http.post(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
639 updateRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
642 [requirementData.capability]: [requirementData]
645 return this.http.put(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
648 deleteRequirement(component: Component, reqId: string): Observable<Requirement> {
649 return this.http.delete<Requirement>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/requirements/' + reqId);
652 getDirectiveList(): Observable<string[]> {
653 return this.http.get<ListDirectiveResponse>(this.baseUrl + "directives")
654 .pipe(map(response => response.directives));
657 updateComponentInstanceInterfaceOperation(componentMetaDataId: string,
658 componentMetaDataType: string,
659 componentInstanceId: string,
660 operation: InterfaceOperationModel): Observable<ComponentInstance> {
661 const operationList = {
663 [operation.interfaceType]: {
664 type: operation.interfaceType,
666 [operation.name]: new BEInterfaceOperationModel(operation)
671 return this.http.put<ComponentInstance>(this.baseUrl + this
672 .getServerTypeUrl(componentMetaDataType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/interfaceOperation', operationList);
675 getDefaultCustomFunction(type='ALL'): Observable<CustomToscaFunction[]> {
676 return this.http.get<DefaultCustomFunctions>(this.baseUrl + "customToscaFunctions/" + type)
677 .pipe(map(response => response && response.defaultCustomToscaFunction ? response.defaultCustomToscaFunction : []));
680 createComponentInstanceInterfaceOperation(componentMetaDataId: string, componentInstanceId: string,
681 operation: InterfaceOperationModel): Observable<InterfaceOperationModel> {
682 const operationList = {
684 [operation.interfaceType]: {
685 type: operation.interfaceType,
687 [operation.name]: new BEInterfaceOperationModel(operation)
692 return this.http.post<any>(this.baseUrl + 'services/' + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/interfaceOperation', operationList)
694 const interf: InterfaceModel = _.find(res.interfaces, interf => interf.type === operation.interfaceType);
695 const newOperation: OperationModel = _.find(interf.operations, op => op.name === operation.name);
697 return new InterfaceOperationModel({
699 interfaceType: interf.type,
700 interfaceId: interf.uniqueId,