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);
50 data.source = data.forwardingPathLink.fromNode;
51 data.target = data.forwardingPathLink.toNode;
52 data.pathId = forwardingPath.uniqueId;
53 data.pathName = forwardingPath.name;
54 this.commonGraphUtils.insertServicePathLinkToGraph(cy, data);
58 public createOrUpdateServicePath = (scope:ICompositionGraphScope, path: any): void => {
59 let service = <Service>scope.component;
60 this.loaderService.showLoader('composition-graph');
62 let onSuccess: (response: ForwardingPath) => void = (response: ForwardingPath) => {
64 service.forwardingPaths[response.uniqueId] = response;
65 scope.selectedPathId = response.uniqueId;
68 this.generalGraphUtils.getGraphUtilsServerUpdateQueue().addBlockingUIActionWithReleaseCallback(
69 () => this.serviceService.createOrUpdateServicePath(service, path).subscribe(onSuccess),
70 () => this.loaderService.hideLoader('composition-graph')
75 ServicePathGraphUtils.$inject = [
77 'CompositionGraphGeneralUtils',