6
6
from zgw_consumers .concurrent import parallel
7
7
8
8
from .api_models import Zaak
9
- from .clients import (
10
- CatalogiClient ,
11
- ZakenClient ,
12
- build_catalogi_client ,
13
- build_zaken_client ,
14
- )
15
- from .models import ZaakTypeConfig , ZaakTypeStatusTypeConfig
9
+ from .clients import CatalogiClient , ZakenClient
10
+ from .models import ZaakTypeConfig , ZaakTypeStatusTypeConfig , ZGWApiGroupConfig
16
11
from .utils import is_zaak_visible
17
12
18
13
logger = logging .getLogger (__name__ )
19
14
20
15
21
- def resolve_zaak_type (case : Zaak , client : CatalogiClient | None = None ) -> None :
16
+ def resolve_zaak_type (case : Zaak , client : CatalogiClient ) -> None :
22
17
"""
23
18
Resolve `case.zaaktype` (`str`) to a `ZaakType(ZGWModel)` object
24
19
25
20
Note: the result of `fetch_single_case_type` is cached, hence a request
26
21
is only made for new case type urls
27
22
"""
28
23
case_type_url = case .zaaktype
29
- client = client or build_catalogi_client ()
30
24
if client :
31
25
case_type = client .fetch_single_case_type (case_type_url )
32
26
case .zaaktype = case_type
@@ -36,7 +30,6 @@ def resolve_status(case: Zaak, client: ZakenClient | None = None) -> None:
36
30
"""
37
31
Resolve `case.status` (`str`) to a `Status(ZGWModel)` object
38
32
"""
39
- client = client or build_zaken_client ()
40
33
if client :
41
34
case .status = client .fetch_single_status (case .status )
42
35
@@ -46,7 +39,6 @@ def resolve_status_type(case: Zaak, client: CatalogiClient | None = None) -> Non
46
39
Resolve `case.status.statustype` (`str`) to a `StatusType(ZGWModel)` object
47
40
"""
48
41
statustype_url = case .status .statustype
49
- client = client or build_catalogi_client ()
50
42
if client :
51
43
case .status .statustype = client .fetch_single_status_type (statustype_url )
52
44
@@ -55,16 +47,14 @@ def resolve_resultaat(case: Zaak, client: ZakenClient | None = None) -> None:
55
47
"""
56
48
Resolve `case.resultaat` (`str`) to a `Resultaat(ZGWModel)` object
57
49
"""
58
- client = client or build_zaken_client ()
59
- if client and case .resultaat :
50
+ if case .resultaat :
60
51
case .resultaat = client .fetch_single_result (case .resultaat )
61
52
62
53
63
54
def resolve_resultaat_type (case : Zaak , client : CatalogiClient | None = None ) -> None :
64
55
"""
65
56
Resolve `case.resultaat.resultaattype` (`str`) to a `ResultaatType(ZGWModel)` object
66
57
"""
67
- client = client or build_catalogi_client ()
68
58
if client and case .resultaat :
69
59
case .resultaat .resultaattype = client .fetch_single_resultaat_type (
70
60
case .resultaat .resultaattype
@@ -102,30 +92,28 @@ def add_status_type_config(case: Zaak) -> None:
102
92
pass
103
93
104
94
105
- def preprocess_data (cases : list [Zaak ]) -> list [Zaak ]:
95
+ def preprocess_data (cases : list [Zaak ], group : ZGWApiGroupConfig ) -> list [Zaak ]:
106
96
"""
107
97
Resolve zaaktype and statustype, add status type config, filter for visibility
108
98
109
99
Note: we need to iterate twice over `cases` because the `zaak_type` must be
110
100
resolved to a `ZaakType` object before we can filter by visibility
111
101
"""
112
- zaken_client = build_zaken_client ()
113
- catalogi_client = build_catalogi_client ()
114
102
115
103
def preprocess_case (case : Zaak ) -> None :
116
- resolve_status (case , client = zaken_client )
117
- resolve_status_type (case , client = catalogi_client )
118
- resolve_resultaat (case , client = zaken_client )
119
- resolve_resultaat_type (case , client = catalogi_client )
104
+ resolve_status (case , client = group . zaken_client )
105
+ resolve_status_type (case , client = group . catalogi_client )
106
+ resolve_resultaat (case , client = group . zaken_client )
107
+ resolve_resultaat_type (case , client = group . catalogi_client )
120
108
add_zaak_type_config (case )
121
109
add_status_type_config (case )
122
110
123
111
# TODO error handling if these are none?
124
112
# use contextmanager to ensure the `requests.Session` is reused
125
- with zaken_client , catalogi_client :
113
+ with group . catalogi_client , group . zaken_client :
126
114
with parallel (max_workers = settings .CASE_LIST_NUM_THREADS ) as executor :
127
115
futures = [
128
- executor .submit (resolve_zaak_type , case , client = catalogi_client )
116
+ executor .submit (resolve_zaak_type , case , client = group . catalogi_client )
129
117
for case in cases
130
118
]
131
119
concurrent .futures .wait (futures )
0 commit comments