2 # -*- coding: utf-8 -*-
4 # COPYRIGHT NOTICE STARTS HERE
6 # Copyright 2020 . Samsung Electronics Co., Ltd.
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
20 # COPYRIGHT NOTICE ENDS HERE
27 # Script to convert given Enriched CDS CBA model to Data Dictionary output
29 # ./cba2dd.py --cba_dir <path to cba main directory> | python3 -m json.tool
32 def get_resources_definition_file(cba_dir):
33 definitions_dir = cba_dir + os.sep + "Definitions"
34 resource_definition_file = definitions_dir + os.sep + "resources_definition_types.json"
35 if not os.path.exists(definitions_dir):
36 raise RuntimeError("'%s' directory does not exists or is not CBA directory" % cba_dir)
37 if not os.path.exists(resource_definition_file):
38 raise RuntimeError("'%s' file does not exists in CBA Definitions directory. CBA is not Enriched!" % resource_definition_file)
39 return resource_definition_file
41 def create_dd(cba_dir):
42 with open(get_resources_definition_file(cba_dir)) as f:
43 output_json = json.load(f)
45 for _, entry in output_json.items():
46 dd.append(build_dd_entry(entry))
49 def build_dd_entry(definition_entry):
50 """Builds Data Dictionary entry from given dictionary entry. Given entry
51 itself is added as value for "definition" key.
59 "definition": definition_entry
63 out_dict["name"] = definition_entry["name"]
64 out_dict["tags"] = definition_entry["tags"]
65 out_dict["data_type"] = definition_entry["property"]["type"]
66 out_dict["description"] = definition_entry["property"]["description"]
67 out_dict["entry_schema"] = definition_entry["property"]["type"]
68 out_dict["updatedBy"] = definition_entry["updated-by"]
69 out_dict["definition"] = definition_entry
73 description = """Script to convert given Enriched CDS CBA model to Data Dictionary output.
75 ./cba2dd.py --cba_dir cba | python3 -m json.tool
77 parser = argparse.ArgumentParser(description=description,
78 formatter_class=argparse.RawTextHelpFormatter)
79 parser.add_argument('--cba_dir',
80 help='Path to CDS CBA model main directory',
82 args = parser.parse_args()
84 create_dd(args.cba_dir)
85 except Exception as e:
90 if __name__ == '__main__':