|
| 1 | +# DTL Support |
| 2 | + |
| 3 | +Starting with version 3.2.0, IoP supports DTL transformations. |
| 4 | +DTL the Data Transformation Layer in IRIS Interoperability. |
| 5 | +DTL transformations are used to transform data from one format to another with a graphical editor. |
| 6 | +It supports also `jsonschema` structures. |
| 7 | + |
| 8 | +## How to use DTL in with Message |
| 9 | + |
| 10 | +First you need to register you message class is a `settings.py` file. |
| 11 | + |
| 12 | +To do so, you need to add the following line in the `settings.py` file: |
| 13 | + |
| 14 | +`settings.py` |
| 15 | +``` |
| 16 | +from msg import MyMessage |
| 17 | +
|
| 18 | +SCHEMAS = [MyMessage] |
| 19 | +``` |
| 20 | + |
| 21 | +Then you can use iop migration command to generate schema files for your message classes. |
| 22 | + |
| 23 | +```bash |
| 24 | +iop --migrate /path/to/your/project/settings.py |
| 25 | +``` |
| 26 | + |
| 27 | +### Example |
| 28 | + |
| 29 | +`msg.py` |
| 30 | +```python |
| 31 | +from iop import Message |
| 32 | +from dataclasses import dataclass |
| 33 | + |
| 34 | +@dataclass |
| 35 | +class MyMessage(Message): |
| 36 | + name: str = None |
| 37 | + age: int = None |
| 38 | +``` |
| 39 | + |
| 40 | +`settings.py` |
| 41 | +```python |
| 42 | +from msg import MyMessage |
| 43 | + |
| 44 | +SCHEMAS = [MyMessage] |
| 45 | +``` |
| 46 | + |
| 47 | +Migrate the schema files |
| 48 | +```bash |
| 49 | +iop --migrate /path/to/your/project/settings.py |
| 50 | +``` |
| 51 | + |
| 52 | +## Building a DTL Transformation |
| 53 | + |
| 54 | +To build a DTL transformation, you need to create a new DTL transformation class. |
| 55 | + |
| 56 | +Go to the IRIS Interoperability Management Portal and create a new DTL transformation. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +Then select the source and target message classes. |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +And it's schema. |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +Then you can start building your transformation. |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +You can even test your transformation. |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +Example of payload to test as a source message: |
| 77 | + |
| 78 | +```xml |
| 79 | +<test> |
| 80 | + <Message> |
| 81 | + <json><![CDATA[ |
| 82 | +{ |
| 83 | +"list_str":["toto","titi"], |
| 84 | +"post":{"Title":"foo","Selftext":"baz"}, |
| 85 | +"list_post":[{"Title":"bar","Selftext":"baz"},{"Title":"foo","Selftext":"foo"}] |
| 86 | +} |
| 87 | +]]></json> |
| 88 | + </Message> |
| 89 | +</test> |
| 90 | +``` |
| 91 | + |
| 92 | +## JsonSchema Support |
| 93 | + |
| 94 | +Starting with version 3.2.0, IoP supports `jsonschema` structures for DTL transformations. |
| 95 | + |
| 96 | +Same as for message classes, you need to register your `jsonschema`. |
| 97 | +To do so, you need to invoke his iris command: |
| 98 | + |
| 99 | +```objectscript |
| 100 | +zw ##class(IOP.Message.JSONSchema).ImportFromFile("/irisdev/app/random_jsonschema.json","Demo","Demo") |
| 101 | +``` |
| 102 | + |
| 103 | +Where the first argument is the path to the jsonschema file, the second argument is the package name and the third argument is the name of the schema. |
| 104 | + |
| 105 | +Then you can use it in your DTL transformation. |
| 106 | +The schema will be available in the name of `Demo`. |
0 commit comments