RIFT-14705 - UI Composer: Add IVLD to VNFD is broken
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / descriptors / VirtualLink.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 'use strict';
20
21 import UID from '../../../libraries/UniqueId'
22 import DescriptorModel from '../DescriptorModel'
23 import DescriptorModelFactory from '../DescriptorModelFactory'
24 import DescriptorModelMetaFactory from '../DescriptorModelMetaFactory'
25
26 export default class VirtualLink extends DescriptorModel {
27
28 static get type() {
29 return 'vld';
30 }
31
32 static get className() {
33 return 'VirtualLink';
34 }
35
36 static get qualifiedType() {
37 return 'nsd.' + VirtualLink.type;
38 }
39
40 constructor(model, parent) {
41 super(model, parent);
42 this.type = VirtualLink.type;
43 this.uiState['qualified-type'] = VirtualLink.qualifiedType;
44 this.className = VirtualLink.className;
45 }
46
47 get title() {
48 const title = this.model['short-name'] || this.model.name || (this.model.type + '/' + this.id);
49 if (title && title.length > 18) {
50 return title.substr(0, 18) + '...';
51 }
52 return title;
53 }
54
55 get connection() {
56 if (!this.model['vnfd-connection-point-ref']) {
57 this.model['vnfd-connection-point-ref'] = [];
58 }
59 return this.model['vnfd-connection-point-ref'].map(d => DescriptorModelFactory.newVnfdConnectionPointRef(d, this));
60 }
61
62 set connection(connections) {
63 this.updateModelList('vnfd-connection-point-ref', connections, DescriptorModelFactory.VnfdConnectionPointRef);
64 }
65
66 createVnfdConnectionPointRef(model) {
67 model = model || DescriptorModelMetaFactory.createModelInstanceForType('nsd.vld.vnfd-connection-point-ref');
68 return this.connection = DescriptorModelFactory.newVnfdConnectionPointRef(model, this);
69 }
70
71 removeVnfdConnectionPointRefKey(cpRefKey) {
72 const child = this.connection.filter(d => d.key === cpRefKey)[0];
73 return this.removeModelListItem('connection', child);
74 }
75
76 addConnectionPoint(cp) {
77 this.parent.removeAnyConnectionsForConnector(cp);
78 const cpRef = cp.toVnfdConnectionPointRef();
79 this.connection = this.connection.concat(cpRef);
80 }
81
82 findConnectionPointRef(vnfdId, vnfdIndex, vnfdConnectionPointName) {
83 return this.connection.filter(d => d.vnfdId === vnfdId && d.vnfdIndex === vnfdIndex && d.vnfdConnectionPointName === vnfdConnectionPointName)[0];
84 }
85
86 remove() {
87 const nsdc = this.parent;
88 return nsdc.removeVLD(this);
89 }
90
91 removeVnfdConnectionPointRefForVnfdIndex(vnfdIndex) {
92 const size = this.connection.length;
93 if (typeof vnfdIndex !== 'undefined') {
94 this.connection = this.connection.filter(d => d.vnfdIndex !== vnfdIndex).map(d => d.model);
95 }
96 return size !== this.connection.length;
97 }
98
99 }