From 6b3289d92e806f301fef27a978c46b27de67db77 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Wed, 28 Feb 2024 13:40:58 +0100
Subject: [PATCH] wip

---
 .../table_json_conversion/fill_xlsx.py        |  7 +-
 .../create_jsonschema.py                      |  9 +-
 .../table_json_conversion/model_schema.json   | 96 ++++++++++++-------
 3 files changed, 72 insertions(+), 40 deletions(-)

diff --git a/src/caosadvancedtools/table_json_conversion/fill_xlsx.py b/src/caosadvancedtools/table_json_conversion/fill_xlsx.py
index b9e1a93f..3b22f1f9 100644
--- a/src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+++ b/src/caosadvancedtools/table_json_conversion/fill_xlsx.py
@@ -31,7 +31,8 @@ def _fill_leaves(json_doc: dict, workbook):
         for el in value:
             if isinstance(el, dict):
                 _fill_leaves(el, workbook)
-            wb.cell(1,2, el)
+            wb.cell(1, 2, el)
+
 
 def _get_row_type_column(worksheet):
     for col in worksheet.columns:
@@ -40,6 +41,7 @@ def _get_row_type_column(worksheet):
                 return cell.column
     raise ValueError("The column which defines row types (COL_TYPE, PATH, ...) is missing")
 
+
 def _get_path_rows(worksheet):
     rows = []
     rt_col = _get_row_type_column(worksheet)
@@ -50,7 +52,6 @@ def _get_path_rows(worksheet):
     return rows
 
 
-
 def _generate_path_col_mapping(workbook):
     rt_col = _get_row_type_column(workbook)
 
@@ -58,7 +59,7 @@ def _generate_path_col_mapping(workbook):
         pass
 
 
-def fill_template(template_path: str, json_path: str, result_path: str)-> None:
+def fill_template(template_path: str, json_path: str, result_path: str) -> None:
     """
     Fill the contents of the JSON document stored at ``json_path`` into the template stored at
     ``template_path`` and store the result under ``result_path``.
diff --git a/unittests/table_json_conversion/create_jsonschema.py b/unittests/table_json_conversion/create_jsonschema.py
index 8e122718..6f556863 100755
--- a/unittests/table_json_conversion/create_jsonschema.py
+++ b/unittests/table_json_conversion/create_jsonschema.py
@@ -30,15 +30,16 @@ import tomli
 
 # TODO why do I need a running LA instance?
 
+
 def prepare_datamodel():
     model = parser.parse_model_from_yaml("./model.yml")
 
     exporter = jsex.JsonSchemaExporter(additional_properties=False,
-                                       #additional_options_for_text_props=additional_text_options,
-                                       #name_and_description_in_properties=True,
+                                       # additional_options_for_text_props=additional_text_options,
+                                       # name_and_description_in_properties=True,
                                        name_property_for_new_records=True,
-                                       #do_not_create=do_not_create,
-                                       #do_not_retrieve=do_not_retrieve,
+                                       do_not_create=["Organisation"],
+                                       # do_not_retrieve=do_not_retrieve,
                                        )
     schema_top = exporter.recordtype_to_json_schema(model.get_deep("Training"))
     schema_pers = exporter.recordtype_to_json_schema(model.get_deep("Person"))
diff --git a/unittests/table_json_conversion/model_schema.json b/unittests/table_json_conversion/model_schema.json
index 4be94811..6b27c8b6 100644
--- a/unittests/table_json_conversion/model_schema.json
+++ b/unittests/table_json_conversion/model_schema.json
@@ -53,19 +53,29 @@
                 "type": "string"
               },
               "Organisation": {
-                "type": "object",
-                "required": [],
-                "additionalProperties": false,
-                "title": "Organisation",
-                "properties": {
-                  "name": {
-                    "type": "string",
-                    "description": "The name of the Record to be created"
+                "oneOf": [
+                  {
+                    "title": "Existing entries",
+                    "enum": [
+                      "Federal Reserve"
+                    ]
                   },
-                  "Country": {
-                    "type": "string"
+                  {
+                    "type": "object",
+                    "required": [],
+                    "additionalProperties": false,
+                    "title": "Create new",
+                    "properties": {
+                      "name": {
+                        "type": "string",
+                        "description": "The name of the Record to be created"
+                      },
+                      "Country": {
+                        "type": "string"
+                      }
+                    }
                   }
-                }
+                ]
               }
             }
           }
@@ -87,19 +97,29 @@
               "type": "string"
             },
             "Organisation": {
-              "type": "object",
-              "required": [],
-              "additionalProperties": false,
-              "title": "Organisation",
-              "properties": {
-                "name": {
-                  "type": "string",
-                  "description": "The name of the Record to be created"
+              "oneOf": [
+                {
+                  "title": "Existing entries",
+                  "enum": [
+                    "Federal Reserve"
+                  ]
                 },
-                "Country": {
-                  "type": "string"
+                {
+                  "type": "object",
+                  "required": [],
+                  "additionalProperties": false,
+                  "title": "Create new",
+                  "properties": {
+                    "name": {
+                      "type": "string",
+                      "description": "The name of the Record to be created"
+                    },
+                    "Country": {
+                      "type": "string"
+                    }
+                  }
                 }
-              }
+              ]
             }
           }
         },
@@ -132,19 +152,29 @@
           "type": "string"
         },
         "Organisation": {
-          "type": "object",
-          "required": [],
-          "additionalProperties": false,
-          "title": "Organisation",
-          "properties": {
-            "name": {
-              "type": "string",
-              "description": "The name of the Record to be created"
+          "oneOf": [
+            {
+              "title": "Existing entries",
+              "enum": [
+                "Federal Reserve"
+              ]
             },
-            "Country": {
-              "type": "string"
+            {
+              "type": "object",
+              "required": [],
+              "additionalProperties": false,
+              "title": "Create new",
+              "properties": {
+                "name": {
+                  "type": "string",
+                  "description": "The name of the Record to be created"
+                },
+                "Country": {
+                  "type": "string"
+                }
+              }
             }
-          }
+          ]
         }
       },
       "$schema": "https://json-schema.org/draft/2020-12/schema"
-- 
GitLab