3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2022 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 import {Component, Input, OnInit} from '@angular/core';
23 import {Store} from '@ngxs/store';
25 CapabilitiesGroup, Capability,
26 Component as TopologyTemplate,
27 FullComponentInstance,
29 PropertyBEModel, PropertyModel,
31 import {DEPENDENCY_EVENTS} from 'app/utils/constants';
32 import {ComponentMetadata} from '../../../../../../models/component-metadata';
33 import {ServiceInstanceObject} from '../../../../../../models/service-instance-properties-and-interfaces';
34 import {EventListenerService} from '../../../../../../services/event-listener-service';
35 import {TopologyTemplateService} from '../../../../../services/component-services/topology-template.service';
36 import {ComponentGenericResponse} from '../../../../../services/responses/component-generic-response';
37 import {WorkspaceService} from '../../../../workspace/workspace.service';
38 import {SelectedComponentType} from '../../../common/store/graph.actions';
39 import {CompositionService} from '../../../composition.service';
40 import {FilterConstraint} from "../../../../../../models/filter-constraint";
43 selector: 'service-dependencies-tab',
44 templateUrl: 'service-dependencies-tab.component.html',
45 styleUrls: ['service-dependencies-tab.component.less']
47 export class ServiceDependenciesTabComponent implements OnInit {
48 isComponentInstanceSelected: boolean;
50 selectedInstanceSiblings: ServiceInstanceObject[];
51 componentInstancesConstraints: any[];
52 selectedInstanceConstraints: FilterConstraint[];
53 selectedInstanceProperties: PropertyBEModel[];
54 componentInstanceProperties: PropertiesGroup;
55 componentInstanceCapabilityProperties: CapabilitiesGroup;
56 metaData: ComponentMetadata;
57 componentInstanceCapabilitiesMap : Map<string, PropertyModel[]> = new Map();
59 @Input() isViewOnly: boolean;
60 @Input() componentType: SelectedComponentType;
61 @Input() component: FullComponentInstance | TopologyTemplate;
64 constructor(private store: Store,
65 private topologyTemplateService: TopologyTemplateService,
66 private workspaceService: WorkspaceService,
67 private compositionService: CompositionService,
68 private eventListenerService: EventListenerService) {
72 this.metaData = this.workspaceService.metadata;
73 this.isComponentInstanceSelected = this.componentType === SelectedComponentType.COMPONENT_INSTANCE;
74 this.initInstancesWithProperties();
75 this.loadConstraints();
76 this.initInstancesWithProperties();
77 this.initInstancesWithCapabilityProperties()
80 public loadConstraints = (): void => {
81 this.topologyTemplateService.getServiceFilterConstraints(this.metaData.componentType, this.metaData.uniqueId).subscribe((response) => {
82 this.componentInstancesConstraints = response.nodeFilterforNode;
86 public notifyDependencyEventsObserver = (isChecked: boolean): void => {
87 this.eventListenerService.notifyObservers(DEPENDENCY_EVENTS.ON_DEPENDENCY_CHANGE, isChecked);
90 public updateSelectedInstanceConstraints = (constraintsList:Array<FilterConstraint>):void => {
91 this.componentInstancesConstraints[this.component.uniqueId].properties = constraintsList;
92 this.selectedInstanceConstraints = this.componentInstancesConstraints[this.component.uniqueId].properties;
95 public updateSelectedInstanceCapabilitiesConstraints = (constraintsList:Array<FilterConstraint>):void => {
96 this.componentInstancesConstraints[this.component.uniqueId].capabilities = constraintsList;
97 this.selectedInstanceConstraints = this.componentInstancesConstraints[this.component.uniqueId].capabilities;
100 private initInstancesWithProperties = (): void => {
101 this.topologyTemplateService.getComponentInstanceProperties(this.metaData.componentType, this.metaData.uniqueId).subscribe((genericResponse: ComponentGenericResponse) => {
102 this.componentInstanceProperties = genericResponse.componentInstancesProperties;
103 this.updateInstanceAttributes();
107 private updateInstanceAttributes = (): void => {
108 if (this.isComponentInstanceSelected && this.componentInstanceProperties) {
109 const instancesMappedList = this.compositionService.componentInstances.map((coInstance) => new ServiceInstanceObject({
110 id: coInstance.uniqueId,
111 name: coInstance.name,
112 properties: this.componentInstanceProperties[coInstance.uniqueId] || []
114 this.selectedInstanceProperties = this.componentInstanceProperties[this.component.uniqueId];
115 this.selectedInstanceSiblings = instancesMappedList.filter((coInstance) => coInstance.id !== this.component.uniqueId);
119 private initInstancesWithCapabilityProperties(): void {
120 this.componentInstanceCapabilityProperties = this.component.capabilities;
121 this.updateComponentInstanceCapabilities();
124 private updateComponentInstanceCapabilities = (): void => {
125 if (this.isComponentInstanceSelected && this.componentInstanceCapabilityProperties) {
126 _.forEach(_.flatten(_.values(this.componentInstanceCapabilityProperties)), (capability: Capability) => {
127 if (capability.properties) {
128 this.componentInstanceCapabilitiesMap.set(capability.name, capability.properties);