5153e5f1240f790b90b7bfcc9216752482ca1838
[osm/riftware.git] /
1 /*
2  * STANDARD_RIFT_IO_COPYRIGHT
3  */
4 /**
5  * Created by onvelocity on 11/23/15.
6  */
7
8 'use strict';
9
10 import Position from '../../graph/Position'
11 import DescriptorModel from '../DescriptorModel'
12 import RspConnectionPointRef from './RspConnectionPointRef'
13 import VnfdConnectionPointRef from './VnfdConnectionPointRef'
14 import DescriptorModelFactory from '../DescriptorModelFactory'
15
16 /**
17  * A VirtualNetworkFunctionConnectionPoint is always a child of a VNFD. We use it to build VnfdConnectionPointRef instances. So convenience
18  * methods are add to access the fields needed to do that.
19  */
20 export default class ConnectionPoint extends DescriptorModel {
21
22         static get type() {
23                 return 'connection-point';
24         }
25
26         static get className() {
27                 return 'VirtualNetworkFunctionConnectionPoint';
28         }
29
30         static get qualifiedType() {
31                 return 'vnfd.' + ConnectionPoint.type;
32         }
33
34         constructor(model, parent) {
35                 super(model, parent);
36                 this.type = ConnectionPoint.type;
37                 this.uiState['qualified-type'] = ConnectionPoint.qualifiedType;
38                 this.className = 'VirtualNetworkFunctionConnectionPoint';
39                 this.location = 'bottom-left';
40                 this.position = new Position(parent.position.value());
41                 this.position.top = parent.position.bottom;
42                 this.position.width = 14;
43                 this.position.height = 14;
44         }
45
46         get id() {
47                 return this.model.name;
48         }
49
50         get key() {
51                 return this.parent.key + '/' + this.model.name;
52         }
53
54         get name() {
55                 return this.model.name;
56         }
57
58         get vnfdIndex() {
59                 return this.parent.vnfdIndex;
60         }
61
62         get vnfdId() {
63                 return this.parent.vnfdId;
64         }
65
66         get cpNumber() {
67                 return this.uiState.cpNumber;
68         }
69
70         set cpNumber(n) {
71                 this.uiState.cpNumber = n;
72         }
73
74         /**
75          * Convenience method to generate a VnfdConnectionPointRef instance from any given VirtualNetworkFunctionConnectionPoint.
76          *
77          * @returns {RspConnectionPointRef}
78          */
79         toRspConnectionPointRef() {
80                 const ref = new RspConnectionPointRef({});
81                 ref.vnfdId = this.vnfdId;
82                 ref.vnfdIndex = this.vnfdIndex;
83                 ref.vnfdConnectionPointName = this.name;
84                 ref.cpNumber = this.cpNumber;
85                 return ref;
86         }
87
88         toVnfdConnectionPointRef() {
89                 const ref = new VnfdConnectionPointRef({});
90                 ref.vnfdId = this.vnfdId;
91                 ref.vnfdIndex = this.vnfdIndex;
92                 ref.vnfdConnectionPointName = this.name;
93                 ref.cpNumber = this.cpNumber;
94                 return ref;
95         }
96
97         canConnectTo(obj) {
98                 return (DescriptorModelFactory.isVirtualLink(obj) || DescriptorModelFactory.isConnectionPoint(obj)) && obj.parent !== this.parent;
99         }
100
101         remove() {
102                 return this.parent.removeConnectionPoint(this);
103         }
104
105 }