|
6 | 6 | import xmltodict |
7 | 7 | import pkg_resources |
8 | 8 | import importlib |
| 9 | +import json |
| 10 | +from dc_schema import get_schema |
9 | 11 |
|
10 | 12 | class _Utils(): |
11 | 13 | @staticmethod |
@@ -33,6 +35,33 @@ def setup(path:str = None): |
33 | 35 | if path: |
34 | 36 | _Utils.raise_on_error(iris.cls('%SYSTEM.OBJ').LoadDir(path,'cubk',"*.cls",1)) |
35 | 37 |
|
| 38 | + @staticmethod |
| 39 | + def register_message_schema(cls): |
| 40 | + """ |
| 41 | + It takes a class and registers the schema |
| 42 | + |
| 43 | + :param cls: The class to register |
| 44 | + """ |
| 45 | + schema = get_schema(cls) |
| 46 | + schema_name = cls.__module__ + '.' + cls.__name__ |
| 47 | + schema_str = json.dumps(schema) |
| 48 | + categories = schema_name |
| 49 | + _Utils.register_schema(schema_name,schema_str,categories) |
| 50 | + |
| 51 | + @staticmethod |
| 52 | + def register_schema(schema_name:str, schema_str:str,categories:str): |
| 53 | + """ |
| 54 | + It takes a schema name, a schema string, and a category string, and registers the schema |
| 55 | + |
| 56 | + :param schema_name: The name of the schema |
| 57 | + :type schema_name: str |
| 58 | + :param schema_str: The schema as a string |
| 59 | + :type schema_str: str |
| 60 | + :param categories: The categories of the schema |
| 61 | + :type categories: str |
| 62 | + """ |
| 63 | + _Utils.raise_on_error(iris.cls('IOP.Message.JSONSchema').Import(schema_str,categories,schema_name)) |
| 64 | + |
36 | 65 | @staticmethod |
37 | 66 | def register_component(module:str,classname:str,path:str,overwrite:int=1,iris_classname:str='Python'): |
38 | 67 | """ |
@@ -128,7 +157,7 @@ def _register_file(filename:str,path:str,overwrite:int=1,iris_package_name:str=' |
128 | 157 | extend = klass.bases[0].id |
129 | 158 | else: |
130 | 159 | extend = klass.bases[0].attr |
131 | | - if extend in ('BusinessOperation','BusinessProcess','BusinessService','DuplexService','DuplexProcess','DuplexOperation','InboundAdapter','OutboundAdapter'): |
| 160 | + if extend in ('BusinessOperation','BusinessProcess','BusinessService','DuplexService','DuplexProcess','DuplexOperation','InboundAdapter','OutboundAdapter'): |
132 | 161 | module = _Utils.filename_to_module(filename) |
133 | 162 | iris_class_name = f"{iris_package_name}.{module}.{klass.name}" |
134 | 163 | # strip "_" for iris class name |
@@ -188,6 +217,8 @@ def migrate(filename=None): |
188 | 217 | list of dictionaries: |
189 | 218 | * key: the name of the production |
190 | 219 | * value: a dictionary containing the settings for the production |
| 220 | + * SCHEMAS |
| 221 | + List of classes |
191 | 222 | """ |
192 | 223 | path = None |
193 | 224 | # try to load the settings file |
@@ -216,6 +247,12 @@ def migrate(filename=None): |
216 | 247 | _Utils.set_productions_settings(settings.PRODUCTIONS,path) |
217 | 248 | except AttributeError: |
218 | 249 | print("No productions to register") |
| 250 | + try: |
| 251 | + # set the schemas |
| 252 | + for cls in settings.SCHEMAS: |
| 253 | + _Utils.register_message_schema(cls) |
| 254 | + except AttributeError: |
| 255 | + print("No schemas to register") |
219 | 256 | try: |
220 | 257 | sys.path.remove(path) |
221 | 258 | except ValueError: |
|
0 commit comments