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,
43 import {API_QUERY_PARAMS, ArtifactGroupType, COMPONENT_FIELDS} from "app/utils";
44 import {ComponentGenericResponse} from "../responses/component-generic-response";
45 import {InstanceBePropertiesMap} from "../../../models/properties-inputs/property-fe-map";
46 import {ComponentType, ServerTypeUrl, SERVICE_FIELDS} from "../../../utils/constants";
47 import {ISdcConfig, SdcConfigToken} from "../../config/sdc-config.config";
48 import {IDependenciesServerResponse} from "../responses/dependencies-server-response";
49 import {AutomatedUpgradeGenericResponse} from "../responses/automated-upgrade-response";
50 import {IAutomatedUpgradeRequestObj} from "../../pages/automated-upgrade/automated-upgrade.service";
51 import {ComponentInstance} from "../../../models/componentsInstances/componentInstance";
52 import {CommonUtils} from "../../../utils/common-utils";
53 import {RelationshipModel} from "../../../models/graph/relationship";
54 import {ServiceGenericResponse} from "../responses/service-generic-response";
55 import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http";
56 import {HttpHelperService} from "../http-hepler.service";
57 import {ConsumptionInput} from "../../components/logic/service-consumption/service-consumption.component";
58 import {PolicyInstance} from "../../../models/graph/zones/policy-instance";
59 import {PropertyBEModel} from "../../../models/properties-inputs/property-be-model";
60 import {map} from "rxjs/operators";
61 import {BEInterfaceOperationModel, InterfaceOperationModel} from "../../../models/interfaceOperation";
62 import {AttributeBEModel} from "../../../models/attributes-outputs/attribute-be-model";
63 import {InstanceAttributesAPIMap} from "../../../models/attributes-outputs/attribute-fe-map";
64 import {FilterConstraint} from "../../../models/filter-constraint";
66 /* we need to use this service from now, we will remove component.service when we finish remove the angular1.
67 The service is duplicated since we can not use downgrades service with NGXS*/
70 export class TopologyTemplateService {
74 constructor(protected http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
75 this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
78 getFullComponent(componentType: string, uniqueId: string): Observable<Component> {
79 return this.http.get<Component>(this.baseUrl + this.getServerTypeUrl(componentType) + uniqueId);
82 getComponentMetadata(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
83 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_METADATA]);
86 getComponentInstanceAttributesAndProperties(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
87 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
90 getComponentInstanceAttributesAndPropertiesAndInputs(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
91 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_INPUTS]);
94 async getComponentAttributes(componentType: string, componentId: string): Promise<ComponentGenericResponse> {
95 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]).toPromise();
98 getComponentCompositionData(componentUniqueId: string, componentType: string): Observable<ComponentGenericResponse> {
99 const params: string[] = [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES,
100 COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS];
101 if (componentType === ComponentType.SERVICE) {
102 params.push(COMPONENT_FIELDS.FORWARDING_PATHS);
104 return this.getComponentDataByFieldsName(componentType, componentUniqueId, params);
107 getComponentResourcePropertiesData(component: Component): Observable<ComponentGenericResponse> {
108 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId,
109 [COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS]);
112 getComponentInstances(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
113 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES]);
116 getComponentInputs(component: Component): Observable<ComponentGenericResponse> {
117 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
120 getComponentInputsValues(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
121 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
124 getComponentInputsWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
125 return this.getComponentDataByFieldsName(componentType, componentId,
126 [COMPONENT_FIELDS.COMPONENT_INPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
129 getComponentOutputsWithAttributes(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
130 return this.getComponentDataByFieldsName(componentType, componentId,
131 [COMPONENT_FIELDS.COMPONENT_OUTPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_ATTRIBUTES,COMPONENT_FIELDS.COMPONENT_INSTANCES_OUTPUTS]);
134 getComponentDeploymentArtifacts(component: Component): Observable<ComponentGenericResponse> {
135 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS]);
138 getComponentInformationalArtifacts(component: Component): Observable<ComponentGenericResponse> {
139 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS]);
142 getComponentInterfaceOperations(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
143 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INTERFACE_OPERATIONS]);
146 getComponentInformationalArtifactsAndInstances(component: Component): Observable<ComponentGenericResponse> {
147 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
150 getComponentToscaArtifacts(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
151 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS]);
154 getComponentProperties(component: Component): Observable<ComponentGenericResponse> {
155 return this.findAllComponentProperties(component.componentType, component.uniqueId);
158 findAllComponentProperties(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> {
159 return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
162 findAllComponentAttributes(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> {
163 return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]);
166 findAllComponentAttributesAndProperties(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> {
167 return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
170 getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
171 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
174 getRequirementsAndCapabilitiesWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
175 return this.getComponentDataByFieldsName(componentType, componentId,
176 [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
179 getDeploymentGraphData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
180 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_GROUPS]);
183 createInput(component: Component, inputsToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
184 const inputs = isSelf ? { serviceProperties: inputsToCreate.componentInstanceProperties } : inputsToCreate;
185 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/inputs', inputs);
188 createOutput(component: Component, outputsToCreate: InstanceAttributesAPIMap, isSelf: boolean): Observable<any> {
189 const outputs = isSelf ? { serviceProperties: outputsToCreate.componentInstanceAttributes } : outputsToCreate;
190 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/outputs', outputs);
193 restoreComponent(componentType: string, componentId: string) {
194 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/restore', {});
197 archiveComponent(componentType: string, componentId: string) {
198 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/archive', {});
201 deleteInput(component: Component, input: InputBEModel): Observable<InputBEModel> {
202 return this.http.delete<InputBEModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/delete/' + input.uniqueId + '/input')
204 return new InputBEModel(res);
208 updateComponentInputs(component: Component, inputs: InputBEModel[]): Observable<InputBEModel[]> {
209 return this.http.post<InputBEModel[]>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/update/inputs', inputs)
211 return res.map((input) => new InputBEModel(input));
215 filterComponentInstanceProperties(component: Component, filterData: FilterPropertiesAssignmentData): Observable<InstanceBePropertiesMap> {// instance-property-be-map
216 let params: HttpParams = new HttpParams();
217 _.forEach(filterData.selectedTypes, (type: string) => {
218 params = params.append('resourceType', type);
221 // tslint:disable-next-line:object-literal-shorthand
222 return this.http.get<InstanceBePropertiesMap>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {params: params});
225 createServiceProperty(componentId: string, propertyModel: PropertyBEModel): Observable<PropertyBEModel> {
226 const serverObject = {};
227 serverObject[propertyModel.name] = propertyModel;
228 return this.http.post<PropertyBEModel>(this.baseUrl + 'services/' + componentId + '/properties', serverObject)
230 const property: PropertyBEModel = new PropertyBEModel(res);
235 createServiceAttribute(componentId: string, attributeModel: AttributeBEModel): Observable<AttributeBEModel> {
236 const serverObject = {};
237 serverObject[attributeModel.name] = attributeModel;
238 return this.http.post<AttributeBEModel>(this.baseUrl + 'services/' + componentId + '/attributes', serverObject)
240 const attribute: AttributeBEModel = new AttributeBEModel(res);
245 getServiceProperties(componentId: string): Observable<PropertyBEModel[]> {
246 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/properties')
249 return new Array<PropertyBEModel>();
251 return CommonUtils.initBeProperties(res);
255 getServiceAttributes(componentId: string): Observable<AttributeBEModel[]> {
256 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/attributes')
259 return new Array<AttributeBEModel>();
261 return CommonUtils.initAttributes(res);
265 updateServiceProperties(componentId: string, properties: PropertyBEModel[]) {
266 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/properties', properties)
269 return _.map(resJson,
270 (resValue: PropertyBEModel) => new PropertyBEModel(resValue));
274 updateServiceAttributes(componentId: string, attributes: AttributeBEModel[]) {
275 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/attributes', attributes)
278 return _.map(resJson,
279 (resValue: AttributeBEModel) => new AttributeBEModel(resValue));
283 deleteServiceProperty(componentId: string, property: PropertyBEModel): Observable<string> {
284 return this.http.delete(this.baseUrl + 'services/' + componentId + '/properties/' + property.uniqueId )
285 .map((res: Response) => {
286 return property.uniqueId;
290 createServiceInput(componentId: string, inputModel: InputBEModel): Observable<InputBEModel> {
291 const serverObject = {};
292 serverObject[inputModel.name] = inputModel;
293 return this.http.post<InputBEModel>(this.baseUrl + 'services/' + componentId + '/create/input', serverObject)
295 const input: InputBEModel = new InputBEModel(res);
300 deleteServiceAttribute(componentId: string, attribute: AttributeBEModel): Observable<string> {
301 return this.http.delete(this.baseUrl + 'services/' + componentId + '/attributes/' + attribute.uniqueId )
302 .map((res: Response) => {
303 return attribute.uniqueId;
307 getDependencies(componentType: string, componentId: string): Observable<IDependenciesServerResponse[]> {
308 return this.http.get<IDependenciesServerResponse[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/dependencies');
311 automatedUpgrade(componentType: string, componentId: string, componentsIdsToUpgrade: IAutomatedUpgradeRequestObj[]): Observable<AutomatedUpgradeGenericResponse> {
312 return this.http.post<AutomatedUpgradeGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/automatedupgrade', componentsIdsToUpgrade);
315 updateComponentInstance(componentMetaDataId: string, componentType: string, componentInstance:ComponentInstance): Observable<ComponentInstance> {
316 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstance/' + componentInstance.uniqueId, componentInstance);
319 updateMultipleComponentInstances(componentId: string, componentType: string, instances: ComponentInstance[]): Observable<ComponentInstance[]> {
320 return this.http.post<ComponentInstance[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/multipleComponentInstance', instances)
322 return CommonUtils.initComponentInstances(res);
326 createRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
327 return this.http.post<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/associate', link)
329 return new RelationshipModel(res);
333 deleteRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
334 return this.http.put<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/dissociate', link)
336 return new RelationshipModel(res);
340 createComponentInstance(componentType: string, componentId: string, componentInstance: ComponentInstance): Observable<ComponentInstance> {
341 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance', componentInstance)
343 return new ComponentInstance(res);
347 deleteComponentInstance(componentType: string, componentId: string, componentInstanceId: string): Observable<ComponentInstance> {
348 return this.http.delete<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/' + componentInstanceId)
350 return new ComponentInstance(res);
354 fetchRelation(componentType: string, componentId: string, linkId: string): Observable<RelationshipModel> {
355 return this.http.get<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/relationId/' + linkId)
357 return new RelationshipModel(res);
361 addOrUpdateArtifact = (componentType: string, componentId: string, artifact: ArtifactModel): Observable<ArtifactModel> => {
362 let headerObj: HttpHeaders = new HttpHeaders();
363 if (artifact.payloadData) {
364 headerObj = headerObj.append('Content-MD5', HttpHelperService.getHeaderMd5(artifact));
367 let artifactID: string = '';
368 if (artifact.uniqueId) {
369 artifactID = '/' + artifact.uniqueId;
371 return this.http.post<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts' + artifactID, JSON.stringify(artifact), {headers: headerObj}).map(
372 (res) => new ArtifactModel(res)
376 deleteArtifact = (componentId: string, componentType: string, artifactId: string, artifactLabel: string): Observable<ArtifactModel> => {
377 return this.http.delete<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId + '?operation=' + artifactLabel)
378 .map((res) => new ArtifactModel(res));
381 downloadArtifact = (componentType: string, componentId: string, artifactId: string): Observable<IFileDownload> => {
382 return this.http.get<IFileDownload>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId);
385 // ------------------------------------------------ Properties API --------------------------------------------------//
386 addProperty = (componentType: string, componentId: string, property: PropertyModel):Observable<PropertyModel> => {
387 return this.http.post<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', property.convertToServerObject())
389 return new PropertyModel(response);
393 updateProperty = (componentType: string, componentId: string, property: PropertyModel): Observable<PropertyModel> => {
394 const propertiesList: PropertyBEModel[] = [property];
395 return this.http.put<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', propertiesList)
397 return new PropertyModel(response[Object.keys(response)[0]]);
401 deleteProperty = (componentType: string, componentId: string, propertyId: string): Observable<PropertyModel> => {
402 return this.http.delete<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties/' + propertyId);
405 // ------------------------------------------------ Attributes API --------------------------------------------------//
406 addAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
407 return this.http.post<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes', attribute.convertToServerObject())
409 return new AttributeModel(response);
413 updateAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
414 const payload = attribute.convertToServerObject();
416 return this.http.put<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, payload)
418 return new AttributeModel(response);
423 addAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
424 return this.addAttribute(componentType, componentId, attribute).toPromise();
427 updateAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
428 return this.updateAttribute(componentType, componentId, attribute).toPromise();
431 deleteAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<any> => {
432 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, {}).toPromise();
435 getArtifactsByType(componentType: string, componentId: string, artifactsType: ArtifactGroupType) {
436 return this.getComponentDataByFieldsName(componentType, componentId, [this.convertArtifactTypeToUrl(artifactsType)]);
439 getServiceConsumptionData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
440 return this.getComponentDataByFieldsName(componentType, componentId, [
441 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INTERFACES,
442 COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES,
443 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INPUTS,
444 COMPONENT_FIELDS.COMPONENT_INPUTS,
445 COMPONENT_FIELDS.COMPONENT_INSTANCES,
446 COMPONENT_FIELDS.COMPONENT_CAPABILITIES
450 getServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, interfaceId: string, operation: OperationModel): Observable<ConsumptionInput[]> {
451 return this.http.get<ConsumptionInput[]>
452 (this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId + '/interfaces/' + interfaceId + '/operations/' + operation.uniqueId + '/inputs');
455 createOrUpdateServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, consumptionInputsList: Array<{[id: string]: ConsumptionInput[]}>): Observable<any> {
456 return this.http.post(this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId, consumptionInputsList);
459 getServiceFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
460 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.NODE_FILTER]);
463 getSubstitutionFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
464 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.SUBSTITUTION_FILTER]);
467 getComponentInstanceProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
468 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]);
471 findAllComponentInstanceAttributes(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
472 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
475 getComponentInstanceCapabilityProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
476 return this.getComponentDataByFieldsName(componentType, componentId,
477 [COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
480 createServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: FilterConstraint, componentType: string, constraintType: string): Observable<any> {
481 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
484 createServiceFilterCapabilitiesConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: FilterConstraint, componentType: string, constraintType: string): Observable<any> {
485 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
488 updateServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: FilterConstraint, componentType: string, constraintType: string, constraintIndex: number):Observable<any>{
489 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter', constraint)
492 updateServiceFilterCapabilitiesConstraint(componentMetaDataId: string, componentInstanceId: string, constraints: FilterConstraint, componentType: string, constraintType: string, constraintIndex: number):Observable<any>{
493 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter', constraints)
496 deleteServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
497 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter')
500 getComponentPropertiesAndInputsForSubstitutionFilter(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
501 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INPUTS]);
504 createSubstitutionFilterConstraints(componentMetaDataId: string, constraint: FilterConstraint, componentType: string, constraintType: string): Observable<any> {
505 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
508 updateSubstitutionFilterConstraint(componentId: string, constraint: FilterConstraint, componentType: string, constraintType: string,
509 index: number): Observable<any> {
510 const url = `${this.baseUrl}${this.getServerTypeUrl(componentType)}${componentId}/substitutionFilter/${constraintType}/${index}`;
511 return this.http.put<any>(url, constraint);
514 deleteSubstitutionFilterConstraints(componentMetaDataId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
515 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType + "/" + constraintIndex)
518 deletePolicy(component: Component, policy: PolicyInstance): Observable<PolicyInstance> {
519 return this.http.put<PolicyInstance>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policy.uniqueId + '/undeclare', policy)
522 createListInput(component: Component, input: any, isSelf: boolean): Observable<any> {
525 // change componentInstanceProperties -> serviceProperties
527 componentInstInputsMap: {
528 serviceProperties: input.componentInstInputsMap.componentInstanceProperties
530 listInput: input.listInput
535 return this.http.post<any>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/listInput', inputs);
538 createPolicy(component: Component, policiesToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
541 // tslint:disable-next-line:object-literal-key-quotes
542 {'componentPropertiesToPolicies': {
543 ...policiesToCreate.componentInstanceProperties
546 // tslint:disable-next-line:object-literal-key-quotes
547 {'componentInstancePropertiesToPolicies': {
548 ...policiesToCreate.componentInstanceProperties
551 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/policies', policiesList);
554 protected getComponentDataByFieldsName(componentType: string, componentId: string, fields: string[]): Observable<ComponentGenericResponse> {
555 let params: HttpParams = new HttpParams();
556 _.forEach(fields, (field: string): void => {
557 params = params.append(API_QUERY_PARAMS.INCLUDE, field);
559 // tslint:disable-next-line:object-literal-shorthand
560 return this.http.get<ComponentGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {params: params})
562 return componentType === ComponentType.SERVICE ? new ServiceGenericResponse().deserialize(res) :
563 new ComponentGenericResponse().deserialize(res);
567 private getServerTypeUrl = (componentType: string): string => {
568 switch (componentType) {
569 case ComponentType.SERVICE:
570 case ComponentType.SERVICE_PROXY:
571 case ComponentType.SERVICE_SUBSTITUTION:
572 return ServerTypeUrl.SERVICES;
574 return ServerTypeUrl.RESOURCES;
578 private convertArtifactTypeToUrl = (artifactType: ArtifactGroupType): string => {
579 switch (artifactType) {
580 case ArtifactGroupType.TOSCA:
581 return COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS;
582 case ArtifactGroupType.INFORMATION:
583 return COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS;
584 case ArtifactGroupType.DEPLOYMENT:
585 return COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS;
586 case ArtifactGroupType.SERVICE_API:
587 return COMPONENT_FIELDS.SERVICE_API_ARTIFACT;
591 // createCapability(component: Component, capabilityData: Capability): Observable<Capability[]> {
592 createCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
595 [capabilityData.type]: [capabilityData]
598 return this.http.post<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
601 updateCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
604 [capabilityData.type]: [capabilityData]
607 return this.http.put<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
610 deleteCapability(component: Component, capId: string): Observable<Capability> {
611 return this.http.delete<Capability>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/capabilities/' + capId);
614 createRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
617 [requirementData.capability]: [requirementData]
620 return this.http.post(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
623 updateRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
626 [requirementData.capability]: [requirementData]
629 return this.http.put(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
632 deleteRequirement(component: Component, reqId: string): Observable<Requirement> {
633 return this.http.delete<Requirement>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/requirements/' + reqId);
636 getDirectiveList(): Observable<string[]> {
637 return this.http.get<ListDirectiveResponse>(this.baseUrl + "directives")
638 .pipe(map(response => response.directives));
641 updateComponentInstanceInterfaceOperation(componentMetaDataId: string,
642 componentMetaDataType: string,
643 componentInstanceId: string,
644 operation: InterfaceOperationModel): Observable<ComponentInstance> {
645 const operationList = {
647 [operation.interfaceType]: {
648 type: operation.interfaceType,
650 [operation.name]: new BEInterfaceOperationModel(operation)
655 return this.http.put<ComponentInstance>(this.baseUrl + this
656 .getServerTypeUrl(componentMetaDataType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/interfaceOperation', operationList);