Add new code new version
[sdc.git] / dox-sequence-diagram-ui / src / main / webapp / lib / ecomp / asdc / sequencer / model / Metamodel.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16
17 import _merge from 'lodash/merge';
18
19 import Common from '../common/Common';
20
21 /**
22  * Rules governing what a definition can contain.
23  */
24 export default class Metamodel {
25
26   // ///////////////////////////////////////////////////////////////////////////////////////////////
27
28   /**
29    * Construct from JSON definition.
30    * @param json schema definition.
31    */
32   constructor(json) {
33     Common.assertType(json, 'Object');
34     const dfault = require('./templates/default.metamodel.json');
35     this.json = _merge({}, dfault, json);
36   }
37
38   // ///////////////////////////////////////////////////////////////////////////////////////////////
39
40   /**
41    * Get schema identifier.
42    * @returns ID.
43    */
44   getId() {
45     return this.json.diagram.metadata.id;
46   }
47
48   // ///////////////////////////////////////////////////////////////////////////////////////////////
49
50   /**
51    * Get lifeline constraints.
52    * @returns {*}
53    */
54   getConstraints() {
55     return this.json.diagram.lifelines.constraints;
56   }
57
58   // ///////////////////////////////////////////////////////////////////////////////////////////////
59
60   /**
61    * Get lifeline metadata by lifeline ID.
62    * @param id sought lifeline.
63    * @returns lifeline if found.
64    */
65   getLifelineById(id) {
66     for (const lifeline of this.json.diagram.lifelines.lifelines) {
67       if (lifeline.id === id) {
68         return lifeline;
69       }
70     }
71     return undefined;
72   }
73
74   // ///////////////////////////////////////////////////////////////////////////////////////////////
75
76   /**
77    * Get original JSON.
78    * @returns JSON.
79    */
80   unwrap() {
81     return this.json;
82   }
83
84   // ///////////////////////////////////////////////////////////////////////////////////////////////
85
86   /**
87    * Get default schema.
88    * @returns Metamodel default (permissive) Metamodel.
89    */
90   static getDefault() {
91     return new Metamodel({});
92   }
93
94 }