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