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