update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / descriptors / ConnectionPoint.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, readonly) {
49 super(model, parent, readonly);
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 get order() {
89 return this.model['order'];
90 }
91
92 set order(n) {
93 this.model['order'] = n;
94 }
95
96 /**
97 * Convenience method to generate a VnfdConnectionPointRef instance from any given VirtualNetworkFunctionConnectionPoint.
98 *
99 * @returns {RspConnectionPointRef}
100 */
101 toRspConnectionPointRef() {
102 const ref = new RspConnectionPointRef({});
103 ref.vnfdId = this.vnfdId;
104 ref.vnfdIndex = this.vnfdIndex;
105 ref.vnfdConnectionPointName = this.name;
106 ref.cpNumber = this.cpNumber;
107 ref.order = this.order;
108 return ref;
109 }
110
111 toVnfdConnectionPointRef() {
112 const ref = new VnfdConnectionPointRef({});
113 ref.vnfdId = this.vnfdId;
114 ref.vnfdIndex = this.vnfdIndex;
115 ref.vnfdConnectionPointName = this.name;
116 ref.cpNumber = this.cpNumber;
117 ref.order = this.order;
118 return ref;
119 }
120
121 canConnectTo(obj) {
122 return (DescriptorModelFactory.isVirtualLink(obj) || DescriptorModelFactory.isConnectionPoint(obj)) && obj.parent !== this.parent;
123 }
124
125 remove() {
126 return this.parent.removeConnectionPoint(this);
127 }
128
129 }