Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / descriptors / Classifier.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 Position from '../../graph/Position'
25 import DescriptorModel from '../DescriptorModel'
26 import DescriptorModelFactory from '../DescriptorModelFactory'
27 import DescriptorModelMetaFactory from '../DescriptorModelMetaFactory'
28 import ClassifierConnectionPointRef from './ClassifierConnectionPointRef'
29
30 /**
31 * A VirtualNetworkFunctionConnectionPoint is always a child of a VNFD. We use it to build VnfdConnectionPointRef instances. So convenience
32 * methods are add to access the fields needed to do that.
33 */
34 export default class Classifier extends DescriptorModel {
35
36 static get type() {
37 return 'classifier';
38 }
39
40 static get className() {
41 return 'Classifier';
42 }
43
44 static get qualifiedType() {
45 return 'nsd.vnffgd.' + Classifier.type;
46 }
47
48 constructor(model, parent) {
49 super(model, parent);
50 this.type = Classifier.type;
51 this.uiState['qualified-type'] = Classifier.qualifiedType;
52 this.className = Classifier.className;
53 this.position = new Position();
54 this._vnfdConnectionPointRef = new ClassifierConnectionPointRef(this);
55 }
56
57 get matchAttributes() {
58 if (!this.model['match-attributes']) {
59 this.model['match-attributes'] = {};
60 }
61 return this.model['match-attributes'].map(d => DescriptorModelFactory.newClassifierMatchAttributes(d, this));
62 }
63
64 set matchAttributes(obj) {
65 return this.updateModelList('match-attributes', obj, DescriptorModelFactory.ClassifierMatchAttributes);
66 }
67
68 createMatchAttributes() {
69 const model = DescriptorModelMetaFactory.createModelInstanceForType(DescriptorModelFactory.ClassifierMatchAttributes.qualifiedType);
70 return this.matchAttributes = DescriptorModelFactory.newClassifierMatchAttributes(model, this);
71 }
72
73 removeMatchAttributes(matchAttributes) {
74 return this.removeModelListItem('matchAttributes', matchAttributes);
75 }
76
77 get vnfdConnectionPointRef() {
78 return this._vnfdConnectionPointRef || {};
79 }
80
81 // vnfdConnectionPointRef is read only by design
82
83 addVnfdConnectionPoint(cp) {
84 this.vnfdConnectionPointRef.vnfdRef = cp.parent.vnfdRef;
85 this.vnfdConnectionPointRef.vnfdId = cp.vnfdId;
86 this.vnfdConnectionPointRef.vnfdIndex = cp.vnfdIndex;
87 this.vnfdConnectionPointRef.vnfdConnectionPointName = cp.name;
88 this.vnfdConnectionPointRef.cpNumber = cp.cpNumber;
89 }
90
91 remove() {
92 return this.parent.removeClassifier(this);
93 }
94
95 }