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 {LoaderService} from "app/services";
23 import {CompositionGraphGeneralUtils} from "./composition-graph-general-utils";
24 import {ICompositionGraphScope} from "../composition-graph.directive";
25 import {ServiceServiceNg2} from 'app/ng2/services/component-services/service.service';
26 import {Service} from "../../../../models/components/service";
27 import {ForwardingPath} from "app/models/forwarding-path";
28 import {ForwardingPathLink} from "app/models/forwarding-path-link";
29 import {CompositionCiServicePathLink} from "../../../../models/graph/graph-links/composition-graph-links/composition-ci-service-path-link";
30 import {CommonGraphUtils} from "app/directives/graphs-v2/common/common-graph-utils";
32 export class ServicePathGraphUtils {
35 private loaderService:LoaderService,
36 private generalGraphUtils:CompositionGraphGeneralUtils,
37 private serviceService:ServiceServiceNg2,
38 private commonGraphUtils:CommonGraphUtils
41 public deletePathsFromGraph(cy: Cy.Instance, service:Service){
42 cy.remove(`[type="${CompositionCiServicePathLink.LINK_TYPE}"]`);
45 public drawPath(cy: Cy.Instance, forwardingPath: ForwardingPath, service:Service) {
46 let pathElements = forwardingPath.pathElements.listToscaDataDefinition;
48 _.forEach(pathElements, (link: ForwardingPathLink) => {
49 let data:CompositionCiServicePathLink = new CompositionCiServicePathLink(link);
51 service.componentInstances,
52 instance => instance.name === data.forwardingPathLink.fromNode
55 service.componentInstances,
56 instance => instance.name === data.forwardingPathLink.toNode
58 data.pathId = forwardingPath.uniqueId;
59 data.pathName = forwardingPath.name;
60 this.commonGraphUtils.insertServicePathLinkToGraph(cy, data);
64 public createOrUpdateServicePath = (scope:ICompositionGraphScope, path: any): void => {
65 let service = <Service>scope.component;
66 this.loaderService.showLoader('composition-graph');
68 let onSuccess: (response: ForwardingPath) => void = (response: ForwardingPath) => {
70 service.forwardingPaths[response.uniqueId] = response;
71 scope.selectedPathId = response.uniqueId;
74 this.generalGraphUtils.getGraphUtilsServerUpdateQueue().addBlockingUIActionWithReleaseCallback(
75 () => this.serviceService.createOrUpdateServicePath(service, path).subscribe(onSuccess),
76 () => this.loaderService.hideLoader('composition-graph')
81 ServicePathGraphUtils.$inject = [
83 'CompositionGraphGeneralUtils',