Skip to content

Commit 91c46e7

Browse files
committed
[WIP] improved zgw importing
1 parent 90fe8b2 commit 91c46e7

File tree

5 files changed

+3589
-1033
lines changed

5 files changed

+3589
-1033
lines changed

src/open_inwoner/openzaak/management/commands/zgw_import_data.py

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,28 @@
22

33
from open_inwoner.openzaak.models import ZGWApiGroupConfig
44
from open_inwoner.openzaak.zgw_imports import (
5-
import_catalog_configs,
6-
import_zaaktype_configs,
7-
import_zaaktype_informatieobjecttype_configs,
8-
import_zaaktype_resultaattype_configs,
9-
import_zaaktype_statustype_configs,
5+
ZGWCatalogusImporter,
106
)
117

128

139
class Command(BaseCommand):
1410
help = "Import ZGW catalog data"
1511

16-
def log_supplement_imports_to_stdout(
17-
self, import_func: callable, config_type: str
18-
) -> None:
19-
"""
20-
Convenience function for logging zaaktype config types to stdout
21-
22-
Example input:
23-
import_func=import_zaaktype_informatieobjecttype_configs
24-
config_type="informatiebjecttype"
25-
26-
Example output:
27-
imported 3 new zaaktype-informatiebjecttype configs
28-
AAA - zaaktype-aaa
29-
info-aaa-1
30-
info-aaa-2
31-
BBB - zaaktype-bbb
32-
info-bbb
33-
"""
34-
imported = import_func()
35-
36-
count = sum(len(t[1]) for t in imported)
37-
self.stdout.write(f"imported {count} new zaaktype-{config_type} configs")
38-
39-
for ztc, config_types in sorted(imported, key=lambda t: str(t[0])):
40-
self.stdout.write(str(ztc))
41-
for c in sorted(map(str, config_types)):
42-
self.stdout.write(f" {c}")
43-
44-
self.stdout.write("")
45-
4612
def handle(self, *args, **options):
47-
if ZGWApiGroupConfig.objects.count() == 0:
13+
if not ZGWApiGroupConfig.objects.exists():
4814
self.stdout.write(
4915
"Please define at least one ZGWApiGroupConfig before running this command."
5016
)
5117
return
5218

53-
# catalogus config
54-
imported = import_catalog_configs()
55-
56-
self.stdout.write(f"imported {len(imported)} new catalogus configs")
57-
for c in sorted(map(str, imported)):
58-
self.stdout.write(c)
59-
60-
self.stdout.write("")
61-
62-
# zaaktype config
63-
imported = import_zaaktype_configs()
64-
65-
self.stdout.write(f"imported {len(imported)} new zaaktype configs")
66-
for c in sorted(map(str, imported)):
67-
self.stdout.write(c)
19+
importers = [
20+
ZGWCatalogusImporter(api_group)
21+
for api_group in ZGWApiGroupConfig.objects.all()
22+
]
6823

69-
self.stdout.write("")
24+
output = ""
25+
for importer in importers:
26+
result = importer.import_all()
27+
output = output + result.pretty_print() + "\n"
7028

71-
# supplemental configs
72-
self.log_supplement_imports_to_stdout(
73-
import_zaaktype_informatieobjecttype_configs, "informatiebjecttype"
74-
)
75-
self.log_supplement_imports_to_stdout(
76-
import_zaaktype_statustype_configs, "statustype"
77-
)
78-
self.log_supplement_imports_to_stdout(
79-
import_zaaktype_resultaattype_configs, "resultaattype"
80-
)
29+
self.stdout.write(output)

0 commit comments

Comments
 (0)