2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import * as _ from "lodash";
22 import {CompositionGraphGeneralUtils} from "./composition-graph-general-utils";
23 import {ServiceServiceNg2} from 'app/ng2/services/component-services/service.service';
24 import {Service} from "app/models/components/service";
25 import {ForwardingPath} from "app/models/forwarding-path";
26 import {ForwardingPathLink} from "app/models/forwarding-path-link";
27 import {ComponentRef, Injectable} from "@angular/core";
28 import {CompositionCiServicePathLink} from "app/models/graph/graph-links/composition-graph-links/composition-ci-service-path-link";
29 import {SdcUiServices} from "onap-ui-angular";
30 import {QueueServiceUtils} from "app/ng2/utils/queue-service-utils";
31 import {ServicePathsListComponent} from "app/ng2/pages/composition/graph/service-paths-list/service-paths-list.component";
32 import {ButtonModel, ModalModel} from "app/models";
33 import {ServicePathCreatorComponent} from "app/ng2/pages/composition/graph/service-path-creator/service-path-creator.component";
34 import {ModalService} from "app/ng2/services/modal.service";
35 import {ModalComponent} from "app/ng2/components/ui/modal/modal.component";
36 import {Select, Store} from "@ngxs/store";
37 import {WorkspaceState} from "app/ng2/store/states/workspace.state";
38 import {WorkspaceService} from "app/ng2/pages/workspace/workspace.service";
39 import {CompositionService} from "../../composition.service";
40 import {CommonGraphUtils} from "../common/common-graph-utils";
41 import {GRAPH_EVENTS} from "app/utils/constants";
42 import {EventListenerService} from "app/services/event-listener-service";
45 export class ServicePathGraphUtils {
48 private generalGraphUtils: CompositionGraphGeneralUtils,
49 private serviceService: ServiceServiceNg2,
50 private commonGraphUtils: CommonGraphUtils,
51 private loaderService: SdcUiServices.LoaderService,
52 private queueServiceUtils: QueueServiceUtils,
53 private modalService: ModalService,
54 private workspaceService: WorkspaceService,
55 private compositionService: CompositionService,
57 private eventListenerService: EventListenerService
61 private isViewOnly = (): boolean => {
62 return this.store.selectSnapshot(state => state.workspace.isViewOnly);
64 private modalInstance: ComponentRef<ModalComponent>;
66 public deletePathsFromGraph(cy: Cy.Instance) {
67 cy.remove(`[type="${CompositionCiServicePathLink.LINK_TYPE}"]`);
70 public drawPath(cy: Cy.Instance, forwardingPath: ForwardingPath) {
71 let pathElements = forwardingPath.pathElements.listToscaDataDefinition;
73 _.forEach(pathElements, (link: ForwardingPathLink) => {
74 let data: CompositionCiServicePathLink = new CompositionCiServicePathLink(link);
76 this.compositionService.componentInstances,
77 instance => instance.name === data.forwardingPathLink.fromNode
80 this.compositionService.componentInstances,
81 instance => instance.name === data.forwardingPathLink.toNode
83 data.pathId = forwardingPath.uniqueId;
84 data.pathName = forwardingPath.name;
85 this.commonGraphUtils.insertServicePathLinkToGraph(cy, data);
89 public createOrUpdateServicePath = (path: any): void => {
90 this.loaderService.activate();
92 let onSuccess: (response: ForwardingPath) => void = (response: ForwardingPath) => {
93 this.loaderService.deactivate();
94 this.compositionService.forwardingPaths[response.uniqueId] = response;
95 this.eventListenerService.notifyObservers(GRAPH_EVENTS.ON_SERVICE_PATH_CREATED, response.uniqueId)
98 this.queueServiceUtils.addBlockingUIAction(
99 () => this.serviceService.createOrUpdateServicePath(this.workspaceService.metadata.uniqueId, path).subscribe(onSuccess
100 , (error) => {this.loaderService.deactivate()})
104 public onCreateServicePath = (): void => {
105 // this.showServicePathMenu = false;
106 let cancelButton: ButtonModel = new ButtonModel('Cancel', 'outline white', this.modalService.closeCurrentModal);
107 let saveButton: ButtonModel = new ButtonModel('Create', 'blue', this.createPath, this.getDisabled);
108 let modalModel: ModalModel = new ModalModel('l', 'Create Service Flow', '', [saveButton, cancelButton], 'standard', true);
109 this.modalInstance = this.modalService.createCustomModal(modalModel);
110 this.modalService.addDynamicContentToModal(this.modalInstance, ServicePathCreatorComponent, {serviceId: this.workspaceService.metadata.uniqueId});
111 this.modalInstance.instance.open();
114 public onListServicePath = (): void => {
115 // this.showServicePathMenu = false;
116 let cancelButton: ButtonModel = new ButtonModel('Close', 'outline white', this.modalService.closeCurrentModal);
117 let modalModel: ModalModel = new ModalModel('md', 'Service Flows List', '', [cancelButton], 'standard', true);
118 this.modalInstance = this.modalService.createCustomModal(modalModel);
119 this.modalService.addDynamicContentToModal(this.modalInstance, ServicePathsListComponent, {
120 serviceId: this.workspaceService.metadata.uniqueId,
121 onCreateServicePath: this.onCreateServicePath,
122 onEditServicePath: this.onEditServicePath,
123 isViewOnly: this.isViewOnly()
125 this.modalInstance.instance.open();
128 public onEditServicePath = (id: string): void => {
129 let cancelButton: ButtonModel = new ButtonModel('Cancel', 'outline white', this.modalService.closeCurrentModal);
130 let saveButton: ButtonModel = new ButtonModel('Save', 'blue', this.createPath, this.getDisabled);
131 let modalModel: ModalModel = new ModalModel('l', 'Edit Path', '', [saveButton, cancelButton], 'standard', true);
132 this.modalInstance = this.modalService.createCustomModal(modalModel);
133 this.modalService.addDynamicContentToModal(this.modalInstance, ServicePathCreatorComponent, {
134 serviceId: this.workspaceService.metadata.uniqueId,
137 this.modalInstance.instance.open();
140 public getDisabled = (): boolean => {
141 return this.isViewOnly() || !this.modalInstance.instance.dynamicContent.instance.checkFormValidForSubmit();
144 public createPath = (): void => {
145 this.createOrUpdateServicePath(this.modalInstance.instance.dynamicContent.instance.createServicePathData());
146 this.modalService.closeCurrentModal();