update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / descriptors / InternalVirtualLink.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 DescriptorModel from '../DescriptorModel'
22 import DescriptorModelFactory from '../DescriptorModelFactory'
23 import DescriptorModelMetaFactory from '../DescriptorModelMetaFactory'
24
25 export default class InternalVirtualLink extends DescriptorModel {
26
27 static get type() {
28 return 'internal-vld';
29 }
30
31 static get className() {
32 return 'InternalVirtualLink';
33 }
34
35 static get qualifiedType() {
36 return 'vnfd.' + InternalVirtualLink.type;
37 }
38
39 constructor(model, parent, readonly) {
40 super(model, parent, readonly);
41 this.type = InternalVirtualLink.type;
42 this.uiState['qualified-type'] = InternalVirtualLink.qualifiedType;
43 this.className = InternalVirtualLink.className;
44 }
45
46 get title() {
47 return super.title || (this.type + '/' + this.id);
48 }
49
50 get connection() {
51 if (!this.model['internal-connection-point']) {
52 this.model['internal-connection-point'] = [];
53 }
54 return this.model['internal-connection-point'].map(d => DescriptorModelFactory.newInternalConnectionPointRef(d, this));
55 }
56
57 set connection(connections) {
58 return this.updateModelList('internal-connection-point', connections, DescriptorModelFactory.InternalConnectionPointRef);
59 }
60
61 createInternalConnectionPoint(model) {
62 model = model || DescriptorModelMetaFactory.createModelInstanceForType('vnfd.internal-vld.internal-connection-point');
63 return this.connection = DescriptorModelFactory.newInternalConnectionPointRef(model, this);
64 }
65
66 removeInternalConnectionPointRefForIdRefKey(cpRefKey) {
67 const child = this.connection.filter(d => d.key === cpRefKey)[0];
68 return this.removeModelListItem('connection', child);
69 }
70
71 addConnectionPoint(icp) {
72 this.parent.removeAnyConnectionsForConnector(icp);
73 const icpRef = icp.toInternalConnectionPointRef();
74 // this.connection = icp.toInternalConnectionPointRef();
75 this.connection = this.connection.concat(icpRef);
76 }
77
78 removeInternalConnectionPointRefForId(idRef) {
79 // return this.connection = this.connection.filter(d => d.idRef !== idRef).map(d => d.idRef);
80 // KKTODO: Check if below works instead
81 return this.connection = this.connection.filter(d => d.idRef !== idRef).map(d => d.model);
82 }
83
84 remove() {
85 return this.parent.removeInternalVirtualLink(this);
86 }
87
88 }