Improve auto generation of list key values. (RIFT-15923)
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / descriptors / ForwardingGraph.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 Classifier from './Classifier'
25 import DescriptorModel from '../DescriptorModel'
26 import RecordServicePath from './RecordServicePath'
27 import DescriptorModelFactory from '../DescriptorModelFactory'
28 import DescriptorModelMetaFactory from '../DescriptorModelMetaFactory'
29
30 export default class ForwardingGraph extends DescriptorModel {
31
32 static get type() {
33 return 'vnffgd';
34 }
35
36 static get className() {
37 return 'ForwardingGraph';
38 }
39
40 constructor(model, parent) {
41 super(model, parent);
42 this.type = 'vnffgd';
43 this.uiState['qualified-type'] = 'nsd.vnffgd';
44 this.className = 'ForwardingGraph';
45 }
46
47 get rsp() {
48 if (!this.model.rsp) {
49 this.model.rsp = [];
50 }
51 return this.model.rsp.map(d => DescriptorModelFactory.newRecordServicePath(d, this));
52 }
53
54 set rsp(obj) {
55 this.updateModelList('rsp', obj, RecordServicePath);
56 }
57
58 createRsp() {
59 const property = DescriptorModelMetaFactory.getModelMetaForType('nsd.vnffgd.rsp');
60 const uniqueName = DescriptorModelMetaFactory.generateItemUniqueName(this.rsp, property);
61 const model = DescriptorModelMetaFactory.createModelInstanceForType('nsd.vnffgd.rsp', uniqueName);
62 return this.rsp = new RecordServicePath(model, this);
63 }
64
65 removeRsp(obj) {
66 this.children.filter(d => d.id === obj.id).forEach(rsp => rsp.remove());
67 }
68
69 get recordServicePaths() {
70 return this.rsp;
71 }
72
73 removeRecordServicePath(child) {
74 this.rsp = this.rsp.filter(rsp => rsp.uid !== child.uid);
75 this.removeChild(child);
76 }
77
78 get classifier() {
79 if (!this.model['classifier']) {
80 this.model['classifier'] = [];
81 }
82 return this.model['classifier'].map(d => DescriptorModelFactory.newClassifier(d, this));
83 }
84
85 set classifier(obj) {
86 this.updateModelList('classifier', obj, Classifier);
87 }
88
89 createClassifier(model) {
90 model = model || DescriptorModelMetaFactory.createModelInstanceForType(DescriptorModelFactory.Classifier.qualifiedType);
91 return this.classifier = DescriptorModelFactory.newClassifier(model, this);
92 }
93
94 removeClassifier(child) {
95 return this.removeModelListItem('classifier', child);
96 }
97
98 remove() {
99 if (this.parent) {
100 return this.parent.removeVnffgd(this);
101 }
102 }
103
104 getColor() {
105
106 }
107
108 createClassifierForRecordServicePath(rsp) {
109 const classifier = this.createClassifier();
110 classifier.model['rsp-id-ref'] = rsp.id;
111 }
112
113 removeVnfdConnectionPointRefForVnfdIndex(vnfdIndex) {
114 this.rsp.forEach(rsp => rsp.removeVnfdConnectionPointRefForVnfdIndex(vnfdIndex));
115 }
116
117 }
118