10
10
11
11
from ..constants import RegistrationAttribute
12
12
from ..registry import register
13
- from .filters import ListInformatieObjectTypenQueryParamsSerializer
13
+ from .filters import (
14
+ APIGroupQueryParamsSerializer ,
15
+ ListInformatieObjectTypenQueryParamsSerializer ,
16
+ )
14
17
from .serializers import (
18
+ CatalogusDomainSerializer ,
15
19
ChoiceWrapper ,
16
20
InformatieObjectTypeChoiceSerializer ,
17
21
RegistrationAttributeSerializer ,
@@ -56,6 +60,35 @@ def get_objects(self):
56
60
return [ChoiceWrapper (choice ) for choice in choices ]
57
61
58
62
63
+ @extend_schema_view (
64
+ get = extend_schema (
65
+ summary = _ ("List available Catalogus" ),
66
+ parameters = [APIGroupQueryParamsSerializer ],
67
+ ),
68
+ )
69
+ class CatalogusListView (ListMixin , APIView ):
70
+ """
71
+ List the available Catalogus based on the provided API group.
72
+ """
73
+
74
+ authentication_classes = (authentication .SessionAuthentication ,)
75
+ permission_classes = (permissions .IsAdminUser ,)
76
+ serializer_class = CatalogusDomainSerializer
77
+
78
+ def get_objects (self ):
79
+ filter_serializer = APIGroupQueryParamsSerializer (
80
+ data = self .request .query_params
81
+ )
82
+ filter_serializer .is_valid (raise_exception = True )
83
+
84
+ client = filter_serializer .get_ztc_client ()
85
+ if not client :
86
+ return []
87
+
88
+ catalogus_data = client .get_all_catalogi ()
89
+ return factory (Catalogus , catalogus_data )
90
+
91
+
59
92
@extend_schema_view (
60
93
get = extend_schema (
61
94
summary = _ ("List available InformatieObjectTypen" ),
@@ -65,6 +98,10 @@ def get_objects(self):
65
98
class InformatieObjectTypenListView (ListMixin , APIView ):
66
99
"""
67
100
List the available InformatieObjectTypen based on the configured registration backend and ZGW APIs services.
101
+
102
+ Each InformatieObjectType is uniquely identified by its 'omschrijving', 'catalogus',
103
+ and beginning and end date. If multiple same InformatieObjectTypen exist for different dates,
104
+ only one entry is returned.
68
105
"""
69
106
70
107
authentication_classes = (authentication .SessionAuthentication ,)
@@ -86,13 +123,48 @@ def get_objects(self):
86
123
catalogus ["url" ]: catalogus for catalogus in catalogus_data
87
124
}
88
125
89
- iotypen_data = client .get_all_informatieobjecttypen ()
90
- iotypen = [
91
- {
92
- "informatieobjecttype" : factory (InformatieObjectType , iotype ),
93
- "catalogus" : factory (Catalogus , catalogus_mapping [iotype ["catalogus" ]]),
94
- }
95
- for iotype in iotypen_data
96
- ]
126
+ if "catalogus_domein" in filter_serializer .validated_data :
127
+ domein = filter_serializer .validated_data ["catalogus_domein" ]
128
+ # `catalogus_rsin` is guaranteed to be present if `catalogus_domein` is:
129
+ rsin = filter_serializer .validated_data ["catalogus_rsin" ]
130
+
131
+ matching_catalogus : str | None = next (
132
+ (
133
+ catalogus ["url" ]
134
+ for catalogus in catalogus_data
135
+ if catalogus ["domein" ] == domein and catalogus ["rsin" ] == rsin
136
+ ),
137
+ None ,
138
+ )
139
+
140
+ if matching_catalogus is None :
141
+ return []
142
+
143
+ iotypen_data = client .get_all_informatieobjecttypen (
144
+ catalogus = matching_catalogus
145
+ )
146
+ else :
147
+ iotypen_data = client .get_all_informatieobjecttypen ()
148
+
149
+ iotypen = []
150
+
151
+ for iotype in iotypen_data :
152
+ # fmt: off
153
+ exists = any (
154
+ existing_iotype ["informatieobjecttype" ].omschrijving == iotype ["omschrijving" ]
155
+ and existing_iotype ["informatieobjecttype" ].catalogus == iotype ["catalogus" ]
156
+ for existing_iotype in iotypen
157
+ )
158
+ # fmt: on
159
+
160
+ if not exists :
161
+ iotypen .append (
162
+ {
163
+ "informatieobjecttype" : factory (InformatieObjectType , iotype ),
164
+ "catalogus" : factory (
165
+ Catalogus , catalogus_mapping [iotype ["catalogus" ]]
166
+ ),
167
+ }
168
+ )
97
169
98
170
return iotypen
0 commit comments