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',
20 function getPathForType(type
) {
21 if (exportInnerTypesMap
[type
]) {
22 return exportInnerTypesMap
[type
];
27 let modelMetaByPropertyNameMap
= [];
29 let cachedDescriptorModelMetaRequest
= null;
33 if (!cachedDescriptorModelMetaRequest
) {
34 cachedDescriptorModelMetaRequest
= new Promise(function(resolve
, reject
) {
35 CommonUtils
.getDescriptorModelMeta().then(function(data
) {
36 let DescriptorModelMetaJSON
= data
;
37 modelMetaByPropertyNameMap
= Object
.keys(DescriptorModelMetaJSON
).reduce((map
, key
) => {
38 function mapProperties(parentMap
, parentObj
) {
39 parentMap
[':meta'] = parentObj
;
40 const properties
= parentObj
&& parentObj
.properties
? parentObj
.properties
: [];
41 properties
.forEach(p
=> {
42 parentMap
[p
.name
] = mapProperties({}, assign(p
, {':qualified-type': parentObj
[':qualified-type'] + '.' + p
.name
}));
47 map
[key
] = mapProperties({}, assign(DescriptorModelMetaJSON
[key
], {':qualified-type': key
}));
52 // initialize the UI centric properties that CONFD could care less about
53 utils
.assignPathValue(modelMetaByPropertyNameMap
, 'nsd.meta.:meta.preserve-line-breaks', true);
54 utils
.assignPathValue(modelMetaByPropertyNameMap
, 'vnfd.meta.:meta.preserve-line-breaks', true);
55 utils
.assignPathValue(modelMetaByPropertyNameMap
, 'vnfd.vdu.cloud-init.:meta.preserve-line-breaks', true);
56 utils
.assignPathValue(modelMetaByPropertyNameMap
, 'nsd.constituent-vnfd.vnf-configuration.config-template.:meta.preserve-line-breaks', true);
60 cachedDescriptorModelMetaRequest
= null;
65 return cachedDescriptorModelMetaRequest
;
67 createModelInstanceForType(typeOrPath
) {
68 const modelMeta
= this.getModelMetaForType(typeOrPath
);
69 return DescriptorModelMetaProperty
.createModelInstance(modelMeta
);
71 getModelMetaForType(typeOrPath
, filterProperties
= () => true) {
72 // resolve paths like 'nsd' or 'vnfd.vdu' or 'nsd.constituent-vnfd'
73 const found
= utils
.resolvePath(modelMetaByPropertyNameMap
, getPathForType(typeOrPath
));
75 const uiState
= _
.cloneDeep(found
[':meta']);
76 uiState
.properties
= uiState
.properties
.filter(filterProperties
);
79 console
.warn('no model uiState found for type', typeOrPath
);
81 getModelFieldNamesForType(typeOrPath
) {
82 // resolve paths like 'nsd' or 'vnfd.vdu' or 'nsd.constituent-vnfd'
83 const found
= utils
.resolvePath(modelMetaByPropertyNameMap
, getPathForType(typeOrPath
));
86 found
[':meta'].properties
.map((p
) => {
88 if(p
.type
== 'choice') {
90 return p
.properties
.map(function(q
){
91 result
.push(q
.properties
[0].name
);
95 return result
.push(p
.name
);
100 console
.warn('no model uiState found for type', typeOrPath
);