RIFT-15726 - optimize download size -> lodash usage in UI
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / descriptors / RecordServicePath.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 DescriptorModel from '../DescriptorModel'
25 import RspConnectionPointRef from './RspConnectionPointRef'
26 import DescriptorModelFactory from '../DescriptorModelFactory'
27 import DescriptorModelMetaFactory from '../DescriptorModelMetaFactory'
28
29 export default class RecordServicePath extends DescriptorModel {
30
31 static get type() {
32 return 'rsp';
33 }
34
35 static get className() {
36 return 'RecordServicePath';
37 }
38
39 constructor(model, parent) {
40 super(model, parent);
41 this.type = 'rsp';
42 this.uiState['qualified-type'] = 'nsd.vnffgd.rsp';
43 this.className = 'RecordServicePath';
44 }
45
46 get vnfdConnectionPointRef() {
47 if (!this.model['vnfd-connection-point-ref']) {
48 this.model['vnfd-connection-point-ref'] = [];
49 }
50 return this.model['vnfd-connection-point-ref'].map(d => DescriptorModelFactory.newRspConnectionPointRef(d, this));
51 }
52
53 set vnfdConnectionPointRef(obj) {
54 this.updateModelList('vnfd-connection-point-ref', obj, RspConnectionPointRef);
55 }
56
57 createVnfdConnectionPointRef(connectionPoint) {
58 let ref;
59 if (DescriptorModelFactory.isConnectionPoint(connectionPoint)) {
60 ref = connectionPoint.toRspConnectionPointRef();
61 } else {
62 const model = DescriptorModelMetaFactory.createModelInstanceForType('nsd.vnffgd.rsp.vnfd-connection-point-ref');
63 ref = new RspConnectionPointRef(model, this);
64 }
65 this.vnfdConnectionPointRef = ref;
66 return ref;
67 }
68
69 get connectionPoints() {
70 return this.vnfdConnectionPointRef;
71 }
72 remove() {
73 return this.parent.removeRecordServicePath(this);
74 }
75
76 /**
77 * Remove all connection points refs associate with this vnfd.
78 *
79 * @param vnfdIndex
80 */
81 removeVnfdConnectionPointRefForVnfdIndex(vnfdIndex) {
82 if (typeof vnfdIndex !== 'undefined') {
83 const len = this.vnfdConnectionPointRef.length;
84 this.vnfdConnectionPointRef = this.vnfdConnectionPointRef.filter(d => d.vnfdIndex !== vnfdIndex);
85 return len !== this.vnfdConnectionPointRef.length;
86 }
87 }
88
89 removeRspConnectionPointRef(child) {
90 return this.removeModelListItem('vnfdConnectionPointRef', child);
91 }
92
93 createClassifier() {
94 this.parent.createClassifierForRecordServicePath(this);
95 }
96
97 }