Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / descriptors / NetworkServiceConnectionPoint.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 /**
19 * Created by onvelocity on 11/23/15.
20 */
21
22 'use strict';
23
24 import Position from '../../graph/Position'
25 import DescriptorModel from '../DescriptorModel'
26 import RspConnectionPointRef from './RspConnectionPointRef'
27 import VnfdConnectionPointRef from './VnfdConnectionPointRef'
28 import DescriptorModelFactory from '../DescriptorModelFactory'
29
30 /**
31 * A VirtualNetworkFunctionConnectionPoint is always a child of a VNFD. We use it to build VnfdConnectionPointRef instances. So convenience
32 * methods are add to access the fields needed to do that.
33 */
34 export default class ConnectionPoint extends DescriptorModel {
35
36 static get type() {
37 return 'connection-point';
38 }
39
40 static get className() {
41 return 'VirtualNetworkFunctionConnectionPoint';
42 }
43
44 static get qualifiedType() {
45 return 'vnfd.' + ConnectionPoint.type;
46 }
47
48 constructor(model, parent) {
49 super(model, parent);
50 this.type = ConnectionPoint.type;
51 this.uiState['qualified-type'] = ConnectionPoint.qualifiedType;
52 this.className = 'VirtualNetworkFunctionConnectionPoint';
53 this.location = 'bottom-left';
54 this.position = new Position(parent.position.value());
55 this.position.top = parent.position.bottom;
56 this.position.width = 14;
57 this.position.height = 14;
58 }
59
60 get id() {
61 return this.model.name;
62 }
63
64 get key() {
65 return this.parent.key + '/' + this.model.name;
66 }
67
68 get name() {
69 return this.model.name;
70 }
71
72 get vnfdIndex() {
73 return this.parent.vnfdIndex;
74 }
75
76 get vnfdId() {
77 return this.parent.vnfdId;
78 }
79
80 get cpNumber() {
81 return this.uiState.cpNumber;
82 }
83
84 set cpNumber(n) {
85 this.uiState.cpNumber = n;
86 }
87
88 /**
89 * Convenience method to generate a VnfdConnectionPointRef instance from any given VirtualNetworkFunctionConnectionPoint.
90 *
91 * @returns {RspConnectionPointRef}
92 */
93 toRspConnectionPointRef() {
94 const ref = new RspConnectionPointRef({});
95 ref.vnfdId = this.vnfdId;
96 ref.vnfdIndex = this.vnfdIndex;
97 ref.vnfdConnectionPointName = this.name;
98 ref.cpNumber = this.cpNumber;
99 return ref;
100 }
101
102 toVnfdConnectionPointRef() {
103 const ref = new VnfdConnectionPointRef({});
104 ref.vnfdId = this.vnfdId;
105 ref.vnfdIndex = this.vnfdIndex;
106 ref.vnfdConnectionPointName = this.name;
107 ref.cpNumber = this.cpNumber;
108 return ref;
109 }
110
111 canConnectTo(obj) {
112 return (DescriptorModelFactory.isVirtualLink(obj) || DescriptorModelFactory.isConnectionPoint(obj)) && obj.parent !== this.parent;
113 }
114
115 remove() {
116 return this.parent.removeConnectionPoint(this);
117 }
118
119 }