2 * Created by onvelocity on 1/27/16.
4 * This class provides methods to get the metadata about descriptor models.
10 import utils
from './../utils'
11 import DescriptorModelMetaProperty
from './DescriptorModelMetaProperty'
12 import CommonUtils
from 'utils/utils';
13 const assign
= Object
.assign
;
15 const exportInnerTypesMap
= {
16 'constituent-vnfd': 'nsd.constituent-vnfd',
17 'config-parameter-map': 'nsd.config-parameter-map',
21 function getPathForType(type
) {
22 if (exportInnerTypesMap
[type
]) {
23 return exportInnerTypesMap
[type
];
28 let modelMetaByPropertyNameMap
= [];
30 let cachedDescriptorModelMetaRequest
= null;
34 if (!cachedDescriptorModelMetaRequest
) {
35 cachedDescriptorModelMetaRequest
= new Promise(function(resolve
, reject
) {
36 CommonUtils
.getDescriptorModelMeta().then(function(data
) {
37 let DescriptorModelMetaJSON
= data
;
38 modelMetaByPropertyNameMap
= Object
.keys(DescriptorModelMetaJSON
).reduce((map
, key
) => {
39 function mapProperties(parentMap
, parentObj
) {
40 parentMap
[':meta'] = parentObj
;
41 const properties
= parentObj
&& parentObj
.properties
? parentObj
.properties
: [];
42 properties
.forEach(p
=> {
43 parentMap
[p
.name
] = mapProperties({}, assign(p
, {':qualified-type': parentObj
[':qualified-type'] + '.' + p
.name
}));
48 map
[key
] = mapProperties({}, assign(DescriptorModelMetaJSON
[key
], {':qualified-type': key
}));
53 // initialize the UI centric properties that CONFD could care less about
54 utils
.assignPathValue(modelMetaByPropertyNameMap
, 'nsd.meta.:meta.preserve-line-breaks', true);
55 utils
.assignPathValue(modelMetaByPropertyNameMap
, 'vnfd.meta.:meta.preserve-line-breaks', true);
56 utils
.assignPathValue(modelMetaByPropertyNameMap
, 'vnfd.vdu.cloud-init.:meta.preserve-line-breaks', true);
57 utils
.assignPathValue(modelMetaByPropertyNameMap
, 'nsd.constituent-vnfd.vnf-configuration.config-template.:meta.preserve-line-breaks', true);
61 cachedDescriptorModelMetaRequest
= null;
66 return cachedDescriptorModelMetaRequest
;
68 createModelInstanceForType(typeOrPath
) {
69 const modelMeta
= this.getModelMetaForType(typeOrPath
);
70 return DescriptorModelMetaProperty
.createModelInstance(modelMeta
);
72 getModelMetaForType(typeOrPath
, filterProperties
= () => true) {
73 // resolve paths like 'nsd' or 'vnfd.vdu' or 'nsd.constituent-vnfd'
74 const found
= utils
.resolvePath(modelMetaByPropertyNameMap
, getPathForType(typeOrPath
));
76 const uiState
= _
.cloneDeep(found
[':meta']);
77 uiState
.properties
= uiState
.properties
.filter(filterProperties
);
80 console
.warn('no model uiState found for type', typeOrPath
);
82 getModelFieldNamesForType(typeOrPath
) {
83 // resolve paths like 'nsd' or 'vnfd.vdu' or 'nsd.constituent-vnfd'
84 const found
= utils
.resolvePath(modelMetaByPropertyNameMap
, getPathForType(typeOrPath
));
87 found
[':meta'].properties
.map((p
) => {
89 if(p
.type
== 'choice') {
91 return p
.properties
.map(function(q
){
92 result
.push(q
.properties
[0].name
);
96 return result
.push(p
.name
);
101 console
.warn('no model uiState found for type', typeOrPath
);